From: kkalev Date: Fri, 6 Sep 2002 16:17:26 +0000 (+0000) Subject: * Allow for multiple default values. Also add a generic flag in ldap attrmap. If... X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=2485130a158a53b057255cf49aed52849788fe80;p=freeradius-dialup-admin.git * 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. --- diff --git a/Changelog b/Changelog index 53df19e..0db2a6e 100644 --- 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 * 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 diff --git a/conf/extra.ldap-attrmap b/conf/extra.ldap-attrmap index 8edf30f..69b5320 100644 --- a/conf/extra.ldap-attrmap +++ b/conf/extra.ldap-attrmap @@ -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 diff --git a/htdocs/group_new.php3 b/htdocs/group_new.php3 index d668b54..2feb03a 100644 --- a/htdocs/group_new.php3 +++ b/htdocs/group_new.php3 @@ -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 << diff --git a/htdocs/user_admin.php3 b/htdocs/user_admin.php3 index fb84a2e..6fd8d6a 100644 --- a/htdocs/user_admin.php3 +++ b/htdocs/user_admin.php3 @@ -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 != ''){ diff --git a/htdocs/user_edit.php3 b/htdocs/user_edit.php3 index c4afb71..86325c5 100644 --- a/htdocs/user_edit.php3 +++ b/htdocs/user_edit.php3 @@ -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; diff --git a/htdocs/user_new.php3 b/htdocs/user_new.php3 index e239e1f..145b983 100644 --- a/htdocs/user_new.php3 +++ b/htdocs/user_new.php3 @@ -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 << diff --git a/htdocs/user_state.php3 b/htdocs/user_state.php3 index e9a31d9..a8e4595 100644 --- a/htdocs/user_state.php3 +++ b/htdocs/user_state.php3 @@ -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'; diff --git a/lib/defaults.php3 b/lib/defaults.php3 index 1bdce8f..3d081a6 100644 --- a/lib/defaults.php3 +++ b/lib/defaults.php3 @@ -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"); diff --git a/lib/functions.php3 b/lib/functions.php3 index 48bbc40..1a60c1f 100644 --- a/lib/functions.php3 +++ b/lib/functions.php3 @@ -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; +} ?> diff --git a/lib/ldap/attrmap.php3 b/lib/ldap/attrmap.php3 index f7a3199..e5aac1c 100644 --- a/lib/ldap/attrmap.php3 +++ b/lib/ldap/attrmap.php3 @@ -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; } ?> diff --git a/lib/ldap/change_attrs.php3 b/lib/ldap/change_attrs.php3 index 23692bd..5d03a60 100644 --- a/lib/ldap/change_attrs.php3 +++ b/lib/ldap/change_attrs.php3 @@ -1,4 +1,5 @@ $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"]; + } } } } diff --git a/lib/sql/change_attrs.php3 b/lib/sql/change_attrs.php3 index 617caba..9fbfc15 100644 --- a/lib/sql/change_attrs.php3 +++ b/lib/sql/change_attrs.php3 @@ -1,4 +1,5 @@ Delete failed for attribute $key: " . da_sql_error($link,$config) . "
\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{ diff --git a/lib/sql/create_group.php3 b/lib/sql/create_group.php3 index 9a0bdb2..bae7175 100644 --- a/lib/sql/create_group.php3 +++ b/lib/sql/create_group.php3 @@ -45,13 +45,13 @@ if ($link){ echo "Invalid operator ($op_val) for attribute $key
\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 "Query failed for attribute $key: " . da_sql_error($link,$config) . "
\n"; } diff --git a/lib/sql/create_user.php3 b/lib/sql/create_user.php3 index dd3b384..7271325 100644 --- a/lib/sql/create_user.php3 +++ b/lib/sql/create_user.php3 @@ -61,6 +61,8 @@ if ($link){ echo "Could not add user to group $Fgroup: " . da_sql_error($link,$config) . "
\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 "Invalid operator ($op_val) for attribute $key
\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 "Query failed for attribute $key: " . da_sql_error($link,$config) . "
\n"; } diff --git a/lib/sql/defaults.php3 b/lib/sql/defaults.php3 index 4a2f079..6c706a5 100644 --- a/lib/sql/defaults.php3 +++ b/lib/sql/defaults.php3 @@ -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"]; } } }