From fab7ff44cbc8d2faf0d0a270d8edb8d65807557e Mon Sep 17 00:00:00 2001 From: Bill Marquette Date: Fri, 13 Apr 2007 03:26:35 +0000 Subject: Backport usermanager code from HEAD so I can get it in the snaps and start testing it properly There's still some CSS/HTML fixes needed but the code seems to work --- usr/local/www/fbegin.inc | 4 +- usr/local/www/guiconfig.inc | 22 +- usr/local/www/headjs.php | 156 +++++ usr/local/www/system_groupmanager.php | 798 ++++++++++++++++++++++++++ usr/local/www/system_usermanager.php | 478 +++++++++++++++ usr/local/www/system_usermanager_settings.php | 111 ++++ 6 files changed, 1567 insertions(+), 2 deletions(-) create mode 100644 usr/local/www/headjs.php create mode 100644 usr/local/www/system_groupmanager.php create mode 100644 usr/local/www/system_usermanager.php create mode 100755 usr/local/www/system_usermanager_settings.php (limited to 'usr') diff --git a/usr/local/www/fbegin.inc b/usr/local/www/fbegin.inc index dc8f5bd..d4d4674 100755 --- a/usr/local/www/fbegin.inc +++ b/usr/local/www/fbegin.inc @@ -122,11 +122,13 @@ require_once("notices.inc");
  • Advanced
  • Firmware
  • General Setup
  • +
  • Logout
  • Packages
  • Setup wizard
  • Static routes
  • +
  • User Manager
  • @@ -280,4 +282,4 @@ require_once("notices.inc"); echo ""; } -?> \ No newline at end of file +?> diff --git a/usr/local/www/guiconfig.inc b/usr/local/www/guiconfig.inc index a6c1c00..b140bf4 100755 --- a/usr/local/www/guiconfig.inc +++ b/usr/local/www/guiconfig.inc @@ -41,7 +41,7 @@ if (!$omit_nocacheheaders) { /* Include authentication routines */ /* THIS MUST BE ABOVE ALL OTHER CODE */ -require_once("auth.inc"); +require_once("authgui.inc"); /* parse the configuration and include all configuration functions */ require_once("config.inc"); @@ -305,6 +305,26 @@ function captiveportal_users_sort() { usort($config['captiveportal']['user'], "cpusercmp"); } +function admin_groups_sort() { + global $g, $config; + + function cpusercmp($a, $b) { + return strcasecmp($a['name'], $b['name']); + } + + usort($config['system']['group'], "cpusercmp"); +} + +function admin_users_sort() { + global $g, $config; + + function cpusercmp($a, $b) { + return strcasecmp($a['name'], $b['name']); + } + + usort($config['system']['user'], "cpusercmp"); +} + /* sort by interface only, retain the original order of rules that apply to the same interface */ function filter_rules_sort() { diff --git a/usr/local/www/headjs.php b/usr/local/www/headjs.php new file mode 100644 index 0000000..e2b4e20 --- /dev/null +++ b/usr/local/www/headjs.php @@ -0,0 +1,156 @@ +<\/div>\"; + new Insertion.Before('submit', to_insert); + } + } + + function submit_form(e){ + // debugging helper + //alert(Form.serialize($('iform'))); + + if($('inputerrors')) + $('inputerrors').innerHTML = ''; + + /* dsh: Introduced because pkg_edit tries to set some hidden fields + * if executing submit's onclick event. Tho click gets deleted + * by Ajax. Hence using onkeydown instead. + */ + if($('submit') && $('submit').onkeydown) + $('submit').onkeydown(); + if($('submit')) + $('submit').style.visibility = 'hidden'; + if($('cancelbutton')) + $('cancelbutton').style.visibility = 'hidden'; + $('loading').style.visibility = 'visible'; + // submit the form using Ajax + "; + + + isset($HTTP_SERVER_VARS['AUTH_USER']) ? $scriptName = split("/", $_SERVER["SCRIPT_FILENAME"]) : $scriptName = split("/", "/index.php"); + isset($HTTP_SERVER_VARS['AUTH_USER']) ? $loggedin = "var isLoggedIn = true;" : $loggedin = "var isLoggedIn = false;"; + $scriptElms = count($scriptName); + $scriptName = $scriptName[$scriptElms-1]; + $realScriptName = $_SERVER["SCRIPT_NAME"]; + + $headjs .= " + {$loggedin} + + if (! isLoggedIn) { + var newInput = document.createElement('input'); + newInput.setAttribute('id', 'scriptname'); + newInput.setAttribute('name', 'scriptname'); + newInput.setAttribute('value', '$realScriptName'); + newInput.setAttribute('type', 'hidden'); + + $('iform').appendChild(newInput); + } + + new Ajax.Request('{$scriptName}', { + method : 'post', + parameters : Form.serialize($('iform')), + onSuccess : formSubmitted, + onFailure : formFailure + }); + } + + function formSubmitted(resp) { + var responseText = resp.responseText; + + // debugging helper + //alert(responseText); + + if(responseText.indexOf('html') > 0) { + /* somehow we have been fed an html page! */ + //alert('Somehow we have been fed an html page! Forwarding to /.'); + document.location.href = '/'; + } + + eval(responseText); + } + + /* this function will be called if an HTTP error will be triggered */ + function formFailure(resp) { + alert('An error occured while saving the data ' + resp.responseText); + } + + function showajaxmessage(message) { + var message_html; + + if (message == '') { + NiftyCheck(); + Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\"); + Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\"); + + if($('submit')) + $('submit').style.visibility = 'visible'; + if($('cancelbutton')) + $('cancelbutton').style.visibility = 'visible'; + if($('loading')) + $('loading').style.visibility = 'hidden'; + + return; + } + + message_html = '
    '; + message_html += '
    '; + message_html += ' +
    '; + message_html += '   '; + message_html += ''; + message_html += '<\/td>'; + message_html += '' + message + '<\/b><\/font><\/td>'; + + if(message.indexOf('apply') > 0) { + message_html += ''; + message_html += ''; + message_html += '<\/td>'; + } + + message_html += '<\/tr><\/table><\/div><\/td><\/table>
    '; + $('inputerrors').innerHTML = message_html; + + NiftyCheck(); + Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\"); + Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\"); + + if($('submit')) + $('submit').style.visibility = 'visible'; + if($('cancelbutton')) + $('cancelbutton').style.visibility = 'visible'; + if($('loading')) + $('loading').style.visibility = 'hidden'; + if($('inputerrors')) + window.scrollTo(0, 0); + if($('inputerrors')) + new Effect.Shake($('inputerrors')); + } + "; + + return $headjs; +} + +?> diff --git a/usr/local/www/system_groupmanager.php b/usr/local/www/system_groupmanager.php new file mode 100644 index 0000000..ca63f9d --- /dev/null +++ b/usr/local/www/system_groupmanager.php @@ -0,0 +1,798 @@ +. + All rights reserved. + + Copyright (C) 2005 Paul Taylor . + All rights reserved. + + Copyright (C) 2003-2005 Manuel Kasper . + 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 "
  • $a
      "; + $treeItemID++; + walkArea($title, + $a, + $aa, + $id, + $counter, + $script_tag, + $tmpfname, + $group); + echo "
    \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 "
  •  "; + $idForOnClick = $treeItemID; + $treeItemID++; + echo " "; + $treeItemID++; + echo "{$a}
  • \n"; + $idForScript = $treeItemID; + $treeItemID++; + +//echo "$script_tag
    "; + $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 = <<= 0) { + document.iform.elements[i].checked = true; + document.iform.elements[i].click(); + } + } + } + +EOD; + +// XXX: billm TODO +//$pfSenseHead->addScript("\n"); +//$pfSenseHead->addLink(""); +//echo $pfSenseHead->getHTML(); + +?> +"> + + + + + + + + + + +
    + +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    + + + +
    + +
    + + + +
    + +
    + +
    + +
    + + $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 "\n"; + eval($tmp); + } + + echo "" . gettext("webConfigurator") . "
      \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 "
    • $title
        "; + $treeItemID++; + if (is_array($m) && count($m) > 0) { + foreach($m as $t => $area) { + if (is_array($area) && count($area) > 0) { + echo "
      • $t
          "; + $treeItemID++; + walkArea("{$title}_{$t}", + $t, + $area, + $id, + $counter, + $script_tag, + $tmpfname, + $group); + echo "
        \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"
      •  "; + $idForOnClick = $treeItemID; + $treeItemID++; + echo "  "; + echo " {$t}
      • \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 "
      \n"; + } + } + echo "
    \n"; + +?> +
    + + + + + + + + + + + + + +
    +
    + +
    + " /> + + + +

    + + + : + + + +

    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + +
    + + Group + + Group + +   + + +
    +
    + + + + + + + + + + + + " width="17" height="17" border="0" alt="" /> + + ')"> + " width="17" height="17" border="0" alt="" /> + +
    + + " width="17" height="17" border="0" alt="" /> + +
    +

    + +

    +

    + +

    +
    +
    + + + + + + diff --git a/usr/local/www/system_usermanager.php b/usr/local/www/system_usermanager.php new file mode 100644 index 0000000..19a69ec --- /dev/null +++ b/usr/local/www/system_usermanager.php @@ -0,0 +1,478 @@ +. + All rights reserved. + + Copyright (C) 2003-2005 Manuel Kasper . + 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 (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") . "
    "; + } + } 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") . "
    "; + } + } + + 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(); +?> + +"> + + + + + + + + + + +
    + +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + /> + +
    + +
    +   +
    + /> +
    + +
    + +
    + +
    + + + + + + + + + + + ""): ?> + + + + + + + + + + + + + + + + +
    > + + > + + > +   + + + + + + + +
    ')">
    + +
    + + + + +
    +
    +
    + +
    + +
    + +
    + +
      + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + +
    UsernameFull nameGroup
    + + + + + +
    + + User + + User + +   + + +
    +
      +   + + + edit user + + +   + ')"> + delete user + + +
    + + add user + +
    +

    + +

    +

    + +

    +
    + +
    + 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
    "; + } + } +?> + +getHTML(); +?> + + + + "> +
    + + + + + + + + + + + + + + + +
    's Password
    Password + +
    + +   +
    + +
      + " /> +
    +
    + + + + + diff --git a/usr/local/www/system_usermanager_settings.php b/usr/local/www/system_usermanager_settings.php new file mode 100755 index 0000000..c62771c --- /dev/null +++ b/usr/local/www/system_usermanager_settings.php @@ -0,0 +1,111 @@ + + 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"); +// XXX billm FIXME +//echo $pfSenseHead->getHTML(); +?> + +"> + + + + + + + + + +
    + +
    +
    +
    + + + + + + + + + + +
    Session Timeout +
    +
    +
      " /> +
    +
    +
    +
    + + + + -- cgit v1.1