diff --git a/includes/ajaxHandler.class.php b/includes/ajaxHandler.class.php index 1b2aac30..557ab3ac 100644 --- a/includes/ajaxHandler.class.php +++ b/includes/ajaxHandler.class.php @@ -635,6 +635,83 @@ class AjaxHandler return null; } + private function handleAdmin() + { + if (empty($this->get['action']) || !$this->params) + return null; + + if ($this->params[0] == 'siteconfig') + { + if (!User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN)) + return null; + + switch ($this->get['action']) + { + case 'remove': + if (empty($this->get['id'])) + return 'invalid configuration option given'; + + if (DB::Aowow()->query('DELETE FROM ?_config WHERE `key` = ? AND (`flags` & ?d) = 0', $this->get['id'], CON_FLAG_PERSISTANT)) + return ''; + else + return 'option name is either protected or was not found'; + case 'add': + $key = strtolower(trim(@$this->get['id'])); + $val = trim(@$this->get['val']); + + if (!strlen($key)) + return 'empty option name given'; + if (!strlen($val)) + return 'empty value given'; + + if (preg_match('/[^a-z0-9_\.\-]/i', $key, $m)) + return 'invalid chars in option name: "'.$m[0].'"'; + + if (ini_get($key) === false || ini_set($key, $val) === false) + return 'this configuration option cannot be set'; + + if (DB::Aowow()->selectCell('SELECT 1 FROM ?_config WHERE `flags` & ?d AND `key` = ?', CON_FLAG_PHP, $key)) + return 'this configuration option is already in use'; + + DB::Aowow()->query('INSERT IGNORE INTO ?_config (`key`, `value`, `flags`) VALUES (?, ?, ?d)', $key, $val, CON_FLAG_TYPE_STRING | CON_FLAG_PHP); + return ''; + case 'update': + $key = trim(@$this->get['id']); + $val = trim(@$this->get['val']); + + if (!strlen($key)) + return 'empty option name given'; + if (!strlen($val)) + return 'empty value given'; + + if (substr($key, 0, 4) == 'CFG_') + $key = substr($key, 4); + + $flags = DB::Aowow()->selectCell('SELECT `flags` FROM ?_config WHERE `key` = ?', $key); + if (!$flags) + return 'configuration option not found'; + + if (preg_match('/[^a-z0-9_\-]/i', $key, $m)) + return 'invalid chars in option name: "'.$m[0].'"'; + + if ($flags & CON_FLAG_TYPE_INT && !preg_match('/^-?\d+$/i', $val)) + return "value must be integer"; + else if ($flags & CON_FLAG_TYPE_FLOAT && !preg_match('/^-?\d*(,|.)?\d+$/i', $val)) + return "value must be float"; + else if ($flags & CON_FLAG_TYPE_BOOL) + $val = (int)!!$val; // *snort* bwahahaa + + DB::Aowow()->query('UPDATE ?_config SET `value` = ? WHERE `key` = ?', $val, $key); + return ''; + default: + return null; + } + } + + return null; + } + + /**********/ /* Helper */ /**********/ @@ -996,8 +1073,6 @@ class AjaxHandler // hey, still here? you're not a Tauren/Nelf as bear or cat, are you? return DB::Aowow()->selectCell('SELECT IF(?d == 1, IFNULL(displayIdA, displayIdH), IFNULL(displayIdH, displayIdA)) FROM ?_shapeshiftform WHERE id = ?d', Util::sideByRaceMask(1 << ($char['race'] - 1)), $form); } - - } ?> diff --git a/includes/defines.php b/includes/defines.php index 57a4851a..9d4f3c82 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -83,6 +83,16 @@ define('SITEREP_ACTION_ARTICLE', 16); // Guide approved (a define('SITEREP_ACTION_USER_WARNED', 17); // Moderator Warning define('SITEREP_ACTION_USER_SUSPENDED', 18); // Moderator Suspension +// config flags +define('CON_FLAG_TYPE_INT', 0x01); // validate with intVal() +define('CON_FLAG_TYPE_FLOAT', 0x02); // validate with floatVal() +define('CON_FLAG_TYPE_BOOL', 0x04); // 0 || 1 +define('CON_FLAG_TYPE_STRING', 0x08); // +define('CON_FLAG_OPT_LIST', 0x10); // single option +define('CON_FLAG_BITMASK', 0x20); // multiple options +define('CON_FLAG_PHP', 0x40); // applied with ini_set() [restrictions apply!] +define('CON_FLAG_PERSISTANT', 0x80); // can not be deleted + // Auth Result define('AUTH_OK', 0); define('AUTH_WRONGUSER', 1); diff --git a/includes/kernel.php b/includes/kernel.php index 6288a435..1cbbe965 100644 --- a/includes/kernel.php +++ b/includes/kernel.php @@ -4,8 +4,6 @@ if (!defined('AOWOW_REVISION')) die('illegal access'); -ini_set('serialize_precision', 4); - require 'includes/defines.php'; require 'config/config.php'; require 'includes/libs/DbSimple/Generic.php'; // Libraray: http://en.dklab.ru/lib/DbSimple (using variant: https://github.com/ivan1986/DbSimple/tree/master) @@ -66,9 +64,34 @@ unset($AoWoWconf); // link set up: dele // load config to constants -$sets = DB::Aowow()->select('SELECT `key` AS ARRAY_KEY, intValue as i, strValue as s FROM ?_config'); +$sets = DB::Aowow()->select('SELECT `key` AS ARRAY_KEY, `value`, `flags` FROM ?_config'); foreach ($sets as $k => $v) - define('CFG_'.strtoupper($k), $v['s'] ?: intVal($v['i'])); +{ + // this should not have been possible + if (!strlen($v['value'])) + continue; + + $php = $v['flags'] & CON_FLAG_PHP; + + if ($v['flags'] & CON_FLAG_TYPE_INT) + $val = intVal($v['value']); + else if ($v['flags'] & CON_FLAG_TYPE_FLOAT) + $val = floatVal($v['value']); + else if ($v['flags'] & CON_FLAG_TYPE_BOOL) + $val = (bool)$v['value']; + else if ($v['flags'] & CON_FLAG_TYPE_STRING) + $val = preg_replace('/[^\p{L}0-9\s_\-\'\.,]/ui', '', $v['value']); + else + { + Util::addNote(U_GROUP_ADMIN | U_GROUP_DEV, 'Kernel: '.($php ? 'PHP' : 'Aowow').' config value '.($php ? strtolower($k) : 'CFG_'.strtoupper($k)).' has no type set. Value forced to 0!'); + $val = 0; + } + + if ($php) + ini_set(strtolower($k), $val); + else + define('CFG_'.strtoupper($k), $val); +} $secure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || CFG_FORCE_SSL; diff --git a/index.php b/index.php index 107f8674..8848ab7a 100644 --- a/index.php +++ b/index.php @@ -31,6 +31,8 @@ switch ($pageCall) /* called by user */ case '': // no parameter given -> MainPage $altClass = 'home'; + case 'home': + case 'admin': case 'account': // account management [nyi] case 'achievement': case 'achievements': @@ -81,7 +83,7 @@ switch ($pageCall) // case 'user': // tool: user profiles [nyi] case 'zone': case 'zones': - if (in_array($pageCall, ['account', 'profile'])) + if (in_array($pageCall, ['admin', 'account', 'profile'])) { if (($_ = (new AjaxHandler($pageParam))->handle($pageCall)) !== null) { diff --git a/pages/admin.php b/pages/admin.php new file mode 100644 index 00000000..689e5ca2 --- /dev/null +++ b/pages/admin.php @@ -0,0 +1,502 @@ +reqUGroup = U_GROUP_ADMIN | U_GROUP_DEV; + $this->generator = 'handlePhpInfo'; + $this->tpl = 'list-page-generic'; + + array_push($this->path, 2, 21); + $this->name = 'PHP Information'; + break; + case 'siteconfig': + $this->reqUGroup = U_GROUP_ADMIN | U_GROUP_DEV; + $this->generator = 'handleConfig'; + $this->tpl = 'list-page-generic'; + + array_push($this->path, 2, 18); + $this->name = 'Site Configuration'; + break; + default: // error out through unset template + } + + parent::__construct($pageCall, $pageParam); + } + + protected function generateContent() + { + if (!$this->generator || function_exists($this->generator)) + return; + + $this->{$this->generator}(); + } + + private function handleConfig() + { + $this->addCSS(array( + ['string' => '.grid input[type=\'text\'] { width:250px; }'], + ['string' => '.grid input[type=\'button\'] { width:65px; padding:2px; }'], + ['string' => '.disabled { opacity:0.4 !important; }'], + ['string' => '.grid a.tip { margin:0px 5px; opacity:0.8; }'], + ['string' => '.grid a.tip:hover { opacity:1; }'], + ['string' => '.status { position:absolute; right:5px; }'], + )); + + // well .. fuck! + ob_start(); +?> + +extraHTML = ob_get_contents(); + ob_end_clean(); + // eof (end of fuckup) + + $head = '
| Key | Value | Options |
|---|