diff options
Diffstat (limited to 'packages/authng/www/php')
-rw-r--r-- | packages/authng/www/php/head.inc | 669 | ||||
-rw-r--r-- | packages/authng/www/php/system_groupmanager.php | 797 | ||||
-rw-r--r-- | packages/authng/www/php/system_usermanager.php | 482 | ||||
-rw-r--r-- | packages/authng/www/php/system_usermanager_edit.php | 294 | ||||
-rwxr-xr-x | packages/authng/www/php/system_usermanager_settings.php | 110 |
5 files changed, 2352 insertions, 0 deletions
diff --git a/packages/authng/www/php/head.inc b/packages/authng/www/php/head.inc new file mode 100644 index 00000000..dbbf7a49 --- /dev/null +++ b/packages/authng/www/php/head.inc @@ -0,0 +1,669 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + authng_classdefs.xml + part of pfSense (http://www.pfSense.com) + Copyright (C) 2007 Daniel S. Haischt <me@daniel.stefan.haischt.name> + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>. + All rights reserved. + */ +/* ========================================================================== */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ +/* ========================================================================== */ +require("headjs.inc"); + +/* if user has selected a custom template, use it. + * otherwise default to pfsense tempalte + */ +if($config['theme'] <> "") { + $g['theme'] = $config['theme']; +} else { + $g['theme'] = "pfsense"; +} + +// navigation level separator string +$navlevelsep = ": "; + +//function gentitle($title) { +// global $navlevelsep; +// +// if(!is_array($title)) { +// return $title; +// } +// +// return join($navlevelsep, $title); +//} + +function genhtmltitle($title) { + global $config; + //return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . gentitle($title); + return gentitle($title); +} + +$scriptName = split("/", $_SERVER["SCRIPT_FILENAME"]); +$scriptElms = count($scriptName); +$scriptName = $scriptName[$scriptElms-1]; + +$pfSenseHead = new pfSenseHTMLHead(); +$pfSenseHead->setCloseHead(true); +$pfSenseHead->setTitle(genhtmltitle($pgtitle)); + +/* all.css has to be treated a bit different, compared to generic stylesheets */ +$allID = $pfSenseHead->addLink("<link rel=\"stylesheet\" type=\"text/css\" href=\"/themes/" . $g['theme'] . "/all.css\" media=\"all\" />\n"); +$pfSenseHead->setAllCssID($allID); + +$pfSenseHead->addLink("<link rel='shortcut icon' href='/themes/{$g['theme']}/images/icons/favicon.ico' />\n"); +$pfSenseHead->addScript("<script type='text/javascript'>\nvar theme = '" . $g['theme'] . "';\nvar dontUseCustomBGColor = true;\n</script>\n", 1); +$pfSenseHead->addScript("<script type='text/javascript' src=\"/themes/" . $g['theme'] . "/loader.js\"></script>\n", 2); +//TODO: if ((($_POST || $_GET || isAjax()) && +if ((($_POST || $_GET) && + is_array($error_bucket)) || + strpos($_SERVER['SCRIPT_NAME'], "wizard.php") !== false) { + $pfSenseHead->addScript("<script type='text/javascript' src='/javascript/domTT/domLib.js'></script>", 500); + $pfSenseHead->addScript("<script type='text/javascript' src='/javascript/domTT/domTT.js'></script>", 510); + $pfSenseHead->addScript("<script type='text/javascript' src='/javascript/domTT/behaviour.js'></script>", 520); + $pfSenseHead->addScript("<script type='text/javascript' src='/javascript/domTT/fadomatic.js'></script>", 530); +} + +/* + * Find all javascript files that need to be included + * for this page ... from the arrays ... :) + * Coded by: Erik Kristensen + */ +$scriptWeight = 100; + +$dir = trim(basename($_SERVER["SCRIPT_FILENAME"]), '.php'); +$path = "/usr/local/www/javascript/" . $dir . "/"; +if (is_dir($path)) { + if ($dh = opendir($path)) { + while (($file = readdir($dh)) !== false) { + if (is_dir($file)) { continue; } + if (strpos($file, ".js") === false) { continue; } + + $pfSenseHead->addScript("<script type='text/javascript' src='/javascript/{$dir}/{$file}'></script>\n", $scriptWeight); + $scriptWeight++; + } + closedir($dh); + } +} + +/* + * Find all JavaScript files that may be provided by the current theme + * TODO: Commented because this pulls in PHP5 specific stuff from the theme. + * + */ +//$path = "/usr/local/www/themes/{$g['theme']}/javascript/"; + +//if (is_dir($path)) { +// if ($dh = opendir($path)) { +// while (($file = readdir($dh)) !== false) { +// if (is_dir($file)) { continue; } +// if (strpos($file, ".js") !== false) { +// $pfSenseHead->addScript("<script type='text/javascript' src='/themes/{$g['theme']}/javascript/{$file}'></script>\n", $scriptWeight); +// } else if (strpos($file, ".php") !== false && +// strpos($file, "-head") !== false && +// strpos($file, ".disabled") === false) { +// $filename = ucfirst(trim(trim($file, '.php'), '-head')); +// require_once("themes/{$g['theme']}/javascript/{$file}"); + +// if (function_exists("{$g['theme']}{$filename}GetHeadJS")) { +// $jsfunction = "{$g['theme']}{$filename}GetHeadJS"; +// $jscript = $jsfunction(); +// $pfSenseHead->addScript("<script type='text/javascript'>\n<!--\n{$jscript}\n-->\n</script>\n", $scriptWeight); +// } +// } else { +// continue; +// } + +// $scriptWeight++; +// } +// closedir($dh); +// } +//} + +/* + * Find all JavaScript events that may be provided by the current theme + * + */ +$path = "/usr/local/www/themes/{$g['theme']}/jsevents/"; +if (is_dir($path)) { + if ($dh = opendir($path)) { + while (($file = readdir($dh)) !== false) { + if (is_dir($file)) { continue; } + if (strpos($file, ".def") !== false) { + if (empty($jsevents)) { $jsevents = array(); } + + switch ($file) { + case "body.def": + $contents = file_get_contents("/usr/local/www/themes/{$g['theme']}/jsevents/{$file}"); + $contents_a = split("\n", $contents); + foreach ($contents_a as $line) { + if (strpos($line, "#") === 0) { continue; } + if (strpos($line, "!") !== false) { + $events_forbidden_pages = split("!", $line); + $keyval = split("=", $events_forbidden_pages[0]); + + if (strpos($events_forbidden_pages[1], basename($_SERVER['SCRIPT_NAME'])) !== false) { continue; } + } else { + $keyval = split("=", $line); + } + $jsevents["body"][$keyval[0]] = $keyval[1]; + } + break; + } + } else { + continue; + } + } + closedir($dh); + } +} + +/* + * Find all CSS files that may be provided by the current theme + * TODO: Not needed right now. + */ +//$path = "/usr/local/www/themes/{$g['theme']}/styles/"; +//if (is_dir($path)) { +// if ($dh = opendir($path)) { +// while (($file = readdir($dh)) !== false) { +// if (is_dir($file)) { continue; } +// if (strpos($file, ".css") === false) { continue; } + +// $pfSenseHead->addLink("<link rel='stylesheet' type='text/css' href='/themes/{$g['theme']}/styles/{$file}' media='all' />\n"); +// } +// closedir($dh); +// } +//} + +if ($oSajax) { +$pfSenseHead->addScript("<script type='text/javascript'>\n" . + $oSajax->sajax_get_javascript() . "\n</script>\n", ++$scriptWeight); +} + +// TODO: This line needs to be commented if any PHP calls +// $pfSenseHead->getHTML(); on its own. +//echo $pfSenseHead->getHTML(); + +/** + * pfSenseHTMLHead + * + * @package www + * @author Daniel S. Haischt <me@daniel.stefan.haischt.name> + * @copyright Copyright (c) 2006 + * @version $Id$ + * @access public + **/ +class pfSenseHTMLHead +{ + var $xmlHead = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"; + var $docType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; + var $title = "UNSET"; + var $meta = array(); + var $link = array(); + var $script = array(); + var $style = array(); + var $html = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"%LANG%\" lang=\"%LANG%\">\n<head>\n<title>%TITLE%</title>\n%META%\n%STYLE%\n%LINK%\n%SCRIPT%"; + var $closehead = true; + var $returnedHTML = false; + var $allCSSID = "NOT-SET"; + + /** + * pfSenseHTMLHead::pfSenseHTMLHead() + * + * Class Konstructor + **/ + function pfSenseHTMLHead() { + $this->meta[] = array("meta" => " <meta http-equiv=\"Content-Type\" " . + "content=\"text/html; charset=iso-8859-1\" />", + "ID" => "meta-" . strval(microtime())); + $this->link[] = array("link" => " <link rel=\"stylesheet\" type=\"text/css\" " . + "href=\"/niftycssprintCode.css\" media=\"print\" />", + "ID" => "link-" . strval(microtime())); + $this->script[] = array("script" => " <script type=\"text/javascript\" " . + "src=\"/javascript/scriptaculous/prototype.js\"></script>", + "weight" => 3, + "ID" => "script-" . strval(microtime())); + $this->script[] = array("script" => " <script type=\"text/javascript\" " . + "src=\"/javascript/scriptaculous/scriptaculous.js\"></script>", + "weight" => 4, + "ID" => "script-" . strval(microtime())); +// $this->script[] = array("script" => " <script type=\"text/javascript\">\n<!--\n" . getHeadJS() . "\n//-->\n</script>", +// "weight" => 5, +// "ID" => "script-" . strval(microtime())); + } + + /** + * pfSenseHTMLHead::getAllCssID() + * + * Allows to store the ID associated with the all CSS file. + * @return an ID + **/ + function getAllCssID() { + return $this->allCSSID; + } + + /** + * pfSenseHTMLHead::setAllCssID() + * + * Allows to set the ID associated with the all CSS file. + * @param mixed $myID a string representing an ID that was already generated. + **/ + function setAllCssID($myID = "") { + if ($myID == "") { return; } + + $this->allCSSID = $myID; + } + + /** + * pfSenseHTMLHead::setCloseHead() + * + * Should the HTML <head /> element be closed by the class or + * do you want to close it manually? + * @param mixed $myCloseHead Boolean value which indicates whether <head /> should be closed by the class + * @return + **/ + function setCloseHead($myCloseHead = true) { + $this->closehead = $myCloseHead; + } + + /** + * pfSenseHTMLHead::setTitle() + * + * Set the HTML <title /> element. + * @param string $myTitle The title (without any markup) + * @return NULL + **/ + function setTitle($myTitle = "") { + $this->title = $myTitle; + } + + /** + * pfSenseHTMLHead::addStyle() + * + * Allows to add a complete HTML <style /> element to the current + * meta element array. You can provide an ID if you want to access your + * particular element at a later time, for example to delete it from the + * array etc.. If you don't provide an ID, a random ID will be generated + * and returned. + * @param string $myStyleElement an HTML string that represents a <style /> tag. + * @param string $myID an ID that identifies this element. + * @return the ID that identifies the particular element that you've just added. + **/ + function addStyle($myStyleElement = "", $myID = "") { + if ($myID == "") { $myID = "style-" . strval(microtime()); } + + $this->style[] = array("style" => $myStyleElement, + "ID" => $myID); + + return $myID; + } + + /** + * pfSenseHTMLHead::getStyleArray() + * + * @return a reference to the meta element array. + **/ + function &getStyleArray() { + return $this->style; + } + + /** + * pfSenseHTMLHead::getStyleByID() + * + * Returns a reference to an array element that is identified by an ID. + * Can be used for example to manipulate an array element after it was + * already stored in the array. + * @param string $myID an ID that identifies the element that should be retrieved. + * @return a reference to an array element or NULL if the element does not exist. + **/ + function &getStyleByID($myID = "") { + foreach($this->style as $styleel){ + if ($styleel["ID"] == $myID) { + return $styleel; + } + } + return NULL; + } + + /** + * pfSenseHTMLHead::removeStyleByID() + * + * Provides a way to delete an element from an HTML element array. + * You must provide an ID which identifies the element to be deleted. + * @param string $myID an ID the identifies the element. + * @return 1 if the element was found or 0 if it does not exist. + **/ + function removeStyleByID($myID = "") { + foreach($this->style as $styleel){ + if ($styleel["ID"] == $myID) { + unset($styleel); + return 1; + } + } + return 0; + } + + /** + * pfSenseHTMLHead::addMeta() + * + * Allows to add a complete HTML <meta /> element to the current + * meta element array. You can provide an ID if you want to access your + * particular element at a later time, for example to delete it from the + * array etc.. If you don't provide an ID, a random ID will be generated + * and returned. + * @param string $myMetaElement an HTML string that represents a <meta /> tag. + * @param string $myID an ID that identifies this element. + * @return the ID that identifies the particular element that you've just added. + **/ + function addMeta($myMetaElement = "", $myID = "") { + if ($myID == "") { $myID = "meta-" . strval(microtime()); } + + $this->meta[] = array("meta" => $myMetaElement, + "ID" => $myID); + + return $myID; + } + + /** + * pfSenseHTMLHead::getMetaArray() + * + * @return a reference to the meta element array. + **/ + function &getMetaArray() { + return $this->meta; + } + + /** + * pfSenseHTMLHead::getMetaByID() + * + * Returns a reference to an array element that is identified by an ID. + * Can be used for example to manipulate an array element after it was + * already stored in the array. + * @param string $myID an ID that identifies the element that should be retrieved. + * @return a reference to an array element or NULL if the element does not exist. + **/ + function &getMetaByID($myID = "") { + foreach($this->meta as $metael){ + if ($metael["ID"] == $myID) { + return $metael; + } + } + return NULL; + } + + /** + * pfSenseHTMLHead::removeMetaByID() + * + * Provides a way to delete an element from an HTML element array. + * You must provide an ID which identifies the element to be deleted. + * @param string $myID an ID the identifies the element. + * @return 1 if the element was found or 0 if it does not exist. + **/ + function removeMetaByID($myID = "") { + foreach($this->meta as $metael){ + if ($metael["ID"] == $myID) { + unset($metael); + return 1; + } + } + return 0; + } + + /** + * pfSenseHTMLHead::addLink() + * + * Allows to add a complete HTML <link /> element to the current + * link element array. You can provide an ID if you want to access your + * particular element at a later time, for example to delete it from the + * array etc.. If you don't provide an ID, a random ID will be generated + * and returned. + * @param string $myLinkElement an HTML string that represents a <link /> tag. + * @param string $myID an ID that identifies this element. + * @return the ID that identifies the particular element that you've just added. + **/ + function addLink ($myLinkElement = "", $myID = "") { + if ($myID == "") { $myID = "link-" . strval(microtime()); } + + $this->link[] = array("link" => $myLinkElement, + "ID" => $myID); + + return $myID; + } + + /** + * pfSenseHTMLHead::getLinkArray() + * + * @return a reference to the link element array. + **/ + function &getLinkArray() { + return $this->link; + } + + /** + * pfSenseHTMLHead::getLinkByID() + * + * Returns a reference to an array element that is identified by an ID. + * Can be used for example to manipulate an array element after it was + * already stored in the array. + * @param string $myID an ID that identifies the element that should be retrieved. + * @return a reference to an array element or NULL if the element does not exist. + **/ + function &getLinkByID($myID = "") { + foreach($this->link as $linkel){ + if ($linkel["ID"] == $myID) { + return $linkel; + } + } + return NULL; + } + + /** + * pfSenseHTMLHead::removeLinkByID() + * + * Provides a way to delete an element from an HTML element array. + * You must provide an ID which identifies the element to be deleted. + * @param string $myID an ID the identifies the element. + * @return 1 if the element was found or 0 if it does not exist. + **/ + function removeLinkByID($myID = "") { + foreach($this->link as $linkel){ + if ($linkel["ID"] == $myID) { + unset($linkel); + return 1; + } + } + return 0; + } + + /** + * pfSenseHTMLHead::replaceLinkByID() + * + * Provides a way to replace an element from an HTML element array. + * You must provide an ID which identifies the element to be replace. + * @param string $myID an ID the identifies the element. + * @return 1 if the element was found or 0 if it does not exist. + **/ + function replaceLinkByID($myID = "", $byWhat = "") { + for ($i = 0; $i < count($this->link); $i++) { + $linkel =& $this->link[$i]; + if ($linkel["ID"] == $myID) { + $linkel["link"] = $byWhat; + return 1; + } + } + + return 0; + } + + /** + * pfSenseHTMLHead::addScript() + * + * Allows to add a complete HTML <link /> element to the current + * link element array. You can provide an ID if you want to access your + * particular element at a later time, for example to delete it from the + * array etc.. If you don't provide an ID, a random ID will be generated + * and returned. + * + * The <code>weight</code> parameter can be used to force the <script /> + * element to appear at the beginning of the HTML <head /> element or at + * its end. The greater the value for weight, the later the <script /> + * element will appear within the HTML <head /> element. + * @param string $myScriptElement an HTML string that represents a <script /> tag. + * @param integer $weight allows to position this element within the HTML <head /> + * @param string $myID an ID that identifies this element. + * @return the ID that identifies the particular element that you've just added. + **/ + function addScript($myScriptElement = "", $weight = 1000000, $myID = "") { + if ($myID == "") { $myID = "script-" . strval(microtime()); } + + $this->script[] = array("script" => $myScriptElement, + "weight" => $weight, + "ID" => $myID); + } + + /** + * pfSenseHTMLHead::getScriptArray() + * + * @return a reference to the script element array. + **/ + function &getScriptArray() { + return $this->script; + } + + /** + * pfSenseHTMLHead::getScriptByID() + * + * Returns a reference to an array element that is identified by an ID. + * Can be used for example to manipulate an array element after it was + * already stored in the array. + * @param string $myID an ID that identifies the element that should be retrieved. + * @return a reference to an array element or NULL if the element does not exist. + **/ + function &getScriptByID($myID = "") { + foreach($this->script as $scriptel){ + if ($scriptel["ID"] == $myID) { + return $scriptel; + } + } + return NULL; + } + + /** + * pfSenseHTMLHead::removeScriptByID() + * + * Provides a way to delete an element from an HTML element array. + * You must provide an ID which identifies the element to be deleted. + * @param string $myID an ID the identifies the element. + * @return 1 if the element was found or 0 if it does not exist. + **/ + function removeScriptByID($myID = "") { + foreach($this->script as $scriptel){ + if ($scriptel["ID"] == $myID) { + unset($scriptel); + return 1; + } + } + return 0; + } + + /** + * pfSenseHTMLHead::getHTML() + * + * This function finally renders the HTML string representation of the + * HTML document header that is represented by this class. If you did + * specify to not close the HTML <head /> element via <code>closehead</code> + * you need to close it manually. + * + * @return a string that contains a HTML <head /> element. + **/ + function getHTML () { + $language = $GLOBALS['config']['system']['language']; + + if ($this->returnedHTML) { + return; + } else { + $metastr = ""; + if (is_array($this->meta) && count($this->meta) > 0) + foreach($this->meta as $metael) { + $metastr .= $metael["meta"] . "\n"; + } + + $linkstr = ""; + if (is_array($this->link) && count($this->link) > 0) + foreach($this->link as $linkel) { + $linkstr .= $linkel["link"] . "\n"; + } + + $stylestr = ""; + if (is_array($this->style) && count($this->style) > 0) + foreach($this->style as $styleel) { + $stylestr .= $styleel["style"] . "\n"; + } + + $scriptstr = ""; + usort($this->script, "sortScriptArray"); + if (is_array($this->script) && count($this->script) > 0) + foreach($this->script as $scriptel) { + + $scriptstr .= $scriptel["script"] . "\n"; + } + + $this->html = str_replace("%TITLE%", $this->title, $this->html); + $this->html = str_replace("%META%", $metastr, $this->html); + $this->html = str_replace("%STYLE%", $stylestr, $this->html); + $this->html = str_replace("%LINK%", $linkstr, $this->html); + $this->html = str_replace("%SCRIPT%", $scriptstr, $this->html); + $this->html = str_replace("%LANG%", $language, $this->html); + $this->html = $this->xmlHead . $this->docType . $this->html; + + $this->returnedHTML = true; + + return $this->closehead ? ($this->html . "</head>") : ($this->html); + } + } +} + +/** + * sortScriptArray() + * + * Sorts the script array according of the weight of a particular + * script element. + * @param mixed $a + * @param mixed $b + * @return + **/ +function sortScriptArray($a, $b) { + if ($a["weigth"] == $b["weight"]) { + return 0; + } + + return (intval($a["weight"]) > intval($b["weight"])) ? 1 : -1; +} + +?> diff --git a/packages/authng/www/php/system_groupmanager.php b/packages/authng/www/php/system_groupmanager.php new file mode 100644 index 00000000..13259e63 --- /dev/null +++ b/packages/authng/www/php/system_groupmanager.php @@ -0,0 +1,797 @@ +<?php +/* + $Id$ + part of pfSense (http://www.pfSense.com) + originally part of part of m0n0wall (http://m0n0.ch/wall) + + Copyright (C) 2006 Scott Ullrich <sullrich@gmail.com>. + All rights reserved. + + Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>. + All rights reserved. + + Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +require("guiconfig.inc"); + +$_SESSION['NO_AJAX'] = true; + +$pgtitle = array(gettext("System"), gettext("Group manager")); +$treeItemID = 0; + +function walkArea($title, + $t, + $area, + $id, + &$counter, + &$script_tag, + $tmpfname, + &$group) { + global $treeItemID; + + foreach($area as $a => $aa) { + if (is_array($aa) && count($aa) > 0) { + $title .= "_{$a}"; + echo "<li class=\"closed\"><a id=\"treeitem_{$treeItemID}\" href=\"#\">$a</a><ul>"; + $treeItemID++; + walkArea($title, + $a, + $aa, + $id, + $counter, + $script_tag, + $tmpfname, + $group); + echo "</ul>\n"; + } else { + $tmp_string = "{$t}"; + $tmp_string .= ": "; + $tmp_string .= $a; + $trimmed_title = trim($title); + $trimmed_a = trim($a); + $this_id = "{$trimmed_title}_{$trimmed_a}_{$counter}"; + $this_id = str_replace(" ", "", $this_id); + $this_id = str_replace("/", "", $this_id); + $stripped_session = str_replace("/tmp/", "", $tmpfname); + $allowed = false; + if (is_array($group['pages'][0]['page'])) { + foreach($group['pages'][0]['page'] as $page) { + if (stristr($aa, $page)) + $allowed = true; + // echo "$page || $aa"; + } + } + $allowed ? $checked = " checked=\"checked\"" : $checked = ""; + echo " <li id=\"treeitem_{$treeItemID}\" class=\"closed\" title=\"{$aa}\"><a name=\"anchor_{$treeItemID}\" style=\"display: none;\"> </a>"; + $idForOnClick = $treeItemID; + $treeItemID++; + echo "<input type=\"checkbox\" class=\"formfld\" id=\"treeitem_{$treeItemID}\" "; + $treeItemID++; + echo "name=\"treeitem_{$treeItemID}\" title=\"{$area}\" onClick=\"getURL('system_groupmanager.php?id={$id}&toggle={$aa}&item={$idForOnClick}&session={$stripped_session}', after_request_callback); rotate();\" {$checked} /> "; + $treeItemID++; + echo "<a id=\"treeitem_{$treeItemID}\" href=\"#anchor_{$idForOnClick}\" onclick=\"getURL('system_groupmanager.php?id={$id}&toggle={$aa}&item={$idForOnClick}&session={$stripped_session}', after_request_callback); rotate();\">{$a}</a></li>\n"; + $idForScript = $treeItemID; + $treeItemID++; + +//echo "$script_tag <hr />"; + $script_tag .= "var item = document.getElementById('treeitem_{$idForScript}');\n"; + if ($allowed) { + $script_tag .= "item.style.backgroundImage = \"url('/tree/page-file_play.gif')\";\n"; + } else { + $script_tag .= "item.style.backgroundImage = \"url('/tree/page-file_x.gif')\";\n"; + } + $counter++; + } // end if + } // end foreach +} + +function init_ajax_helper_file($tmpfname) +{ + global $config, $id, $global; + $a_group = &$config['system']['group']; + $id = $_GET['id']; + if (isset($id) && $a_group[$id]) + $group = $a_group[$id]; + else + $group = array(); + $fd = fopen("/tmp/{$tmpfname}", "w"); + if ($group['pages'][0]['page']) + foreach($group['pages'][0]['page'] as $page) { + fwrite($fd, $page . "\n"); + } + fclose($fd); + return; +} + +if ($_GET['toggle'] <> "") { + /* AJAX is calling, lets take care of it */ + if (!file_exists("/tmp/" . $_GET['session'])) { + init_ajax_helper_file($_GET['session']); + } + $fc = file_get_contents("/tmp/" . $_GET['session']); + $file_split = split("\n", $fc); + $found = -1; + for($x = 0; $x < count($file_split); $x++) { + if ($file_split[$x] == $_GET['toggle']) { + $found = $x; + } + } + if ($found == -1) { + $file_split[] = $_GET['toggle']; + $image = "/tree/page-file_play.gif"; + } else { + unset($file_split[$found]); + $image = "/tree/page-file_x.gif"; + } + $fd = fopen("/tmp/{$_GET['session']}", "w"); + if ($file_split) + foreach($file_split as $fs) { + if ($fs) + fwrite($fd, $fs . "\n"); + } + fclose($fd); + echo $_GET['item'] . "_a||" . "{$image}"; + exit; +} + +function convert_array_to_pgtitle($orig) +{ + $newstring = ""; + foreach($orig as $o) { + if ($newstring <> "") + $newstring .= ": "; + $newstring .= $o; + } + return $newstring; +} +// Returns an array of pages with their descriptions +function getAdminPageList() +{ + global $g; + + $tmp = Array(); + + if ($dir = opendir($g['www_path'])) { + while ($file = readdir($dir)) { + // Make sure the file exists and is not a directory + if ($file == "." or $file == ".." or $file[0] == '.') + continue; + // Is this a .inc.php file? pfSense! + if (fnmatch('guiconfig.inc', $file)) + continue; + if (fnmatch('*.inc', $file)) + continue; + if (fnmatch('*.inc.php', $file)) + continue; + if (fnmatch('*.php', $file)) { + // Read the description out of the file + $contents = file_get_contents($file); + $contents_split = split("\n", $contents); + $mlinestr = ""; + foreach($contents_split as $contents) { + $pgtitle = ""; + // Looking for a line like: + // $pgtitle = array(gettext("System"), gettext("Group manager")); // - DO NOT REMOVE. + if ($mlinestr == "" && stristr($contents, "\$pgtitle") == false) + continue; + if ($mlinestr == "" && stristr($contents, "=") == false) + continue; + if (stristr($contents, "<")) + continue; + if (stristr($contents, ">")) + continue; + /* at this point its evalable */ + $contents = trim ($contents); + $lastchar = substr($contents, strlen($contents) - 1, strlen($contents)); + $firstchar = substr($contents, 0, 1); + + /* check whether pgtitle is on one or multible lines */ + if ($firstchar <> "/" && $firstchar <> "#" && $lastchar <> ";") { + /* remember the partitial pgtitle string for the next loop iteration */ + $mlinestr .= $contents; + continue; + } else if ($mlinestr <> "" && $lastchar == ";") { + /* this is the final pgtitle part including the semicolon */ + $mlinestr .= $contents; + } else if ($mlinestr == "" && $lastchar == ";") { + /* this is a single line pgtitle, hence just + * copy its contents into mlinestr + */ + $mlinestr = $contents; + } else if ($firstchar == "/" || $firstchar == "#") { + /* same applies for comment lines */ + $mlinestr = $contents; + } + + eval($mlinestr); + + /* after eval, if not an array, continue */ + if (!is_array($pgtitle)) { + /* reset mlinestr for the next loop iteration */ + $mlinestr = ""; + continue; + } + + $tmp[$file] = convert_array_to_pgtitle($pgtitle); + + /* break out of the for loop, on to next file */ + break; + } + } + } + + /* loop through and read in wizard information */ + if ($dir = opendir("{$g['www_path']}/wizards")) { + while ($file = readdir($dir)) { + // Make sure the file exists and is not directory + if ($file == "." or $file == ".." or $file[0] == '.') + continue; + // Is this a .xml file? pfSense! + if (fnmatch('*.xml', $file)) { + /* parse package and retrieve the package title */ + $pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/{$file}", "pfsensewizard"); + $title = $pkg['title']; + if ($title) + $tmp[$file] = trim($title); + } + } + } + + /* loop through and read in package information */ + if ($dir = opendir("{$g['pkg_path']}")) { + while ($file = readdir($dir)) { + // Make sure the file exists and is not directory + if ($file == "." or $file == ".." or $file[0] == '.') + continue; + // Is this a .xml file? pfSense! + if (fnmatch('*.xml', $file)) { + /* parse package and retrieve the package title */ + $pkg = parse_xml_config_pkg("{$g['pkg_path']}/{$file}", "packagegui"); + $title = $pkg['title']; + if ($title) + $tmp[$file] = trim($title); + } + } + } + + closedir($dir); + // Sets Interfaces:Optional page that didn't read in properly with the above method, + // and pages that don't have descriptions. + $tmp['interfaces_opt.php'] = ("Interfaces: Optional"); + $tmp['graph.php'] = ("Status: Traffic Graph"); + $tmp['graph_cpu.php'] = ("Diagnostics: CPU Utilization"); + $tmp['exec_raw.php'] = ("Hidden: Exec Raw"); + $tmp['uploadconfig.php'] = ("Hidden: Upload Configuration"); + $tmp['index.php'] = ("Status: System"); + $tmp['system_usermanager.php'] = ("System: User Password"); + $tmp['diag_logs_settings.php'] = ("Diagnostics: Logs: Settings"); + $tmp['diag_logs_vpn.php'] = ("Diagnostics: Logs: PPTP VPN"); + $tmp['diag_logs_filter.php'] = ("Diagnostics: Logs: Firewall"); + $tmp['diag_logs_portal.php'] = ("Diagnostics: Logs: Captive Portal"); + $tmp['diag_logs_dhcp.php'] = ("Diagnostics: Logs: DHCP"); + $tmp['diag_logs.php'] = ("Diagnostics: Logs: System"); + + $tmp['ifstats.php'] = ("Hidden: *XMLRPC Interface Stats"); + $tmp['license.php'] = ("System: License"); + $tmp['progress.php'] = ("Hidden: *No longer included"); + $tmp['diag_logs_filter_dynamic.php'] = ("Hidden: *No longer included"); + $tmp['preload.php'] = ("Hidden: *XMLRPC Preloader"); + $tmp['xmlrpc.php'] = ("Hidden: *XMLRPC Library"); + $tmp['pkg.php'] = ("System: *Renderer for XML based package GUIs (Part I)"); + $tmp['pkg_edit.php'] = ("System: *Renderer for XML based package GUIs (Part II)"); + + $tmp['functions.inc.php'] = ("Hidden: Ajax Helper 1"); + $tmp['javascript.inc.php'] = ("Hidden: Ajax Helper 2 "); + $tmp['sajax.class.php'] = ("Hidden: Ajax Helper 3"); + + asort($tmp); + + return $tmp; + } +} +// Get a list of all admin pages & Descriptions +$pages = getAdminPageList(); + +if (!is_array($config['system']['group'])) { + $config['system']['group'] = array(); +} +admin_groups_sort(); +$a_group = &$config['system']['group']; + +$id = $_GET['id']; +if (isset($_POST['id'])) + $id = $_POST['id']; + +if ($_GET['act'] == "del") { + if ($a_group[$_GET['id']]) { + $ok_to_delete = true; + if (isset($config['system']['user'])) { + foreach ($config['system']['user'] as $userent) { + if ($userent['groupname'] == $a_group[$_GET['id']]['name']) { + $ok_to_delete = false; + $input_errors[] = gettext("users still exist who are members of this group!"); + break; + } + } + } + if ($ok_to_delete) { + unset($a_group[$_GET['id']]); + write_config(); + pfSenseHeader("system_groupmanager.php"); + exit; + } + } +} + +if ($_POST) { + unset($input_errors); + $pconfig = $_POST; + /* input validation */ + $reqdfields = explode(" ", "groupname"); + $reqdfieldsn = explode(",", "Group Name"); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname'])) + $input_errors[] = gettext("The group name contains invalid characters."); + + if (!$input_errors && !(isset($id) && $a_group[$id])) { + /* make sure there are no dupes */ + foreach ($a_group as $group) { + if ($group['name'] == $_POST['groupname']) { + $input_errors[] = gettext("Another entry with the same group name already exists."); + break; + } + } + } + + if (!$input_errors) { + if (isset($id) && $a_group[$id]) + $group = $a_group[$id]; + + $group['name'] = $_POST['groupname']; + isset($_POST['homepage']) ? $group['home'] = $_POST['homepage'] : $group['home'] = "index.php"; + isset($_POST['gtype']) ? $group['scope'] = $_POST['gtype'] : $group['scope'] = "system"; + $group['description'] = $_POST['description']; + unset($group['pages'][0]['page']); + + $file_split = split("\n", file_get_contents("/tmp/" . $_POST['session'])); + for($x = 0; $x < count($file_split); $x++) { + if ($file_split[$x]) + $group['pages'][0]['page'][] = $file_split[$x]; + } + + if (isset($id) && $a_group[$id]) + $a_group[$id] = $group; + else + $a_group[] = $group; + + write_config(); + + unlink_if_exists("/tmp/" . $_GET['session']); + + pfSenseHeader("system_groupmanager.php"); + exit; + } +} + +include("head.inc"); + +$checkallstr = <<<EOD + function checkallareas(enable) { + var elem = document.iform.elements.length; + var endis = (document.iform.checkall.checked || enable); + + for (i = 0; i < elem; i++) { + if (document.iform.elements[i].name.indexOf("chk-") >= 0) { + document.iform.elements[i].checked = true; + document.iform.elements[i].click(); + } + } + } + +EOD; + +$pfSenseHead->addScript("<script type=\"text/javascript\">\n" . $checkallstr . "</script>\n"); +$pfSenseHead->addLink("<link href=\"/tree/tree.css\" rel=\"stylesheet\" type=\"text/css\" />"); +echo $pfSenseHead->getHTML(); + +?> +<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>"> +<?php include("fbegin.inc");?> +<?php if ($input_errors) print_input_errors($input_errors);?> +<?php if ($savemsg) print_info_box($savemsg);?> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td class="tabnavtbl"> +<?php + $tab_array = array(); + $tab_array[] = array(gettext("Users"), false, "system_usermanager.php"); + $tab_array[] = array(gettext("Group"), true, "system_groupmanager.php"); + $tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php"); + display_top_tabs($tab_array); +?> + </td> + </tr> + <tr> + <td class="tabcont"> +<?php +if ($_GET['act'] == "new" || $_GET['act'] == "edit") { + $tmpfname = tempnam("/tmp", "edit_add_groupmanager"); + $tmpfname = str_replace("/tmp/", "", $tmpfname); + unlink("/tmp/$tmpfname"); + init_ajax_helper_file($tmpfname); + if ($_GET['act'] == "edit") { + if (isset($id) && $a_group[$id]) { + $pconfig['name'] = $a_group[$id]['name']; + $pconfig['description'] = $a_group[$id]['description']; + $pconfig['home'] = $a_group[$id]['home']; + $pconfig['gtype'] = $a_group[$id]['scope']; + $pconfig['pages'] = $a_group[$id]['pages'][0]['page']; + } + } else if ($_GET['act'] == "new") { + /* set this value cause the text field is read only + * and the user should not be able to mess with this + * setting. + */ + $pconfig['gtype'] = "user"; + } + +?> + <form action="system_groupmanager.php" method="post" name="iform" id="iform"> + <div id="inputerrors"></div> +<script type="text/javascript"> +if (typeof getURL == 'undefined') { + getURL = function(url, callback) { + if (!url) + throw 'No URL for getURL'; + try { + if (typeof callback.operationComplete == 'function') + callback = callback.operationComplete; + } catch (e) {} + if (typeof callback != 'function') + throw 'No callback function for getURL'; + var http_request = null; + if (typeof XMLHttpRequest != 'undefined') { + http_request = new XMLHttpRequest(); + } + else if (typeof ActiveXObject != 'undefined') { + try { + http_request = new ActiveXObject('Msxml2.XMLHTTP'); + } catch (e) { + try { + http_request = new ActiveXObject('Microsoft.XMLHTTP'); + } catch (e) {} + } + } + if (!http_request) + throw 'Both getURL and XMLHttpRequest are undefined'; + http_request.onreadystatechange = function() { + if (http_request.readyState == 4) { + callback( { success : true, + content : http_request.responseText, + contentType : http_request.getResponseHeader("Content-Type") } ); + } + } + http_request.open('GET', url, true); + http_request.send(null); + } +} +function after_request_callback(callback_data) { + var data = callback_data.content; + data_split = data.split("||"); + var item = document.getElementById(data_split[0]); + var check = document.getElementById("chk-" + data_split[0]); + item.style.backgroundImage = 'url(' + data_split[1] + ')'; + if (data_split[1] == "/tree/page-file_play.gif") { + check.checked = true; + } else { + check.checked = false; + } + $('troot_text').innerHTML = '<?= gettext("webConfigurator"); ?>'; +} + +function rotate() { + $('troot_text').innerHTML = '<img src="/themes/<?= $g['theme'] ?>/images/misc/loader.gif" alt="" />'; +} +</script> + + <input type="hidden" name="session" value="<?=$tmpfname?>" /> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr> + <td width="22%" valign="top" class="vncellreq"> + <?=gettext("Group name");?> + </td> + <td width="78%" class="vtable"> + <input name="groupname" type="text" class="formfld group" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" /> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"> + <?=gettext("Home Page");?> + </td> + <td width="78%" class="vtable"> + <input name="homepage" type="text" class="formfld url" id="homepage" size="20" value="<?=htmlspecialchars($pconfig['home']);?>" /> + <br /> + <?=gettext("A webpage that should be shown to the user after having logged in.");?> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncellreq"> + <?=gettext("Group Type");?> + </td> + <td width="78%" class="vtable"> + <input name="gtype" type="text" class="formfld unknown" id="gtype" size="20" value="<?=htmlspecialchars($pconfig['gtype']);?>" readonly="readonly" /> + <br /> + <?=gettext("Indicates whether this is a system (aka non-deletable) group or a group created by the user.");?> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td> + <td width="78%" class="vtable"> + <textarea name="description" class="formpre" id="description" rows="2" cols="20"><?=htmlspecialchars($pconfig['description']);?></textarea> + <br /> + <?=gettext("Group description, for your own information only");?> + </td> + </tr> + <tr> + <td colspan="5"> + <script type="text/javascript" src="/tree/tree.js"></script> +<?php + if (isset($id) && $a_group[$id]) + $group = $a_group[$id]; + else + $group = array(); + $menu_array = array(); + /* build up an array similar to fbegin.inc's $menu */ + foreach ($pages as $fname => $title) { + $identifier = str_replace('.php', '', $fname); + $identifier = $fname; + $title_split = split(": ", $title); + $tmp = "\$menu_array"; + foreach($title_split as $ts) + $tmp .= "['{$ts}']"; + $tmp .= " = \"{$identifier}\";"; + echo "<!-- $tmp -->\n"; + eval($tmp); + } + + echo "<span id=\"troot_text\" style=\"position: relative; top: 12px;\">" . gettext("webConfigurator") . "</span><ul class=\"tree\" id=\"troot\">\n"; + $counter = 0; + /* XXX: we may wanna pull from or add to each row a +e item (+edit) */ + $script_tag = ""; + + if (is_array($menu_array) && count($menu_array) > 0) { + foreach($menu_array as $title => $m) { + echo "<li class=\"closed\"><a id=\"treeitem_{$treeItemID}\" href=\"#\">$title</a><ul>"; + $treeItemID++; + if (is_array($m) && count($m) > 0) { + foreach($m as $t => $area) { + if (is_array($area) && count($area) > 0) { + echo "<li class=\"closed\"><a id=\"treeitem_{$treeItemID}\" href=\"#\">$t</a><ul>"; + $treeItemID++; + walkArea("{$title}_{$t}", + $t, + $area, + $id, + $counter, + $script_tag, + $tmpfname, + $group); + echo "</ul>\n"; + } else { + $trimmed_title = trim($title); + $trimmed_t = trim($t); + $this_id = "{$trimmed_title}_{$trimmed_t}_{$counter}"; + $this_id = str_replace(" ", "", $this_id); + $this_id = str_replace("/", "", $this_id); + $allowed = false; + if (is_array($group['pages'][0]['page'])) { + foreach($group['pages'][0]['page'] as $page) { + if (stristr($area, $page)) + $allowed = true; + // echo "$page || $area || $t"; + } + } + $allowed ? $checked = " checked=\"checked\"" : $checked = ""; + $stripped_session = str_replace("/tmp/", "", $tmpfname); + echo"<li id=\"treeitem_{$treeItemID}\" class=\"closed\" title=\"{$area}\"><a name=\"anchor_{$treeItemID}\" style=\"display: none;\"> </a>"; + $idForOnClick = $treeItemID; + $treeItemID++; + echo " <input type=\"checkbox\" class=\"formfld\" id=\"treeitem_{$treeItemID}\" "; + $treeItemID++; + echo "name=\"treeitem_{$treeItemID}\" title=\"{$area}\" onclick=\"getURL('system_groupmanager.php?id={$id}&toggle={$area}&item={$idForOnClick}&session={$stripped_session}', after_request_callback); rotate();\" {$checked}/> "; + echo " <a id=\"treeitem_{$treeItemID}\" "; + $idForScript = $treeItemID; + $treeItemID++; + echo "href=\"#anchor_{$idForOnClick}\" onclick=\"getURL('system_groupmanager.php?id={$id}&toggle={$area}&item={$idForOnClick}&session={$stripped_session}', after_request_callback); rotate();\">{$t}</a></li>\n"; + $treeItemID++; + $script_tag .= "var item = document.getElementById('treeitem_{$idForScript}');\n"; + if ($allowed) { + $script_tag .= "item.style.backgroundImage = \"url('/tree/page-file_play.gif')\";\n"; + } else { + $script_tag .= "item.style.backgroundImage = \"url('/tree/page-file_x.gif')\";\n"; + } + $counter++; + } + } + } + echo "</ul>\n"; + } + } + echo "</ul>\n"; + +?> + </td> + </tr> + <tr> + <td colspan="5"> + <table> + <tr> + <td><input type="checkbox" name="checkall" id="checkall" title="Check/Uncheck all areas" onclick="checkallareas();"/></td> + <td><?=gettext("Check/Uncheck all areas");?></td> + </tr> + <tr> + <td><img src="/tree/page-file_play.gif" alt="" /></td> + <td><?=gettext("Allowed access to area");?></td> + </tr> + <tr> + <td><img src="/tree/page-file_x.gif" alt="" /></td> + <td><?=gettext("Disallowed access to area");?></td> + </tr> + </table> + </td> + </tr> + <tr> + <td colspan="5"> + <?=gettext("Select that pages that this group may access. Members of this group will be able to perform all actions that are possible from each individual web page. Ensure you set access levels appropriately.");?> + </td> + </tr> + <tr> + <td colspan="5"> + <input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> + <?php if (isset($id) && $a_group[$id]): ?> + <input name="id" type="hidden" value="<?=$id;?>" /> + <?php endif;?> + <p> + <span class="vexpl"> + <span class="red"> + <strong><?=gettext("Note");?>: </strong> + </span> + <?=gettext("Pages marked with an * are strongly recommended for every group.");?> + </span> + </p> + </td> + </tr> + </table> + </form> + </td> <!-- end <td class="tabcont"/> --> + </tr> + </table> +<?php +} else { + +?> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td width="35%" class="listhdrr"><?=gettext("Group name");?></td> + <td width="20%" class="listhdrr"><?=gettext("Description");?></td> + <td width="20%" class="listhdrr"><?=gettext("Pages Accessible");?></td> + <td width="10%" class="list"></td> + </tr> +<?php + $i = 0; + foreach($a_group as $group): +?> + <tr> + <td class="listlr" valign="middle" nowrap="nowrap"> + <table border="0" cellpadding="0" cellspacing="0"> + <tr> + <td align="left" valign="middle"> + <?php if($group['scope'] == "user"): ?> + <img src="/themes/<?=$g['theme'];?>/images/icons/icon_system-group.png" alt="Group" title="Group" border="0" height="20" width="20" /> + <?php else: ?> + <img src="/themes/<?=$g['theme'];?>/images/icons/icon_system-group-grey.png" alt="Group" title="Group" border="0" height="20" width="20" /> + <?php endif; ?> + + </td> + <td align="left" valign="middle"> + <? + if($group['name'] != "") + echo htmlspecialchars($group['name']); + else + echo " "; + ?> + </td> + </tr> + </table> + </td> + <td class="listr"> + <? + if($group['description'] != "") + echo htmlspecialchars($group['description']); + else + echo " "; + ?> + </td> + <td class="listbg"> + <?php if(is_array($group['pages'][0])): ?> + <font color="white"><?=count($group['pages'][0]['page']);?></font> + <?php elseif (isset($group['pages'][0])): ?> + <font color="white"><?=$group['pages'][0];?></font> + <?php else: ?> + <font color="white"><?=gettext("NOT SET");?></font> + <?php endif; ?> + </td> + <?php if($group['scope'] == "user"): ?> + <td valign="middle" nowrap class="list"> + <a href="system_groupmanager.php?act=edit&id=<?=$i;?>"> + <img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit group");?>" width="17" height="17" border="0" alt="" /> + </a> + <a href="system_groupmanager.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this group?");?>')"> + <img src="./themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete group");?>" width="17" height="17" border="0" alt="" /> + </a> + </td> + <?php endif; ?> + </tr> +<?php + $i++; + endforeach; +?> + <tr> + <td class="list" colspan="3"></td> + <td class="list"> + <a href="system_groupmanager.php?act=new"> + <img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add group");?>" width="17" height="17" border="0" alt="" /> + </a> + </td> + </tr> + <tr> + <td colspan="3"> + <p> + <?=gettext("Additional webConfigurator admin groups can be added here. Each group can be restricted to specific portions of the webConfigurator. Individually select the desired web pages each group may access. For example, a troubleshooting group could be created which has access only to selected Status and Diagnostics pages.");?> + </p> + <p> + <?=gettext("A group icon that appears grey indicates that it is a system group and thus can't be modified or deleted.");?> + </p> + </td> + </tr> + </table> +</td></tr> +</table> +<?php +} +?> + +<script type="text/javascript"> + window.setTimeout('afterload()', '10'); + function afterload() { + <?php echo $script_tag ?> + } +</script> +<?php include("fend.inc");?> +</body> +</html> diff --git a/packages/authng/www/php/system_usermanager.php b/packages/authng/www/php/system_usermanager.php new file mode 100644 index 00000000..1af4bdc3 --- /dev/null +++ b/packages/authng/www/php/system_usermanager.php @@ -0,0 +1,482 @@ +<?php +/* $Id$ */ +/* ========================================================================== */ +/* + system_usermanager.php + part of pfSense (http://www.pfSense.com) + Copyright (C) 2007 Daniel S. Haischt <me@daniel.stefan.haischt.name> + All rights reserved. + + Based on m0n0wall (http://m0n0.ch/wall) + Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>. + All rights reserved. + */ +/* ========================================================================== */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ +/* ========================================================================== */ + +require("guiconfig.inc"); +// The page title for non-admins +$pgtitle = array(gettext("System"), gettext("User password")); + +if ($userPeer->isSystemAdmin($HTTP_SERVER_VARS['AUTH_USER'])) { + // Page title for main admin + $pgtitle = array(gettext("System"), gettext("User manager")); + + $id = $_GET['id']; + if (isset($_POST['id'])) + $id = $_POST['id']; + + if (!is_array($config['system']['user'])) { + $config['system']['user'] = array(); + } + + admin_users_sort(); + $a_user = &$config['system']['user']; + $t_privs = $a_user[$id]['priv']; + + if ($_GET['act'] == "del" && $_GET['what'] == "user") { + if ($a_user[$_GET['id']]) { + $userdeleted = $a_user[$_GET['id']]['name']; + unset($a_user[$_GET['id']]); + write_config(); + $retval = system_password_configure(); + $savemsg = get_std_save_message($retval); + $savemsg = gettext("User") . " " . $userdeleted . " " . gettext("successfully deleted") . "<br />"; + } + } else if ($_GET['act'] == "del" && $_GET['what'] == "priv") { + if ($t_privs[$_GET['privid']]) { + $privdeleted = $t_privs[$_GET['privid']]['id']; + unset($t_privs[$_GET['privid']]); + write_config(); + $_GET['act'] = "edit"; + $retval = 0; + $savemsg = get_std_save_message($retval); + $savemsg = gettext("Privilege") . " " . $privdeleted . " " . gettext("of user") . " " . $a_user[$_GET['id']]['name'] . " " . gettext("successfully deleted") . "<br />"; + } + } + + if ($_POST) { + unset($input_errors); + $pconfig = $_POST; + + /* input validation */ + if (isset($id) && ($a_user[$id])) { + $reqdfields = explode(" ", "usernamefld"); + $reqdfieldsn = explode(",", "Username"); + } else { + $reqdfields = explode(" ", "usernamefld passwordfld1"); + $reqdfieldsn = explode(",", "Username,Password"); + } + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + if (hasShellAccess($_POST['usernamefld'])) { + if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['usernamefld'])) + $input_errors[] = gettext("The username contains invalid characters."); + } else { + if (preg_match("/[^a-zA-Z0-9\@\.\-_]/", $_POST['usernamefld'])) + $input_errors[] = gettext("The username contains invalid characters."); + } + + if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2'])) + $input_errors[] = gettext("The passwords do not match."); + + if (!$input_errors && !(isset($id) && $a_user[$id])) { + /* make sure there are no dupes */ + foreach ($a_user as $userent) { + if ($userent['name'] == $_POST['usernamefld']) { + $input_errors[] = gettext("Another entry with the same username already exists."); + break; + } + } + } + + if ($pconfig['utype'] <> "system" && !isset($groupindex[$_POST['groupname']])) { + $input_errors[] = gettext("group does not exist, please define the group before assigning users."); + } + + if (isset($config['system']['ssh']['sshdkeyonly']) && + empty($_POST['authorizedkeys'])) { + $input_errors[] = gettext("You must provide an authorized key otherwise you won't be able to login into this system."); + } + + /* if this is an AJAX caller then handle via JSON */ + if (isAjax() && is_array($input_errors)) { + input_errors2Ajax($input_errors); + exit; + } + + if (!$input_errors) { + if (isset($id) && $a_user[$id]) + $userent = $a_user[$id]; + + /* the user did change his username */ + if ($_POST['usernamefld'] <> $_POST['oldusername']) { + $_SERVER['REMOTE_USER'] = $_POST['usernamefld']; + } + + $userent['name'] = $_POST['usernamefld']; + $userent['fullname'] = $_POST['fullname']; + if ($pconfig['utype'] <> "system") { + $userent['groupname'] = $_POST['groupname']; + } + isset($_POST['utype']) ? $userent['scope'] = $_POST['utype'] : $userent['scope'] = "system"; + + if ($_POST['passwordfld1']) + $userent['password'] = crypt($_POST['passwordfld1']); + + if(isset($config['system']['ssh']['sshdkeyonly'])) { + $userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']); + } + + if (isset($id) && $a_user[$id]) + $a_user[$id] = $userent; + else + $a_user[] = $userent; + + write_config(); + $retval = system_password_configure(); + sync_webgui_passwords(); + + pfSenseHeader("system_usermanager.php"); + } + } + + include("head.inc"); + echo $pfSenseHead->getHTML(); +?> + +<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>"> +<?php include("fbegin.inc");?> +<?php if ($input_errors) print_input_errors($input_errors);?> +<?php if ($savemsg) print_info_box($savemsg);?> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td class="tabnavtbl"> +<?php + $tab_array = array(); + $tab_array[] = array(gettext("Users"), true, "system_usermanager.php"); + $tab_array[] = array(gettext("Group"), false, "system_groupmanager.php"); + $tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php"); + display_top_tabs($tab_array); +?> + </td> + </tr> + <tr> + <td class="tabcont"> +<?php + if ($_GET['act'] == "new" || $_GET['act'] == "edit" || $input_errors) { + if ($_GET['act'] == "edit") { + if (isset($id) && $a_user[$id]) { + $pconfig['usernamefld'] = $a_user[$id]['name']; + $pconfig['fullname'] = $a_user[$id]['fullname']; + $pconfig['groupname'] = $a_user[$id]['groupname']; + $pconfig['utype'] = $a_user[$id]['scope']; + $pconfig['authorizedkeys'] = base64_decode($a_user[$id]['authorizedkeys']); + } + } else if ($_GET['act'] == "new") { + /* set this value cause the text field is read only + * and the user should not be able to mess with this + * setting. + */ + $pconfig['utype'] = "user"; + } +?> + <form action="system_usermanager.php" method="post" name="iform" id="iform"> + <div id="inputerrors"></div> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr> + <td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td> + <td width="78%" class="vtable"> + <input name="usernamefld" type="text" class="formfld user" id="usernamefld" size="20" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" <?php if ($pconfig['utype'] == "system") { echo "readonly=\"readonly\" "; }?>/> + <input name="oldusername" type="hidden" id="oldusername" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" /> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncellreq" rowspan="2"><?=gettext("Password");?></td> + <td width="78%" class="vtable"> + <input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" value="" /> + </td> + </tr> + <tr> + <td width="78%" class="vtable"> + <input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" value="" /> <?= gettext("(confirmation)"); ?> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Full name");?></td> + <td width="78%" class="vtable"> + <input name="fullname" type="text" class="formfld unknown" id="fullname" size="20" value="<?=htmlspecialchars($pconfig['fullname']);?>" <?php if ($pconfig['utype'] == "system") { echo "readonly=\"readonly\" "; }?>/> + <br /> + <?=gettext("User's full name, for your own information only");?> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("User type");?></td> + <td width="78%" class="vtable"> + <input name="utype" type="text" class="formfld unknown" id="utype" size="20" value="<?=htmlspecialchars($pconfig['utype']);?>" readonly="readonly" /> + <br /> + <?=gettext("Indicates whether this is a system (aka non-deletable) user or a user created by a particular user.");?> + </td> + </tr> + <?php if (isSystemAdmin($HTTP_SERVER_VARS['AUTH_USER'])): ?> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("User Privileges");?></td> + <td width="78%" class="vtable"> + <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td width="5%" class="listhdrr"><?=gettext("ID");?></td> + <td width="30%" class="listhdrr"><?=gettext("Name");?></td> + <td width="40%" class="listhdrr"><?=gettext("Description");?></td> + <td width="5%" class="list"></td> + </tr> + + <?php if(is_array($t_privs)): ?> + <?php $i = 0; foreach ($t_privs as $priv): ?> + <?php if($priv['id'] <> ""): ?> + <tr> + <td class="listlr" <?php if($a_user[$id]['scope'] == "user") echo "ondblclick=\"document.location='system_usermanager_edit.php?id={$i}&userid={$id}&useract={$_GET['act']}';\""; ?>> + <?=htmlspecialchars($priv['id']);?> + </td> + <td class="listlr" <?php if($a_user[$id]['scope'] == "user") echo "ondblclick=\"document.location='system_usermanager_edit.php?id={$i}&userid={$id}&useract={$_GET['act']}';\""; ?>> + <?=htmlspecialchars($priv['name']);?> + </td> + <td class="listbg" <?php if($a_user[$id]['scope'] == "user") echo "ondblclick=\"document.location='system_usermanager_edit?id={$i}&userid={$id}&useract={$_GET['act']}';\""; ?>> + <font color="#FFFFFF"><?=htmlspecialchars($priv['descr']);?> </font> + </td> + <td valign="middle" nowrap class="list"> + <?php if($a_user[$id]['scope'] == "user"): ?> + <table border="0" cellspacing="0" cellpadding="1"> + <tr> + <td valign="middle"><a href="system_usermanager_edit.php?id=<?=$i;?>&userid=<?= $id ?>&useract=<?= $_GET['act'] ?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="" /></a></td> + <td valign="middle"><a href="system_usermanager.php?act=del&privid=<?=$i;?>&what=priv&id=<?= $id ?>" onclick="return confirm('<?=gettext("Do you really want to delete this mapping?");?>')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="" /></a></td> + </tr> + </table> + <?php endif; ?> + </td> + </tr> + <?php endif; ?> + <?php $i++; endforeach; ?> + <?php endif; ?> + + <?php if($a_user[$id]['scope'] == "user"): ?> + <tr> + <td class="list" colspan="3"></td> + <td class="list"> + <table border="0" cellspacing="0" cellpadding="1"> + <tr> + <td valign="middle"><a href="system_usermanager_edit.php?userid=<?= $id ?>&useract=<?= $_GET['act'] ?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="" /></a></td> + </tr> + </table> + </td> + </tr> + <?php endif; ?> + </table> + </td> + </tr> + <?php endif; ?> + <?php if (isset($config['system']['ssh']['sshdkeyonly'])): ?> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Authorized keys");?></td> + <td width="78%" class="vtable"> + <textarea name="authorizedkeys" cols="65" rows="7" id="authorizedkeys" class="formfld_cert" wrap="off"><?=htmlspecialchars($pconfig['authorizedkeys']);?></textarea> + <br /> + <?=gettext("Paste an authorized keys file here.");?> + </td> + </tr> + <?php endif; ?> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Group Name");?></td> + <td width="78%" class="vtable"> + <select name="groupname" class="formselect" id="groupname" <?php if ($pconfig['utype'] == "system") { echo "disabled=\"disabled\" "; } ?>> + <?php foreach ($config['system']['group'] as $group): ?> + <option value="<?=$group['name'];?>" <?php if ($group['name'] == $pconfig['groupname']) { echo "selected"; } ?>> + <?=htmlspecialchars($group['name']);?> + </option> + <?php endforeach;?> + </select> + <br /> + <?=gettext("The admin group to which this user is assigned.");?> + </td> + </tr> + <tr> + <td width="22%" valign="top"> </td> + <td width="78%"> + <input id="submit" name="save" type="submit" class="formbtn" value="Save" /> + <?php if (isset($id) && $a_user[$id]): ?> + <input name="id" type="hidden" value="<?=$id;?>" /> + <?php endif;?> + </td> + </tr> + </table> + </form> +<?php + } else { +?> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td width="35%" class="listhdrr">Username</td> + <td width="20%" class="listhdrr">Full name</td> + <td width="20%" class="listhdrr">Group</td> + <td width="10%" class="list"></td> + </tr> +<?php + $i = 0; + foreach($a_user as $userent): +?> + <tr ondblclick="document.location='system_usermanager.php?act=edit&id=<?=$i;?>'"> + <td class="listlr"> + <table border="0" cellpadding="0" cellspacing="0"> + <tr> + <td align="left" valign="middle"> + <?php if($userent['scope'] == "user"): ?> + <img src="/themes/<?=$g['theme'];?>/images/icons/icon_system-user.png" alt="User" title="User" border="0" height="20" width="20" /> + <?php else: ?> + <img src="/themes/<?=$g['theme'];?>/images/icons/icon_system-user-grey.png" alt="User" title="User" border="0" height="20" width="20" /> + <?php endif; ?> + + </td> + <td align="left" valign="middle"> + <?=htmlspecialchars($userent['name']);?> + </td> + </tr> + </table> + </td> + <td class="listr"><?=htmlspecialchars($userent['fullname']);?> </td> + <td class="listbg"> + <font color="white"><?=htmlspecialchars($userent['groupname']);?></font> + </td> + <td valign="middle" nowrap class="list"> + <a href="system_usermanager.php?act=edit&id=<?=$i;?>"> + <img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="edit user" alt="edit user" width="17" height="17" border="0" /> + </a> + <?php if($userent['scope'] == "user"): ?> + + <a href="system_usermanager.php?act=del&what=user&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this User?");?>')"> + <img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="delete user" alt="delete user" width="17" height="17" border="0" /> + </a> + <?php endif; ?> + </td> + </tr> +<?php + $i++; + endforeach; +?> + <tr> + <td class="list" colspan="3"></td> + <td class="list"> + <a href="system_usermanager.php?act=new"> + <img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="add user" alt="add user" width="17" height="17" border="0" /> + </a> + </td> + </tr> + <tr> + <td colspan="3"> + <p> + <?=gettext("Additional webConfigurator users can be added here. User permissions are determined by the admin group they are a member of.");?> + </p> + <p> + <?=gettext("An user icon that appears grey indicates that it is a system user and thus it's only possible to modified a subset of the regular user data. Additionally such an user can't be deleted.");?> + </p> + </td> + </tr> + </table> +<?php + } +?> + </td> + </tr> +</table> +<?php +} else { // end of admin user code, start of normal user code + if (isset($_POST['save'])) { + unset($input_errors); + + /* input validation */ + $reqdfields = explode(" ", "passwordfld1"); + $reqdfieldsn = explode(",", "Password"); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + if ($_POST['passwordfld1'] != $_POST['passwordfld2']) + $input_errors[] = "The passwords do not match."; + + if (!$input_errors) { + // all values are okay --> saving changes + $config['system']['user'][$userindex[$HTTP_SERVER_VARS['AUTH_USER']]]['password'] = crypt(trim($_POST['passwordfld1'])); + + write_config(); + + sync_webgui_passwords(); + + $retval = system_password_configure(); + $savemsg = get_std_save_message($retval); + $savemsg = "Password successfully changed<br />"; + } + } +?> + +<?php + include("head.inc"); + echo $pfSenseHead->getHTML(); +?> +<?php include("fbegin.inc");?> +<?php if ($input_errors) print_input_errors($input_errors);?> +<?php if ($savemsg) print_info_box($savemsg);?> + <body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>"> + <form action="system_usermanager.php" method="post" name="iform" id="iform"> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr> + <td colspan="2" valign="top" class="listtopic"><?=$HTTP_SERVER_VARS['AUTH_USER']?>'s Password</td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell" rowspan="2">Password</td> + <td width="78%" class="vtable"> + <input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" /> + </td> + </tr> + <tr> + <td width="78%" class="vtable"> + <input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" /> + <?=gettext("(confirmation)");?> + <br /> + <span class="vexpl"><?=gettext("Select a new password");?></span> + </td> + </tr> + <tr> + <td width="22%" valign="top"> </td> + <td width="78%"> + <input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> + </td> + </tr> + </table> + </form> +<?php +} // end of normal user code +?> + +<?php include("fend.inc");?> +</body> +</html> diff --git a/packages/authng/www/php/system_usermanager_edit.php b/packages/authng/www/php/system_usermanager_edit.php new file mode 100644 index 00000000..25dc2ac3 --- /dev/null +++ b/packages/authng/www/php/system_usermanager_edit.php @@ -0,0 +1,294 @@ +<?php +/* $Id$ */ +/* + system_usermanager_edit.php + + Copyright (C) 2006 Daniel S. Haischt. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +$pgtitle = array(gettext("System"), + gettext("User manager"), + gettext("Edit Privilege")); + +require("guiconfig.inc"); + +/* + The following code presumes, that the following XML structure exists or + if it does not exist, it will be created. + + <priv> + <id>fooid</id> + <name>foo</name> + <descr>foo desc</descr> + </priv> + <priv> + <id>barid</id> + <name>bar</name> + <descr>bar desc</descr> + </priv> +*/ + +$useract = $_GET['useract']; +if (isset($_POST['useract'])) + $useract = $_POST['useract']; + +/* USERID must be set no matter whether this is a new entry or an existing entry */ +$userid = $_GET['userid']; +if (isset($_POST['userid'])) + $userid = $_POST['userid']; + +/* ID is only set if the user wants to edit an existing entry */ +$id = $_GET['id']; +if (isset($_POST['id'])) + $id = $_POST['id']; + +if (empty($config['system']['user'][$userid])) { + pfSenseHeader("system_usermanager.php?id={$userid}&act={$_GET['useract']}"); + exit; +} + +if (!is_array($config['system']['user'][$userid]['priv'])) { + $config['system']['user'][$userid]['priv'] = array(); +} + +$t_privs = &$config['system']['user'][$userid]['priv']; + +if (isset($id) && $t_privs[$id]) { + $pconfig['pid'] = $t_privs[$id]['id']; + $pconfig['pname'] = $t_privs[$id]['name']; + $pconfig['descr'] = $t_privs[$id]['descr']; +} else { + $pconfig['pid'] = $_GET['pid']; + $pconfig['pname'] = $_GET['pname']; + $pconfig['descr'] = $_GET['descr']; +} + +if ($_POST) { + + unset($input_errors); + $pconfig = $_POST; + + /* input validation */ + $reqdfields = explode(" ", "pid pname"); + $reqdfieldsn = explode(",", "ID, Privilege Name"); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + /* check for overlaps */ + foreach ($t_privs as $priv) { + if (isset($id) && ($t_privs[$id]) && ($t_privs[$id] === $priv)) { + continue; + } + if ($priv['id'] == $pconfig['pid']) { + $input_errors[] = gettext("This privilege ID already exists."); + break; + } + } + + if (hasShellAccess($userindex[$userid]['name']) || + isAllowedToCopyFiles($userindex[$userid]['name'])) { + if (preg_match("/[^a-zA-Z0-9\.\-_]/", $userindex[$userid]['name'])) + $input_errors[] = gettext("The username contains invalid characters " . + "((this means this user can't be used to create" . + " a shell account)."); + } + + /* if this is an AJAX caller then handle via JSON */ + if(isAjax() && is_array($input_errors)) { + input_errors2Ajax($input_errors); + exit; + } + + if (!$input_errors) { + $priv = array(); + $priv['id'] = $pconfig['pid']; + $priv['name'] = $pconfig['pname']; + $priv['descr'] = $pconfig['descr']; + + if (isset($id) && $t_privs[$id]) + $t_privs[$id] = $priv; + else + $t_privs[] = $priv; + + if ($priv['id'] == "hasshell") { + assignUID($user['name']); + assignGID($user['groupname']); + } + + write_config(); + + $retval = 0; + config_lock(); + config_unlock(); + + $savemsg = get_std_save_message($retval); + + pfSenseHeader("system_usermanager.php?id={$userid}&act={$useract}"); + exit; + } +} + +/* if ajax is calling, give them an update message */ +if(isAjax()) + print_info_box_np($savemsg); + +include("head.inc"); +/* put your custom HTML head content here */ +/* using some of the $pfSenseHead function calls */ + +$jscriptstr = <<<EOD +<script type="text/javascript"> +<!-- + + var privs = new Array(); + + +EOD; + +$privs =& getSystemPrivs(); + +if (is_array($privs)) { + $id = 0; + + $jscriptstr .= "privs[{$id}] = new Object();\n"; + $jscriptstr .= "privs[{$id}]['id'] = 'custom';\n"; + $jscriptstr .= "privs[{$id}]['name'] = '*** Custom privilege ***';\n"; + $jscriptstr .= "privs[{$id}]['desc'] = 'This is your own, user defined privilege that you may change according to your requirements.';\n"; + $id++; + + foreach($privs as $priv){ + $jscriptstr .= "privs[{$id}] = new Object();\n"; + $jscriptstr .= "privs[{$id}]['id'] = '{$priv['id']}';\n"; + $jscriptstr .= "privs[{$id}]['name'] = '{$priv['name']}';\n"; + $jscriptstr .= "privs[{$id}]['desc'] = '{$priv['desc']}';\n"; + $id++; + } +} + +$jscriptstr .= <<<EOD + function setTextFields() { + var idx = document.iform.sysprivs.selectedIndex; + var value = document.iform.sysprivs.options[idx].value; + + for (var i = 0; i < privs.length; i++) { + if (privs[i]['id'] == value && privs[i]['id'] != 'custom') { + document.iform.pid.value = privs[i]['id']; + document.iform.pid.readOnly = true; + document.iform.pname.value = privs[i]['name']; + document.iform.pname.readOnly = true; + document.iform.descr.value = privs[i]['desc']; + document.iform.descr.readOnly = true; + break; + } else if (privs[i]['id'] == value) { + document.iform.pid.value = privs[i]['id']; + document.iform.pid.readOnly = false; + document.iform.pname.value = privs[i]['name']; + document.iform.pname.readOnly = false; + document.iform.descr.value = privs[i]['desc']; + document.iform.descr.readOnly = false; + break; + } + } + } + +//--> +</script> + +EOD; + +$pfSenseHead->addScript($jscriptstr); +echo $pfSenseHead->getHTML(); + +?> + +<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>"> +<?php include("fbegin.inc"); ?> +<?php if ($input_errors) print_input_errors($input_errors); ?> +<?php if ($savemsg) print_info_box($savemsg); ?> + <form action="system_usermanager_edit.php" method="post" name="iform" id="iform"> + <div id="inputerrors"></div> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr> + <td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td> + <td width="78%" class="vtable"> + <select name="sysprivs" id="sysprivs" class="formselect" onchange="setTextFields();"> + <option value="custom">*** Custom privilege ***</option> + <?php + $privs =& getSystemPrivs(); + + if (is_array($privs)) { + foreach($privs as $priv){ + if (isset($config['system']['ssh']['sshdkeyonly']) && $priv['name'] <> "copyfiles") + echo "<option value=\"{$priv['id']}\">${priv['name']}</option>"; + else if (empty($config['system']['ssh']['sshdkeyonly'])) + echo "<option value=\"{$priv['id']}\">${priv['name']}</option>"; + } + } + ?> + </select><br /> + (If you do not want to define your own privilege, you may + select one from this list) + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncellreq"><?=gettext("Privilege Identifier");?></td> + <td width="78%" class="vtable"> + <input name="pid" type="text" class="formfld unknown" id="pid" size="30" value="<?=htmlspecialchars($pconfig['pid']);?>" /> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncellreq"><?=gettext("Privilege Name");?></td> + <td width="78%" class="vtable"> + <input name="pname" type="text" class="formfld unknown" id="pname" size="30" value="<?=htmlspecialchars($pconfig['pname']);?>" /> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td> + <td width="78%" class="vtable"> + <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>" /> + <br /> <span class="vexpl"><?=gettext("You may enter a description here + for your reference (not parsed).");?></span></td> + </tr> + <tr> + <td width="22%" valign="top"> </td> + <td width="78%"> + <input id="submitt" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> + <input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" /> + <?php if (isset($id) && $t_privs[$id]): ?> + <input name="id" type="hidden" value="<?=$id;?>" /> + <?php endif; ?> + <?php if (isset($userid)): ?> + <input name="userid" type="hidden" value="<?=$userid;?>" /> + <?php endif; ?> + <?php if (isset($useract)): ?> + <input name="useract" type="hidden" value="<?=$useract;?>" /> + <?php endif; ?> + </td> + </tr> + </table> + </form> +<?php include("fend.inc"); ?> +</body> +</html> diff --git a/packages/authng/www/php/system_usermanager_settings.php b/packages/authng/www/php/system_usermanager_settings.php new file mode 100755 index 00000000..5853fab4 --- /dev/null +++ b/packages/authng/www/php/system_usermanager_settings.php @@ -0,0 +1,110 @@ +<?php +/* $Id$ */ +/* + part of pfSense (http://www.pfsense.org/) + + Copyright (C) 2007 Bill Marquette <bill.marquette@gmail.com> + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ +require("guiconfig.inc"); + +$pconfig['session_timeout'] = &$config['system']['webgui']['session_timeout']; + +// Page title for main admin +$pgtitle = array(gettext("System"), gettext("User manager settings")); + +if ($_POST) { + unset($input_errors); + + /* input validation */ + $reqdfields = explode(" ", "session_timeout"); + $reqdfieldsn = explode(",", "Session Timeout"); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + if ($_POST['session_timeout'] != "" && !is_numeric($_POST['session_timeout'])) + $input_errors[] = gettext("Session timeout must be an integer with value 0 or greater."); + + /* if this is an AJAX caller then handle via JSON */ + if (isAjax() && is_array($input_errors)) { + input_errors2Ajax($input_errors); + exit; + } + + + if (!$input_errors) { + $pconfig['session_timeout'] = $_POST['session_timeout']; + + write_config(); + pfSenseHeader("system_usermanager_settings.php"); + } +} + +include("head.inc"); +echo $pfSenseHead->getHTML(); +?> + +<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>"> +<?php include("fbegin.inc");?> +<?php if ($input_errors) print_input_errors($input_errors);?> +<?php if ($savemsg) print_info_box($savemsg);?> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td class="tabnavtbl"> +<?php + $tab_array = array(); + $tab_array[] = array(gettext("Users"), false, "system_usermanager.php"); + $tab_array[] = array(gettext("Group"), false, "system_groupmanager.php"); + $tab_array[] = array(gettext("Settings"), true, "system_usermanager_settings.php"); + display_top_tabs($tab_array); +?> + </td> + <tr> + <td> + <div id="mainarea"> + <form id="iform" name="iform" action="system_usermanager_settings.php" method="post"> + <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0"> + <tr> + <td width="22%" valign="top" class="vncell">Session Timeout</td> + <td width="78%" class="vtable"> <input name="session_timeout" id="session_timeout" type="text"size="20" class="formfld unknown" value="<?=htmlspecialchars($pconfig['session_timeout']);?>" /> + <br /> + <?=gettext("Time in minutes to expire idle management sessions.");?><br /> + </td> + </tr> + + <tr> + <td width="22%" valign="top"> </td> + <td width="78%"> <input id="submit" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> + </td> + </tr> + </table> + </form> + </div> + </td> + </tr> + </table> + +<?php include("fend.inc");?> +</body> +</html> |