Initial revision

master
penguinc 2005-01-23 03:05:34 +00:00
commit 8e1ff15e5b
28 changed files with 1340 additions and 0 deletions

32
config/conf.xml Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!-- $Id: conf.xml,v 1.1 2005/01/23 03:05:35 penguinc Exp $ -->
<configuration>
<configtab name="general" desc="General Settings">
<configheader name="serversettings" desc="Server Settings">Server Settings</configheader>
<configsection name="server" desc="Server Settings">
<configstring name="root" desc="Server File Root">/usr/local/games/nwn</configstring>
<configstring name="binary" desc="Server Executable">nwserver</configstring>
</configsection>
<configheader name="systemsettings" desc="System Settings">System
Settings</configheader>
<configsection name="system" desc="System Settings">
<configstring name="ps"
desc="PS Binary">/bin/ps</configstring>
<configstring name="grep"
desc="Grep Binary">/bin/grep</configstring>
<configstring name="echo"
desc="Echo Binary">/usr/bin/echo</configstring>
</configsection>
</configtab>
<configtab name="menu" desc="Menu">
<configsection name="menu" desc="Menu Settings">
<configmultienum name="apps" desc="Select any applications that should be linked in PenguinCoder's menu">
<values>
<configspecial name="list-horde-apps" />
</values>
</configmultienum>
</configsection>
</configtab>
</configuration>

16
index.php Normal file
View File

@ -0,0 +1,16 @@
<?php
/**
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*/
define('NWNADMIN_BASE', dirname(__FILE__));
$nwnadmin_configured = (@is_readable(NWNADMIN_BASE . '/config/conf.php'));
if (!$nwnadmin_configured) {
require NWNADMIN_BASE . '/../lib/Test.php';
Horde_Test::configFilesMissing('NWNAdmin', NWNADMIN_BASE,
array('conf.php'));
} else {
header('Location: ./start.php');
}

21
lib/ModuleForms.php Normal file
View File

@ -0,0 +1,21 @@
<?php
// Required Horde libraries
require_once 'Horde/Variables.php';
require_once 'Horde/Form.php';
require_once 'Horde/Form/Renderer.php';
class NewNWNModule extends Horde_Form
{
function NewNWNModule(&$vars)
{
parent::Horde_Form($vars);
$this->addVariable(_("New Module"), 'module', 'file', true);
$this->setTitle(_("Upload New Module"));
$this->setButtons(_("Upload"));
$this->useToken(true);
}
}

82
lib/NWNAdmin.php Normal file
View File

@ -0,0 +1,82 @@
<?php
class NWNAdmin
{
function getMenu($type = 'object')
{
global $conf, $registry;
require_once 'Horde/Menu.php';
$menu = &new Menu();
if (Auth::isAdmin('nwadmin:admin')) {
$menu->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);
}
}

270
lib/NWNDriver.php Normal file
View File

@ -0,0 +1,270 @@
<?php
require_once 'Horde/DataTree.php';
class NWNSettings extends DataTreeObject
{
var $_datatree;
function NWNSettings($name, $properties = null)
{
parent::DataTreeObject($name);
// dto settings
$this->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 '<pre>' . NWNAdmin::getServerExecutable() .$settingString . ' > ' .
// $this->_getLog() . ' 2>&1 < ' . $this->_checkFifo() . ' &</pre>';
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;
}
}

64
lib/ServerForms.php Normal file
View File

@ -0,0 +1,64 @@
<?php
// Required Horde libraries
require_once 'Horde/Variables.php';
require_once 'Horde/Form.php';
require_once 'Horde/Form/Renderer.php';
class ServerSettings extends Horde_Form
{
function ServerSettings(&$vars)
{
parent::Horde_Form($vars);
$this->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"));
}
}

45
lib/base.php Normal file
View File

@ -0,0 +1,45 @@
<?php
/**
* NWNAdmin base inclusion file.
*
* This file brings in all of the dependencies that every NWNAdmin
* script will need and sets up objects that all scripts use.
*/
// Check for a prior definition of HORDE_BASE (perhaps by an
// auto_prepend_file definition for site customization).
if (!defined('HORDE_BASE')) {
@define('HORDE_BASE', dirname(__FILE__) . '/../..');
}
// Load the Horde Framework core, and set up inclusion paths.
require_once HORDE_BASE . '/lib/core.php';
// Registry.
$registry = &Registry::singleton();
if (is_a(($pushed = $registry->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();

152
module.php Normal file
View File

@ -0,0 +1,152 @@
<?php
@define('NWNADMIN_BASE', dirname(__FILE__));
require_once NWNADMIN_BASE . '/lib/base.php';
require_once NWNADMIN_BASE . '/lib/ModuleForms.php';
// script global variables
global $nwndriver;
$admin = Auth::isAdmin('nwnadmin:admin');
$adminDelete = Auth::isAdmin('nwnadmin:admin', PERMS_DELETE);
$moduleDir = NWNAdmin::getModulePath();
$moduleDirWritable = is_writable($moduleDir);
$serverUp = $nwndriver->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';

137
player.php Normal file
View File

@ -0,0 +1,137 @@
<?php
@define('NWNADMIN_BASE', dirname(__FILE__));
require_once NWNADMIN_BASE . '/lib/base.php';
// script global variables
global $nwndriver;
$admin = Auth::isAdmin('nwnadmin:admin');
$adminDelete = Auth::isAdmin('nwnadmin:admin', PERMS_DELETE);
$serverUp = $nwndriver->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';

125
savegame.php Normal file
View File

@ -0,0 +1,125 @@
<?php
@define('NWNADMIN_BASE', dirname(__FILE__));
require_once NWNADMIN_BASE . '/lib/base.php';
/**
* Delete a file, or a folder and its contents
*
* @author Aidan Lister <aidan@php.net>
* @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';

89
server.php Normal file
View File

@ -0,0 +1,89 @@
<?php
@define('NWNADMIN_BASE', dirname(__FILE__));
require_once NWNADMIN_BASE . '/lib/base.php';
require_once NWNADMIN_BASE . '/lib/ServerForms.php';
global $nwndriver;
$vars = &Variables::getDefaultVariables();
$actionId = Util::getFormData('actionId');
if (is_null($actionId)) {
$settings = &$nwndriver->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';

95
start.php Normal file
View File

@ -0,0 +1,95 @@
<?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';

View File

@ -0,0 +1,26 @@
<?php
if (isset($language)) {
header('Content-type: text/html; charset=' . NLS::getCharset());
header('Vary: Accept-Language');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<!-- Horde Project: http://horde.org/ | Trean: http://horde.org/trean/ -->
<!-- Trean: Copyright 2000-2004, The Horde Project. -->
<?php echo !empty($language) ? '<html lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
<head>
<?php
$page_title = $registry->get('name');
if (!empty($title)) $page_title .= ' :: ' . $title;
if (!empty($refresh_time) && ($refresh_time > 0) && !empty($refresh_url)) {
echo "<meta http-equiv=\"refresh\" content=\"$refresh_time;url=$refresh_url\">\n";
}
Horde::includeScriptFiles();
?>
<title><?php echo $page_title ?></title>
<?php echo Horde::stylesheetLink('horde') ?>
</head>
<body<?php if (Util::nonInputVar('bodyClass')) echo ' class="' . $bodyClass . '"' ?>>

5
templates/menu.inc Normal file
View File

@ -0,0 +1,5 @@
<table id="menu" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="center"><?php echo Horde::img('banner.png', _("Banner"), '', $GLOBALS['registry']->getImageDir('penguincoder')) ?></td></tr>
<tr><td><?php echo NWNAdmin::getMenu('string') ?></td></tr></table>
<br class="spacer"/>
<?php $GLOBALS['notification']->notify(array('listeners' => 'status')) ?>

View File

@ -0,0 +1,2 @@
</table>
</div><br />

View File

@ -0,0 +1,8 @@
<div align="center">
<table cellspacing="0" cellpadding="0" width="100%">
<tr class="header">
<?php if($adminDelete): ?>
<td class="header" width="10%" align="center">Delete</td>
<?php endif; ?>
<td class="header">Name</td>
</tr>

View File

@ -0,0 +1,25 @@
<tr class="<?php echo $style ?>" onmouseover="className='selected-over';"
onmouseout="className='<?php echo $style ?>';">
<?php if($adminDelete): ?>
<td align="center"><?php
$url = Horde::applicationUrl('module.php', true);
$url = Util::addParameter(Util::addParameter($url, 'actionId',
'delete'), 'moduleName', $module);
echo Horde::link($url, _("Delete Module"), '', '', '',
_("Delete Module"));?><?php echo
Horde::img('delete.png', _("Delete Module"), '',
$registry->getImageDir('horde')); ?></a></td>
<?php endif; ?>
<td><?php
if ($admin && $serverUp && !$currentFlag)
{
$url = Horde::applicationUrl('module.php', true);
$url = Util::addParameter(Util::addParameter($url,
'actionId', 'activate'), 'moduleName', $baseModule);
echo Horde::link($url, _("Activate Module"), '', '', '',
_("Activate Module")) . $baseModule . '</a>';
} else {
echo $baseModule;
}
?></td>
</tr>

13
templates/player/ban.inc Normal file
View File

@ -0,0 +1,13 @@
<tr class="<?php echo $style ?>" onmouseover="className='selected';"
onmouseout="className='<?php echo $style ?>';">
<?php if($adminDelete): ?>
<td align="center"><?php
$url = Util::addParameter(Util::addParameter($baseUrl, 'actionId',
$unbantype), 'playerId', $theBan);
echo Horde::link($url, _("Remove Ban"), '', '', '',
_("Remove Ban"));?><?php echo
Horde::img('delete.png', _("Remove Ban"), '',
$registry->getImageDir('horde')); ?></a></td>
<?php endif; ?>
<td align="left"><?php echo $theBan; ?></td>
</tr>

View File

@ -0,0 +1,8 @@
<div align="center">
<table cellspacing="0" cellpadding="0" width="100%">
<tr class="header">
<?php if($adminDelete): ?>
<td class="header" width="10%" align="center">UnBan</td>
<?php endif; ?>
<td class="header">Ban Value</td>
</tr>

View File

@ -0,0 +1,2 @@
</table>
</div><br />

View File

@ -0,0 +1,13 @@
<div align="center">
<table cellspacing="0" cellpadding="0" width="100%">
<tr class="header">
<?php if($adminDelete): ?>
<td class="header" align="center">Kick</td>
<? endif; ?>
<td class="header" align="center">Character Name</td>
<td class="header" align="center">Player Name</td>
<?php if ($admin): ?>
<td class="header" align="center">IP</td>
<td class="header" align="center">CD Key</td>
<? endif; ?>
</tr>

View File

@ -0,0 +1,29 @@
<tr class="<?php echo $style ?>" onmouseover="className='selected';"
onmouseout="className='<?php echo $style ?>';">
<?php if($adminDelete): ?>
<td align="center"><?php
$url = Util::addParameter(Util::addParameter($baseUrl, 'actionId',
'kick'), 'playerId', $player['id']);
echo Horde::link($url, _("Kick Player"), '', '', '',
_("Kick Player"));?><?php echo
Horde::img('logout.png', _("Kick Player"), '',
$registry->getImageDir('horde')); ?></a></td>
<?php endif; ?>
<td align="center"><?php echo $player['character']?></td>
<?php if ($admin): ?>
<td align="center"><?php echo Horde::link(Util::addParameter(
Util::addParameter($baseUrl, 'actionId', 'banname'), 'playerId',
$player['name']), _("Ban Name"), '', '', '', _("Ban Name")) .
$player['name']; ?></a></td>
<td align="center"><?php echo Horde::link(Util::addParameter(
Util::addParameter($baseUrl, 'actionId', 'banip'), 'playerId',
$player['ip']), _("Ban IP"), '', '', '', _("Ban IP")) .
$player['ip']; ?></a></td>
<td align="center"><?php echo Horde::link(Util::addParameter(
Util::addParameter($baseUrl, 'actionId', 'bankey'), 'playerId',
$player['key']), _("Ban Key"), '', '', '', _("Ban Key")) .
$player['key']; ?></a></td>
<? else: ?>
<td align="center"><?php echo $player['name']?></td>
<? endif ?>
</tr>

View File

@ -0,0 +1,2 @@
</table>
</div><br />

View File

@ -0,0 +1,8 @@
<div align="center">
<table cellspacing="0" cellpadding="0" width="100%">
<tr class="header">
<?php if($adminDelete): ?>
<td class="header" width="10%" align="center">Delete</td>
<?php endif; ?>
<td class="header">Name</td>
</tr>

View File

@ -0,0 +1,25 @@
<tr class="<?php echo $style ?>" onmouseover="className='selected';"
onmouseout="className='<?php echo $style ?>';">
<?php if($adminDelete): ?>
<td align="center"><?php
$url = Horde::applicationUrl('savegame.php', true);
$url = Util::addParameter(Util::addParameter($url, 'actionId',
'delete'), 'saveName', $savegame);
echo Horde::link($url, _("Delete Save Game"), '', '', '',
_("Delete Saved Game"));?><?php echo
Horde::img('delete.png', _("Delete Saved Game"), '',
$registry->getImageDir('horde')); ?></a></td>
<?php endif; ?>
<td><?php
if ($admin && $serverUp)
{
$url = Horde::applicationUrl('savegame.php', true);
$url = Util::addParameter(Util::addParameter($url,
'actionId', 'load'), 'saveName', $saveNumber);
echo Horde::link($url, _("Load Save Game"), '', '', '',
_("Load Save Game")) . $baseSave . '</a>';
} else {
echo $baseSave;
}
?></td>
</tr>

39
templates/start/kill.inc Normal file
View File

@ -0,0 +1,39 @@
<form name="stopserver" action="<?php echo Horde::selfUrl() ?>"
method="POST"><table width="100%" cellpadding="0" cellspacing="0">
<tr class="header"><td class="header">Stop Server</td></tr>
<tr class="control"><td class="control"><input type="hidden" name="actionId"
value="stop" /><input type="submit" name="submitbutton" value="Stop"
class="button" /></td></tr>
</table></form>
<br />
<form name="restartserver" action="<?php echo Horde::selfUrl() ?>"
method="POST"><table width="100%" cellpadding="0" cellspacing="0">
<tr class="header"><td class="header">Restart Server</td></tr>
<tr class="control"><td class="control"><input type="hidden" name="actionId"
value="restart" /><input type="submit" name="submitbutton" value="Restart"
class="button" /></td></tr>
</table></form>
<br />
<form name="killserver" action="<?php echo Horde::selfUrl() ?>"
method="POST"><table width="100%" cellpadding="0" cellspacing="0">
<tr class="header"><td class="header">Kill Server</td></tr>
<tr class="control"><td class="control"><input type="hidden" name="actionId"
value="kill" /><input type="submit" name="submitbutton" value="Kill"
class="button" /></td></tr>
</table></form>
<br />
<form name="rawcommand" action="<?php echo Horde::selfUrl() ?>"
method="POST"><table width="100%" cellpadding="0" cellspacing="0">
<tr class="header"><td class="header" colspan="2">Raw Command</td></tr>
<tr class="item0"><td class="item0" align="right">String</td><td
class="item0"><input type="text" name="command" size="30" class="input"
/></td></tr><tr class="control"><td class="control" colspan="2"><input
type="hidden" name="actionId" value="raw" /><input type="submit"
name="submitbutton" value="Send" class="button" /></td></tr>
</table></form>

View File

@ -0,0 +1,7 @@
<form name="serverstart" action="<?php echo Horde::selfUrl() ?>" method="POST">
<table width="100%" cellpadding="0" cellspacing="0">
<tr class="header"><td class="header">Start Server</td></tr>
<tr class="control"><td class="control"><input type="hidden" name="actionId"
value="start" /><input type="submit" name="submitbutton" value="Start"
class="button" /></td></tr>
</table></form>

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B