/** * Verify password of current user * * Return: * * FALSE: password error * TRUE: password ok * * @global resource $SUMO * @author Alberto Basso <*****@*****.**> */ function sumo_verify_datasource_authentication($id = FALSE) { global $SUMO; if (!$_SESSION['ds_connect'][$id]) { $ldap = sumo_get_datasource_info($id); if (!$ldap['port']) { $ldap['port'] = 389; } // $ds is a valid link identifier for a directory server $ds = ldap_connect($ldap['host'], $ldap['port']); $dn = $ldap['ldap_base']; if ($ds && $ldap['host']) { // Encryption type switch ($SUMO['user']['datasource_enctype']) { case 'md5': $password = md5($_SESSION['user']['password']); break; case 'crc32': $password = crc32($_SESSION['user']['password']); break; default: $password = $_SESSION['user']['password']; break; } $sr = ldap_search($ds, $dn, "uid=" . $SUMO['user']['user']); $info = ldap_get_entries($ds, $sr); $ldapbind = ldap_bind($ds, $info[0]["dn"], $password); // verify binding $_SESSION['ds_connect'][$id] = $ldapbind && $info["count"] == 1 ? true : false; ldap_unbind($ds); ldap_close($ds); } else { sumo_write_log('W00047X', $ldap['name'], '0,1', 2); } } return $_SESSION['ds_connect'][$id] ? true : false; }
/** * Delete datasource * * @return boolean * @author Alberto Basso <*****@*****.**> */ function sumo_delete_datasource($id = 0) { $id = intval($id); if ($id > 1) { global $SUMO; $datasource = sumo_get_datasource_info($id, FALSE); $SUMO['DB']->CacheFlush(); $query0 = "DELETE FROM " . SUMO_TABLE_DATASOURCES . " \n \t\t \t WHERE id=" . $id; $query1 = "SELECT * FROM " . SUMO_TABLE_DATASOURCES . " \n \t\t WHERE id=" . $id; $SUMO['DB']->Execute($query0); $SUMO['DB']->Execute($query1); // verify if deleted: $rs = $SUMO['DB']->Execute($query1); // if deleted: if ($rs->PO_RecordCount(SUMO_TABLE_DATASOURCES, "id=" . $id) == 0) { sumo_write_log('I09001X', array($datasource['name'], $id, $SUMO['user']['user']), '0,1', 3, 'system', FALSE); return TRUE; } else { return FALSE; } } else { return FALSE; } }
<?php /** * SUMO MODULE: Network | View Datasource * * @version 0.5.0 * @link http://sumoam.sourceforge.net SUMO Access Manager * @author Alberto Basso <*****@*****.**> * @copyright Copyright © 2003-2009, Alberto Basso * @package SUMO * @category Console */ $tab = sumo_get_datasource_info($_GET['id'], FALSE); $msg = sumo_get_simple_rand_string(4, "123456789"); $delete = "<div class='sub-module-icon' " . "onmouseover='this.style.outline=\"1px solid #999999\";this.style.background=\"#FFFFFF\"' " . "onmouseout='this.style.outline=\"\";this.style.background=\"\"'>" . "<a href=\"javascript:" . "sumo_show_message('msg{$msg}', '" . htmlspecialchars(sumo_get_message('AreYouSureDeleteDataSource', $tab['name'])) . "', \n\t\t\t\t\t\t\t 'h', 0, \n\t\t\t\t\t\t\t '" . base64_encode(sumo_get_form_req('', 'erase_datasource', 'id=' . $tab['id'])) . "',\n\t\t\t\t\t\t\t '" . base64_encode('') . "',\n\t\t\t\t\t\t\t '" . base64_encode("<input type='button' value='" . $language['Cancel'] . "' onclick='javascript:sumo_remove_window(\"msg{$msg}\");' class='button'>") . "',\n\t\t\t\t\t\t\t '" . base64_encode("<input type='submit' value='" . $language['Ok'] . "' onclick='javascript:sumo_remove_window(\"msg{$msg}\");' class='button'>") . "'\n\t\t\t\t\t\t\t);\">" . "<img src='themes/" . $SUMO['page']['theme'] . "/images/modules/network/remove_datasource.png' vspace='4'><br>" . $language['Remove'] . "</a>" . "</div>"; $tpl = array('GET:Theme' => $SUMO['page']['theme'], 'GET:MenuModule' => $tpl['GET:MenuModule'], 'GET:DataSourceName' => $tab['name'], 'GET:DataSourceType' => $language[$tab['type']], 'GET:DataSourceHost' => $tab['host'], 'GET:DataSourcePort' => $tab['port'], 'GET:DataSourceUser' => $tab['username'], 'GET:DataSourcePassword' => $tab['password'] != '' ? '*****' : '', 'GET:DBName' => $tab['db_name'], 'GET:DBTable' => $tab['db_table'], 'GET:DBFieldUser' => $tab['db_field_user'], 'GET:DBFieldPassword' => $tab['db_field_password'], 'GET:EncType' => $tab['enctype'], 'GET:LDAPBase' => $tab['ldap_base'], 'LINK:Add' => sumo_verify_permissions(4, 'sumo') ? sumo_get_action_icon("network", "add_datasource", "network.content", "?module=network&action=new_datasource&decoration=false") : sumo_get_action_icon("", "add_datasource"), 'LINK:Edit' => sumo_verify_permissions(4, 'sumo') && $tab['id'] > 1 ? sumo_get_action_icon("network", "edit_datasource", "network.content", "?module=network&action=edit_datasource&id=" . $tab['id'] . "&decoration=false") : sumo_get_action_icon("", "edit_datasource"), 'LINK:Remove' => sumo_verify_permissions(4, 'sumo') && $tab['id'] > 1 ? $delete : sumo_get_action_icon("", "remove_datasource"), 'BUTTON:Back' => "<input type='button' class='button-red' value='" . $language["Back"] . "' onclick='javascript:sumo_ajax_get(\"network.content\",\"?module=network&action=dlist&decoration=false\");'>");
$field['firstname'] = sumo_search_composer($_SESSION['search_users_list'], 'firstname'); $field['lastname'] = sumo_search_composer($_SESSION['search_users_list'], 'lastname'); $field['email'] = sumo_search_composer($_SESSION['search_users_list'], 'email'); $search = $group_query ? " AND " : " WHERE "; $operand = count($field['lastname'][1]) > 1 ? 'AND' : 'OR'; if ($field['user'][0] && $field['firstname'][0] && $field['lastname'][0]) { $search = $search . "((" . $field['user'][0] . ") OR (" . $field['email'][0] . ") OR " . "((" . $field['firstname'][0] . ") " . $operand . " (" . $field['lastname'][0] . ")) OR " . "(" . $field['usergroup'][0] . "))"; } else { $search = ''; } } $query = "SELECT * FROM " . SUMO_TABLE_USERS . " " . $group_query . " " . $search . " \n\t ORDER BY " . $_SESSION['users']['list']['col_sql'] . " " . $_SESSION['users']['list']['mode_sql']; $rs = $SUMO['DB']->CacheExecute(10, $query); // Get datasources list if ($_SESSION['users']['list']['col'][9]) { $datasources = sumo_get_datasource_info(); for ($d = 0; $d < count($datasources); $d++) { $datasource[$datasources[$d]['id']] = $datasources[$d]['name']; } } switch ($_POST['type']) { case '': case 'csv': $ext = 'csv'; break; case 'xls': $ext = 'xls'; break; case 'csvdump': $ext = 'dump.csv'; break;
* @link http://sumoam.sourceforge.net SUMO Access Manager * @author Alberto Basso <*****@*****.**> * @copyright Copyright © 2003-2009, Alberto Basso * @package SUMO * @category Console */ $tab = sumo_get_user_info($_GET['id'], 'id', false); if (sumo_verify_permissions(4, $tab['group'], null, false) || sumo_verify_permissions(false, false, $tab['username'], false) || $SUMO['user']['id'] == $tab['owner_id']) { $tpl['PUT:NewPassword'] = $tpl['PUT:NewPassword'] ? $tpl['PUT:NewPassword'] : ''; $tpl['PUT:ReNewPassword'] = $tpl['PUT:ReNewPassword'] ? $tpl['PUT:ReNewPassword'] : ''; // If id not exist if (!$tab['username']) { $tpl['MESSAGE:H'] = sumo_get_message('W00001C', $_GET['id']); } // get data source of user $datasource = sumo_get_datasource_info($tab['datasource_id']); $tpl['PUT:Status'] = ""; $tpl['PUT:GroupLevel'] = sumo_put_user_grouplevel($_GET['id']); $tpl['PUT:AddGroupLevel'] = $tab['username'] == 'sumo' ? "<input type='hidden' name='newgroup' value='sumo:7'>" : sumo_add_user_grouplevel('ModifyUsers', sumo_get_grouplevel($tab['usergroup'], true)); $tpl['BUTTON:AddGroup'] = $tab['username'] == 'sumo' ? "" : "<input type='submit' class='button' value='" . $language['AddGroup'] . "'>"; $tpl['PUT:DataSourceType'] = ($tab['username'] == 'sumo' || $tab['username'] == $SUMO['user']['user']) && $SUMO['user']['id'] != $tab['owner_id'] ? "<input name='datasource_id' type='hidden' value='" . $datasource['id'] . "'>" . $datasource['name'] : sumo_put_datasource($datasource['id']); $tpl['GET:LastLogin'] = sumo_get_human_date($tab['last_login']); $tpl['GET:PwdUpdated'] = sumo_get_human_date($tab['pwd_updated']); $tpl['GET:AccountCreated'] = sumo_get_human_date($tab['created']); $tpl['GET:Modified'] = sumo_get_human_date($tab['modified']); $tpl['GET:UserAccessPages'] = sumo_get_user_accesspoints($tab['id'], true); $tpl['GET:UpdateForm'] = sumo_get_form_req('', 'modify', 'id=' . $tab['id'], 'POST', ' enctype="multipart/form-data"'); $tpl['GET:Expire'] = $tab['day_limit'] ? sumo_get_human_date($tab['day_limit'] * 86400 + $SUMO['server']['time'], false) : $language['Never']; $tpl['GET:User'] = $tab['username'] . "<input type='hidden' name='user' value='" . $tab['username'] . "'>"; $tpl['IMG:User'] = "******" . $tab['id'] . "' alt='" . $tab['username'] . "' class='user'>"; $tpl['IMG:Language'] = "<img src='themes/" . $SUMO['page']['theme'] . "/images/flags/" . $tab['language'] . ".png' alt='" . ucwords(sumo_get_string_languages($tab['language'])) . "' class='flag' id='userflag'>";
session_destroy(); break; case 'ORACLECONNECTIONFAILED': $sumo_message = sumo_get_message('W00053C'); $datasource = sumo_get_datasource_info($SUMO['user']['datasource_id']); sumo_write_log("W00053X", $datasource['name'], '0,1', 2); session_destroy(); break; case 'UNIXCONNECTIONFAILED': $sumo_message = sumo_get_message('W00054C'); sumo_write_log("W00054X", '', '0,1', 2); session_destroy(); break; case 'UNDEFINEDDS': $sumo_message = sumo_get_message('E00125C'); $datasource = sumo_get_datasource_info($SUMO['user']['datasource_id']); sumo_write_log("E00125X", $datasource['name'], '0,1', 2); session_destroy(); break; case 'IPDENIED': $update_req = TRUE; $sumo_message = sumo_get_message('W00004C', $SUMO['client']['ip']); sumo_write_log('W00045X', array($SUMO['client']['ip'], $SUMO['user']['user'], $SUMO['client']['country'], $SUMO['page']['url']), '0,1', 2, 'errors'); session_destroy(); break; case 'GROUPDENIED': $update_req = TRUE; $sumo_message = sumo_get_message('W00005C'); sumo_write_log('W00046X', array($SUMO['user']['user'], $SUMO['user']['group'], $SUMO['page']['url'], $SUMO['page']['group']), '0,1', 2, 'errors'); session_destroy(); break;
/** * Validate data * * See sumo_validate_data_<module name> for specific validation * into library module * * @author Alberto Basso <*****@*****.**> */ function sumo_validate_data($data = array(), $message = FALSE) { $elements = count($data); $err = FALSE; if ($elements > 0) { for ($d = 0; $d < $elements; $d++) { if ($data[$d][2] || !$data[$d][2] && $data[$d][1]) { switch ($data[$d][0]) { // the "user" can be also an e-mail address case 'username': if (!preg_match('/^[a-z0-9' . SUMO_REGEXP_ALLOWED_CHARS . ']{3,100}$/i', $data[$d][1]) && !sumo_validate_email($data[$d][1])) { $err = 'W00006C'; } break; case 'name': if (!preg_match("/^[a-z" . SUMO_REGEXP_ALLOWED_CHARS . "\\&\\;\\\\'\\ ]{1,49}\$/i", $data[$d][1])) { $err = 'W00022C'; } break; case 'password': if (!preg_match('/^[\\.a-z0-9]{40}$/i', $data[$d][1])) { $err = 'W00011C'; } // for sha1 string break; case 'email': if (!sumo_validate_email($data[$d][1])) { $err = 'W00007C'; } break; case 'active': if (!preg_match('/^[0-1]{1}$/', $data[$d][1])) { $err = 'W00018C'; } break; case 'ip': $ip = sumo_get_iprange($data[$d][1]); for ($i = 0; $i < count($ip); $i++) { if (!sumo_validate_ip($ip[$i])) { $err = 'W00016C'; } break; } break; case 'usergroup': if (!sumo_validate_group($data[$d][1])) { $err = 'W00017C'; } break; case 'datasource_id': $ds = sumo_get_datasource_info($data[$d][1], false); if (empty($ds)) { $err = 'W00023C'; } break; case 'hostname': if (!preg_match('/[a-z0-9\\.\\_\\-]{3,255}$/i', $data[$d][1])) { $err = 'W00025C'; } break; case 'port': if ($data[$d][1] < 1 || $data[$d][1] > 65535) { $err = 'W00026C'; } break; case 'ldap_base': if (!preg_match('/^[a-z0-9\\.\\,\\:\\;\\_\\-\\=\\\\/\\+\\*\\ ' . SUMO_REGEXP_ALLOWED_CHARS . ']{4,255}$/i', $data[$d][1])) { $err = 'W00027C'; } break; case 'new_password': if (!sumo_validate_data(array(array('password', $data[$d][1][0])))) { $err = 'W00011C'; } if ($data[$d][1][0] != $data[$d][1][1]) { $err = 'W00024C'; } break; // Joomla // Joomla case 'new_password2': if ($data[$d][1][0] != $data[$d][1][1]) { $err = 'W00024C'; } break; case 'day_limit': if (!preg_match('/^[0-9]{1,4}$/', $data[$d][1])) { $err = 'W00020C'; } break; case 'language': if (!in_array($data[$d][1], sumo_get_available_languages())) { $err = 'W00021C'; } break; case 'id': // INT = 256^4-1 if ($data[$d][1] < 1 || $data[$d][1] > 4294967296) { $err = 'W00029C'; } break; default: $err = 'W00019C'; break; } if ($err) { break; } } } if ($message) { return !$err ? array(TRUE, '') : array(FALSE, sumo_get_message($err)); } else { return !$err ? TRUE : FALSE; } } else { return FALSE; } }
<?php /** * SUMO MODULE: Users | View * * @version 0.5.0 * @link http://sumoam.sourceforge.net SUMO Access Manager * @author Alberto Basso <*****@*****.**> * @copyright Copyright © 2003-2009, Alberto Basso * @package SUMO * @category Console */ $tab = sumo_get_user_info($_GET['id'], 'id', FALSE); if (sumo_verify_permissions(3, $tab['group']) || sumo_verify_permissions(FALSE, FALSE, $SUMO['user']['user'])) { $datasource = sumo_get_datasource_info($tab['datasource_id'], FALSE); $tpl['GET:User'] = $tab['username']; $tpl['GET:Email'] = $tab['email']; $tpl['GET:DayLimit'] = !$tab['day_limit'] ? $language['Unlimited'] : $tab['day_limit']; $tpl['GET:FirstName'] = htmlspecialchars($tab['firstname'], ENT_QUOTES); $tpl['GET:LastName'] = htmlspecialchars($tab['lastname'], ENT_QUOTES); $tpl['GET:IP'] = implode("; ", $tab['ip']); $tpl['GET:Language'] = ucwords(sumo_get_string_languages($tab['language'])); $tpl['GET:LastLogin'] = sumo_get_human_date($tab['last_login']); $tpl['GET:AccountCreated'] = sumo_get_human_date($tab['created']); $tpl['GET:Modified'] = sumo_get_human_date($tab['modified']); $tpl['GET:UserAccessPages'] = sumo_get_user_accesspoints($tab['id'], TRUE); $tpl['GET:GroupLevel'] = sumo_get_user_grouplevel($tab['group_level']); $tpl['GET:Expire'] = $tab['day_limit'] != NULL ? sumo_get_human_date($tab['day_limit'] * 86400 + $SUMO['server']['time'], FALSE) : $language['Never']; $tpl['GET:DataSourceType'] = $datasource['name'] ? "<a href='javascript:sumo_ajax_get(\"network\",\"?module=network&action=view_datasource&id=" . $datasource['id'] . "\");'>" . $datasource['name'] . "</a>" : ''; $tpl['GET:Email'] = "<a href='mailto:" . $tab['email'] . "' title='Send e-mail'>" . $tab['email'] . "</a>"; $tpl['LINK:AddUser'] = sumo_get_action_icon("", "new", "users.content", "?module=users&action=new&decoration=false");
/** * Update user data */ function sumo_update_user_data($data = array()) { if (!empty($data)) { global $SUMO; $id = intval($data['id']); $day_limit = intval($data['day_limit']); $active = $data['active'] !== '' ? intval($data['active']) : FALSE; $firstname = ucwords(preg_replace('/[\\s\\,]+/', ' ', $data['firstname'])); $lastname = ucwords(preg_replace('/[\\s\\,]+/', ' ', $data['lastname'])); $ip = str_replace(";;", ";", str_replace(",", ";", preg_replace('/[\\s\\,]+/', ';', $data['ip']))); $email = strtolower($data['email']); $language = $data['language']; $sumogroup = sumo_verify_sumogroup($data['usergroup']); $group = $sumogroup ? $sumogroup : $data['usergroup']; $group = sumo_get_normalized_group($group); if ($day_limit > 0) { $daylimit[0] = 'day_limit=' . $day_limit . ', '; $daylimit[1] = 'day_limit=' . $day_limit . ' AND '; } else { $daylimit[0] = 'day_limit=NULL, '; $daylimit[1] = 'day_limit IS NULL AND '; } // Get user data $userdata = sumo_get_user_info($id, 'id', FALSE); $sumouser = sumo_get_user_info($SUMO['user']['user']); $datasource = sumo_get_datasource_info($data['datasource_id'], FALSE); // Change password if ($data['password'] && ($SUMO['user']['id'] == $id || $SUMO['user']['id'] == $userdata['owner_id'] || $SUMO['user']['user'] == 'sumo')) { switch ($datasource['type']) { case 'Unix': case 'SUMO': $record['password'] = "******" . $data['password'] . "'"; sumo_update_password_date($id, $data['password']); break; case 'MySQLUsers': require SUMO_PATH . '/libs/lib.datasource.mysql_users.php'; $sumo_update_password($userdata['username'], $data['password']); break; case 'Joomla15': require SUMO_PATH . '/libs/lib.datasource.joomla15.php'; $sumo_update_password($userdata['username'], $data['password']); break; default: $record['password'] = ""; break; } } if ($group) { $record['usergroup'] = "usergroup='{$group}'"; } // group if ($sumouser['id'] != $id) { $record['active'] = "active=" . $active; } // active // verify if user can change some parameters... if ($SUMO['user']['id'] == $id || in_array('sumo', $SUMO['user']['group']) || $SUMO['user']['id'] == $userdata['owner_id']) { $firstname = get_magic_quotes_gpc() ? $firstname : addslashes($firstname); $lastname = get_magic_quotes_gpc() ? $lastname : addslashes($lastname); $record['firstname'] = "firstname='" . $firstname . "'"; $record['lastname'] = "lastname='" . $lastname . "'"; $record['email'] = "email='{$email}'"; $record['language'] = "language='{$language}'"; } else { $record['firstname'] = ""; $record['lastname'] = ""; $record['email'] = ""; $record['language'] = ""; } //... to change IP address if (in_array('sumo', $SUMO['user']['group']) || $SUMO['user']['id'] == $userdata['owner_id']) { $record['ip'] = "ip='" . $ip . "'"; } else { $record['ip'] = ""; } // Data source $record['datasource_id'] = "datasource_id=" . $data['datasource_id']; // modified $record['modified'] = "modified=" . $SUMO['server']['time']; // Create fields for query $new_record = array_values($record); for ($r = 0; $r < count($new_record); $r++) { if ($new_record[$r]) { $records[$r] = $new_record[$r]; } } $update = implode(', ', $records); $select = implode(' AND ', $records); // create query for update $query = "UPDATE " . SUMO_TABLE_USERS . "\n\t\t SET " . $daylimit[0] . " " . $update . "\n\t\t WHERE id=" . $id; $SUMO['DB']->Execute($query); if ($select || $day_limit[1]) { $select = $select . " AND "; } // verify query success $query = "SELECT * FROM " . SUMO_TABLE_USERS . "\n\t\t WHERE " . $daylimit[1] . "\n\t\t " . $select . "\n\t\t id=" . $id; $rs = $SUMO['DB']->Execute($query); $tab = $rs->FetchRow(); $upd = $rs->PO_RecordCount(); // if updated: if ($upd == 1) { $SUMO['DB']->CacheFlush(); if ($record['password']) { // ...to change current session password if ($id == $SUMO['user']['id']) { $_SESSION['user']['password'] = sumo_get_hex_hmac_sha1($SUMO['connection']['security_string'], $data['password']); $_SESSION['pwd_changed'] = $SUMO['server']['time']; } else { sumo_delete_session(NULL, NULL, $data['user']); } } sumo_write_log('I01000X', array($tab['username'], $SUMO['user']['user']), 3, 3, 'system', FALSE); // Send user notify if ($SUMO['config']['accounts']['notify']['updates'] && $email) { if (!$SUMO['config']['server']['admin']['email']) { sumo_write_log('E06000X', '', '0,1', 2, 'system', FALSE); } else { $object = sumo_get_message("I00001M", $SUMO['server']['name']); $message = sumo_get_message("I00106M", array($firstname . " " . $lastname, $SUMO['server']['name'], $SUMO['user']['user'])); $m = new Mail(); $m->From($SUMO['config']['server']['admin']['email']); $m->To($email); $m->Subject($object); $m->Body($message, SUMO_CHARSET); $m->Priority(1); $m->Send(); } } return TRUE; } else { return FALSE; } } else { return FALSE; } }
* @version 0.5.0 * @link http://sumoam.sourceforge.net SUMO Access Manager * @author Alberto Basso <*****@*****.**> * @copyright Copyright © 2003-2009, Alberto Basso * @package SUMO * @category Console */ if (sumo_verify_permissions(5, $SUMO['user']['group'])) { $data = array(array('username', $_POST['user'], 1), array('name', $_POST['firstname']), array('name', $_POST['lastname']), array('active', $_POST['active'], 1), array('datasource_id', $_POST['datasource_id'], 1), array('email', $_POST['email']), array('language', $_POST['language']), array('usergroup', $_POST['newgroup'], 1), array('ip', $_POST['ip']), array('day_limit', $_POST['day_limit']), array('new_password', array($_POST['new_password'], $_POST['renew_password']))); $validate = sumo_validate_data($data, TRUE); // verify if user already exist if (sumo_verify_user_exist($_POST['user'])) { $validate = array(FALSE, sumo_get_message('W00028C', $_POST['user'])); } // verify if password is not null (for SUMO datasource) $ds = sumo_get_datasource_info($_POST['datasource_id']); if (!$_POST['new_password'] && $ds['type'] == 'SUMO') { $validate = array(FALSE, $language['NoPasswordForSumoDS']); } if ($validate[0]) { // Verify submittedd groups with current user group $available_group = sumo_get_available_group(); $newgroup = explode(":", $_POST['newgroup']); if (!in_array($newgroup[0], $available_group)) { $validate = array(FALSE, sumo_get_message('GroupNotAvailable', $newgroup[0])); } if (!in_array('sumo', $SUMO['user']['group']) || $newgroup[0] == 'sumo') { if ($SUMO['user']['group_level'][$newgroup[0]] < $newgroup[1]) { $validate = array(FALSE, sumo_get_message('WrongLevel', $newgroup[1])); } }