-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
97 lines (87 loc) · 2.91 KB
/
start.php
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
<?php
@define('NWNADMIN_BASE', dirname(__FILE__));
require_once NWNADMIN_BASE . '/lib/base.php';
// script global variables
global $nwndriver;
$params = &$nwndriver->getParams();
$configured = false;
$rawResult = false;
$wait = false;
// no regular users allowed on this page
if (!Auth::isAdmin('nwnadmin:admin')) {
header('Location: ./server.php');
}
// hack the page if the server is not configured
if (!$params || is_a($params, 'PEAR_Error') ||
!isset($params['servername']) || $params['servername'] == '') {
$notification->push(_("The server is not configured!"), 'horde.warning');
} else {
$configured = true;
}
$actionId = Util::getFormData('actionId');
switch ($actionId) {
case 'stop':
$wait = true;
$result = $nwndriver->stopServer();
if (is_a($result, 'PEAR_Error')) {
$notification->push(_("There was a problem stopping the server: ") .
$result->getMessage(), 'horde.error');
} else {
$notification->push(
_("The server was stopped. Reload if still running."),
'horde.success');
}
break;
case 'start':
$wait = true;
$result = $nwndriver->startServer();
if (is_a($result, 'PEAR_Error')) {
$notification->push(_("There was a problem starting the server: ") .
$result->getMessage(), 'horde.error');
} else {
$notification->push(_("The server was started."), 'horde.success');
}
break;
case 'kill':
$wait = true;
$result = $nwndriver->killServer();
if (is_a($result, 'PEAR_Error')) {
$notification->push(_("There was a problem killing the server: ") .
$result->getMessage(), 'horde.error');
} else {
$notification->push(_("The server was killed."), 'horde.warning');
}
case 'raw':
$wait = true;
$result = $nwndriver->sendCommand(Util::getFormData('command'), true);
if (is_a($result, 'PEAR_Error')) {
$notification->push(_("There was a problem sending the command: ") .
$result->getMessage(), 'horde.error');
} else {
$rawResult = $result;
$notification->push(_("The command was accepted."), 'horde.success');
}
}
// select form to display
if ($wait) { sleep(2); }
if ($nwndriver->serverRunning()) {
$title = _("Stop/Restart/Kill Server");
$form = 'kill.inc';
} else {
$title = _("Run Server");
$form = 'start.inc';
}
// start the page
require_once NWNADMIN_TEMPLATES . '/common-header.inc';
require_once NWNADMIN_TEMPLATES . '/menu.inc';
// this is cheap, but the redirect/notification combination doesn't work right
if ($configured) {
// output the form
include NWNADMIN_TEMPLATES . '/start/' . $form;
}
if ($rawResult) {
printf("<br /><div class='header'>Command Result</div><br />" .
"<div class='fixed'>%s</div>", nl2br($nwndriver->getLogContent()));
}
// finish up the page
require_once $registry->get('templates', 'horde') . '/common-footer.inc';