Subversion Repositories ALCASAR

Rev

Rev 2384 | Rev 2698 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
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
 
509 richard 33
		/*Ajout en vue de l'impression des données (thank's to Geoffroy MUSITELLI)*/
508 richard 34
		$passwd_imp = $passwd;
35
		/*Fin Ajout*/
325 richard 36
		$passwd = da_encrypt($passwd);
1805 clement.si 37
		$passwd = da_sql_escape_string($link, $passwd);
38
		$res = da_sql_query($link,$config,
325 richard 39
		"INSERT INTO $config[sql_check_table] (attribute,value,username $text)
40
		VALUES ('$config[sql_password_attribute]','$passwd','$login' $passwd_op);");
1805 clement.si 41
		if (!$res || !da_sql_affected_rows($link,$res,$config)){
325 richard 42
			echo "<b>Unable to add user $login: " . da_sql_error($link,$config) . "</b><br>\n";
43
			$da_abort=1;
44
		}
1805 clement.si 45
		if ($config['sql_use_user_info_table'] == 'true' && !$da_abort){
46
			$res = da_sql_query($link,$config,
325 richard 47
			"SELECT username FROM $config[sql_user_info_table] WHERE
48
			username = '$login';");
49
			if ($res){
1805 clement.si 50
				if (!da_sql_num_rows($res,$config)){
51
					$Fcn = (isset($Fcn)) ? da_sql_escape_string($link, $Fcn) : '';
52
					$Fmail = (isset($Fmail)) ? da_sql_escape_string($link, $Fmail) : '';
53
					$Fou = (isset($Fou)) ? da_sql_escape_string($link, $Fou) : '';
54
					$Fhomephone = (isset($Fhomephone)) ? da_sql_escape_string($link, $Fhomephone) : '';
55
					$Ftelephonenumber = (isset($Ftelephonenumber)) ? da_sql_escape_string($link, $Ftelephonenumber) : '';
56
					$Fmobile = (isset($Fmobile)) ? da_sql_escape_string($link, $Fmobile) : '';
57
					$res = da_sql_query($link,$config,
325 richard 58
					"INSERT INTO $config[sql_user_info_table]
59
					(username,name,mail,department,homephone,workphone,mobile) VALUES
60
					('$login','$Fcn','$Fmail','$Fou','$Fhomephone','$Ftelephonenumber','$Fmobile');");
1805 clement.si 61
					if (!$res || !da_sql_affected_rows($link,$res,$config))
325 richard 62
						echo "<b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
63
				}
64
				else
65
					echo "<b>Cet usager existe d&eacute;j&agrave; dans la table 'info'</b><br>\n";
66
			}
67
			else
68
				echo "<b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
69
		}
1805 clement.si 70
		if (isset($Fgroup) && $Fgroup != ''){
71
			$Fgroup = da_sql_escape_string($link, $Fgroup);
72
			$res = da_sql_query($link,$config,
325 richard 73
			"SELECT username FROM $config[sql_usergroup_table]
74
			WHERE username = '$login' AND groupname = '$Fgroup';");
75
			if ($res){
1805 clement.si 76
				if (!da_sql_num_rows($res,$config)){
77
					$res = da_sql_query($link,$config,
325 richard 78
					"INSERT INTO $config[sql_usergroup_table]
79
					(username,groupname) VALUES ('$login','$Fgroup');");
1805 clement.si 80
					if (!$res || !da_sql_affected_rows($link,$res,$config))
325 richard 81
						echo "<b>Could not add user to group $Fgroup. SQL Error</b><br>\n";
82
				}
83
				else
84
					echo "<b>User already is a member of group $Fgroup</b><br>\n";
85
			}
86
			else
87
				echo "<b>Could not add user to group $Fgroup: " . da_sql_error($link,$config) . "</b><br>\n";
88
		}
89
		if (!$da_abort){
1805 clement.si 90
			if (isset($Fgroup) && $Fgroup != '')
325 richard 91
				require('../lib/defaults.php');
92
			foreach($show_attrs as $key => $attr){
93
				if ($attrmap["$key"] == 'none')
94
					continue;
1377 richard 95
				if ($key == "Filter-Id" && $$attrmap["$key"] == "None")
96
					continue;
325 richard 97
				if ($attrmap["$key"] == ''){
98
					$attrmap["$key"] = $key;
99
					$attr_type["$key"] = 'replyItem';
100
					$rev_attrmap["$key"] = $key;
101
				}
1805 clement.si 102
				if (isset($attr_type["$key"]) && $attr_type["$key"] == 'checkItem'){
325 richard 103
					$table = "$config[sql_check_table]";
104
					$type = 1;
105
				}
1805 clement.si 106
				else if (isset($attr_type["$key"]) && $attr_type["$key"] == 'replyItem'){
325 richard 107
					$table = "$config[sql_reply_table]";
108
					$type = 2;
109
				}
1805 clement.si 110
				$val = (isset($$attrmap["$key"])) ? $$attrmap["$key"] : '';
509 richard 111
				/*Ajout en vue de l'impression des données (thank's to Geoffroy MUSITELLI)*/
508 richard 112
				if($key == "Session-Timeout") $sto_imp = $val;
901 richard 113
				if($key == "Max-All-Session") $mas_imp = $val;
508 richard 114
				if($key == "Max-Daily-Session") $mds_imp = $val;
115
				if($key == "Max-Monthly-Session") $mms_imp = $val;
116
				/*Fin Ajout*/
1805 clement.si 117
				$val = da_sql_escape_string($link, $val);
325 richard 118
				$op_name = $attrmap["$key"] . '_op';
1805 clement.si 119
				$op_val = (isset($$op_name)) ? $$op_name : '';
325 richard 120
				if ($op_val != ''){
1805 clement.si 121
					$op_val = da_sql_escape_string($link, $op_val);
325 richard 122
					if (check_operator($op_val,$type) == -1){
123
						echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
508 richard 124
						continue;
325 richard 125
					}
126
					$op_val2 = ",'$op_val'";
127
				}
1805 clement.si 128
				$chkdef = (isset($default_vals["$key"])) ? check_defaults($val,$op_val,$default_vals["$key"]) : 0;
129
				if ($val == '' || $chkdef)
325 richard 130
					continue;
1805 clement.si 131
				$sqlquery = "INSERT INTO $table (attribute,value,username $text)
132
					VALUES ('$attrmap[$key]','$val','$login' $op_val2);";
133
				$res = da_sql_query($link,$config,$sqlquery);
134
				if (!$res || !da_sql_affected_rows($link,$res,$config))
325 richard 135
					echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
136
			}
137
		}
2226 richard 138
		echo "<center><b>$l_user '$login' $l_created</b></center><br>";
325 richard 139
	}
140
	else
141
		echo "<b>Could not open encryption library file</b><br>\n";
142
}
143
else
144
	echo "<b>Could not connect to SQL database</b><br>\n";
145
?>