-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
137 lines (114 loc) · 4.9 KB
/
Copy pathindex.php
File metadata and controls
137 lines (114 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
require_once __DIR__ . '/src/core.php';
// load the settings
if (file_exists(__DIR__ . '/settings.php')) {
require_once __DIR__ . '/settings.php';
} else {
require_once __DIR__ . '/settings.example.php';
}
require_once __DIR__ . '/src/views/head.php';
// check if configs are valid
handle_config_validation();
// check the password
authentication();
// load the process status
$processID = get_current_process_id();
$isRunning = $processID !== false;
if (isset($_POST['start']) && !$isRunning) {
start_process();
refresh_page();
} else if (isset($_POST['stop']) && $isRunning) {
stop_process();
refresh_page();
} else {
foreach (get_custom_actions() as $action => $options) {
if (isset($_POST[$action])) {
if (is_custom_action_doable($action)) {
run_custom_action($action);
refresh_page();
}
}
}
}
// re-load the process status
$processID = get_current_process_id();
$isRunning = $processID !== false;
$logs = load_logs();
?>
<div>
<form method="GET">
<?php if (count(COMMANDS) > 1) { ?>
<b>Process</b>: <select class="dropdown" onchange="event.target.parentNode.submit()" name="command">
<?php $currentSelectedCommand = isset($_GET['command']) ? $_GET['command'] : ''; ?>
<?php foreach (COMMANDS as $command => $options) { ?>
<option <?= $currentSelectedCommand == $command ? 'selected' : '' ?> value="<?= $command ?>"><?= $command ?></option>
<?php } ?>
</select>
<?php } else { ?>
<b><?= get_current_selected_command()['name'] ?></b>
<?php } ?>
<p><?= get_current_selected_command()['description'] ?></p>
</form>
</div>
<div>
<b>Status</b>: <?= $isRunning ? '<span style="color: green;">Running</span>' : '<span style="color: red;">Not running</span>' ?>
<?php if ($isRunning) { ?>
<br />
<b>Current process ID</b>: <?= $processID ?>
<?php } else { ?>
<br />
<br />
<?php } ?>
</div>
<?php if (user_has_permission(PERMISSION_START) || user_has_permission(PERMISSION_STOP) || is_there_any_visible_custom_action()) { ?>
<hr />
<div>
<h4>Actions</h4>
<form method="POST">
<?php if (user_has_permission(PERMISSION_START)) { ?>
<div class="action-section">
<button class="button green-button" <?= $isRunning ? 'disabled' : '' ?> type="submit" name="start">Start</button>
</div>
<?php } ?>
<?php if (user_has_permission(PERMISSION_STOP)) { ?>
<div class="action-section">
<button class="button red-button" <?= $isRunning ? '' : 'disabled' ?> type="submit" name="stop">Stop</button>
</div>
<?php } ?>
<?php foreach (get_custom_actions() as $action => $options) { ?>
<?php if (is_custom_action_visible($action)) { ?>
<div class="action-section">
<?php if (count($options['parameters']) > 0 && is_custom_action_enabled($action)) { ?>
<div class="action-params action-<?= $action ?>-params" id="action_<?= $action ?>_params">
<span onclick="action_close()" class="action-close">X</span>
<?php foreach ($options['parameters'] as $param => $description) { ?>
<?= $description ?>: <input class="text-input" placeholder="<?= $description ?>" type="text" name="param_<?= $action ?>_<?= $param ?>" />
<?php } ?>
</div>
<?php } ?>
<button <?= count($options['parameters']) > 0 ? 'onclick="action_handle_params()"' : '' ?> title="<?= $options['description'] ?>" class="button <?= $options['button_color'] ?>-button" <?= is_custom_action_enabled($action) ? '' : 'disabled' ?> type="submit" name="<?= $action ?>"><?= $options['title'] ?></button>
</div>
<?php } ?>
<?php } ?>
</form>
</div>
<?php } ?>
<?php if (user_has_permission(PERMISSION_READ_LOG)) { ?>
<hr />
<div>
<h4 style="float: left;">Logs</h4>
<a href="" class="button blue-button" style="float: right; text-decoration: none;">Refresh</a>
<div style="clear: both;"></div>
<pre class="logs-container"><?= htmlspecialchars($logs) ?></pre>
</div>
<?php } ?>
<?php if (user_has_permission(PERMISSION_READ_STATS)) { ?>
<hr />
<div>
<h4 style="float: left;">Stats</h4>
<a href="" class="button blue-button" style="float: right; text-decoration: none;">Refresh</a>
<div style="clear: both;"></div>
<pre class="logs-container">Coming soon...</pre>
</div>
<?php } ?>
<?php require_once __DIR__ . '/src/views/foot.php'; ?>