sql_use_operators configuration directive. Hope everything works.
* Fixed a bug in sql/change_attrs which did not allow multi valued attributes in sql.
* unset item_vals before adding info in ldap and sql user_info files.
* Fix a bug in config.php3 when we have a directive containing ':'
* Fix a bug in lib/ldap/change_attrs.php3 that did not allow changing more than one value of a
multivalued attribute simultaneously.
+* Added selection of ordering in user_accounting.php3. Now it can be either ascending (older records
+ first) or descending (most recent records first). Added a corresponding configuration directive.
+* Added operator support in sql. The eq(=),set(:=) and add(+=) operators are supported. Added an
+ sql_use_operators configuration directive. Hope everything works.
+* Fixed a bug in sql/change_attrs which did not allow multi valued attributes in sql.
+* unset item_vals before adding info in ldap and sql user_info files.
Ver 1.28:
* Make user_delete.php3 print something when a user is deleted
* Cache nas hostname lookups in user_accounting
# true or false
#
sql_use_user_info_table: true
+sql_use_operators: true
+#
+#
sql_password_attribute: Crypt-Password
sql_date_format: Y-m-d
sql_full_date_format: Y-m-d H:i:s
require('../lib/defaults.php3');
if (is_file("../lib/$config[general_lib_type]/user_info.php3"))
include("../lib/$config[general_lib_type]/user_info.php3");
+if ($config[general_lib_type] == 'sql' && $config[sql_use_operators] == 'true'){
+ $colspan=2;
+ $show_ops = 1;
+ $op_eq = '=';
+ $op_set = ':=';
+ $op_add = '+=';
+}
+else{
+ $show_ops = 0;
+ $colspan=1;
+}
+
echo <<<EOM
<html>
<input type=hidden name=badusers value="0">
<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
<tr>
-<td align=right bgcolor="#d0ddb0">
+<td align=right colspan=<?php print $colspan ?> bgcolor="#d0ddb0">
User Password (changes only)
</td>
<td>
if ($name == 'none')
continue;
unset($vals);
- if (count($item_vals["$key"])){
- for($i=0;$i<$item_vals["$key"][count];$i++)
+ unset($selected);
+ unset($ops);
+ if ($item_vals["$key"][count]){
+ for($i=0;$i<$item_vals["$key"][count];$i++){
$vals[] = $item_vals["$key"][$i];
+ $ops[] = $item_vals["$key"][operator][$i];
+ }
}
- else
+ else{
$vals[] = $default_vals["$key"];
- if ($add && $name == $add_attr)
+ $ops[] = '=';
+ }
+ if ($add && $name == $add_attr){
array_push($vals, $default_vals["$key"]);
+ array_push($ops, '=');
+ }
$i = 0;
foreach($vals as $val){
$name1 = $name . $i;
+ $oper_name = $name1 . '_op';
+ $oper = $ops[$i];
+ $selected[$oper] = 'selected';
$i++;
print <<<EOM
<tr>
<td align=right bgcolor="#d0ddb0">
$desc
</td>
+EOM;
+
+ if ($show_ops)
+ print <<<EOM
+<td>
+<select name=$oper_name>
+<option $selected[$op_eq] value="=">=
+<option $selected[$op_set] value=":=">:=
+<option $selected[$op_add] value="+=">+=
+</select>
+</td>
+EOM;
+
+ print <<<EOM
<td>
<input type=text name="$name1" value="$val" size=40>
</td>
}
?>
<tr>
-<td align=right bgcolor="#d0ddb0">
+<td align=right colspan=<?php print $colspan ?> bgcolor="#d0ddb0">
Add Attribute
</td>
<td>
require('../conf/config.php3');
require('../lib/attrshow.php3');
require('../lib/defaults.php3');
+
+if ($config[general_lib_type] == 'sql' && $config[sql_use_operators] == 'true'){
+ $colspan=2;
+ $show_ops=1;
+ $op_eq = '=';
+ $op_set = ':=';
+ $op_add = '+=';
+}else{
+ $show_ops = 0;
+ $colspan=1;
+}
+
?>
<html>
<?php
echo <<<EOM
<tr>
- <td align=right bgcolor="#d0ddb0">
+ <td align=right colspan=$colspan bgcolor="#d0ddb0">
Username
</td><td>
<input type=text name="login" value="$login" size=35>
</td>
</tr>
<tr>
- <td align=right bgcolor="#d0ddb0">
+ <td align=right colspan=$colspan bgcolor="#d0ddb0">
Password
</td><td>
<input type=text name="passwd" size=35>
</td>
</tr>
<tr>
- <td align=right bgcolor="#d0ddb0">
+ <td align=right colspan=$colspan bgcolor="#d0ddb0">
Name (First Name Surname)
</td><td>
<input type=text name="cn" value="$cn" size=35>
</td>
</tr>
<tr>
- <td align=right bgcolor="#d0ddb0">
+ <td align=right colspan=$colspan bgcolor="#d0ddb0">
Mail
</td><td>
<input type=text name="mail" value="$mail" size=35>
</td>
</tr>
<tr>
- <td align=right bgcolor="#d0ddb0">
+ <td align=right colspan=$colspan bgcolor="#d0ddb0">
Departement
</td><td>
<input type=text name="ou" value="$ou" size=35>
</td>
</tr>
<tr>
- <td align=right bgcolor="#d0ddb0">
+ <td align=right colspan=$colspan bgcolor="#d0ddb0">
Home Phone
</td><td>
<input type=text name="homephone" value="$homephone" size=35>
</td>
</tr>
<tr>
- <td align=right bgcolor="#d0ddb0">
+ <td align=right colspan=$colspan bgcolor="#d0ddb0">
Work Phone
</td><td>
<input type=text name="telephonenumber" value="$telephonenumber" size=35>
</td>
</tr>
<tr>
- <td align=right bgcolor="#d0ddb0">
+ <td align=right colspan=$colspan bgcolor="#d0ddb0">
Mobile Phone
</td><td>
<input type=text name="mobile" value="$mobile" size=35>
$name = $attrmap["$key"];
if ($name == 'none')
continue;
+ $oper_name = $name . '_op';
$val = ($item_vals["$key"][0] != "") ? $item_vals["$key"][0] : $default_vals["$key"];
print <<<EOM
<tr>
<td align=right bgcolor="#d0ddb0">
$desc
</td>
+EOM;
+
+ if ($show_ops)
+ print <<<EOM
+<td>
+<select name=$oper_name>
+<option selected value="=">=
+<option value=":=">:=
+<option value="+=">+=
+</select>
+</td>
+EOM;
+
+ print <<<EOM
<td>
<input type=text name="$name" value="$val" size=35>
</td>
$user_exists = 'no';
else{
$user_exists = 'yes';
+ unset($item_vals);
$k = init_decoder();
$cn = ($info[0]['cn'][0]) ? $info[0]['cn'][0] : '-';
$cn_lang = $info[0]["cn;lang-$config[general_prefered_lang]"][0];
echo "<b>Could not include SQL library</b><br>\n";
exit();
}
+if ($config[sql_use_operators] == 'true'){
+ $use_ops=1;
+ $text1 = 'AND op =';
+ $text2 = ',op';
+}
$link = @da_sql_pconnect($config);
if ($link){
foreach($show_attrs as $key => $desc){
while(isset($$name)){
$val=$$name;
+ $op_name = $name . '_op';
+ $op_val = $$op_name;
+ if ($op_val != ''){
+ $op_val1 = "'$op_val'";
+ $op_val2 = ",'$op_val'";
+ }
$i++;
$j++;
$name = $attrmap["$key"] . $i;
$table = $config[sql_check_table];
else if ($attr_type["$key"] == 'replyItem')
$table = $config[sql_reply_table];
+ // if we have operators the operator has changed and the corresponding value exists then update
+ if ($use_ops && isset($item_vals["$key"][operator][$j]) &&
+ $op_val != $item_vals["$key"][operator][$j] ){
+ $res = @da_sql_query($link,$config,
+ "UPDATE $table SET op = '$op_val' WHERE UserName = '$login'
+ AND Attribute = '$sql_attr' AND Value = '$val';");
+ if (!$res || !@da_sql_affected_rows($link,$res,$config))
+ echo "<b>Operator change failed for attribute $key</b><br>\n";
+ }
+
// if value is the same as that in the sql database do nothing
if ($val == $item_vals["$key"][$j])
continue;
continue;
// if value differs from the sql value then update
else{
- if (isset($item_vals["$key"][$j]))
+ if (isset($item_vals["$key"][$j])){
+ $old_val = $item_vals["$key"][$j];
$res = @da_sql_query($link,$config,
"UPDATE $table SET Value = '$val' WHERE UserName = '$login' AND
- Attribute = '$sql_attr';");
+ Attribute = '$sql_attr' AND Value = '$old_val';");
+ }
else
$res = @da_sql_query($link,$config,
- "INSERT INTO $table (UserName,Attribute,Value)
- VALUES ('$login','$sql_attr','$val');");
+ "INSERT INTO $table (UserName,Attribute,Value $text2)
+ VALUES ('$login','$sql_attr','$val' $op_val2);");
if (!$res || !@da_sql_affected_rows($link,$res,$config))
echo "<b>Change failed for attribute $key</b><br>\n";
}
echo "<b>Could not include SQL library</b><br>\n";
exit();
}
+if ($config[sql_use_operator] == 'true'){
+ $text1 = ',op';
+ $text2 = ",':='";
+ $text3 = "AND op = ':='";
+}
$link = @da_sql_pconnect($config);
if ($link){
if (is_file("../lib/crypt/$config[general_encryption_method].php3")){
$row = @da_sql_fetch_array($res,$config);
if ($row){
$res = @da_sql_query($link,$config,
- "UPDATE $config[sql_check_table] SET Value = '$passwd' WHERE
+ "UPDATE $config[sql_check_table] SET Value = '$passwd' $text3 WHERE
Attribute = '$config[sql_password_attribute]' AND UserName = '$login';");
if (!$res || !@da_sql_affected_rows($link,$res,$config))
echo "<b>Error while changing password</b><br>\n";
}
else{
$res = @da_sql_query($link,$config,
- "INSERT INTO $config[sql_check_table] (Attribute,Value,UserName)
- VALUES ('$config[sql_password_attribute]','$passwd','$login');");
+ "INSERT INTO $config[sql_check_table] (Attribute,Value,UserName $text1)
+ VALUES ('$config[sql_password_attribute]','$passwd','$login' $text2);");
if (!$res || !@da_sql_affected_rows($link,$res,$config))
echo "<b>Error while changing password</b><br>\n";
}
echo "<b>Could not include SQL library</b><br>\n";
exit();
}
+if ($config[sql_use_operators] == 'true'){
+ $text = ',op';
+ $passwd_op = ",':='";
+}
$da_abort=0;
$link = @da_sql_pconnect($config);
if ($link){
include("../lib/crypt/$config[general_encryption_method].php3");
$passwd = da_encrypt($passwd);
$res = @da_sql_query($link,$config,
- "INSERT INTO $config[sql_check_table] (Attribute,Value,UserName)
- VALUES ('$config[sql_password_attribute]','$passwd','$login');");
+ "INSERT INTO $config[sql_check_table] (Attribute,Value,UserName $text)
+ VALUES ('$config[sql_password_attribute]','$passwd','$login' $passwd_op);");
if (!$res || !@da_sql_affected_rows($link,$res,$config)){
echo "<b>Unable to add user $login. SQL error</b><br>\n";
$da_abort=1;
else if ($attr_type[$key] == 'replyItem')
$table = "$config[sql_reply_table]";
$val = $$attrmap["$key"];
+ $op_name = $attrmap["$key"] . '_op';
+ $op_val = $$op_name;
+ if ($op_val != '')
+ $op_val = ",'$op_val'";
if ($val == '' || $val == $default_vals["$key"])
continue;
$res = @da_sql_query($link,$config,
- "INSERT INTO $table (Attribute,Value,UserName)
- VALUES ('$attrmap[$key]','$val','$login');");
+ "INSERT INTO $table (Attribute,Value,UserName $text)
+ VALUES ('$attrmap[$key]','$val','$login' $op_val);");
if (!$res || !@da_sql_affected_rows($link,$res,$config))
echo "<b>Query failed for attribute $key</b><br>\n";
}
echo "<b>Could not include SQL library</b><br>\n";
exit();
}
+if ($config[sql_use_operators] == 'true'){
+ $op = ',op';
+ $use_op = 1;
+}else{
+ $op = "";
+ $use_op = 0;
+}
$user_exists = 'no';
+unset($item_vals);
+unset($tmp);
$link = @da_sql_pconnect($config);
if ($link){
$res = @da_sql_query($link,$config,
- "SELECT Attribute,Value FROM $config[sql_check_table] WHERE UserName = '$login';");
+ "SELECT Attribute,Value $op FROM $config[sql_check_table] WHERE UserName = '$login';");
if ($res){
if (@da_sql_num_rows($res,$config))
$user_exists = 'yes';
while(($row = @da_sql_fetch_array($res,$config))){
$attr = $row[Attribute];
$val = $row[Value];
+ if ($use_op){
+ $oper = $row[op];
+ $tmp["$attr"][operator][]="$oper";
+ }
$tmp["$attr"][]="$val";
$tmp["$attr"][count]++;
}
$res = @da_sql_query($link,$config,
- "SELECT Attribute,Value FROM $config[sql_reply_table] WHERE UserName = '$login';");
+ "SELECT Attribute,Value $op FROM $config[sql_reply_table] WHERE UserName = '$login';");
if ($res){
while(($row = @da_sql_fetch_array($res,$config))){
$attr = $row[Attribute];
$val = $row[Value];
+ if ($use_op){
+ $oper = $row[op];
+ $tmp["$attr"][operator][]="$oper";
+ }
$tmp["$attr"][] = "$val";
$tmp["$attr"][count]++;
}
if (isset($tmp[$val])){
$item_vals["$key"] = $tmp[$val];
$item_vals["$key"][count] = $tmp[$val][count];
+ if ($use_op)
+ $item_vals["$key"][operator] = $tmp[$val][operator];
+
}
}