function handleEditPage() { include_once 'login.php'; include_once 'showEventFunction.php'; $backURL = "<br/><a href = \"index.php\">Back to Home</a>"; // client side validation, if error, disable submit // if form is set and not empty, continue $showError = true; $errOutput = isFormFilled($showError); if ($errOutput) { $output = "<h1>Error</h1>"; return $output . $errOutput . $backURL; } $event = array(); $errMsg = array(); // prevent sql injection & data sanitize foreach ($_POST as $field => $value) { $event[$field] = sanitizeData($value); } include_once 'database_conn.php'; $columnLengthSql = "\n\t\tSELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH\n\t\tFROM INFORMATION_SCHEMA.COLUMNS\n\t\tWHERE TABLE_NAME = 'te_events'\n\t\tAND (column_name = 'eventTitle'\n\t\tOR column_name = 'eventDescription')"; //, DATA_TYPE $COLUMN_LENGTH = getColumnLength($conn, $columnLengthSql); // check data type and length validation $isError = false; $errMsg[] = validateStringLength($event['title'], $COLUMN_LENGTH['eventTitle']); //title $errMsg[] = validateStringLength($event['desc'], $COLUMN_LENGTH['eventDescription']); //desc $errMsg[] = validateDate($event['startTime']); //startTime $errMsg[] = validateDate($event['endTime']); //endTime $errMsg[] = validateDecimal($event['price']); //price for ($i = 0; $i < count($errMsg); $i++) { if (!($errMsg[$i] === true)) { $pageHeader = "Error"; $output = "<h1>{$pageHeader}</h1>"; $output . "{$errMsg[$i]}"; $isError = true; } } //if contain error, halt continue executing the code if ($isError) { return $output . $backURL; } // prepare sql statement $sql = "UPDATE te_events SET \n\t\teventTitle=?, eventDescription=?, \n\t\tvenueID=?, catID=?, eventStartDate=?, \n\t\teventEndDate=?, eventPrice=? WHERE eventID=?;"; $stmt = mysqli_prepare($conn, $sql); mysqli_stmt_bind_param($stmt, "ssssssss", $event['title'], $event['desc'], $event['venue'], $event['category'], $event['startTime'], $event['endTime'], $event['price'], $event['e_id']); // execute update statement mysqli_stmt_execute($stmt); // check is it sucess update if (mysqli_stmt_affected_rows($stmt)) { $output = "<h1>{$event['title']} was successfully updated.</h1>"; return $output . $backURL; } else { $output = "<h1>Nothing update for {$event['title']}</h1>"; return $output . $backURL; } echo "<br/>"; return; }
function login() { include_once 'database_conn.php'; // check is form filled if (isFormFilled()) { // if not filled, stop return; } $uid = sanitizeData($_POST['username']); $pswd = sanitizeData($_POST['password']); $columnLengthSql = "\n\t\t\tSELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH\n\t\t\tFROM INFORMATION_SCHEMA.COLUMNS\n\t\t\tWHERE TABLE_NAME = 'te_users'\n\t\t\tAND (column_name = 'username'\n\t\t\tOR column_name = 'passwd')"; $COLUMN_LENGTH = getColumnLength($conn, $columnLengthSql); $isError = false; $errMsg[] = validateStringLength($uid, $COLUMN_LENGTH['username']); //uid $errMsg[] = validateStringLength($pswd, $COLUMN_LENGTH['passwd']); //pswd for ($i = 0; $i < count($errMsg); $i++) { if (!($errMsg[$i] === true)) { echo "{$errMsg[$i]}"; $isError = true; } } //if contain error, halt continue executing the code if ($isError) { return; } // check is uid exist $checkUIDSql = "SELECT passwd, salt FROM te_users WHERE username = ?"; $stmt = mysqli_prepare($conn, $checkUIDSql); mysqli_stmt_bind_param($stmt, "s", $uid); mysqli_stmt_execute($stmt); mysqli_stmt_store_result($stmt); if (mysqli_stmt_num_rows($stmt) <= 0) { echo "Sorry we don't seem to have that username."; return; } mysqli_stmt_bind_result($stmt, $getHashpswd, $getSalt); while (mysqli_stmt_fetch($stmt)) { $hashPswd = $getHashpswd; $salt = $getSalt; } // if exist, then get salt and db hashed password // create hash based on password // hash pswd using sha256 algorithm // concat salt in db by uid // hash using sha256 algorithm $pswd = hash("sha256", $salt . hash("sha256", $pswd)); // check does it match with hased password from db if (strcmp($pswd, $hashPswd) === 0) { echo "Success login<br/>"; // add session $_SESSION['logged-in'] = $uid; // go to url $url = $_SERVER['REQUEST_URI']; header("Location: {$url}"); } else { echo "Fail login<br/>"; } }
function validatePost($post) { global $fmdb, $__FM_CONFIG; if (empty($post['server_name'])) { return __('No server name defined.'); } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_name'); if ($field_length !== false && strlen($post['server_name']) > $field_length) { return sprintf(dngettext($_SESSION['module'], 'Server name is too long (maximum %d character).', 'Server name is too long (maximum %d characters).', $field_length), $field_length); } /** Does the record already exist for this account? */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', $post['server_name'], 'server_', 'server_name', "AND server_id!='{$post['server_id']}'"); if ($fmdb->num_rows) { return __('This server name already exists.'); } if (empty($post['server_config_file'])) { $post['server_config_file'] = $__FM_CONFIG['fw']['config_file']['default']; if (!is_array($__FM_CONFIG['fw']['config_file'][$post['server_type']]) && $__FM_CONFIG['fw']['config_file'][$post['server_type']]) { $post['server_config_file'] = $__FM_CONFIG['fw']['config_file'][$post['server_type']]; } elseif (is_array($__FM_CONFIG['fw']['config_file'][$post['server_type']])) { if (isset($post['server_os_distro'])) { $distro = $post['server_os_distro']; } else { if ($post['action'] == 'edit') { $distro = getNameFromID($post['server_id'], 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_', 'server_id', 'server_os_distro'); } } if (isset($distro) && array_key_exists($distro, $__FM_CONFIG['fw']['config_file'][$post['server_type']])) { $post['server_config_file'] = $__FM_CONFIG['fw']['config_file'][$post['server_type']][$distro]; } } } /** Set default ports */ if (empty($post['server_update_port']) || isset($post['server_update_port']) && $post['server_update_method'] == 'cron') { $post['server_update_port'] = 0; } if (!empty($post['server_update_port']) && !verifyNumber($post['server_update_port'], 1, 65535, false)) { return __('Server update port must be a valid TCP port.'); } if (empty($post['server_update_port']) && isset($post['server_update_method'])) { if ($post['server_update_method'] == 'http') { $post['server_update_port'] = 80; } elseif ($post['server_update_method'] == 'https') { $post['server_update_port'] = 443; } elseif ($post['server_update_method'] == 'ssh') { $post['server_update_port'] = 22; } } return $post; }
function validatePost($post) { global $fmdb, $__FM_CONFIG; $post['group_name'] = sanitize($post['group_name']); if (empty($post['group_name'])) { return __('No group name defined.'); } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG['fmSQLPass']['prefix'] . 'groups', 'group_name'); if ($field_length !== false && strlen($post['group_name']) > $field_length) { return sprintf(__('Group name is too long (maximum %d characters).'), $field_length); } /** Does the record already exist for this account? */ basicGet('fm_' . $__FM_CONFIG['fmSQLPass']['prefix'] . 'groups', sanitize($post['group_name']), 'group_', 'group_name'); if ($fmdb->num_rows) { $result = $fmdb->last_result; if ($result[0]->group_id != $post['group_id']) { return __('This group name already exists.'); } } return $post; }
function validatePost($post) { global $fmdb, $__FM_CONFIG; if (empty($post['object_name'])) { return __('No object name defined.'); } if (empty($post['object_address'])) { return __('No object address defined.'); } if ($post['object_type'] == 'network') { if (empty($post['object_mask'])) { return __('No object netmask defined.'); } } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'objects', 'object_name'); if ($field_length !== false && strlen($post['object_name']) > $field_length) { return sprintf(dngettext($_SESSION['module'], 'Object name is too long (maximum %d character).', 'Object name is too long (maximum %d characters).', $field_length), $field_length); } /** Does the record already exist for this account? */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'objects', $post['object_name'], 'object_', 'object_name', "AND object_type='{$post['object_type']}' AND object_id!={$post['object_id']}"); if ($fmdb->num_rows) { return __('This object name already exists.'); } /** Check address and mask */ if (!verifyIPAddress($post['object_address'])) { return __('Address is invalid.'); } if ($post['object_type'] == 'network') { if (!verifyIPAddress($post['object_mask'])) { return __('Netmask is invalid.'); } } return $post; }
function validatePost($post) { global $fmdb, $__FM_CONFIG; if (empty($post['time_name'])) { return __('No name defined.'); } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'time', 'time_name'); if ($field_length !== false && strlen($post['time_name']) > $field_length) { return sprintf(dngettext($_SESSION['module'], 'Name is too long (maximum %d character).', 'Name is too long (maximum %d characters).', $field_length), $field_length); } /** Does the record already exist for this account? */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'time', $post['time_name'], 'time_', 'time_name', "AND time_id!={$post['time_id']}"); if ($fmdb->num_rows) { return __('This name already exists.'); } /** Process time */ $post['time_start_time'] = $post['time_start_time_hour'] . ':' . $post['time_start_time_min']; $post['time_end_time'] = $post['time_end_time_hour'] . ':' . $post['time_end_time_min']; /** Process weekdays */ if (@is_array($post['time_weekdays'])) { $decimals = 0; foreach ($post['time_weekdays'] as $dec => $checked) { $decimals += $dec; } $post['time_weekdays'] = $decimals; } else { $post['time_weekdays'] = 0; } /** Process dates */ if (empty($post['time_start_date'])) { unset($post['time_start_date']); } if (empty($post['time_end_date'])) { unset($post['time_end_date']); } return $post; }
/** * Displays the form to add new user * * @since 1.0 * @package facileManager */ function printUsersForm($data = '', $action = 'add', $form_bits = array(), $button_text = 'Save', $button_id = 'submit', $action_page = 'admin-users.php', $print_form_head = true, $display_type = 'popup') { global $__FM_CONFIG, $fm_name, $fm_login; $user_id = 0; $user_login = $user_password = $cpassword = null; $ucaction = ucfirst($action); $disabled = isset($_GET['id']) && $_SESSION['user']['id'] == $_GET['id'] ? 'disabled' : null; $button_disabled = null; $user_email = $user_default_module = null; $hidden = $user_perm_form = $return_form_rows = null; $user_force_pwd_change = $user_template_only = null; if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) { if (is_array($_POST)) { extract($_POST); } } elseif (@is_object($data[0])) { extract(get_object_vars($data[0])); $user_password = null; } $popup_title = $action == 'add' ? __('Add User') : __('Edit User'); $popup_header = buildPopup('header', $popup_title); $popup_footer = buildPopup('footer'); if (in_array('user_login', $form_bits)) { /** Get field length */ $field_length = getColumnLength('fm_users', 'user_login'); $username_form = $action == 'add' ? '<input name="user_login" id="user_login" type="text" value="' . $user_login . '" size="40" maxlength="' . $field_length . '" />' : '<span id="form_username">' . $user_login . '</span>'; $hidden = '<input type="hidden" name="user_id" value="' . $user_id . '" />'; $hidden .= $action != 'add' ? '<input type="hidden" name="user_login" value="' . $user_login . '" />' : null; $return_form_rows .= '<tr> <th width="33%" scope="row"><label for="user_login">' . _('User Login') . '</label></th> <td width="67%">' . $username_form . '</td> </tr>'; } if (in_array('user_email', $form_bits)) { /** Get field length */ $field_length = getColumnLength('fm_users', 'user_login'); $return_form_rows .= '<tr> <th width="33%" scope="row"><label for="user_email">' . _('User Email') . '</label></th> <td width="67%"><input name="user_email" id="user_email" type="email" value="' . $user_email . '" size="32" maxlength="' . $field_length . '" ' . $disabled . ' /></td> </tr>'; } if (in_array('user_auth_method', $form_bits) && getOption('auth_method')) { if (!isset($user_auth_type)) { $user_auth_type = 1; } $auth_method_types = $__FM_CONFIG['options']['auth_method']; if (array_shift($auth_method_types) && count($auth_method_types) > 1) { $return_form_rows .= '<tr> <th width="33%" scope="row"><label for="user_email">' . _('Authentication Method') . '</label></th> <td width="67%">' . buildSelect('user_auth_type', 'user_auth_type', $auth_method_types, $user_auth_type) . '</td> </tr>'; } } if (in_array('user_password', $form_bits) || array_key_exists('user_password', $form_bits)) { if ($action == 'add') { $button_disabled = 'disabled'; } $strength = $GLOBALS['PWD_STRENGTH']; if (array_key_exists('user_password', $form_bits)) { $strength = $form_bits['user_password']; } $return_form_rows .= '<tr class="user_password"> <th width="33%" scope="row"><label for="user_password">' . _('User Password') . '</label></th> <td width="67%"><input name="user_password" id="user_password" type="password" value="" size="40" onkeyup="javascript:checkPasswd(\'user_password\', \'' . $button_id . '\', \'' . $strength . '\');" /></td> </tr> <tr class="user_password"> <th width="33%" scope="row"><label for="cpassword">' . _('Confirm Password') . '</label></th> <td width="67%"><input name="cpassword" id="cpassword" type="password" value="" size="40" onkeyup="javascript:checkPasswd(\'cpassword\', \'' . $button_id . '\', \'' . $strength . '\');" /></td> </tr> <tr class="user_password"> <th width="33%" scope="row">' . _('Password Validity') . '</th> <td width="67%"><div id="passwd_check">' . _('No Password') . '</div></td> </tr> <tr class="pwdhint user_password"> <th width="33%" scope="row">' . _('Hint') . '</th> <td width="67%">' . $__FM_CONFIG['password_hint'][$strength][1] . '</td> </tr>'; } if (in_array('user_module', $form_bits)) { $active_modules = $user_id == $_SESSION['user']['id'] ? getActiveModules(true) : getActiveModules(); $user_module_options = buildSelect('user_default_module', 'user_default_module', $active_modules, $user_default_module); unset($active_modules); $return_form_rows .= '<tr> <th width="33%" scope="row">' . _('Default Module') . '</th> <td width="67%">' . $user_module_options . '</td> </tr>'; } if (in_array('user_options', $form_bits)) { $force_pwd_check = $user_force_pwd_change == 'yes' ? 'checked disabled' : null; $user_template_only_check = $user_template_only == 'yes' ? 'checked' : null; $return_form_rows .= '<tr> <th width="33%" scope="row">' . _('Options') . '</th> <td width="67%"> <input name="user_force_pwd_change" id="user_force_pwd_change" value="yes" type="checkbox" ' . $force_pwd_check . '/><label for="user_force_pwd_change">' . _('Force Password Change at Next Login') . '</label><br /> <input name="user_template_only" id="user_template_only" value="yes" type="checkbox" ' . $user_template_only_check . '/><label for="user_template_only">' . _('Template User') . '</label> </td> </tr>'; } if (in_array('verbose', $form_bits)) { $hidden .= '<input type="hidden" name="verbose" value="0" />' . "\n"; $return_form_rows .= '<tr> <th width="33%" scope="row">' . _('Options') . '</th> <td width="67%"><input name="verbose" id="verbose" type="checkbox" value="1" checked /><label for="verbose">' . _('Verbose Output') . '</label></td> </tr>'; } do { if (in_array('user_perms', $form_bits)) { /** Cannot edit perms of super-admin if logged in user is not a super-admin */ if (userCan($user_id, 'do_everything') && !currentUserCan('do_everything')) { break; } $user_is_super_admin = userCan($user_id, 'do_everything'); $fm_perm_boxes = $perm_boxes = null; $i = 1; $fm_user_caps = getAvailableUserCapabilities(); foreach ($fm_user_caps[$fm_name] as $key => $title) { if ($key != 'do_everything' && $user_is_super_admin) { $checked = null; } else { $checked = userCan($user_id, $key) ? 'checked' : null; } if ($key == 'do_everything') { $title = "<b>{$title}</b>"; } $fm_perm_boxes .= ' <input name="user_caps[' . $fm_name . '][' . $key . ']" id="fm_perm_' . $key . '" type="checkbox" value="1" ' . $checked . '/> <label for="fm_perm_' . $key . '">' . $title . '</label>' . "\n"; /** Display checkboxes three per row */ if ($i == 3) { $fm_perm_boxes .= "<br />\n"; $i = 0; } $i++; } if (!empty($fm_perm_boxes)) { $perm_boxes .= <<<PERM \t\t\t\t<tr id="userperms"> \t\t\t\t\t<th width="33%" scope="row">{$fm_name}</th> \t\t\t\t\t<td width="67%"> \t\t\t\t\t\t<input type="hidden" name="process_user_caps" value="1" /> \t\t\t\t\t\t{$fm_perm_boxes} \t\t\t\t\t</td> \t\t\t\t</tr> PERM; } /** Process module permissions */ $active_modules = getActiveModules(); foreach ($active_modules as $module_name) { $module_perm_boxes = null; $i = 1; if (array_key_exists($module_name, $fm_user_caps)) { foreach ($fm_user_caps[$module_name] as $key => $title) { $checked = userCan($user_id, $key, $module_name) && !$user_is_super_admin ? 'checked' : null; $module_perm_boxes .= ' <input name="user_caps[' . $module_name . '][' . $key . ']" id="fm_perm_' . $module_name . '_' . $key . '" type="checkbox" value="1" ' . $checked . '/> <label for="fm_perm_' . $module_name . '_' . $key . '">' . $title . '</label>' . "\n"; /** Display checkboxes three per row */ if ($i == 3) { $module_perm_boxes .= "<br />\n"; $i = 0; } $i++; } $module_extra_functions = ABSPATH . 'fm-modules' . DIRECTORY_SEPARATOR . $module_name . DIRECTORY_SEPARATOR . 'functions.extra.php'; if (file_exists($module_extra_functions)) { include $module_extra_functions; $function = 'print' . $module_name . 'UsersForm'; if (function_exists($function)) { $module_perm_boxes .= $function(getUserCapabilities($user_id), $module_name); } } } if (!empty($module_perm_boxes)) { $perm_boxes .= <<<PERM \t\t\t\t\t<tr id="userperms"> \t\t\t\t\t\t<th width="33%" scope="row">{$module_name}</th> \t\t\t\t\t\t<td width="67%"> \t\t\t\t\t\t{$module_perm_boxes} \t\t\t\t\t\t</td> \t\t\t\t\t</tr> \t PERM; } } if (!empty($perm_boxes)) { $user_perm_form = sprintf('<tr><td colspan="2"><br /><br /><i>%s</i></td></tr>', _('User Permissions')) . $perm_boxes; } } } while (false); $return_form = $print_form_head ? '<form name="manage" id="manage" method="post" action="' . $action_page . '">' . "\n" : null; if ($display_type == 'popup') { $return_form .= $popup_header; } $return_form .= ' <div> <form id="fm_user_profile"> <input type="hidden" name="action" value="' . $action . '" />' . $hidden . ' <table class="form-table" width="495px"> <tr><td colspan="2"><i>' . _('User Details') . '</i></td></tr>' . $return_form_rows . $user_perm_form; $return_form .= '</table></div>'; if ($display_type == 'popup') { $return_form .= ' </div> <div class="popup-footer"> <input type="submit" id="' . $button_id . '" name="submit" value="' . $button_text . '" class="button primary" ' . $button_disabled . '/> <input type="button" value="' . _('Cancel') . '" class="button left" id="cancel_button" /> </div> </form> <script> $(document).ready(function() { $("select").select2({ containerCss: { "min-width": "165px" }, minimumResultsForSearch: -1 }); $("select.wide_select").select2({ width: "300px", minimumResultsForSearch: -1 }); }); </script>'; } return $return_form; }
function validatePost($post) { global $fmdb, $__FM_CONFIG; if (!$post['domain_id']) { unset($post['domain_id']); } /** Empty domain names are not allowed */ if (empty($post['domain_name'])) { return __('No zone name defined.'); } if ($post['domain_template'] != 'yes') { $post['domain_name'] = rtrim(strtolower($post['domain_name']), '.'); /** Perform domain name validation */ if (!isset($post['domain_mapping'])) { global $map; $post['domain_mapping'] = $map; } if ($post['domain_mapping'] == 'reverse') { $post['domain_name'] = $this->fixDomainTypos($post['domain_name']); } else { $post['domain_name'] = function_exists('idn_to_ascii') ? idn_to_ascii($post['domain_name']) : $post['domain_name']; } if (!$this->validateDomainName($post['domain_name'], $post['domain_mapping'])) { return __('Invalid zone name.'); } } /** Is this based on a template? */ if ($post['domain_template_id']) { $include = array('action', 'domain_template_id', 'domain_name', 'domain_template', 'domain_mapping'); foreach ($include as $key) { $new_post[$key] = $post[$key]; } $post = $new_post; unset($new_post, $post['domain_template']); $post['domain_type'] = getNameFromID($post['domain_template_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_type'); $post['domain_view'] = getNameFromID($post['domain_template_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_view'); return $post; } else { $post['domain_template_id'] = 0; } /** Format domain_clone_domain_id */ if (!$post['domain_clone_domain_id'] && $post['action'] == 'add') { $post['domain_clone_domain_id'] = 0; } /** domain_clone_dname override */ if (!$post['domain_clone_dname_override']) { $post['domain_clone_dname'] = null; } else { unset($post['domain_clone_dname_override']); } /** Ensure domain_view is set */ if (!array_key_exists('domain_view', $post)) { $post['domain_view'] = $post['domain_clone_domain_id'] ? -1 : 0; } /** Reverse zones should have form of x.x.x.in-addr.arpa */ if ($post['domain_mapping'] == 'reverse') { $post['domain_name'] = $this->setReverseZoneName($post['domain_name']); } /** Does the record already exist for this account? */ $domain_id_sql = isset($post['domain_id']) ? 'AND domain_id!=' . sanitize($post['domain_id']) : null; basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'views', $_SESSION['user']['account_id'], 'view_', 'account_id'); if (!$fmdb->num_rows) { /** No views defined - all zones must be unique */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', $domain_id_sql); if ($fmdb->num_rows) { return __('Zone already exists.'); } } else { /** All zones must be unique per view */ $defined_views = $fmdb->last_result; /** Format domain_view */ if (!$post['domain_view'] || in_array(0, $post['domain_view'])) { basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', $domain_id_sql); if ($fmdb->num_rows) { /** Zone exists for views, but what about on the same server? */ if (!$post['domain_name_servers'] || in_array('0', $post['domain_name_servers'])) { return __('Zone already exists for all views.'); } } } if (is_array($post['domain_view'])) { $domain_view = null; foreach ($post['domain_view'] as $val) { if ($val == 0 || $val == '') { $domain_view = 0; break; } $domain_view .= $val . ';'; basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', "AND (domain_view='{$val}' OR domain_view=0 OR domain_view LIKE '{$val};%' OR domain_view LIKE '%;{$val};%' OR domain_view LIKE '%;{$val}') {$domain_id_sql}"); if ($fmdb->num_rows) { $view_name = getNameFromID($val, 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'views', 'view_', 'view_id', 'view_name'); return sprintf(__("Zone already exists for the '%s' view."), $view_name); } } $post['domain_view'] = rtrim($domain_view, ';'); } } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', 'domain_name'); if ($field_length !== false && strlen($post['domain_name']) > $field_length) { return sprintf(dngettext($_SESSION['module'], 'Zone name is too long (maximum %d character).', 'Zone name is too long (maximum %d characters).', $field_length), $field_length); } /** No need to process more if zone is cloned */ if ($post['domain_clone_domain_id']) { return $post; } /** Cleans up acl_addresses for future parsing **/ $clean_fields = array('forwarders', 'masters'); foreach ($clean_fields as $val) { $post['domain_required_servers'][$val] = verifyAndCleanAddresses($post['domain_required_servers'][$val], 'no-subnets-allowed'); if (strpos($post['domain_required_servers'][$val], 'not valid') !== false) { return $post['domain_required_servers'][$val]; } } /** Forward zones require forward servers */ if ($post['domain_type'] == 'forward') { if (empty($post['domain_required_servers']['forwarders'])) { return __('No forward servers defined.'); } $post['domain_required_servers'] = $post['domain_required_servers']['forwarders']; } /** Slave and stub zones require master servers */ if (in_array($post['domain_type'], array('slave', 'stub'))) { if (empty($post['domain_required_servers']['masters'])) { return __('No master servers defined.'); } $post['domain_required_servers'] = $post['domain_required_servers']['masters']; } return $post; }
/** * Displays the form to add new server */ function printForm($data = '', $action = 'add') { global $fmdb, $__FM_CONFIG; $server_id = 0; $server_name = $server_groups = $server_type = $server_port = null; $server_cred_user = $server_cred_password = $server_credentials = null; $server_type = 'database'; $ucaction = ucfirst($action); /** Build groups options */ basicGetList('fm_' . $__FM_CONFIG['fmSQLPass']['prefix'] . 'groups', 'group_name', 'group_'); $group_options = null; $group_count = $fmdb->num_rows; $group_results = $fmdb->last_result; for ($i = 0; $i < $group_count; $i++) { $group_options[$i][] = $group_results[$i]->group_name; $group_options[$i][] = $group_results[$i]->group_id; } if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) { if (is_array($data)) { extract($data); } } elseif (@is_object($data[0])) { extract(get_object_vars($data[0])); } /** Check name field length */ $server_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmSQLPass']['prefix'] . 'servers', 'server_name'); $server_types = buildSelect('server_type', 'server_type', $this->getServerTypes(), $server_type); $groups = is_array($group_options) ? buildSelect('server_groups', 1, $group_options, $server_groups, 4, null, true) : __('Server Groups need to be defined first.'); /** Handle credentials */ if (isSerialized($server_credentials)) { $server_credentials = unserialize($server_credentials); list($server_cred_user, $server_cred_password) = $server_credentials; unset($server_credentials); } $popup_title = $action == 'add' ? __('Add Server') : __('Edit Server'); $popup_header = buildPopup('header', $popup_title); $popup_footer = buildPopup('footer'); $return_form = sprintf('<form name="manage" id="manage" method="post" action=""> %s <input type="hidden" name="action" id="action" value="%s" /> <input type="hidden" name="server_type" id="server_type" value="%s" /> <input type="hidden" name="server_id" id="server_id" value="%d" /> <table class="form-table"> <tr> <th width="33%" scope="row"><label for="server_name">%s</label></th> <td width="67%"><input name="server_name" id="server_name" type="text" value="%s" size="40" maxlength="%s" /></td> </tr> <tr> <th width="33%" scope="row"><label for="server_type">%s</label></th> <td width="67%">%s</td> </tr> <tr> <th width="33%" scope="row"><label for="server_port">%s</label></th> <td width="67%"><input type="number" name="server_port" value="%d" placeholder="3306" onkeydown="return validateNumber(event)" maxlength="5" max="65535" /></td> </tr> <tr> <th width="33%" scope="row"><label for="server_groups">%s</label></th> <td width="67%">%s</td> </tr> <tr> <th width="33%" scope="row"><label for="server_cred_user">%s</label></th> <td width="67%"><input name="server_credentials[]" id="server_cred_user" type="text" value="%s" size="40" /></td> </tr> <tr> <th width="33%" scope="row"><label for="server_cred_password">%s</label></th> <td width="67%"><input name="server_credentials[]" id="server_cred_password" type="password" value="%s" size="40" /></td> </tr> </table> %s </form> <script> $(document).ready(function() { $("#manage select").select2({ width: "200px", minimumResultsForSearch: 10 }); }); </script>', $popup_header, $action, $server_type, $server_id, __('Hostname'), $server_name, $server_name_length, __('Server Type'), $server_types, __('Server Port'), $server_port, __('Groups'), $groups, __('Username'), $server_cred_user, __('Password'), $server_cred_password, $popup_footer); return $return_form; }
/** * Displays the form to add new server */ function printForm($data = '', $action = 'add', $type = 'servers') { global $__FM_CONFIG; $server_id = $group_id = 0; $server_name = $server_root_dir = $server_zones_dir = $runas = $server_type = $server_update_port = null; $server_update_method = $server_key = $server_run_as = $server_config_file = $server_run_as_predefined = null; $server_chroot_dir = $group_name = null; $server_installed = false; if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) { if (is_array($_POST)) { extract($_POST); } } elseif (@is_object($data[0])) { extract(get_object_vars($data[0])); } if ($type == 'groups') { $server_id = $group_id; } if ($action == 'add') { $popup_title = $type == 'servers' ? __('Add Server') : __('Add Group'); } else { $popup_title = $type == 'servers' ? __('Edit Server') : __('Edit Group'); } $popup_header = buildPopup('header', $popup_title); $popup_footer = buildPopup('footer'); $return_form = <<<FORM \t\t\t<form name="manage" id="manage" method="post" action="?type={$type}"> \t\t\t{$popup_header} \t\t\t\t<input type="hidden" name="action" value="{$action}" /> \t\t\t\t<input type="hidden" name="server_id" value="{$server_id}" /> \t\t\t\t<input type="hidden" name="sub_type" value="{$type}" /> FORM; if ($type == 'servers') { /** Show/hide divs */ if (isset($server_run_as_predefined) && $server_run_as_predefined == 'as defined:') { $runashow = 'block'; } else { $runashow = 'none'; $server_run_as = null; } $server_update_port_style = $server_update_method == 'cron' ? 'style="display: none;"' : 'style="display: block;"'; $disabled = $server_installed == 'yes' ? 'disabled' : null; if ($server_installed == 'yes') { if (strpos($server_update_method, 'http') === false) { $server_update_method_choices = array($server_update_method); } else { $server_update_method_choices = array('http', 'https'); } } else { $server_update_method_choices = enumMYSQLSelect('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_update_method'); } /** Check name field length */ $server_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_name'); $server_config_file_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_config_file'); $server_root_dir_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_root_dir'); $server_chroot_dir_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_chroot_dir'); $server_zones_dir_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_zones_dir'); $server_type = buildSelect('server_type', 'server_type', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_type'), $server_type, 1); $server_update_method = buildSelect('server_update_method', 'server_update_method', $server_update_method_choices, $server_update_method, 1); $server_key = buildSelect('server_key', 'server_key', $this->availableItems('key'), $server_key); $server_run_as_predefined = buildSelect('server_run_as_predefined', 'server_run_as_predefined', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_run_as_predefined'), $server_run_as_predefined, 1, '', false, "showHideBox('run_as', 'server_run_as_predefined', 'as defined:')"); $alternative_help = $action == 'add' && getOption('client_auto_register') ? sprintf('<p><b>%s</b> %s</p>', __('Note:'), __('The client installer can automatically generate this entry.')) : null; $return_form .= $alternative_help . sprintf('<table class="form-table"> <tr> <th width="33%" scope="row"><label for="server_name">%s</label></th> <td width="67%"><input name="server_name" id="server_name" type="text" value="%s" size="40" placeholder="dns1.local" maxlength="%d" /></td> </tr> <tr> <th width="33%" scope="row"><label for="server_key">%s</label></th> <td width="67%">%s</td> </tr> <tr> <th width="33%" scope="row"><label for="server_type">%s</label></th> <td width="67%">%s</td> </tr> <tr> <th width="33%" scope="row"><label for="server_run_as_predefined">%s</label></th> <td width="67%">%s <div id="run_as" style="display: %s"><input name="server_run_as" id="server_run_as" type="text" placeholder="%s" value="%s" /></div></td> </tr> <tr> <th width="33%" scope="row"><label for="server_update_method">%s</label></th> <td width="67%">%s<div id="server_update_port_option" %s><input type="number" name="server_update_port" value="%s" placeholder="80" onkeydown="return validateNumber(event)" maxlength="5" max="65535" /></div></td> </tr> <tr> <th width="33%" scope="row"><label for="server_config_file">%s</label></th> <td width="67%"><input name="server_config_file" id="server_config_file" type="text" value="%s" size="40" placeholder="%s" maxlength="%s" /></td> </tr> <tr> <th width="33%" scope="row"><label for="server_root_dir">%s</label></th> <td width="67%"><input name="server_root_dir" id="server_root_dir" type="text" value="%s" size="40" placeholder="%s" maxlength="%s" /></td> </tr> <tr> <th width="33%" scope="row"><label for="server_chroot_dir">%s</label></th> <td width="67%"><input name="server_chroot_dir" id="server_chroot_dir" type="text" value="%s" size="40" placeholder="%s" maxlength="%s" /></td> </tr> <tr> <th width="33%" scope="row"><label for="server_zones_dir">%s</label></th> <td width="67%"><input name="server_zones_dir" id="server_zones_dir" type="text" value="%s" size="40" placeholder="%s" maxlength="%s" /></td> </tr> </table> %s </form> <script> $(document).ready(function() { $("#manage select").select2({ minimumResultsForSearch: 10, allowClear: true }); }); </script>', __('Server Name'), $server_name, $server_name_length, __('Key'), $server_key, __('Server Type'), $server_type, __('Run-as Account'), $server_run_as_predefined, $runashow, __('Other run-as account'), $server_run_as, __('Update Method'), $server_update_method, $server_update_port_style, $server_update_port, __('Config File'), $server_config_file, $__FM_CONFIG['ns']['named_config_file'], $server_config_file_length, __('Server Root'), $server_root_dir, $__FM_CONFIG['ns']['named_root_dir'], $server_root_dir_length, __('Server Chroot'), $server_chroot_dir, $__FM_CONFIG['ns']['named_chroot_dir'], $server_chroot_dir_length, __('Zone File Directory'), $server_zones_dir, $__FM_CONFIG['ns']['named_zones_dir'], $server_zones_dir_length, $popup_footer); } elseif ($type == 'groups') { $group_masters = isset($group_masters) ? explode(';', $group_masters) : null; $group_slaves = isset($group_slaves) ? explode(';', $group_slaves) : null; $group_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'server_groups', 'group_name'); $group_masters = buildSelect('group_masters', 'group_masters', $this->availableItems('server'), $group_masters, 1, null, true, null, null, __('Select master servers')); $group_slaves = buildSelect('group_slaves', 'group_slaves', $this->availableItems('server'), $group_slaves, 1, null, true, null, null, __('Select slave servers')); $return_form .= sprintf(' <table class="form-table"> <tr> <th width="33%" scope="row"><label for="group_name">%s</label></th> <td width="67%"><input name="group_name" id="group_name" type="text" value="%s" size="40" maxlength="%d" /></td> </tr> <tr> <th width="33%" scope="row"><label for="group_masters">%s</label></th> <td width="67%">%s</td> </tr> <tr> <th width="33%" scope="row"><label for="group_slaves">%s</label></th> <td width="67%">%s</td> </tr> </table> %s </form> <script> $(document).ready(function() { $("#manage select").select2({ minimumResultsForSearch: 10, allowClear: true, width: "230px" }); }); </script>', __('Group Name'), $group_name, $group_name_length, __('Master Servers'), $group_masters, __('Slave Servers'), $group_slaves, $popup_footer); } else { $return_form = buildPopup('header', _('Error')); $return_form .= sprintf('<h3>%s</h3><p>%s</p>', __('Oops!'), __('Invalid request.')); $return_form .= buildPopup('footer', _('OK'), array('cancel')); } return $return_form; }
/** * Displays the form to add new key */ function printForm($data = '', $action = 'add') { global $__FM_CONFIG, $fm_dns_zones; include_once ABSPATH . 'fm-modules/fmDNS/classes/class_zones.php'; $key_id = 0; $key_name = $key_root_dir = $key_zones_dir = $key_comment = null; $ucaction = ucfirst($action); $key_algorithm = $key_view = $key_secret = null; if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) { if (is_array($_POST)) { extract($_POST); } } elseif (@is_object($data[0])) { extract(get_object_vars($data[0])); } /** Check name field length */ $key_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', 'key_name'); $key_secret_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', 'key_secret'); $key_algorithm = buildSelect('key_algorithm', 'key_algorithm', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'keys', 'key_algorithm'), $key_algorithm, 1); $key_view = buildSelect('key_view', 'key_view', $fm_dns_zones->availableViews(), $key_view); $popup_title = $action == 'add' ? __('Add Key') : __('Edit Key'); $popup_header = buildPopup('header', $popup_title); $popup_footer = buildPopup('footer'); $return_form = sprintf('<form name="manage" id="manage" method="post" action=""> %s <input type="hidden" name="action" value="%s" /> <input type="hidden" name="key_id" value="%d" /> <table class="form-table"> <tr> <th width="33%" scope="row"><label for="key_name">%s</label></th> <td width="67%"><input name="key_name" id="key_name" type="text" value="%s" size="40" maxlength="%d" /></td> </tr> <tr> <th width="33%" scope="row"><label for="key_view">%s</label></th> <td width="67%">%s</td> </tr> <tr> <th width="33%" scope="row"><label for="key_algorithm">%s</label></th> <td width="67%">%s</td> </tr> <tr> <th width="33%" scope="row"><label for="key_secret">%s</label></th> <td width="67%"><input name="key_secret" id="key_secret" type="text" value="%s" size="40" maxlength="%d" /></td> </tr> <tr> <th width="33%" scope="row"><label for="key_comment">%s</label></th> <td width="67%"><textarea id="key_comment" name="key_comment" rows="4" cols="30">%s</textarea></td> </tr> </table> %s </form> <script> $(document).ready(function() { $("#manage select").select2({minimumResultsForSearch: 10}); }); </script>', $popup_header, $action, $key_id, __('Key Name'), $key_name, $key_name_length, __('View'), $key_view, __('Algorithm'), $key_algorithm, __('Secret'), $key_secret, $key_secret_length, __('Comment'), $key_comment, $popup_footer); return $return_form; }
/** * Displays the form to add new acl */ function printForm($data = '', $action = 'add') { global $__FM_CONFIG; $acl_id = 0; $acl_name = $acl_addresses = $acl_comment = null; $acl_predefined = 'as defined:'; $ucaction = ucfirst($action); $server_serial_no = isset($_REQUEST['request_uri']['server_serial_no']) && (is_int($_REQUEST['request_uri']['server_serial_no']) && $_REQUEST['request_uri']['server_serial_no'] > 0 || $_REQUEST['request_uri']['server_serial_no'][0] == 'g') ? sanitize($_REQUEST['request_uri']['server_serial_no']) : 0; if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) { if (is_array($_POST)) { extract($_POST); } } elseif (@is_object($data[0])) { extract(get_object_vars($data[0])); } $acl_predefined = buildSelect('acl_predefined', 'acl_predefined', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'acls', 'acl_predefined'), $acl_predefined); $acl_addresses = str_replace(',', "\n", rtrim(str_replace(' ', '', $acl_addresses), ';')); /** Get field length */ $acl_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'acls', 'acl_name'); $popup_title = $action == 'add' ? __('Add ACL') : __('Edit ACL'); $popup_header = buildPopup('header', $popup_title); $popup_footer = buildPopup('footer'); $return_form = sprintf('<form name="manage" id="manage" method="post" action=""> %s <input type="hidden" name="action" value="%s" /> <input type="hidden" name="acl_id" value="%d" /> <input type="hidden" name="server_serial_no" value="%s" /> <table class="form-table"> <tr> <th width="33%" scope="row"><label for="acl_name">%s</label></th> <td width="67%"><input name="acl_name" id="acl_name" type="text" value="%s" size="40" placeholder="%s" maxlength="%d" /></td> </tr> <tr> <th width="33%" scope="row"><label for="acl_predefined">%s</label></th> <td width="67%">%s<br /> <textarea name="acl_addresses" rows="7" cols="28" placeholder="%s">%s</textarea></td> </tr> <tr> <th width="33%" scope="row"><label for="acl_comment">%s</label></th> <td width="67%"><textarea id="acl_comment" name="acl_comment" rows="4" cols="30">%s</textarea></td> </tr> </table> %s </form> <script> $(document).ready(function() { $("#manage select").select2({ width: "200px", minimumResultsForSearch: 10 }); }); </script>', $popup_header, $action, $acl_id, $server_serial_no, __('ACL Name'), $acl_name, __('internal'), $acl_name_length, __('Matched Address List'), $acl_predefined, __('Addresses and subnets delimited by space, semi-colon, or newline'), $acl_addresses, __('Comment'), $acl_comment, $popup_footer); return $return_form; }
function validatePost($post) { global $fmdb, $__FM_CONFIG; if (empty($post['service_name'])) { return __('No service name defined.'); } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'services', 'service_name'); if ($field_length !== false && strlen($post['service_name']) > $field_length) { return sprintf(dngettext($_SESSION['module'], 'Service name is too long (maximum %d character).', 'Service name is too long (maximum %d characters).', $field_length), $field_length); } /** Does the record already exist for this account? */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'services', $post['service_name'], 'service_', 'service_name', "AND service_type='{$post['service_type']}' AND service_id!={$post['service_id']}"); if ($fmdb->num_rows) { return __('This service name already exists.'); } /** Set ports */ if ($post['service_type'] != 'icmp') { foreach ($post['port_src'] as $port) { if (!empty($port) && !verifyNumber($port, 0, 65535, false)) { return sprintf(__('Source ports must be a valid %s port range.'), strtoupper($post['service_type'])); } if (empty($port) || $port == 0) { $post['port_src'] = array('', ''); break; } } sort($post['port_src']); $post['service_src_ports'] = implode(':', $post['port_src']); if ($post['service_src_ports'] == ':') { $post['service_src_ports'] = null; } foreach ($post['port_dest'] as $port) { if (!empty($port) && !verifyNumber($port, 0, 65535, false)) { return sprintf(__('Destination ports must be a valid %s port range.'), strtoupper($post['service_type'])); } if (empty($port) || $port == 0) { $post['port_dest'] = array('', ''); break; } } sort($post['port_dest']); $post['service_dest_ports'] = implode(':', $post['port_dest']); if ($post['service_dest_ports'] == ':') { $post['service_dest_ports'] = null; } unset($post['service_icmp_code']); unset($post['service_icmp_type']); } else { if (!empty($post['service_icmp_type']) && !verifyNumber($post['service_icmp_type'], -1, 40, false)) { return __('ICMP type is invalid.'); } if (empty($post['service_icmp_type'])) { $post['service_icmp_type'] = 0; } if (!empty($post['service_icmp_code']) && !verifyNumber($post['service_icmp_code'], -1, 15, false)) { return __('ICMP code is invalid.'); } if (empty($post['service_icmp_code'])) { $post['service_icmp_code'] = 0; } } /** Process TCP Flags */ if (@is_array($post['service_tcp_flags']) && $post['service_type'] == 'tcp') { $decimals['settings'] = $decimals['mask'] = 0; foreach ($post['service_tcp_flags'] as $type_array => $dec_array) { foreach ($dec_array as $dec => $checked) { $decimals[$type_array] += $dec; } } $post['service_tcp_flags'] = implode(':', $decimals); } else { $post['service_tcp_flags'] = null; } return $post; }
/** * Displays the form to add new view */ function printForm($data = '', $action = 'add') { global $__FM_CONFIG; $view_id = 0; $view_name = $view_root_dir = $view_zones_dir = $view_comment = null; $ucaction = ucfirst($action); $server_serial_no = isset($_REQUEST['request_uri']['server_serial_no']) && (is_int($_REQUEST['request_uri']['server_serial_no']) && $_REQUEST['request_uri']['server_serial_no'] > 0 || $_REQUEST['request_uri']['server_serial_no'][0] == 'g') ? sanitize($_REQUEST['request_uri']['server_serial_no']) : 0; if (!empty($_POST) && !array_key_exists('is_ajax', $_POST)) { if (is_array($data)) { extract($data); } } elseif (@is_object($data[0])) { extract(get_object_vars($data[0])); } /** Get field length */ $view_name_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'views', 'view_name'); $popup_title = $action == 'add' ? __('Add View') : __('Edit View'); $popup_header = buildPopup('header', $popup_title); $popup_footer = buildPopup('footer'); $return_form = sprintf('<form name="manage" id="manage" method="post" action=""> %s <input type="hidden" name="page" id="page" value="views" /> <input type="hidden" name="action" id="action" value="%s" /> <input type="hidden" name="view_id" id="view_id" value="%d" /> <input type="hidden" name="server_serial_no" value="%s" /> <table class="form-table"> <tr> <th width="33%" scope="row"><label for="view_name">%s</label></th> <td width="67%"><input name="view_name" id="view_name" type="text" value="%s" size="40" placeholder="internal" maxlength="%d" /></td> </tr> <tr> <th width="33%" scope="row"><label for="view_comment">%s</label></th> <td width="67%"><textarea id="view_comment" name="view_comment" rows="4" cols="30">%s</textarea></td> </tr> </table> %s </form>', $popup_header, $action, $view_id, $server_serial_no, __('View Name'), $view_name, $view_name_length, __('Comment'), $view_comment, $popup_footer); return $return_form; }