]> git.entuzijast.net Git - freeradius-dialup-admin.git/commitdiff
* Added operator support in sql. The eq(=),set(:=) and add(+=) operators are supporte...
authorkkalev <kkalev>
Thu, 7 Feb 2002 17:58:36 +0000 (17:58 +0000)
committerkkalev <kkalev>
Thu, 7 Feb 2002 17:58:36 +0000 (17:58 +0000)
  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.

Changelog
conf/admin.conf
htdocs/user_edit.php3
htdocs/user_new.php3
lib/ldap/user_info.php3
lib/sql/change_attrs.php3
lib/sql/change_passwd.php3
lib/sql/create_user.php3
lib/sql/user_info.php3

index ef4b06f0122701fb3cb4644f5f3d088b4808bc84..9d0b751e13865a6edf999953b2fc3dd7557f7632 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -5,6 +5,12 @@ Ver 1.29:
 * 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
index 0d3d9f46a53086ac90d8c585d2047962f511a0b7..b07f517b79ec9d08ad279a3c41d2c2f5693e1304 100644 (file)
@@ -95,6 +95,9 @@ sql_user_info_table: userinfo
 # 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
index 605719913dbca00eef3c95cd4fe4127a12432084..765e2f982cb893f8c90e1dff630eda5ea67f30dd 100644 (file)
@@ -4,6 +4,18 @@ require('../lib/attrshow.php3');
 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>
@@ -69,7 +81,7 @@ else if ($badusers == 1){
       <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>
@@ -82,24 +94,49 @@ User Password (changes only)
                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>
@@ -109,7 +146,7 @@ EOM;
        }
 ?>
 <tr>
-<td align=right bgcolor="#d0ddb0">
+<td align=right colspan=<?php print $colspan ?> bgcolor="#d0ddb0">
 Add Attribute
 </td>
 <td>
index ede6691c40ebc17d7f907c4438716c1451e35289..90104bba101b4464c9984360bff5cd935b39757b 100644 (file)
@@ -6,6 +6,18 @@ if ($show == 1){
 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>
@@ -63,56 +75,56 @@ EOM;
 <?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>
@@ -123,12 +135,27 @@ EOM;
                $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>
index 73242fda233e975bcb0eefb5536ba09e30cac1e8..34fd632c49298186bdd70051a334e114e0409d1f 100644 (file)
@@ -15,6 +15,7 @@ if ($ds) {
                $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];
index de8f76e96d45e4c1a33a3ef7535f6d74f41dfb4f..f12fd1f25f23cf389c8a27bb0460a67d8b218580 100644 (file)
@@ -5,6 +5,11 @@ else{
        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){
@@ -16,6 +21,12 @@ if ($link){
 
                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;
@@ -25,6 +36,16 @@ if ($link){
                                $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;
@@ -40,14 +61,16 @@ if ($link){
                                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";   
                        }
index 77c5f9e21bf13e981145fa4705a84c1630e51de6..dbe908077bc066dc8a92c89663cae86ca535bb5a 100644 (file)
@@ -5,6 +5,11 @@ else{
        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")){
@@ -17,15 +22,15 @@ if ($link){
                        $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";
                        }
index 5c580acd928c2cb82e35d9ec7b520bb13277f960..7cc51855b370c41a3ba421eb415bd4ca7cb9dc84 100644 (file)
@@ -5,6 +5,10 @@ else{
        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){
@@ -12,8 +16,8 @@ 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;
@@ -44,11 +48,15 @@ if ($link){
                                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";
                        }
index 9abae6678a3023776bb9033827df560b3a93075d..0a992488f2555250b113d0743b539f97fcd0c06b 100644 (file)
@@ -6,26 +6,43 @@ else{
        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]++;
                        }
@@ -50,6 +67,9 @@ if ($link){
                        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];
+
                        }
                }