Fixes as posted by Stefan Winter
authorAlan T. DeKok <aland@freeradius.org>
Fri, 7 Jan 2011 11:28:56 +0000 (12:28 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 7 Jan 2011 11:30:04 +0000 (12:30 +0100)
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.

19 files changed:
dialup_admin/Changelog
dialup_admin/conf/admin.conf
dialup_admin/conf/config.php3
dialup_admin/htdocs/accounting.php3
dialup_admin/htdocs/user_accounting.php3
dialup_admin/htdocs/user_edit.php3
dialup_admin/htdocs/user_test.php3
dialup_admin/lib/acctshow.php3
dialup_admin/lib/attrshow.php3
dialup_admin/lib/defaults.php3
dialup_admin/lib/functions.php3
dialup_admin/lib/lang/el/utf8.php3
dialup_admin/lib/ldap/attrmap.php3
dialup_admin/lib/ldap/change_info.php3
dialup_admin/lib/ldap/create_user.php3
dialup_admin/lib/ldap/personattrs.php3
dialup_admin/lib/sql/attrmap.php3
dialup_admin/lib/sql/drivers/mysql/functions.php3
dialup_admin/lib/sql/nas_list.php3

index d47c90b..6c4534f 100644 (file)
@@ -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
index 784de7b..30e2eb7 100644 (file)
@@ -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
+
index cde0b57..7dd6eca 100644 (file)
@@ -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');
index 46cd26e..34a1762 100644 (file)
@@ -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);
index f362519..ce4dceb 100644 (file)
@@ -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 == '')
index a4754e8..1588c57 100644 (file)
@@ -180,7 +180,7 @@ EOM;
                $i = 0;
                foreach($vals as $val){
                        $name1 = $name . $i;
-                       $val = ereg_replace('"','&quot;',$val);
+                       $val = preg_replace('/"/','&quot;',$val);
                        $oper_name = $name1 . '_op';
                        $oper = $ops[$i];
                        $selected[$oper] = 'selected';
index 9630521..68f0513 100644 (file)
@@ -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 = "<b>" . strftime('%A, %e %B %Y, %T %Z') . "</b><br>\n";
                $msg .= "<b>Server: </b><i>$server:$port</i><br><br>\n";
-               if (ereg('code 2', $reply[0]))
+               if (preg_match('/code 2/', $reply[0]))
                        $msg .= "<b>Authentication was <font color=green>successful</font>";
-               else if (ereg('code 3',$reply[0]))
+               else if (preg_match('/code 3/',$reply[0]))
                        $msg .= "<b>Authentication <font color=red>failed</font>";
-               else if (ereg('no response from server', $reply[0]))
+               else if (preg_match('/no response from server/', $reply[0]))
                        $msg .= "<b><font color=red>No response from server</font>";
-               else if (ereg('Connection refused',$reply[0]))
+               else if (preg_match('/Connection refused/',$reply[0]))
                        $msg .= "<b><font color=red>Connection was refused</font>";
                if ($test_login)
                        $msg .= "</b><i> (test user $login)</i><br>\n";
index de39327..ed0a66a 100644 (file)
@@ -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";
index 98f90e7..21a6ca5 100644 (file)
@@ -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;
index c821fa2..1b6db60 100644 (file)
@@ -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']++;
        }
index f3bda86..71e9475 100644 (file)
@@ -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);
       }
index 6d2f173..bca1900 100644 (file)
@@ -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;
 }
index c79b6c4..db05a5b 100644 (file)
@@ -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;
index 492ab14..a7c34b1 100644 (file)
@@ -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;
index dbc94c2..45f368b 100644 (file)
@@ -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";
index 9807d0d..e16aa87 100644 (file)
@@ -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";
 }
 ?>
index ae3a5cd..03ae473 100644 (file)
@@ -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;
index ce5e2c9..3214ed2 100644 (file)
@@ -6,7 +6,7 @@ function da_sql_limit($limit,$point,$config)
                        return '';
                case 1:
                        return '';
-               case 3:
+               case 2:
                        return "LIMIT $limit";
        }
 }
index aee4f08..0eda70e 100644 (file)
@@ -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',";