Skip to content

Commit

Permalink
user_management: provide support for textarea in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jul 23, 2024
1 parent b322282 commit 85bd724
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 76 deletions.
12 changes: 8 additions & 4 deletions config/tools/users/user_management/settings.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
116 changes: 45 additions & 71 deletions web/tools/users/user_management/user_management.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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";
}
}
Expand Down

0 comments on commit 85bd724

Please sign in to comment.