From: Alan T. DeKok Date: Fri, 7 Jan 2011 11:28:56 +0000 (+0100) Subject: Fixes as posted by Stefan Winter X-Git-Tag: release_2_1_11~162 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53ce0e0f09834ea11d18921422d6bed6abadfa67;p=thirdparty%2Ffreeradius-server.git Fixes as posted by Stefan Winter just now I have had to upgrade my dialup_admin installation to a machine running PHP5.3, and also noticed numerous PHP errors. I have fixed the code, see attached patch. It solves the following bugs/deprecated code warnings: * replace ereg -> preg_match, ereg_replace -> preg_replace, split -> preg_split for PHP5.3 compatibility * fix LIMIT not working when using MySQL * add configuration item "timezone" to make PHP 5.1+ happy and adds one (trivial, one-liner) feature: * add comparison operators "!=" and "not like" to Accounting Now, I have an almost error/warning/notice free installation. There is still something bogus around the use of mktime() someplace, but I don't use that part of dialup_admin, so I'll leave that alone. --- diff --git a/dialup_admin/Changelog b/dialup_admin/Changelog index d47c90b6a01..6c4534f3d90 100644 --- a/dialup_admin/Changelog +++ b/dialup_admin/Changelog @@ -1,3 +1,8 @@ +Ver X.XX: +* add comparison operators "!=" and "not like" to Accounting +* replace ereg -> preg_match, ereg_replace -> preg_replace, split -> preg_split for PHP5.3 compatibility +* fix LIMIT not working when using MySQL +* add configuration item "timezone" to make PHP 5.1+ happy Ver 1.80: * Remove snmp_clearsession. It is replaced by clearsession which supports both snmp and telnet methods of removing a user from an access server. Add corresponding configuration directives diff --git a/dialup_admin/conf/admin.conf b/dialup_admin/conf/admin.conf index 784de7bcee9..30e2eb7d660 100644 --- a/dialup_admin/conf/admin.conf +++ b/dialup_admin/conf/admin.conf @@ -344,3 +344,8 @@ counter_default_monthly: none # it configurable # This is not needed if the monthly limit is not none #counter_monthly_calculate_usage: true + +# some of the date/time related functions need to know what timezone we are in + +timezone: Europe/Luxembourg + diff --git a/dialup_admin/conf/config.php3 b/dialup_admin/conf/config.php3 index cde0b57c87c..7dd6ecab775 100644 --- a/dialup_admin/conf/config.php3 +++ b/dialup_admin/conf/config.php3 @@ -2,6 +2,7 @@ # # Things should work even if register_globals is set to off # + $testVer=intval(str_replace(".", "",'4.1.0')); $curVer=intval(str_replace(".", "",phpversion())); if( $curVer >= $testVer ) @@ -24,9 +25,9 @@ if (!isset($config)){ $EXTRA_ARR = array(); foreach($ARR as $val) { $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($key,$v)=split(":[[:space:]]*",$val,2); + list($key,$v)=preg_split("/:[[:space:]]*/",$val,2); if (preg_match("/%\{(.+)\}/",$v,$matches)){ $val=$config[$matches[1]]; $v=preg_replace("/%\{$matches[1]\}/",$val,$v); @@ -45,9 +46,9 @@ if (!isset($config)){ foreach($EXTRA_ARR as $val1) { foreach($val1 as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($key,$v)=split(":[[:space:]]*",$val,2); + list($key,$v)=preg_split("/:[[:space:]]*/",$val,2); if (preg_match("/%\{(.+)\}/",$v,$matches)){ $val=$config[$matches[1]]; $v=preg_replace("/%\{$matches[1]\}/",$val,$v); @@ -87,14 +88,14 @@ if (!isset($mappings) && $config[general_username_mappings_file] != ''){ $ARR = file($config[general_username_mappings_file]); foreach($ARR as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($key,$realm,$v)=split(":[[:space:]]*",$val,3); + list($key,$realm,$v)=preg_split("/:[[:space:]]*/",$val,3); if ($realm == 'accounting' || $realm == 'userdb' || $realm == 'nasdb' || $realm == 'nasadmin') $mappings["$key"][$realm] = $v; if ($realm == 'nasdb'){ $NAS_ARR = array(); - $NAS_ARR = split(',',$v); + $NAS_ARR = preg_split('/,/',$v); foreach ($nas_list as $key => $nas){ foreach ($NAS_ARR as $nas_check){ if ($nas_check == $nas[name]) @@ -107,6 +108,8 @@ if (!isset($mappings) && $config[general_username_mappings_file] != ''){ session_register('mappings'); } +date_default_timezone_set($config[timezone]); + //Include missing.php3 if needed if (!function_exists('array_change_key_case')) include_once('../lib/missing.php3'); diff --git a/dialup_admin/htdocs/accounting.php3 b/dialup_admin/htdocs/accounting.php3 index 46cd26ed75d..34a17628132 100644 --- a/dialup_admin/htdocs/accounting.php3 +++ b/dialup_admin/htdocs/accounting.php3 @@ -24,7 +24,7 @@ EOM; exit(); } -$operators=array( '=','<', '>', '<=', '>=', 'regexp', 'like' ); +$operators=array( '=','<', '>', '<=', '>=', '!=', 'regexp', 'like', 'not like' ); if ($config[sql_type] == 'pg'){ $operators=array( '=','<', '>', '<=', '>=', '~', 'like', '~*', '~~*', '<<=' ); } @@ -233,7 +233,7 @@ if (!is_numeric($maxresults)) unset($query_view); foreach ($accounting_show_attrs as $val) $query_view .= $val . ','; -$query_view = ereg_replace(',$','',$query_view); +$query_view = preg_replace('/,$/','',$query_view); unset($sql_extra_query); if ($config[sql_accounting_extra_query] != '') $sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config); diff --git a/dialup_admin/htdocs/user_accounting.php3 b/dialup_admin/htdocs/user_accounting.php3 index f362519d0ff..ce4dceb51b8 100644 --- a/dialup_admin/htdocs/user_accounting.php3 +++ b/dialup_admin/htdocs/user_accounting.php3 @@ -145,8 +145,8 @@ if ($link){ $acct_terminate_cause = "$row[acctterminatecause]"; if ($acct_terminate_cause == '') $acct_terminate_cause = '-'; - if (ereg('Login-Incorrect',$acct_terminate_cause) || - ereg('Multiple-Logins', $acct_terminate_cause) || ereg('Invalid-User',$acct_terminate_cause)) + if (preg_match('/Login-Incorrect/',$acct_terminate_cause) || + preg_match('/Multiple-Logins/', $acct_terminate_cause) || preg_match('/Invalid-User/',$acct_terminate_cause)) $tr_color='#ffe8e0'; $acct_callerid = "$row[callingstationid]"; if ($acct_callerid == '') diff --git a/dialup_admin/htdocs/user_edit.php3 b/dialup_admin/htdocs/user_edit.php3 index a4754e80475..1588c574ce6 100644 --- a/dialup_admin/htdocs/user_edit.php3 +++ b/dialup_admin/htdocs/user_edit.php3 @@ -180,7 +180,7 @@ EOM; $i = 0; foreach($vals as $val){ $name1 = $name . $i; - $val = ereg_replace('"','"',$val); + $val = preg_replace('/"/','"',$val); $oper_name = $name1 . '_op'; $oper = $ops[$i]; $selected[$oper] = 'selected'; diff --git a/dialup_admin/htdocs/user_test.php3 b/dialup_admin/htdocs/user_test.php3 index 9630521f6cc..68f05133bd8 100644 --- a/dialup_admin/htdocs/user_test.php3 +++ b/dialup_admin/htdocs/user_test.php3 @@ -76,7 +76,7 @@ if ($test_user == 1){ if ($fp){ foreach ($req as $val){ // Ignore comments - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; fwrite($fp,$val); } @@ -100,13 +100,13 @@ if ($test_user == 1){ unlink($tmp_file); $msg = "" . strftime('%A, %e %B %Y, %T %Z') . "
\n"; $msg .= "Server: $server:$port

\n"; - if (ereg('code 2', $reply[0])) + if (preg_match('/code 2/', $reply[0])) $msg .= "Authentication was successful"; - else if (ereg('code 3',$reply[0])) + else if (preg_match('/code 3/',$reply[0])) $msg .= "Authentication failed"; - else if (ereg('no response from server', $reply[0])) + else if (preg_match('/no response from server/', $reply[0])) $msg .= "No response from server"; - else if (ereg('Connection refused',$reply[0])) + else if (preg_match('/Connection refused/',$reply[0])) $msg .= "Connection was refused"; if ($test_login) $msg .= " (test user $login)
\n"; diff --git a/dialup_admin/lib/acctshow.php3 b/dialup_admin/lib/acctshow.php3 index de39327f92e..ed0a66af7ad 100644 --- a/dialup_admin/lib/acctshow.php3 +++ b/dialup_admin/lib/acctshow.php3 @@ -7,9 +7,9 @@ if (!isset($sql_attrs)){ $ARR = file($config[general_sql_attrs_file]); foreach($ARR as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($key,$desc,$show,$func)=split("\t+",$val); + list($key,$desc,$show,$func)=preg_split("/\t+/",$val); $sql_attrs[strtolower($key)][desc] = "$desc"; $sql_attrs[strtolower($key)][show] = "$show"; $sql_attrs[strtolower($key)][func] = ($func == "") ? "nothing" : "$func"; diff --git a/dialup_admin/lib/attrshow.php3 b/dialup_admin/lib/attrshow.php3 index 98f90e7bead..21a6ca596ba 100644 --- a/dialup_admin/lib/attrshow.php3 +++ b/dialup_admin/lib/attrshow.php3 @@ -9,9 +9,9 @@ if (!isset($show_attrs)){ $ARR = file($infile); foreach($ARR as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($key,$v)=split("\t+",$val); + list($key,$v)=preg_split("/\t+/",$val); $show_attrs["$key"]=($v != '') ? "$v" : "$key"; } if ($config[general_use_session] == 'yes') @@ -25,9 +25,9 @@ if (!isset($acct_attrs) && isset($config[general_accounting_attrs_file])){ $ARR = file($infile); foreach ($ARR as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($num,$desc,$showua,$showuf,$showfl)=split("\t+",$val); + list($num,$desc,$showua,$showuf,$showfl)=preg_split("/\t+/",$val); if ($showua == 'yes'){ $acct_attrs["ua"]["num"]++; $acct_attrs["ua"]["$num"]=$desc; diff --git a/dialup_admin/lib/defaults.php3 b/dialup_admin/lib/defaults.php3 index c821fa27785..1b6db603951 100644 --- a/dialup_admin/lib/defaults.php3 +++ b/dialup_admin/lib/defaults.php3 @@ -7,9 +7,9 @@ if (!isset($text_default_vals)){ $ARR=file("$config[general_default_file]"); foreach($ARR as $val) { $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($key,$v)=split(":[[:space:]]*",$val,2); + list($key,$v)=preg_split("/:[[:space:]]*/",$val,2); $text_default_vals["$key"][0]="$v"; $text_default_vals["$key"]['count']++; } diff --git a/dialup_admin/lib/functions.php3 b/dialup_admin/lib/functions.php3 index f3bda863552..71e94753302 100644 --- a/dialup_admin/lib/functions.php3 +++ b/dialup_admin/lib/functions.php3 @@ -24,7 +24,7 @@ function time2str($time) } if ($time) $str .= "$time seconds, "; - $str = ereg_replace(', $','',$str); + $str = preg_replace('/, $/','',$str); return $str; } @@ -124,7 +124,7 @@ function check_defaults($val,$op,$def) } function check_ip($ipaddr) { - if(ereg("^([0-9]{1,3})\x2E([0-9]{1,3})\x2E([0-9]{1,3})\x2E([0-9]{1,3})$", $ipaddr,$digit)) { + if(preg_match("/^([0-9]{1,3})\x2E([0-9]{1,3})\x2E([0-9]{1,3})\x2E([0-9]{1,3})$/", $ipaddr,$digit)) { if(($digit[1] <= 255) && ($digit[2] <= 255) && ($digit[3] <= 255) && ($digit[4] <= 255)) { return(1); } diff --git a/dialup_admin/lib/lang/el/utf8.php3 b/dialup_admin/lib/lang/el/utf8.php3 index 6d2f1730308..bca19007337 100644 --- a/dialup_admin/lib/lang/el/utf8.php3 +++ b/dialup_admin/lib/lang/el/utf8.php3 @@ -72,8 +72,8 @@ function encode_string($line,$k) function decode_string($line,$k) { - $line = ereg_replace("&","&&",$line); - $line = ereg_replace("([,+0-9./() -])", "%\\1", $line); + $line = preg_replace("/&/","&&",$line); + $line = preg_replace("/([,+0-9.\/() -])/", "%\\1", $line); $mline = chunk_split($line, 2, " "); $chars = explode(" ", $mline); foreach ($chars as $c){ @@ -81,10 +81,10 @@ function decode_string($line,$k) $c = ($val != "") ? "$val" : "$c"; $new_line .= $c; } - $new_line = ereg_replace("%%", " ", $new_line); - $new_line = ereg_replace("%([,+0-9./() -])", "\\1", $new_line); - $new_line = ereg_replace("%", " ",$new_line); - $new_line = ereg_replace("&&","&",$new_line); + $new_line = preg_replace("/%%/", " ", $new_line); + $new_line = preg_replace("/%([,+0-9.\/() -])/", "\\1", $new_line); + $new_line = preg_replace("/%/", " ",$new_line); + $new_line = preg_replace("/&&/","&",$new_line); return $new_line; } diff --git a/dialup_admin/lib/ldap/attrmap.php3 b/dialup_admin/lib/ldap/attrmap.php3 index c79b6c4a43c..db05a5bdf57 100644 --- a/dialup_admin/lib/ldap/attrmap.php3 +++ b/dialup_admin/lib/ldap/attrmap.php3 @@ -7,9 +7,9 @@ if (!isset($attrmap)){ $ARR = file("$config[general_ldap_attrmap]"); foreach($ARR as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list(,$key,$v,$g)=split('[[:space:]]+',$val); + list(,$key,$v,$g)=preg_split('/[[:space:]]+/',$val); $v = strtolower($v); $attrmap["$key"]=$v; $attrmap[generic]["$key"]=$g; @@ -17,9 +17,9 @@ if (!isset($attrmap)){ $ARR = file("$config[general_extra_ldap_attrmap]"); foreach($ARR as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list(,$key,$v,$g)=split('[[:space:]]+',$val); + list(,$key,$v,$g)=preg_split('/[[:space:]]+/',$val); $v = strtolower($v); $attrmap["$key"]=$v; $attrmap[generic]["$key"]=$g; diff --git a/dialup_admin/lib/ldap/change_info.php3 b/dialup_admin/lib/ldap/change_info.php3 index 492ab148132..a7c34b1689e 100644 --- a/dialup_admin/lib/ldap/change_info.php3 +++ b/dialup_admin/lib/ldap/change_info.php3 @@ -16,7 +16,7 @@ require_once('../lib/ldap/functions.php3'); $r = @da_ldap_bind($ds,$config); if ($r){ if ($Fcn != '' && $Fcn != '-' && $Fcn != $cn){ - list ($givenname,$sn) = split(' ',$Fcn,2); + list ($givenname,$sn) = preg_split('/ /',$Fcn,2); $mod['cn'] = $Fcn; $mod['cn'] = ($decode_normal) ? encode_string($mod['cn'],$k) : $mod['cn']; $mod['givenname'] = $givenname; diff --git a/dialup_admin/lib/ldap/create_user.php3 b/dialup_admin/lib/ldap/create_user.php3 index dbc94c21d39..45f368b0a64 100644 --- a/dialup_admin/lib/ldap/create_user.php3 +++ b/dialup_admin/lib/ldap/create_user.php3 @@ -8,7 +8,7 @@ require_once('../lib/ldap/functions.php3'); if ($ds){ $r = @da_ldap_bind($ds,$config); if ($r){ - list ($givenname,$sn) = split(' ',$Fcn,2); + list ($givenname,$sn) = preg_split('/ /',$Fcn,2); $dn = 'uid=' . $login . ',' . $config[ldap_default_new_entry_suffix]; $new_user_entry["objectclass"][0]="top"; $new_user_entry["objectclass"][1]="person"; diff --git a/dialup_admin/lib/ldap/personattrs.php3 b/dialup_admin/lib/ldap/personattrs.php3 index 9807d0d1885..e16aa877b99 100644 --- a/dialup_admin/lib/ldap/personattrs.php3 +++ b/dialup_admin/lib/ldap/personattrs.php3 @@ -3,9 +3,9 @@ $ARR = file($config[general_ldap_person_attrs_file]); foreach($ARR as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($key,$desc)=split("\t+",$val); + list($key,$desc)=preg_split("/\t+/",$val); $person_attrs["$key"] = "$desc"; } ?> diff --git a/dialup_admin/lib/sql/attrmap.php3 b/dialup_admin/lib/sql/attrmap.php3 index ae3a5cdd12c..03ae473536b 100644 --- a/dialup_admin/lib/sql/attrmap.php3 +++ b/dialup_admin/lib/sql/attrmap.php3 @@ -13,9 +13,9 @@ else{ $ARR = file("$config[general_sql_attrmap]"); foreach($ARR as $val){ $val=chop($val); - if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val)) + if (preg_match('/^[[:space:]]*#/',$val) || preg_match('/^[[:space:]]*$/',$val)) continue; - list($type,$key,$v)=split('[[:space:]]+',$val); + list($type,$key,$v)=preg_split('/[[:space:]]+/',$val); $attrmap["$key"]=$v; $rev_attrmap["$v"] = $key; $attr_type["$key"]=$type; diff --git a/dialup_admin/lib/sql/drivers/mysql/functions.php3 b/dialup_admin/lib/sql/drivers/mysql/functions.php3 index ce5e2c97255..3214ed2254c 100644 --- a/dialup_admin/lib/sql/drivers/mysql/functions.php3 +++ b/dialup_admin/lib/sql/drivers/mysql/functions.php3 @@ -6,7 +6,7 @@ function da_sql_limit($limit,$point,$config) return ''; case 1: return ''; - case 3: + case 2: return "LIMIT $limit"; } } diff --git a/dialup_admin/lib/sql/nas_list.php3 b/dialup_admin/lib/sql/nas_list.php3 index aee4f0885f3..0eda70e6f2e 100644 --- a/dialup_admin/lib/sql/nas_list.php3 +++ b/dialup_admin/lib/sql/nas_list.php3 @@ -19,7 +19,7 @@ if ($config[sql_nas_table] != ''){ $extra = ''; if (isset($mappings[$auth_user][nasdb])){ $NAS_ARR = array(); - $NAS_ARR = split(',',$mappings[$auth_user][nasdb]); + $NAS_ARR = preg_split('/,/',$mappings[$auth_user][nasdb]); $extra = 'WHERE nasname IN ('; foreach ($NAS_ARR as $nas) $extra .= "'$nasname',";