This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
nwnadmin/start.php

95 lines
2.9 KiB
PHP
Raw Normal View History

2005-01-22 22:05:34 -05:00
<?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: ' . Horde::applicationUrl('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':
case 'restart':
$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."), 'horde.success');
}
if ($actionId == 'stop') { 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':
$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';