* 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:
dialup_admin/Changelog
dialup_admin/conf/extra.ldap-attrmap
dialup_admin/htdocs/group_new.php3
dialup_admin/htdocs/user_admin.php3
dialup_admin/htdocs/user_edit.php3
dialup_admin/htdocs/user_new.php3
dialup_admin/htdocs/user_state.php3
dialup_admin/lib/defaults.php3
dialup_admin/lib/functions.php3
dialup_admin/lib/ldap/attrmap.php3
dialup_admin/lib/ldap/change_attrs.php3
dialup_admin/lib/ldap/create_user.php3
dialup_admin/lib/ldap/defaults.php3
dialup_admin/lib/sql/change_attrs.php3
dialup_admin/lib/sql/create_group.php3
dialup_admin/lib/sql/create_user.php3
dialup_admin/lib/sql/defaults.php3

index 53df19e..0db2a6e 100644 (file)
@@ -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 8edf30f..69b5320 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 d668b54..2feb03a 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 fb84a2e..6fd8d6a 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 c4afb71..86325c5 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 e239e1f..145b983 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 e9a31d9..a8e4595 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 1bdce8f..3d081a6 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 48bbc40..1a60c1f 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 f7a3199..e5aac1c 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 23692bd..5d03a60 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 c2837ba..1115e6f 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 c5fb4a5..3a91826 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 617caba..9fbfc15 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 9a0bdb2..bae7175 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 dd3b384..7271325 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 4a2f079..6c706a5 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"];
                                        }
                                }
                        }