* @author Marcel Pennewiss * @author Peter Grosse * @author Jonas Licht */ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'admin.php'); class admin_plugin_ipgroup extends DokuWiki_Admin_Plugin { /** * This functionality should be available only to administrator */ function forAdminOnly() { return true; } /** * Handles user request */ function handle() { if (isset($_REQUEST['network']) && ($_REQUEST['network'] != '') && isset($_REQUEST['group']) && ($_REQUEST['group'] != '')) { // network and group should be added to the list of trusted networks // check input $config_row = $_REQUEST['network'].';'.$_REQUEST['group']."\n"; $slash_pos = strpos($_REQUEST['network'],'/'); if (($slash_pos) && (filter_var(substr($_REQUEST['network'],0,$slash_pos),FILTER_VALIDATE_IP))) { $filecontent = @file(DOKU_CONF.'ipgroup.conf', FILE_SKIP_EMPTY_LINES); if ($filecontent && (sizeof($filecontent) > 0)) { if (in_array($config_row, $filecontent)) { msg($this->getLang('already'), -1); return; } } io_saveFile(DOKU_CONF.'ipgroup.conf', $config_row, true); } else { msg($this->getLang('invalid_ip'), -1); } } elseif (isset($_REQUEST['delete']) && is_array($_REQUEST['delete']) && (sizeof($_REQUEST['delete']) > 0)) { // delete network/group-mapping from the list if (!io_deleteFromFile(DOKU_CONF.'ipgroup.conf', key($_REQUEST['delete'])."\n")) { msg($this->getLang('failed'), -1); } } elseif (isset($_REQUEST['clear'])) { if (file_exists($conf['cachedir'].'/ipgroup')) { @unlink($conf['cachedir'].'/ipgroup'); } } } /** * Shows edit form */ function html() { global $conf; print $this->locale_xhtml('intro'); print $this->locale_xhtml('list'); ptln("
"); ptln("
"); formSecurityToken(); $networks = @file(DOKU_CONF.'ipgroup.conf', FILE_SKIP_EMPTY_LINES); if ($networks && (sizeof($networks) > 0)) { ptln(""); ptln(""); ptln(""); ptln(""); ptln(""); ptln(""); ptln(""); ptln(""); ptln(""); ptln(""); ptln(""); foreach ($networks as $network) { $network = rtrim($network); list($network, $group) = explode(';', $network); ptln(""); ptln(""); ptln(""); ptln(""); ptln(""); } ptln(""); ptln("
".$this->getLang('network')."".$this->getLang('group')."".$this->getLang('delete')."
".rtrim($network)."".rtrim($group).""); ptln("getLang('delete')."\" class=\"button\">"); ptln("
"); } else { ptln("
".$this->getLang('noips')."
"); } ptln("
"); ptln("
"); print $this->locale_xhtml('add'); ptln("
"); ptln("
"); formSecurityToken(); ptln(""); ptln(""); ptln(""); ptln(""); ptln("getLang('add')."\" class=\"button\">"); ptln("
"); ptln("
"); if (file_exists($conf['cachedir'].'/ipgroup')) { @unlink($conf['cachedir'].'/ipgroup'); } } }