From 8e1ff15e5b46dc3fb1e5e5a77d2d9edd73f59a22 Mon Sep 17 00:00:00 2001 From: penguinc Date: Sun, 23 Jan 2005 03:05:34 +0000 Subject: [PATCH] Initial revision --- config/conf.xml | 32 ++++ index.php | 16 ++ lib/ModuleForms.php | 21 +++ lib/NWNAdmin.php | 82 ++++++++++ lib/NWNDriver.php | 270 ++++++++++++++++++++++++++++++++ lib/ServerForms.php | 64 ++++++++ lib/base.php | 45 ++++++ module.php | 152 ++++++++++++++++++ player.php | 137 ++++++++++++++++ savegame.php | 125 +++++++++++++++ server.php | 89 +++++++++++ start.php | 95 +++++++++++ templates/common-header.inc | 26 +++ templates/menu.inc | 5 + templates/module/footer.inc | 2 + templates/module/header.inc | 8 + templates/module/module.inc | 25 +++ templates/player/ban.inc | 13 ++ templates/player/bheader.inc | 8 + templates/player/footer.inc | 2 + templates/player/pheader.inc | 13 ++ templates/player/player.inc | 29 ++++ templates/savegame/footer.inc | 2 + templates/savegame/header.inc | 8 + templates/savegame/savegame.inc | 25 +++ templates/start/kill.inc | 39 +++++ templates/start/start.inc | 7 + themes/graphics/nwnadmin.png | Bin 0 -> 929 bytes 28 files changed, 1340 insertions(+) create mode 100644 config/conf.xml create mode 100644 index.php create mode 100644 lib/ModuleForms.php create mode 100644 lib/NWNAdmin.php create mode 100644 lib/NWNDriver.php create mode 100644 lib/ServerForms.php create mode 100644 lib/base.php create mode 100644 module.php create mode 100644 player.php create mode 100644 savegame.php create mode 100644 server.php create mode 100644 start.php create mode 100644 templates/common-header.inc create mode 100644 templates/menu.inc create mode 100644 templates/module/footer.inc create mode 100644 templates/module/header.inc create mode 100644 templates/module/module.inc create mode 100644 templates/player/ban.inc create mode 100644 templates/player/bheader.inc create mode 100644 templates/player/footer.inc create mode 100644 templates/player/pheader.inc create mode 100644 templates/player/player.inc create mode 100644 templates/savegame/footer.inc create mode 100644 templates/savegame/header.inc create mode 100644 templates/savegame/savegame.inc create mode 100644 templates/start/kill.inc create mode 100644 templates/start/start.inc create mode 100644 themes/graphics/nwnadmin.png diff --git a/config/conf.xml b/config/conf.xml new file mode 100644 index 0000000..bd98f61 --- /dev/null +++ b/config/conf.xml @@ -0,0 +1,32 @@ + + + + + Server Settings + + /usr/local/games/nwn + nwserver + + + System +Settings + + /bin/ps + /bin/grep + /usr/bin/echo + + + + + + + + + + + + + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..6578944 --- /dev/null +++ b/index.php @@ -0,0 +1,16 @@ +addVariable(_("New Module"), 'module', 'file', true); + + $this->setTitle(_("Upload New Module")); + $this->setButtons(_("Upload")); + + $this->useToken(true); + } +} \ No newline at end of file diff --git a/lib/NWNAdmin.php b/lib/NWNAdmin.php new file mode 100644 index 0000000..8c63721 --- /dev/null +++ b/lib/NWNAdmin.php @@ -0,0 +1,82 @@ +add(Horde::applicationUrl('start.php'), _("Run"), + 'reload.png', $registry->getImageDir('horde')); + + $menu->add(Horde::applicationUrl('player.php'), _("Players"), + 'user.png', $registry->getImageDir('horde')); + } + + $menu->add(Horde::applicationUrl('server.php'), _("Server Settings"), + 'map_eu.png', $registry->getImageDir('horde')); + + $menu->add(Horde::applicationUrl('module.php'), _("Modules"), + 'download.png', $registry->getImageDir('horde')); + + $menu->add(Horde::applicationUrl('savegame.php'), _("Saved Games"), + 'data.png', $registry->getImageDir('horde')); + + if ($type == 'object') { + return $menu; + } + return $menu->render(); + } + + function getServerRoot() + { + global $conf; + return (substr($conf['server']['root'], -1) == '/' ? + $conf['server']['root'] : $conf['server']['root'] . '/' ); + } + + function getModulePath() + { + global $conf; + return (substr($conf['server']['root'], -1) == '/' ? + $conf['server']['root'] : $conf['server']['root'] . '/' ) . + 'modules/'; + } + + function getServerExecutable() + { + global $conf; + return (substr($conf['server']['root'], -1) == '/' ? + $conf['server']['root'] : $conf['server']['root'] . '/' ) . + $conf['server']['binary']; + } + + function getModuleList($moduleDir = null) + { + if (is_null($moduleDir)) { + return array(); + } + return glob(escapeshellcmd($moduleDir ) . '{*.mod,MOD}', GLOB_BRACE); + } + + function getSaveGamePath() + { + global $conf; + return (substr($conf['server']['root'], -1) == '/' ? + $conf['server']['root'] : $conf['server']['root'] . '/') . 'saves/'; + } + + function getSaveGameList($saveDir = null) + { + if (is_null($saveDir)) { + return array(); + } + return glob(escapeshellcmd($saveDir) . '*', GLOB_ONLYDIR); + } +} diff --git a/lib/NWNDriver.php b/lib/NWNDriver.php new file mode 100644 index 0000000..dce12fe --- /dev/null +++ b/lib/NWNDriver.php @@ -0,0 +1,270 @@ +data['type'] = 'nwnsettings'; + $this->data['name'] = isset($properties['name']) ? $properties['name'] : + ''; + + // datatree initialization for persistent storage + global $conf; + $driver = $conf['datatree']['driver']; + $params = Horde::getDriverConfig('datatree', $driver); + $params = array_merge($params, array('group' => 'nwnadmin.settings')); + $this->_datatree = &DataTree::singleton($driver, $params); + + // create the neccessary datatree node if it does not exist + if (!$this->_datatree->exists($this)) { + $this->_datatree->add($this); + } + } + + /** + * Set the attributes of the object. + * + * @param array The attributes to set. + * @param boolean Determines whether the backend should + * be updated or not + */ + function setData($settings) + { + if (!is_array($settings)) { + return PEAR::raiseError("Settings are not an array!"); + } + parent::setData($settings); + return $this->_datatree->updateData($this); + } + + function &getSettings() + { + $rawsettings = + $this->_datatree->getAttributes($this->_datatree->getId($this)); + $result = array(); + foreach ($rawsettings as $setting) { + $result[$setting['name']] = $setting['value']; + } + return $result; + } + + /** + * Map this object's attributes from the data array into a format + * that we can store in the attributes storage backend. + * + * @return array The attributes array. + */ + function _toAttributes() + { + foreach ($this->data as $key => $value) { + $attributes[] = array('name' => $key, + 'key' => '', + 'value' => $value); + } + return $attributes; + } + + /** + * Take in a list of attributes from the backend and map it to our + * internal data array. + * + * @param array $attributes The list of attributes from the + * backend (attribute name, key, + * and value). + */ + function _fromAttributes($attributes) + { + foreach ($attributes as $attribute) { + $this->data[$attribute['name']] = $attribute['value']; + } + } + + function &factory($name, $properties = null) + { + return $ret = &new NWNSettings($name, $properties); + } + + function &singleton($name, $properties = null) + { + static $instance; + + if (!isset($instance)) + { + $instance = &NWNSettings::factory($name, $properties); + } + + return $instance; + } +} + +class NWNDriver +{ + var $_settingsbackend; + + function NWNDriver() + { + $this->_settingsbackend = &NWNSettings::singleton('nwnadmin.settings', + array('name' => 'nwnadmin.settings')); + } + + function setData($settings) + { + return $this->_settingsbackend->setData($settings); + } + + function &getParams() + { + return $this->_settingsbackend->getSettings(); + } + + function &factory() + { + return $ret = &new NWNDriver(); + } + + function &singleton() + { + static $instance; + + if (!isset($instance)) + { + $instance = &NWNDriver::factory(); + } + + return $instance; + } + + function serverRunning() + { + global $conf; + static $command; + if (is_null($command) || empty($command)) { + $command = $conf['system']['ps'] . ' aux| ' . + $conf['system']['grep'] . ' ' . + $conf['server']['binary'] . ' | ' . + $conf['system']['grep'] . ' -v ' . + basename($conf['system']['grep']); + } + $result = shell_exec($command); + if (!empty($result)) { + $sets = preg_split('/\s+/', $result); + $result = $sets[1]; + } + return $result; + } + + function startServer() + { + if ($this->serverRunning()) { + return PEAR::raiseError("Server is up!"); + } + global $conf; + chdir(NWNAdmin::getServerRoot()); + $settings = &$this->_settingsbackend->getSettings(); + $settingString = ''; + foreach ($settings as $key => $val) { + if (!empty($val)) { + if (is_int($val)) { + $settingString .= sprintf(" -%s %s ", $key, $val); + } else { + $settingString .= sprintf(" -%s '%s' ", $key, + escapeshellcmd($val)); + } + } + } + //echo '
' . NWNAdmin::getServerExecutable() .$settingString . ' > ' .
+        //        $this->_getLog() . ' 2>&1 < ' . $this->_checkFifo() . ' &
'; + shell_exec(NWNAdmin::getServerExecutable() .$settingString . ' > ' . + $this->_getLog() . ' 2>&1 < ' . $this->_checkFifo() . ' &'); + + return true; + } + + function stopServer() + { + global $conf; + shell_exec($conf['system']['echo'] . ' quit > ' . $this->_checkFifo()); + return true; + } + + function killServer() + { + if (!($pid = $this->serverRunning())) { + return PEAR::raiseError(_("Server is down!")); + } + return !posix_kill($pid, 9); + } + + function sendCommand($command, $flush = false) + { + if (!$this->serverRunning()) { + return PEAR::raiseError(_("Server is down!")); + } + global $conf; + if ($flush) { + shell_exec(implode(' ', array($conf['system']['echo'], '>', + $this->_getLog()))); + } + shell_exec(implode(' ', array($conf['system']['echo'], + escapeshellcmd($command), '>', $this->_checkFifo()))); + return true; + } + + function getLogContent() + { + $fp = fopen($this->_getLog(), 'r'); + $data = fread($fp, filesize($this->_getLog())); + fclose($fp); + return $data; + } + + function useModule($moduleName) + { + $settings = &$this->_settingsbackend->getSettings(); + $settings['module'] = $moduleName; + if ($this->serverRunning()) { + $this->sendCommand('module ' . $moduleName); + } + return $this->_settingsbackend->setData($settings); + } + + function getModule() + { + $settings = &$this->_settingsbackend->getSettings(); + if (!isset($settings['module'])) { + $settings['module'] = ''; + } + return $settings['module']; + } + + function _getLog() + { + static $logfile; + if (is_null($logfile)) { + $logfile = Horde::getTempDir() . '/nwnadmin.log'; + } + return $logfile; + } + + function _checkFifo() + { + static $fifoName; + if (is_null($fifoName) || empty($fifoName)) { + $fifoName = Horde::getTempDir() . '/nwnadmin-input'; + } + if (!file_exists($fifoName) && + !posix_mkfifo($fifoName)) { + $fifoName = ''; + } + return $fifoName; + } + +} diff --git a/lib/ServerForms.php b/lib/ServerForms.php new file mode 100644 index 0000000..1fcdcb2 --- /dev/null +++ b/lib/ServerForms.php @@ -0,0 +1,64 @@ +addHidden('', 'actionId', 'text', true); + $vars->set('actionId', 'serversettings'); + $this->addVariable(_("Server Name"), 'servername', 'text', true); + $this->addVariable(_("Server Port"), 'port', 'int', false); + $this->addVariable(_("Player Password"), 'playerpass', 'text', false); + $this->addVariable(_("DM Password"), 'dmpass', 'text', false); + $this->addVariable(_("Maximum Clients"), 'maxclients', 'int', true); + $this->addVariable(_("Minimum Player Level"), 'minlevel', 'int', + true); + $this->addVariable(_("Maximum Player Level"), 'maxlevel', 'int', + true); + $this->addVariable(_("Pause And Play"), 'pauseandplay', 'enum', + true, false, null, array(array('0' => 'DM Only', + '1' => 'DM and Players'))); + $this->addVariable(_("Player Vs Player"), 'pvp', 'enum', true, + false, null, array(array('0' => 'None', '1' => 'Party Only', + '2' => 'Free For All'))); + $this->addVariable(_("Server Vault"), 'servervault', 'enum', + true, false, null, array(array('0' => 'Local Characters Only', + '1' => 'Server Characters Only'))); + $this->addVariable(_("Enforce Legal Characters"), 'elc', 'enum', + true, false, null, array(array( + '0' => 'Enforce Legal Characters', '1' => 'Any Characters'))); + $this->addVariable(_("Item Level Restrictions"), 'ilr', 'enum', + true, false, null, array(array( + '0' => 'Enforce Item Restrictions', '1' => 'Any Items'))); + $this->addVariable(_("Game Type"), 'gametype', 'enum', true, + false, null, array(array('0' => 'Action', '1' => 'Story', + '2' => 'Story Lite', '3' => 'Role Play', '4' => 'Team', + '5' => 'Melee', '6' => 'Arena', '7' => 'Aocial', + '8' => 'Alternative', '9' => 'PW Action', '10' => 'PW Story', + '11' => 'Solo', '12' => 'Tech Support'))); + $this->addVariable(_("Parties"), 'oneparty', 'enum', true, false, + null, array(array('0' => 'One Party', + '1' => 'Multiple Parties'))); + $this->addVariable(_("Difficulty"), 'difficulty', 'enum', true, + false, null, array(array('1' => 'Easy', '2' => 'Normal', + '3' => 'D&D Hardcore', '4' => 'Insane'))); + $this->addVariable(_("Auto Save Interval"), 'autosaveinterval', + 'int', true, false, _("In minutes, use 0 to disable")); + $this->addVariable(_("Persistence"), 'reloadwhenempty', 'enum', + true, false, null, array(array('0' => 'Persistent Module', + '1' => 'Reload When Empty'))); + $this->addVariable(_("Server Visibility"), 'publicserver', 'enum', + true, false, null, array(array('0' => 'Private', + '1' => 'Public'))); + + $this->setTitle(_("Configure Server Settings")); + $this->setButtons(_("Update Config")); + } +} \ No newline at end of file diff --git a/lib/base.php b/lib/base.php new file mode 100644 index 0000000..72ece99 --- /dev/null +++ b/lib/base.php @@ -0,0 +1,45 @@ +pushApp('nwnadmin', !defined('AUTH_HANDLER'))), + 'PEAR_Error')) { + if ($pushed->getCode() == 'permission_denied') { + Horde::authenticationFailureRedirect(); + } + Horde::fatal($pushed, __FILE__, __LINE__, false); +} +$conf = &$GLOBALS['conf']; +@define('NWNADMIN_TEMPLATES', $registry->get('templates')); + +// Find the base file path of NWNAdmin. +@define('NWNADMIN_BASE', dirname(__FILE__) . '/..'); + +// Notification system. +$notification = &Notification::singleton(); +$notification->attach('status'); + +// NWNAdmin base libraries. +require_once NWNADMIN_BASE . '/lib/NWNAdmin.php'; +require_once NWNADMIN_BASE . '/lib/NWNDriver.php'; + +// Start compression. +Horde::compressOutput(); + +// global driver +$GLOBALS['nwndriver'] = &NWNDriver::singleton(); \ No newline at end of file diff --git a/module.php b/module.php new file mode 100644 index 0000000..7158a86 --- /dev/null +++ b/module.php @@ -0,0 +1,152 @@ +serverRunning(); +if ($admin && !$serverUp) { + $notification->push( + _("The server is down; module loading is unavailable.")); +} + +// figure out what to do +$actionId = Util::getFormData('actionId'); +$moduleName = Util::getFormData('moduleName'); +if (isset($actionId) && !isset($moduleName)) { + $notification->push(_("Invalid options! Try again..."), 'horde.warning'); +} else { + switch($actionId) { + case 'delete': + if ($adminDelete && + strpos($conf['server']['root'], $moduleName) == 0) { + $moduleName = str_replace('../', '', $moduleName); + $result = unlink(escapeshellcmd($moduleName)); + if (!$result) { + $notification->push(_("Could not delete the module."), + 'horde.error'); + } else { + $notification->push(_("Successfully deleted the module."), + 'horde.success'); + } + } + break; + case 'activate': + if ($admin) { + $result = $nwndriver->useModule($moduleName); + if (is_a($result, 'PEAR_Error')) { + $notification->push( + _("Module load failure: ") . + $result->getMessage(), 'horde.error'); + } else { + $notification->push(_("Module loaded."), 'horde.success'); + } + } + break; + } +} + +// form configuration +$vars = &Variables::getDefaultVariables(); +$renderer = &new Horde_Form_Renderer(); +$form = &Horde_Form::singleton('NewNWNModule', $vars); +$valid = $form->validate($vars); +if ($valid) { + // get the information about the file + $form->getInfo($vars, $info); + if (!empty($info['module']['file'])) { + // as long as it was uploaded and there is information + if (!is_a(Browser::wasFileUploaded('module'), 'PEAR_Error') && + filesize($info['module']['file'])) { + // check the file for validity + $extension = substr($info['module']['name'], -3); + if ($extension == "mod" || $extension == "MOD") { + $moduleOutputName = escapeshellcmd($moduleDir . + $info['module']['name']); + // do not overwrite files + if (file_exists($moduleOutputName)) { + $notification->push(_("Cannot overwrite existing module!"), + 'horde.error'); + } else { + // get the file data + $fp = fopen($info['module']['file'], 'r'); + $data = fread($fp, filesize($info['module']['file'])); + fclose($fp); + + // write the data to the output dir + $fp = @fopen($moduleOutputName, 'wb'); + @fwrite($fp, $data); + @fclose($fp); + + $notification->push(_("Successfully wrote the module: ") . + $info['module']['name'], 'horde.success'); + } + + } else { + $notification->push(_("The uploaded file does not appear ". + "to be a valid NeverWinter module."), 'horde.error'); + } + } else { + // report the error + if (!empty($info['module']['error'])) { + $notification->push(sprintf(_("There was a problem " . + "uploading the module: %s"), + $info['module']['error']), 'horde.error'); + } elseif (!filesize($info['module']['file'])) { + $notification->push(_("The uploaded file appears to " . + "be empty. It may not exist on your computer."), + 'horde.error'); + } else { + $notification->push(_("General failure, please debug!"), + 'horde.error'); + } + } + } +} + +// get the listing of modules +$moduleList = NWNAdmin::getModuleList($moduleDir); +$moduleDone = empty($moduleList); +if ($moduleDone) { + $notification->push(_("No modules were found!"), 'horde.warning'); +} +$currentModule = $nwndriver->getModule(); + +// page setup +$title = _("Modules"); +require_once NWNADMIN_TEMPLATES . '/common-header.inc'; +require_once NWNADMIN_TEMPLATES . '/menu.inc'; + +// render the available modules +if (!$moduleDone) { + require NWNADMIN_TEMPLATES . '/module/header.inc'; + $style = 'item1'; + foreach ($moduleList as $module) { + $currentFlag = false; + $baseModule = substr(basename($module), 0, -4); + if ($style == 'item1') { + $style = 'item0'; + } else { + $style = 'item1'; + } + if ($currentModule == $baseModule && $serverUp) { + $style = 'selectedRow'; $currentFlag = true; + } + include NWNADMIN_TEMPLATES . '/module/module.inc'; + } + require NWNADMIN_TEMPLATES . '/module/footer.inc'; +} + +// render the upload form +if (isset($form) && $admin && $moduleDirWritable) { + $form->renderActive($renderer, $vars, 'module.php', 'post'); +} + +// finish up the page +require_once $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/player.php b/player.php new file mode 100644 index 0000000..129fdeb --- /dev/null +++ b/player.php @@ -0,0 +1,137 @@ +serverRunning(); +if (!$serverUp) { + $notification->push( + _("The server is down; player info is unavailable. ")); +} + +// figure out what to do +$actionId = Util::getFormData('actionId'); +$playerId = Util::getFormData('playerId'); +$valid = false; +$unban = false; +switch($actionId) { +case 'unbanip': +case 'unbanname': +case 'unbankey': + $unban = true; +case 'banip': +case 'banname': +case 'bankey': +case 'kick': + $valid = true; +} +if ($valid && $admin && $serverUp) { + $result = $nwndriver->sendCommand($actionId . ' ' . $playerId); + if (is_a($result, 'PEAR_Error')) { + $notification->push(_("There was a problem with the command: ") . + $result->getMessage()); + } else { + $notification->push(_("Success!"), 'horde.success'); + } +} + +// get the players and bans +$players = array(); +$bans = array(); +if ($serverUp) { + $result = $nwndriver->sendCommand('status', true); + if (is_a($result, 'PEAR_Error')) { + $notification->push(_("There was a problem getting the player info: ") + . $result->getMessage(), 'horde.error'); + } else { + sleep(1); + $playerResult = $nwndriver->getLogContent(); + $resultArray = explode("\n", $playerResult); + foreach ($resultArray as $pr) { + $prA = explode('|', $pr); + if (count($prA) == 5 && trim($prA[0]) !== 'ID') { + $players[] = array('id' => trim($prA[0]), + 'name' => trim($prA[1]), 'ip' => trim($prA[2]), + 'character' => trim($prA[3]), 'key' => trim($prA[4])); + } + } + if (empty($players)) { + $notification->push(_("There are no players connected.")); + } + } + + $result = $nwndriver->sendCommand('listbans', true); + if (is_a($result, 'PEAR_Error')) { + $notification->push(_("There was a problem getting the ban info: ") + . $result->getMessage(), 'horde.error'); + } else { + sleep(1); + $banResult = $nwndriver->getLogContent(); + $resultArray = explode("\n", $banResult); + $banType = ''; + foreach ($resultArray as $theBan) { + $theBan = trim($theBan); + if (strpos($theBan, 'Key')) { + $banType = 'unbankey'; + continue; + } elseif (strpos($theBan, 'Addresses')) { + $banType = 'unbanip'; + continue; + } elseif (strpos($theBan, 'Name')) { + $banType = 'unbanname'; + continue; + } + if (!empty($banType) && !empty($theBan)) { + $bans[$banType][] = $theBan; + } + } + if (empty($bans)) { + $notification->push(_("There are no bans in place.")); + } + } +} + +// page setup +$title = _("Player Information"); +require_once NWNADMIN_TEMPLATES . '/common-header.inc'; +require_once NWNADMIN_TEMPLATES . '/menu.inc'; + +// render the player info +$baseUrl = Horde::applicationUrl('player.php', true); +if (!empty($players)) { + require NWNADMIN_TEMPLATES . '/player/pheader.inc'; + $style = 'item1'; + foreach ($players as $player) { + if ($style == 'item1') { + $style = 'item0'; + } else { + $style = 'item1'; + } + require NWNADMIN_TEMPLATES . '/player/player.inc'; + } + require NWNADMIN_TEMPLATES . '/player/footer.inc'; +} + +// render ban info +if (!empty($bans)) { + require NWNADMIN_TEMPLATES . '/player/bheader.inc'; + foreach ($bans as $unbantype => $b) { + $style = 'item1'; + foreach ($b as $theBan) { + if ($style == 'item1') { + $style = 'item0'; + } else { + $style = 'item1'; + } + require NWNADMIN_TEMPLATES . '/player/ban.inc'; + } + } + require NWNADMIN_TEMPLATES . '/player/footer.inc'; +} + +// finish up the page +require_once $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/savegame.php b/savegame.php new file mode 100644 index 0000000..18e0bb2 --- /dev/null +++ b/savegame.php @@ -0,0 +1,125 @@ + + * @version 1.0.2 + * @param string $dirname Directory to delete + * @return bool Returns TRUE on success, FALSE on failure + */ +function rmdirr($dirname) +{ + // Sanity check + if (!file_exists($dirname)) { + return false; + } + + // Simple delete for a file + if (is_file($dirname)) { + return unlink($dirname); + } + + // Loop through the folder + $dir = dir($dirname); + while (false !== $entry = $dir->read()) { + // Skip pointers + if ($entry == '.' || $entry == '..') { + continue; + } + + // Recurse + rmdirr("$dirname/$entry"); + } + + // Clean up + $dir->close(); + return rmdir($dirname); +} + +// script global variables +global $nwndriver; +$admin = Auth::isAdmin('nwnadmin:admin'); +$adminDelete = Auth::isAdmin('nwnadmin:admin', PERMS_DELETE); +$saveDir = NWNAdmin::getSaveGamePath(); +$serverUp = $nwndriver->serverRunning(); +if ($admin && !$serverUp) { + $notification->push(_("The server is down; save game loading is ". + "unavailable.")); +} + +// figure out what to do +$actionId = Util::getFormData('actionId'); +$saveName = Util::getFormData('saveName'); +if (isset($actionId) && !isset($saveName)) { + $notification->push(_("Invalid options! Try again..."), 'horde.warning'); +} else { + switch($actionId) { + case 'delete': + $result = false; + $length = strlen($conf['server']['root']); + if ($adminDelete && + substr($saveName, 0, $length) == $conf['server']['root']) { + $saveName = str_replace('../', '', $saveName); + $result = rmdirr(escapeshellcmd($saveName)); + } + if (!$result) { + $notification->push(_("Could not delete the save game."), + 'horde.error'); + } else { + $notification->push(_("Successfully deleted the saved game."), + 'horde.success'); + } + break; + case 'load': + $result = false; + if ($admin) { + $result = NWNAdmin::sendCommand('load ' .$saveName); + } + if (is_a($result, 'PEAR_Error')) { + $notification->push( + _("There was a problem loading the game: ") . + $result->getMessage(), 'horde.error'); + } else { + $notification->push(_("Save game loaded."), + 'horde.sucess'); + } + break; + } +} + +// get the listing of modules +$saveList = NWNAdmin::getSaveGameList($saveDir); +$saveDone = empty($saveList); +if ($saveDone) { + $notification->push(_("No save games were found"), 'horde.warning'); +} + +// page setup +$title = _("Saved Games"); +require_once NWNADMIN_TEMPLATES . '/common-header.inc'; +require_once NWNADMIN_TEMPLATES . '/menu.inc'; + +// render the available modules +if (!$saveDone) { + require NWNADMIN_TEMPLATES . '/savegame/header.inc'; + $style = 'item1'; + foreach ($saveList as $savegame) { + $baseSave = basename($savegame); + $args = split("/\s+/", $baseSave); + $saveNumber = sprintf("%d", $args[0]); + if ($style == 'item1') { + $style = 'item0'; + } else { + $style = 'item1'; + } + include NWNADMIN_TEMPLATES . '/savegame/savegame.inc'; + } + require NWNADMIN_TEMPLATES . '/savegame/footer.inc'; +} + +// finish up the page +require_once $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/server.php b/server.php new file mode 100644 index 0000000..7b394e0 --- /dev/null +++ b/server.php @@ -0,0 +1,89 @@ +getParams(); + if (is_null($settings)) { + $notification->push(_("There was a problem fetching the settings!"), + 'horde.error'); + } elseif (!is_a($settings, 'PEAR_Error')) { + foreach ($settings as $key => $val) { + $vars->set($key, $val); + } + } else { + $notification->push(_("There was a problem fetching the settings: ") . + $settings->getMessage(), 'horde.error'); + } +} +$renderer = &new Horde_Form_Renderer(); + +$form = &Horde_Form::singleton('ServerSettings', $vars); +$valid = $form->validate($vars); +if ($valid) { + $newSettings = array( + 'servername' => Util::getFormData('servername'), + 'port' => Util::getFormData('port'), + 'playerpass' => Util::getFormData('playerpass'), + 'dmpass' => Util::getFormData('dmpass'), + 'maxclients' => Util::getFormData('maxclients'), + 'minlevel' => Util::getFormData('minlevel'), + 'maxlevel' => Util::getFormData('maxlevel'), + 'pauseandplay' => Util::getFormData('pauseandplay'), + 'pvp' => Util::getFormData('pvp'), + 'servervault' => Util::getFormData('servervault'), + 'elc' => Util::getFormData('elc'), + 'ilr' => Util::getFormData('ilr'), + 'gametype' => Util::getFormData('gametype'), + 'onetype' => Util::getFormData('oneparty'), + 'difficulty' => Util::getFormData('difficulty'), + 'autosaveinterval' => Util::getFormData('autosaveinterval'), + 'reloadwhenempty' => Util::getFormData('reloadwhenempty'), + 'publicserver' => Util::getFormData('publicserver'), + ); + $result = $nwndriver->setData($newSettings); + if (is_a($result, 'PEAR_Error')) { + $notification->push(_("Error while saving parameters: ") . + $result->getMessage(), 'horde.error'); + } else { + $notification->push(_("Successfully saved the settings."), + 'horde.success'); + } + if ($nwndriver->serverRunning()) { + $result = null; + foreach ($newSettings as $key => $val) { + $result = $nwndriver->sendCommand($key . ' ' . $val); + if (is_a($result, 'PEAR_Error')) { + $notification->push( + _("There was a problem loading the settings: ") . + $result->getMessage(), 'horde.error'); + break; + } + } + if (!is_a($result, 'PEAR_Error')) { + $notification->push(_("Server settings loaded successfully."), + 'horde.success'); + } + } +} + +$title = _("Configure Server"); + +require_once NWNADMIN_TEMPLATES . '/common-header.inc'; +require_once NWNADMIN_TEMPLATES . '/menu.inc'; + +if (isset($form)) { + if (Auth::isAdmin('nwnadmin:admin')) { + $form->renderActive($renderer, $vars, 'server.php', 'post'); + } else { + $form->renderInactive($renderer, $vars, 'server.php', 'post'); + } +} + +require_once $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/start.php b/start.php new file mode 100644 index 0000000..c441d08 --- /dev/null +++ b/start.php @@ -0,0 +1,95 @@ +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("
Command Result

" . + "
%s
", nl2br($nwndriver->getLogContent())); +} + +// finish up the page +require_once $registry->get('templates', 'horde') . '/common-footer.inc'; \ No newline at end of file diff --git a/templates/common-header.inc b/templates/common-header.inc new file mode 100644 index 0000000..154e6e2 --- /dev/null +++ b/templates/common-header.inc @@ -0,0 +1,26 @@ + + + + +' : '' ?> + +get('name'); +if (!empty($title)) $page_title .= ' :: ' . $title; +if (!empty($refresh_time) && ($refresh_time > 0) && !empty($refresh_url)) { + echo "\n"; +} + +Horde::includeScriptFiles(); +?> +<?php echo $page_title ?> + + + +> diff --git a/templates/menu.inc b/templates/menu.inc new file mode 100644 index 0000000..3241fac --- /dev/null +++ b/templates/menu.inc @@ -0,0 +1,5 @@ + + + +
+notify(array('listeners' => 'status')) ?> diff --git a/templates/module/footer.inc b/templates/module/footer.inc new file mode 100644 index 0000000..52e572c --- /dev/null +++ b/templates/module/footer.inc @@ -0,0 +1,2 @@ + +
\ No newline at end of file diff --git a/templates/module/header.inc b/templates/module/header.inc new file mode 100644 index 0000000..25bcc59 --- /dev/null +++ b/templates/module/header.inc @@ -0,0 +1,8 @@ +
+ + + + + + + \ No newline at end of file diff --git a/templates/module/module.inc b/templates/module/module.inc new file mode 100644 index 0000000..77fbc47 --- /dev/null +++ b/templates/module/module.inc @@ -0,0 +1,25 @@ + + + + + + diff --git a/templates/player/ban.inc b/templates/player/ban.inc new file mode 100644 index 0000000..7c555b4 --- /dev/null +++ b/templates/player/ban.inc @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/templates/player/bheader.inc b/templates/player/bheader.inc new file mode 100644 index 0000000..8cfaab9 --- /dev/null +++ b/templates/player/bheader.inc @@ -0,0 +1,8 @@ +
+
DeleteName
getImageDir('horde')); ?>'; + } else { + echo $baseModule; + } + ?>
getImageDir('horde')); ?>
+ + + + + + \ No newline at end of file diff --git a/templates/player/footer.inc b/templates/player/footer.inc new file mode 100644 index 0000000..52e572c --- /dev/null +++ b/templates/player/footer.inc @@ -0,0 +1,2 @@ +
UnBanBan Value
+

\ No newline at end of file diff --git a/templates/player/pheader.inc b/templates/player/pheader.inc new file mode 100644 index 0000000..42cf542 --- /dev/null +++ b/templates/player/pheader.inc @@ -0,0 +1,13 @@ +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/templates/player/player.inc b/templates/player/player.inc new file mode 100644 index 0000000..1a3bcd4 --- /dev/null +++ b/templates/player/player.inc @@ -0,0 +1,29 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/savegame/footer.inc b/templates/savegame/footer.inc new file mode 100644 index 0000000..52e572c --- /dev/null +++ b/templates/savegame/footer.inc @@ -0,0 +1,2 @@ +
KickCharacter NamePlayer NameIPCD Key
getImageDir('horde')); ?>
+

\ No newline at end of file diff --git a/templates/savegame/header.inc b/templates/savegame/header.inc new file mode 100644 index 0000000..25bcc59 --- /dev/null +++ b/templates/savegame/header.inc @@ -0,0 +1,8 @@ +
+ + + + + + + \ No newline at end of file diff --git a/templates/savegame/savegame.inc b/templates/savegame/savegame.inc new file mode 100644 index 0000000..0737b21 --- /dev/null +++ b/templates/savegame/savegame.inc @@ -0,0 +1,25 @@ + + + + + + \ No newline at end of file diff --git a/templates/start/kill.inc b/templates/start/kill.inc new file mode 100644 index 0000000..7fc001b --- /dev/null +++ b/templates/start/kill.inc @@ -0,0 +1,39 @@ +
DeleteName
getImageDir('horde')); ?>'; + } else { + echo $baseSave; + } + ?>
+ + +
Stop Server
+ +
+ +
+ + +
Restart Server
+ +
+ +
+ + +
Kill Server
+ +
+ +
+ + +
Raw Command
String
\ No newline at end of file diff --git a/templates/start/start.inc b/templates/start/start.inc new file mode 100644 index 0000000..0b0f092 --- /dev/null +++ b/templates/start/start.inc @@ -0,0 +1,7 @@ +
+ + + +
Start Server
\ No newline at end of file diff --git a/themes/graphics/nwnadmin.png b/themes/graphics/nwnadmin.png new file mode 100644 index 0000000000000000000000000000000000000000..3a716290eddd9f2da6f45320faf501e7055a5ce9 GIT binary patch literal 929 zcmV;S177@zP)|%Q1g*WTnkSU^w zh%f{N5y7hsFP!4ERY#-ky4kIp8*$b&ZPGMZlbqz_eC8xM#~VAe_`7;}dEVc}%R@}l z1OU7+_0dB^BO{UQ%BoVYZr(1J@AVlb6*CM&=;@(WSf?+%|FMaP-svc2yLI#2hf_KL zFaR(zddfFG`Q)^P5nuN8`gx1B_d;|aIcymEBt_9hns$E2R~!2s4tkuZa%HW+zX9Ol zeL*mk+#L-1$MU(fd++E`PSey=D|hFu)vXPig|@k({d?k1q{i$*{jN=sD|TNXF}W=u z$6ooYHyHAt?N7K*T>jw`yQXQ7Bnf&;MYp3tYw6%zUbr|f8ucwad-%BN_U_AM?rcoo zE3I8(LZL`J8uyHsi;H$y<`D>l;SYEajV7RoJUS)?i^Ymsbqfq*VC}CPWbeM{pv_Lb zs%fot`q1+yQ?islasAr2w!vKw$qgY-_Llgy? zW&47iF10{OlI%2L;k>>uHaCj6bL%Q#n&8|Xn1lk&Fz|T&s8vc>zOjII7vNk$n4sux zw@cB{SSkoucKHJ_R#j^D^yRP7;42^mP*oX(P!JkCu3t+dm;D3DM-G}+d#oS`t#2B9 z?IP{+3@MVR7oA)r77Y1fqL3#xn;kAs9~4DFZ*K^?u7gk}Sk8~c;B$>!j{me=Dt=B( z=}$5~GkeoPaFyAVkGhMMbT~p1-;D`{{*W z&g1}qDwnHdV&VZ^l1jhUd2N|<4=Xgo!7zRB`J(U#k}$x+ARaK*0kK}MfAQ#udmaBk zwyT_a`gBjHYd@MgkUHab*OG2;5}DhxIPlaltY&XPXf(}CM!33BSeaV7@_u1kKy44{ zpWapNR{bkcY-DJfRSB^eO`!o*mB28pVVHDNk?TMH`}jWs0Qh<4opyeGb)izRUfJA~ z`F6WwR4Rh8p6}E|ftl$GhCjv*sGSSWp?@&@{iWB6h1~g2xLzF literal 0 HcmV?d00001