From 85bd724472bbaf092853c612c28e470e95920c09 Mon Sep 17 00:00:00 2001 From: Razvan Crainea Date: Tue, 23 Jul 2024 14:18:04 +0000 Subject: [PATCH] user_management: provide support for textarea in settings --- .../users/user_management/settings.inc.php | 12 +- .../template/tools_config.edit_tools.php | 3 + .../template/user_management.form.php | 2 +- .../users/user_management/user_management.php | 116 +++++++----------- 4 files changed, 57 insertions(+), 76 deletions(-) diff --git a/config/tools/users/user_management/settings.inc.php b/config/tools/users/user_management/settings.inc.php index 93c850cc..a96d6293 100644 --- a/config/tools/users/user_management/settings.inc.php +++ b/config/tools/users/user_management/settings.inc.php @@ -43,12 +43,16 @@ "default" => "^[a-zA-Z0-9&=+$,;?/%]+$", "opt" => true ), - "user_dialplan_func" => array( + "user_format_func" => array( "default" => "", - "name" => "User Dialplan Function To Check Format", - "type" => "text", + "name" => "User Fromat Function", + "type" => "textarea", "tip" => "Function that receives the user as input and shall return true if the username matches, or false otherwise", - "opt" => "true" + "opt" => "true", + "example" => "function(\$user) { + return true; +}" + ), "table_aliases" => array( "default" => array( diff --git a/web/tools/admin/tools_config/template/tools_config.edit_tools.php b/web/tools/admin/tools_config/template/tools_config.edit_tools.php index 6708dbe6..c4239e86 100644 --- a/web/tools/admin/tools_config/template/tools_config.edit_tools.php +++ b/web/tools/admin/tools_config/template/tools_config.edit_tools.php @@ -74,6 +74,9 @@ $flags |= JSON_FORCE_OBJECT; form_generate_input_textarea($params['name'], $current_tip, $module, $opt, json_encode(get_settings_value($module, $box_id), $flags), (isset($params['maxlen'])?$params['maxlen']:NULL), (isset($params['validation_regex'])?$params['validation_regex']:NULL), $validation, (isset($params['json_format'])?$params['json_format']:NULL)); break; + case "textarea": + form_generate_input_textarea($params['name'], $current_tip, $module, $opt, get_settings_value($module, $box_id)); + break; case "dropdown": if (isAssoc($params['options'])) form_generate_select($params['name'], $current_tip, $module, 100, get_settings_value( $module, $box_id), array_values($params['options']), array_keys($params['options'])); diff --git a/web/tools/users/user_management/template/user_management.form.php b/web/tools/users/user_management/template/user_management.form.php index 71c52685..beab88ad 100644 --- a/web/tools/users/user_management/template/user_management.form.php +++ b/web/tools/users/user_management/template/user_management.form.php @@ -24,7 +24,7 @@ require_once("../../../tools/system/domains/lib/functions.inc.php"); require_once("lib/functions.inc.php"); -$dp_func = get_settings_value("user_dialplan_func"); +$dp_func = get_settings_value("user_format_func"); if ($dp_func) { form_generate_input_text("Username", "The name of the user", "uname", "n", $um_form['username'], 128, null, "validate_func", generate_validate_function("username", $dp_func)); } else { diff --git a/web/tools/users/user_management/user_management.php b/web/tools/users/user_management/user_management.php index f2457e9f..ff9cc15c 100644 --- a/web/tools/users/user_management/user_management.php +++ b/web/tools/users/user_management/user_management.php @@ -143,42 +143,29 @@ print "The user's info was modified"; } } else { - $dp = get_settings_value('user_dialplan'); - $res = true; - - if ($dp) { - $mi_connectors = get_proxys_by_assoc_id(get_settings_value('talk_to_this_assoc_id')); - $res = mi_command("dp_translate", array("dpid" => $dp, "input" => $uname), $mi_connectors[0], $errors); - } - - if (!$res) { - $errors[] = "Invalid Username format!"; - $action="edit"; - } else { - $sql = "UPDATE ".$table." SET username=?, domain=?"; - $sql_vals = array($uname,$domain); - foreach ( get_settings_value("subs_extra") as $key => $value ) { - if (!isset($_POST["extra_".$key]) || $_POST["extra_".$key] == "") { - $value = (isset($value["default"])?$value["default"]:NULL); - } else { - $value = $_POST["extra_".$key]; - } - $sql .= ", ".$key."=?"; - array_push( $sql_vals, $value); - } - $sql .= " WHERE id=?"; - array_push( $sql_vals, $id); - - $stm = $link->prepare($sql); - if ($stm === false) { - die('Failed to issue query ['.$sql.'], error message : ' . print_r($link->errorInfo(), true)); - } - if ($stm->execute( $sql_vals ) == false) { - $errors= "Updating record in DB failed: ".print_r($stm->errorInfo(), true); - } else { - print "The user's info was modified, password not changed"; - } - } + $sql = "UPDATE ".$table." SET username=?, domain=?"; + $sql_vals = array($uname,$domain); + foreach ( get_settings_value("subs_extra") as $key => $value ) { + if (!isset($_POST["extra_".$key]) || $_POST["extra_".$key] == "") { + $value = (isset($value["default"])?$value["default"]:NULL); + } else { + $value = $_POST["extra_".$key]; + } + $sql .= ", ".$key."=?"; + array_push( $sql_vals, $value); + } + $sql .= " WHERE id=?"; + array_push( $sql_vals, $id); + + $stm = $link->prepare($sql); + if ($stm === false) { + die('Failed to issue query ['.$sql.'], error message : ' . print_r($link->errorInfo(), true)); + } + if ($stm->execute( $sql_vals ) == false) { + $errors= "Updating record in DB failed: ".print_r($stm->errorInfo(), true); + } else { + print "The user's info was modified, password not changed"; + } } } }else{ @@ -298,33 +285,21 @@ ################# if ($action=="add_verify") { - if(!$_SESSION['read_only']){ - require("lib/".$page_id.".test.inc.php"); - if ($form_valid) { - if (get_settings_value("passwd_mode")==1) { - $ha1 = md5($uname.":".$domain.":".$passwd); - $sha256 = hash("sha256", $uname.":".$domain.":".$passwd); - $sha512t256 = hash("sha512/256", $uname.":".$domain.":".$passwd); - $passwd=""; - } else { - $ha1 = ""; - $sha256 = ""; - $sha512t256 = ""; - } - - $dp = get_settings_value('user_dialplan'); - $res = true; - - if ($dp) { - $mi_connectors = get_proxys_by_assoc_id(get_settings_value('talk_to_this_assoc_id')); - $res = mi_command("dp_translate", array("dpid" => $dp, "input" => $uname), $mi_connectors[0], $errors); - } + if(!$_SESSION['read_only']){ + require("lib/".$page_id.".test.inc.php"); + if ($form_valid) { + if (get_settings_value("passwd_mode")==1) { + $ha1 = md5($uname.":".$domain.":".$passwd); + $sha256 = hash("sha256", $uname.":".$domain.":".$passwd); + $sha512t256 = hash("sha512/256", $uname.":".$domain.":".$passwd); + $passwd=""; + } else { + $ha1 = ""; + $sha256 = ""; + $sha512t256 = ""; + } - if (!$res) { - $errors[] = "Invalid Username format!"; - $action="add"; - } else { - $sql = 'INSERT INTO '.$table.' (username,domain,password,ha1,ha1_sha256,ha1_sha512t256'; + $sql = 'INSERT INTO '.$table.' (username,domain,password,ha1,ha1_sha256,ha1_sha512t256'; foreach ( get_settings_value("subs_extra") as $key => $value ) if (isset($_POST['extra_'.$key]) && $_POST['extra_'.$key]!='') $sql .= ','.$key; @@ -343,7 +318,7 @@ } $sql .= ')'; - $stm = $link->prepare($sql); + $stm = $link->prepare($sql); if ($stm === false) { die('Failed to issue query ['.$sql.'], error message : ' . print_r($link->errorInfo(), true)); } @@ -353,7 +328,7 @@ if ($alias!="") { $sql = 'INSERT INTO '.$alias_type.' (username,domain,alias_username,alias_domain) VALUES (?, ?, ?, ?)'; - $stm = $link->prepare($sql); + $stm = $link->prepare($sql); if ($stm === false) { die('Failed to issue query ['.$sql.'], error message : ' . print_r($link->errorInfo(), true)); } @@ -369,16 +344,15 @@ $passwd=NULL; $confirm_passwd=NULL; - print "New User added!"; - $action="add"; + print "New User added!"; + $action="add"; } + } else { + print $form_error; + $action="add_verify"; } - } else { - print $form_error; - $action="add_verify"; - } -} else { + } else { $errors= "User with Read-Only Rights"; } }