1805 |
clement.si |
1 |
<?php
|
325 |
richard |
2 |
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
|
|
|
3 |
include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
|
|
|
4 |
else{
|
|
|
5 |
echo "<b>Could not include SQL library</b><br>\n";
|
|
|
6 |
exit();
|
|
|
7 |
}
|
|
|
8 |
include_once('../lib/functions.php');
|
1805 |
clement.si |
9 |
if ($config['sql_use_operators'] == 'true'){
|
1091 |
stephane |
10 |
include_once("../lib/operators.php");
|
325 |
richard |
11 |
$text = ',op';
|
|
|
12 |
$passwd_op = ",':='";
|
|
|
13 |
}
|
2384 |
tom.houday |
14 |
|
325 |
richard |
15 |
$da_abort=0;
|
|
|
16 |
$op_val2 = '';
|
1805 |
clement.si |
17 |
$link = da_sql_pconnect($config);
|
325 |
richard |
18 |
if ($link){
|
1878 |
raphael.pi |
19 |
mysqli_set_charset($link,"utf8");
|
325 |
richard |
20 |
if (is_file("../lib/crypt/$config[general_encryption_method].php")){
|
1091 |
stephane |
21 |
include_once("../lib/crypt/$config[general_encryption_method].php");
|
2384 |
tom.houday |
22 |
|
2096 |
raphael.pi |
23 |
//Si auth par @MAC, alors on disocie l'adresse mac du réseau afin que alcasar-macup.sh fasse son travail.
|
2384 |
tom.houday |
24 |
//Si @MAC à auth a la meme adresse IP, on ne fait pas de dhcp-down.(sinon le PHP ne peut pas s'exécuter entierement)
|
|
|
25 |
if ($passwd === 'password' && preg_match('/^([a-fA-F0-9]{2}[:|\-]?){6}$/', $login)) {
|
2392 |
tom.houday |
26 |
$user_ip = exec('sudo /usr/sbin/chilli_query list | awk '.escapeshellarg('($5 == 0) && ($6 == "'.$login.'") {print $2}'));
|
2384 |
tom.houday |
27 |
//on vérifie que l'@IP de l'@MAC est différente de celle de l'admin sur l'ACC
|
|
|
28 |
if ((!empty($user_ip)) && ($user_ip !== $_SERVER['REMOTE_ADDR'])) {
|
2392 |
tom.houday |
29 |
exec('sudo /usr/sbin/chilli_query login mac '.escapeshellarg($login).' username '.escapeshellarg($login).' password '.escapeshellarg($passwd));
|
2384 |
tom.houday |
30 |
}
|
|
|
31 |
}
|
2096 |
raphael.pi |
32 |
|
325 |
richard |
33 |
$passwd = da_encrypt($passwd);
|
1805 |
clement.si |
34 |
$passwd = da_sql_escape_string($link, $passwd);
|
|
|
35 |
$res = da_sql_query($link,$config,
|
325 |
richard |
36 |
"INSERT INTO $config[sql_check_table] (attribute,value,username $text)
|
|
|
37 |
VALUES ('$config[sql_password_attribute]','$passwd','$login' $passwd_op);");
|
1805 |
clement.si |
38 |
if (!$res || !da_sql_affected_rows($link,$res,$config)){
|
325 |
richard |
39 |
echo "<b>Unable to add user $login: " . da_sql_error($link,$config) . "</b><br>\n";
|
|
|
40 |
$da_abort=1;
|
|
|
41 |
}
|
1805 |
clement.si |
42 |
if ($config['sql_use_user_info_table'] == 'true' && !$da_abort){
|
|
|
43 |
$res = da_sql_query($link,$config,
|
325 |
richard |
44 |
"SELECT username FROM $config[sql_user_info_table] WHERE
|
|
|
45 |
username = '$login';");
|
|
|
46 |
if ($res){
|
1805 |
clement.si |
47 |
if (!da_sql_num_rows($res,$config)){
|
|
|
48 |
$Fcn = (isset($Fcn)) ? da_sql_escape_string($link, $Fcn) : '';
|
|
|
49 |
$Fmail = (isset($Fmail)) ? da_sql_escape_string($link, $Fmail) : '';
|
|
|
50 |
$Fou = (isset($Fou)) ? da_sql_escape_string($link, $Fou) : '';
|
|
|
51 |
$Fhomephone = (isset($Fhomephone)) ? da_sql_escape_string($link, $Fhomephone) : '';
|
|
|
52 |
$Ftelephonenumber = (isset($Ftelephonenumber)) ? da_sql_escape_string($link, $Ftelephonenumber) : '';
|
|
|
53 |
$Fmobile = (isset($Fmobile)) ? da_sql_escape_string($link, $Fmobile) : '';
|
|
|
54 |
$res = da_sql_query($link,$config,
|
325 |
richard |
55 |
"INSERT INTO $config[sql_user_info_table]
|
|
|
56 |
(username,name,mail,department,homephone,workphone,mobile) VALUES
|
|
|
57 |
('$login','$Fcn','$Fmail','$Fou','$Fhomephone','$Ftelephonenumber','$Fmobile');");
|
1805 |
clement.si |
58 |
if (!$res || !da_sql_affected_rows($link,$res,$config))
|
325 |
richard |
59 |
echo "<b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
|
|
|
60 |
}
|
|
|
61 |
else
|
|
|
62 |
echo "<b>Cet usager existe déjà dans la table 'info'</b><br>\n";
|
|
|
63 |
}
|
|
|
64 |
else
|
|
|
65 |
echo "<b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
|
|
|
66 |
}
|
1805 |
clement.si |
67 |
if (isset($Fgroup) && $Fgroup != ''){
|
|
|
68 |
$Fgroup = da_sql_escape_string($link, $Fgroup);
|
|
|
69 |
$res = da_sql_query($link,$config,
|
325 |
richard |
70 |
"SELECT username FROM $config[sql_usergroup_table]
|
|
|
71 |
WHERE username = '$login' AND groupname = '$Fgroup';");
|
|
|
72 |
if ($res){
|
1805 |
clement.si |
73 |
if (!da_sql_num_rows($res,$config)){
|
|
|
74 |
$res = da_sql_query($link,$config,
|
325 |
richard |
75 |
"INSERT INTO $config[sql_usergroup_table]
|
|
|
76 |
(username,groupname) VALUES ('$login','$Fgroup');");
|
1805 |
clement.si |
77 |
if (!$res || !da_sql_affected_rows($link,$res,$config))
|
325 |
richard |
78 |
echo "<b>Could not add user to group $Fgroup. SQL Error</b><br>\n";
|
|
|
79 |
}
|
|
|
80 |
else
|
|
|
81 |
echo "<b>User already is a member of group $Fgroup</b><br>\n";
|
|
|
82 |
}
|
|
|
83 |
else
|
|
|
84 |
echo "<b>Could not add user to group $Fgroup: " . da_sql_error($link,$config) . "</b><br>\n";
|
|
|
85 |
}
|
|
|
86 |
if (!$da_abort){
|
1805 |
clement.si |
87 |
if (isset($Fgroup) && $Fgroup != '')
|
325 |
richard |
88 |
require('../lib/defaults.php');
|
|
|
89 |
foreach($show_attrs as $key => $attr){
|
|
|
90 |
if ($attrmap["$key"] == 'none')
|
|
|
91 |
continue;
|
1377 |
richard |
92 |
if ($key == "Filter-Id" && $$attrmap["$key"] == "None")
|
|
|
93 |
continue;
|
325 |
richard |
94 |
if ($attrmap["$key"] == ''){
|
|
|
95 |
$attrmap["$key"] = $key;
|
|
|
96 |
$attr_type["$key"] = 'replyItem';
|
|
|
97 |
$rev_attrmap["$key"] = $key;
|
|
|
98 |
}
|
1805 |
clement.si |
99 |
if (isset($attr_type["$key"]) && $attr_type["$key"] == 'checkItem'){
|
325 |
richard |
100 |
$table = "$config[sql_check_table]";
|
|
|
101 |
$type = 1;
|
|
|
102 |
}
|
1805 |
clement.si |
103 |
else if (isset($attr_type["$key"]) && $attr_type["$key"] == 'replyItem'){
|
325 |
richard |
104 |
$table = "$config[sql_reply_table]";
|
|
|
105 |
$type = 2;
|
|
|
106 |
}
|
1805 |
clement.si |
107 |
$val = (isset($$attrmap["$key"])) ? $$attrmap["$key"] : '';
|
|
|
108 |
$val = da_sql_escape_string($link, $val);
|
325 |
richard |
109 |
$op_name = $attrmap["$key"] . '_op';
|
1805 |
clement.si |
110 |
$op_val = (isset($$op_name)) ? $$op_name : '';
|
325 |
richard |
111 |
if ($op_val != ''){
|
1805 |
clement.si |
112 |
$op_val = da_sql_escape_string($link, $op_val);
|
325 |
richard |
113 |
if (check_operator($op_val,$type) == -1){
|
|
|
114 |
echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
|
508 |
richard |
115 |
continue;
|
325 |
richard |
116 |
}
|
|
|
117 |
$op_val2 = ",'$op_val'";
|
|
|
118 |
}
|
1805 |
clement.si |
119 |
$chkdef = (isset($default_vals["$key"])) ? check_defaults($val,$op_val,$default_vals["$key"]) : 0;
|
|
|
120 |
if ($val == '' || $chkdef)
|
325 |
richard |
121 |
continue;
|
1805 |
clement.si |
122 |
$sqlquery = "INSERT INTO $table (attribute,value,username $text)
|
|
|
123 |
VALUES ('$attrmap[$key]','$val','$login' $op_val2);";
|
|
|
124 |
$res = da_sql_query($link,$config,$sqlquery);
|
|
|
125 |
if (!$res || !da_sql_affected_rows($link,$res,$config))
|
325 |
richard |
126 |
echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
|
|
|
127 |
}
|
|
|
128 |
}
|
2226 |
richard |
129 |
echo "<center><b>$l_user '$login' $l_created</b></center><br>";
|
325 |
richard |
130 |
}
|
|
|
131 |
else
|
|
|
132 |
echo "<b>Could not open encryption library file</b><br>\n";
|
|
|
133 |
}
|
|
|
134 |
else
|
|
|
135 |
echo "<b>Could not connect to SQL database</b><br>\n";
|
|
|
136 |
?>
|