]> git.entuzijast.net Git - freeradius-dialup-admin.git/commitdiff
* Allow for multiple default values. Also add a generic flag in ldap attrmap. If...
authorkkalev <kkalev>
Fri, 6 Sep 2002 16:17:26 +0000 (16:17 +0000)
committerkkalev <kkalev>
Fri, 6 Sep 2002 16:17:26 +0000 (16:17 +0000)
  attribute is generic and user values *do not* overwrite default values. The operators in the generic
  attribute can be used for that. The same is very difficult to implement for sql, so for now user
  values overwrite default values in sql (user edit page).
  A lot of code and a lot of files where changed so there may be bugs somewhere.

17 files changed:
Changelog
conf/extra.ldap-attrmap
htdocs/group_new.php3
htdocs/user_admin.php3
htdocs/user_edit.php3
htdocs/user_new.php3
htdocs/user_state.php3
lib/defaults.php3
lib/functions.php3
lib/ldap/attrmap.php3
lib/ldap/change_attrs.php3
lib/ldap/create_user.php3
lib/ldap/defaults.php3
lib/sql/change_attrs.php3
lib/sql/create_group.php3
lib/sql/create_user.php3
lib/sql/defaults.php3

index 53df19eb04ebf2af44def6b3a8911698a9138f82..0db2a6e14fc29d40a68f41f3aba7d36b3887cc70 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -8,6 +8,11 @@ Ver 1.56:
 * Fix a bug in lib/sql/change_passwd.php3 when not using operators.
   Bug report from Sheldon Fougere <sfougere@solutioninc.com>
 * Add the caller id in the connection status attributes in the show user page
+* Allow for multiple default values. Also add a generic flag in ldap attrmap. If it exists then the
+  attribute is generic and user values *do not* overwrite default values. The operators in the generic
+  attribute can be used for that. The same is very difficult to implement for sql, so for now user
+  values overwrite default values in sql (user edit page).
+  A lot of code and a lot of files where changed so there may be bugs somewhere.
 Ver 1.55:
 * Update the FAQ about missing attributes from the user/group edit pages and add a few comments
   in the configuration files
index 8edf30f048a516a5a9642c531e2a437594b2f432..69b5320a7b51081d2e4dccccf352c22fc6e43b11 100644 (file)
@@ -4,5 +4,5 @@
 checkItem       Dialup-Lock-Msg                radiuslockmsg
 checkItem      User-Password           userpassword
 checkItem      Regular-Profile         radiusProfileDn
-checkItem      Check-Item              radiusCheckItem
-replyItem      Reply-Item              radiusReplyItem
+checkItem      Check-Item              radiusCheckItem         generic
+replyItem      Reply-Item              radiusReplyItem         generic
index d668b5493935be35371d46bdd1d6ab86966b4044..2feb03a7b6511b560bfde183bb6fb51beeebed58 100644 (file)
@@ -104,7 +104,7 @@ EOM;
                if ($name == 'none')
                        continue;
                $oper_name = $name . '_op';
-               $val = ($item_vals["$key"][0] != "") ? $item_vals["$key"][0] : $default_vals["$key"];
+               $val = ($item_vals["$key"][0] != "") ? $item_vals["$key"][0] : $default_vals["$key"][0];
                print <<<EOM
 <tr>
 <td align=right bgcolor="#d0ddb0">
index fb84a2eb5776dbb2071446a3df2d5151c7663330..6fd8d6a2a65fb1ebe38b414dec667964d44813a2 100644 (file)
@@ -44,13 +44,13 @@ EOM;
        exit();
 }
 
-$monthly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'];
+$monthly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'][0];
 $monthly_limit = ($monthly_limit) ? $monthly_limit : $config[counter_default_monthly];
-$weekly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'];
+$weekly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'][0];
 $weekly_limit = ($weekly_limit) ? $weekly_limit : $config[counter_default_weekly];
-$daily_limit = ($item_vals['Max-Daily-Session'][0] != '') ? $item_vals['Max-Daily-Session'][0] : $default_vals['Max-Daily-Session'];
+$daily_limit = ($item_vals['Max-Daily-Session'][0] != '') ? $item_vals['Max-Daily-Session'][0] : $default_vals['Max-Daily-Session'][0];
 $daily_limit = ($daily_limit) ? $daily_limit : $config[counter_default_daily];
-$session_limit = ($item_vals['Session-Timeout'][0] != '') ? $item_vals['Session-Timeout'][0] : $default_vals['Session-Timeout'];
+$session_limit = ($item_vals['Session-Timeout'][0] != '') ? $item_vals['Session-Timeout'][0] : $default_vals['Session-Timeout'][0];
 $session_limit = ($session_limit) ? $session_limit : 'none';
 $remaining = 'unlimited time';
 $log_color = 'green';
@@ -247,7 +247,7 @@ EON;
 else
        $descr = '-';
 
-$expiration = $default_vals['Expiration'];
+$expiration = $default_vals['Expiration'][0];
 if ($item_vals['Expiration'][0] != '')
        $expiration = $item_vals['Expiration'][0];
 if ($expiration != ''){
index c4afb71c7ae2d9a53ded2de5670b35f865f7fda7..86325c514e790657d7e6e367495e02858c465350 100644 (file)
@@ -121,11 +121,13 @@ EOM;
 }
        foreach($show_attrs as $key => $desc){
                $name = $attrmap["$key"];
+               $generic = $attrmap[generic]["$key"];
                if ($name == 'none')
                        continue;
                unset($vals);
                unset($selected);
                unset($ops);
+               $def_added = 0;
                if ($item_vals["$key"][count]){
                        for($i=0;$i<$item_vals["$key"][count];$i++){
                                $vals[] = $item_vals["$key"][$i];
@@ -133,12 +135,27 @@ EOM;
                        }
                }
                else{
-                       $vals[] = $default_vals["$key"];
-                       $ops[] = ($default_vals["$key"][operator] != '') ? $default_vals["$key"][operator] : '=';
+                       if ($default_vals["$key"][count]){
+                               for($i=0;$i<$default_vals["$key"][count];$i++){
+                                       $vals[] = $default_vals["$key"][$i];
+                                       $ops[] = $default_vals["$key"][operator][$i];
+                               }
+                       }
+                       else{
+                               $vals[] = '';
+                               $ops[] = '=';
+                       }
+                       $def_added = 1;
                }
+               if ($generic == 'generic' && $def_added == 0){
+                       for($i=0;$i<$default_vals["$key"][count];$i++){
+                               $vals[] = $default_vals["$key"][$i];
+                               $ops[] = $default_vals["$key"][operator][$i];
+                       }
+               }       
                if ($add && $name == $add_attr){
-                       array_push($vals, $default_vals["$key"]);
-                       array_push($ops, '=');
+                       $vals[] = $default_vals["$key"][0];
+                       $ops[] = ($default_vals["$key"][operator][0] != '') ? $default_vals["$key"][operator][0] : '=';
                }
 
                $i = 0;
index e239e1f7bba7dba25fbe0783a338aa157c461043..145b9833bb88996da2386ba79b4d70f95c8f5a65 100644 (file)
@@ -151,7 +151,7 @@ EOM;
                if ($name == 'none')
                        continue;
                $oper_name = $name . '_op';
-               $val = ($item_vals["$key"][0] != "") ? $item_vals["$key"][0] : $default_vals["$key"];
+               $val = ($item_vals["$key"][0] != "") ? $item_vals["$key"][0] : $default_vals["$key"][0];
                print <<<EOM
 <tr>
 <td align=right bgcolor="#d0ddb0">
index e9a31d9d90e5119e667a333cfc7dcaaf685b0c8c..a8e45955fac3d39411f90a6e6ecaef9b3ca8df2d 100644 (file)
@@ -13,7 +13,7 @@ else
 $vars = array( 'Dialup-Access' => 'TRUE','Dialup-Lock-Msg' => '-',
                'Max-Weekly-Session' => 0,'Max-Daily-Session' => 0);
 foreach($vars as $key => $val){
-       $val = ($item_vals["$key"][0] != "") ? $item_vals["$key"][0] : $default_vals["$key"];
+       $val = ($item_vals["$key"][0] != "") ? $item_vals["$key"][0] : $default_vals["$key"][0];
        $vars["$key"]=$val;
 }
 $vars['Dialup-Access'] = ($vars['Dialup-Access'] == 'FALSE') ? 'inactive' : 'active';
index 1bdce8f2b49337ea766a4cd61f7e425ed9aac485..3d081a67c2dbe38b41aa342bc292b472fe214171 100644 (file)
@@ -5,7 +5,7 @@ foreach($ARR as $val) {
        if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
                continue;
        list($key,$v)=split(":[[:space:]]*",$val);
-       $default_vals["$key"]="$v";
+       $default_vals["$key"][0]="$v";
 }
 if (is_file("../lib/$config[general_lib_type]/defaults.php3"))
         include("../lib/$config[general_lib_type]/defaults.php3");
index 48bbc407b2445fda91369ad40b61e1b0bc7d35cf..1a60c1f3fa57ae019fd88b31482c78517d60e8c4 100644 (file)
@@ -86,6 +86,8 @@ function date2time($date)
 function bytes2str($bytes)
 {
        $bytes=floor($bytes);
+       if ($bytes > 536870912)
+               $str = sprintf("%5.2f GBs", $bytes/1073741824);
        if ($bytes > 524288)
                $str = sprintf("%5.2f MBs", $bytes/1048576);
        else
@@ -98,4 +100,13 @@ function nothing($ret)
 {
        return $ret;
 }
+function check_defaults($val,$op,$def)
+{
+       for($i=0;$i<$def[count];$i++){
+               if ($val == $def[$i] && ($op == '' || $op == $def[operator][$i]))
+                       return 1;
+       }
+
+       return 0;
+}
 ?>
index f7a3199b7c4aca806adf58485a78401bbc290deb..e5aac1c50637ab73d6a342399a816e6eb2945dbe 100644 (file)
@@ -5,17 +5,19 @@ foreach($ARR as $val){
        $val=chop($val);
        if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
                continue;
-       list(,$key,$v)=split('[[:space:]]+',$val);
+       list(,$key,$v,$g)=split('[[:space:]]+',$val);
        $v = strtolower($v);
        $attrmap["$key"]=$v;
+       $attrmap[generic]["$key"]=$g;
 }
 $ARR = file("$config[general_extra_ldap_attrmap]");
 foreach($ARR as $val){
        $val=chop($val);
        if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
                continue;
-       list(,$key,$v)=split('[[:space:]]+',$val);
+       list(,$key,$v,$g)=split('[[:space:]]+',$val);
        $v = strtolower($v);
        $attrmap["$key"]=$v;
+       $attrmap[generic]["$key"]=$g;
 }
 ?>
index 23692bdd5872d8d62ced711ee3b375206252e107..5d03a6009694c45db956f8072f57efe8dada3fe6 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+require('../lib/functions.php3');
        $ds = @ldap_connect($config[ldap_server]);
        if ($ds){
                $r = @ldap_bind($ds,"$config[ldap_binddn]",$config[ldap_bindpw]);
@@ -20,8 +21,7 @@
 //     if value is the same as the default and the corresponding attribute in ldap does not exist or
 //     the value is the same as that in ldap then continue
 //
-                                       if ( ($val == $default_vals["$key"] && !isset($item_vals["$key"][$j])) ||
-                                               $val == $item_vals["$key"][$j])
+                                       if ( (check_defaults($val,'',$default_vals["$key"]) && !isset($item_vals["$key"][$j])) || $val == $item_vals["$key"][$j])
                                                continue;
 //
 //     if value is null and ldap attribute does not exist then continue
@@ -32,7 +32,7 @@
 //     if values is the same as the default or if the value is null and the ldap attribute exists
 //     then delete them
 //
-                                       if (($val == $default_vals["$key"] || $val == '') && 
+                                       if ((check_defaults($val,'',$default_vals["$key"]) || $val == '') && 
                                                isset($item_vals["$key"][$j]))
                                                $del[$attrmap["$key"]][] = $item_vals["$key"][$j];
 //
index c2837ba131e31e3a0bc1c49d1982d1363031d2f1..1115e6f22312d717cae91765d3adc7f2263bcc44 100644 (file)
@@ -40,7 +40,7 @@
 //     if value is the same as the default and the corresponding attribute in ldap does not exist or
 //     the value is the same as that in ldap then continue
 //
-                               if ( $$attrmap["$key"] == $default_vals["$key"])
+                               if ( check_defaults($$attrmap["$key"],'',$default_vals["$key"]))
                                        continue;
                                if ( $$attrmap["$key"] == '')
                                        continue;
index c5fb4a5a65ae427ea2183c7bd5e276db5c0165ac..3a918264a4041410bf2b37349276346910b32dbc 100644 (file)
@@ -10,8 +10,15 @@ if ($config[ldap_default_dn] != ''){
                                $dn = $info[0]['dn'];
                                if ($dn != ''){
                                        foreach($attrmap as $key => $val){
-                                       if ($info[0]["$val"][0] != '')
-                                               $default_vals["$key"] = $info[0]["$val"][0];
+                                               if ($info[0]["$val"][0] != ''){
+                                                       if ($attrmap[generic]["$key"] == 'generic'){
+                                                               for($i=0;$i<$info[0]["$val"][count];$i++)
+                                                                       $default_vals["$key"][] = $info[0]["$val"][$i];
+                                                               $default_vals["$key"][count] += $info[0]["$val"][count];
+                                                       }
+                                                       else
+                                                               $default_vals["$key"] = $info[0]["$val"];
+                                               }
                                }
                        }
                }
@@ -26,8 +33,17 @@ if ($config[ldap_default_dn] != ''){
                                                $dn3 = $info2[0]['dn'];
                                                if ($dn3 != ''){
                                                        foreach($attrmap as $key => $val){
-                                                               if ($info2[0]["$val"][0] != '')
-                                                                       $default_vals["$key"] = $info2[0]["$val"][0];
+                                                               if ($info2[0]["$val"][0] != ''){
+                                                                       if (!isset($default_vals["$key"]))
+                                                                               $default_vals["$key"] = array();
+                                                                       if ($attrmap[generic]["$key"] == 'generic'){
+                                                                               for($i=0;$i<$info2[0]["$val"][count];$i++)
+                                                                                       $default_vals["$key"][] = $info2[0]["$val"][$i];
+                                                                               $default_vals["$key"][count] += $info2[0]["$val"][count];
+                                                                       }
+                                                                       else
+                                                                               $default_vals["$key"] = $info2[0]["$val"];
+                                                               }
                                                        }
                                                }
                                        }
index 617caba36634a98e626275f3f66dae44a3a00857..9fbfc155f8e2a22af6b9aabef278b1ee89969503 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+require('../lib/functions.php3');
 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
 else{
@@ -60,15 +61,15 @@ if ($link){
        //      if value is the same as that in the sql database do nothing
                        if ($val == $item_vals["$key"][$j])
                                continue;
-       //      if value is null and corresponding value exists then delete
-                       else if (($val == $default_vals["$key"] || $val == '') && isset($item_vals["$key"][$j])){
+       //      if value is null or equals the default value and corresponding value exists then delete
+                       else if ((check_defaults($val,$op_val,$default_vals["$key"]) || $val == '') && isset($item_vals["$key"][$j])){
                                $res = @da_sql_query($link,$config,
                                "DELETE FROM $table WHERE $query_key = '$login' AND Attribute = '$sql_attr';");
                                if (!$res || !@da_sql_affected_rows($link,$res,$config))
                                        echo "<b>Delete failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
                        }
-       //      if value is null then don't add it 
-                       else if ($val == '')
+       //      if value is null or equals the default value then don't add it 
+                       else if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
                                continue;
        //      if value differs from the sql value then update
                        else{
index 9a0bdb2da4975c4e40a746f4fb7449421bd03514..bae7175a12d78c72a1fb90213ed8aee2589f9f32 100644 (file)
@@ -45,13 +45,13 @@ if ($link){
                                        echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
                                        coninue;
                                }
-                               $op_val = ",'$op_val'";
+                               $op_val2 = ",'$op_val'";
                        }
-                       if ($val == '' || $val == $default_vals["$key"])
+                       if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
                                continue;
                        $res = @da_sql_query($link,$config,
                        "INSERT INTO $table (Attribute,Value,GroupName $text)
-                       VALUES ('$attrmap[$key]','$val','$login' $op_val);");
+                       VALUES ('$attrmap[$key]','$val','$login' $op_val2;");
                        if (!$res || !@da_sql_affected_rows($link,$res,$config))
                                echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
                }
index dd3b38457f09660bfeff7f25f8b930f4990caf51..7271325a2ac6abffa197e77409ad579525dd207e 100644 (file)
@@ -61,6 +61,8 @@ if ($link){
                                echo "<b>Could not add user to group $Fgroup: " . da_sql_error($link,$config) . "</b><br>\n";
                }
                if (!$da_abort){
+                       if ($Fgroup != '')
+                               require('../lib/defaults.php3');
                        foreach($show_attrs as $key => $attr){
                                if ($attrmap["$key"] == 'none')
                                        continue;
@@ -80,13 +82,13 @@ if ($link){
                                                echo "<b>Invalid operator ($op_val) for attribute $key</b><br>\n";
                                                coninue;
                                        }
-                                       $op_val = ",'$op_val'";
+                                       $op_val2 = ",'$op_val'";
                                }
-                               if ($val == '' || $val == $default_vals["$key"])
+                               if ($val == '' || check_defaults($val,$op_val,$default_vals["$key"]))
                                        continue;
                                $res = @da_sql_query($link,$config,
                                "INSERT INTO $table (Attribute,Value,UserName $text)
-                               VALUES ('$attrmap[$key]','$val','$login' $op_val);");
+                               VALUES ('$attrmap[$key]','$val','$login' $op_val2);");
                                if (!$res || !@da_sql_affected_rows($link,$res,$config))
                                        echo "<b>Query failed for attribute $key: " . da_sql_error($link,$config) . "</b><br>\n";
                        }
index 4a2f0799454914d1b943b3445488804b2ef75e35..6c706a5a890644c8f725fefc4ecf0c7355ce43f8 100644 (file)
@@ -63,10 +63,9 @@ if ($login != ''){
                                foreach($attrmap as $key => $val){
                                        if (isset($tmp[$val])){
                                                if ($use_op)
-                                                       if ($tmp[$val][operator][0] != '')
-                                                               $default_vals["$key"][operator] = $tmp[$val][operator][0];
+                                                       $default_vals["$key"][operator] = $tmp["$val"][operator];
                                                if ($tmp[$val][0] != '')
-                                                       $default_vals["$key"] = $tmp[$val][0];
+                                                       $default_vals["$key"] = $tmp["$val"];
                                        }
                                }
                        }