]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
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:28:56 +0000 (12:28 +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 d47c90b6a01d923c4eb515ba74a2d96a43eff906..6c4534f3d903ae5838baf122863aeef44ab1d5ac 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 784de7bcee977ce2c8d8f646d7f05ae72c789464..30e2eb7d66027256ffd5062c8e962ad47b710ab7 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 cde0b57c87c982681d1a0f53b47290473e7cfb37..7dd6ecab775563edbf6cf4b8bb97c966f4b36604 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 46cd26ed75db0cac46a23e586ac49bbe2086f685..34a176281328444723993bfe4fb11378aac4cd0b 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 f362519d0ffaaec28a68a69c28fb053ac9047660..ce4dceb51b8933bc72ec37e42df37b31d0eb0d05 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 a4754e804754d6b9efaefe8ca1da7572a20bf4ec..1588c574ce6dbe354a0d48d38c8934de8055affa 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 9630521f6cce3511a3e2b41abd99aac9cf5b5b70..68f05133bd843ffc86b85d253a8fa56b825b1568 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 de39327f92e40cd7b4a65b4523e1720732016855..ed0a66af7ad4f3352fa28b356c2c97161fd0db74 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 98f90e7beaddaec8f37497fa4de952b33cce4dc3..21a6ca596bade844cbe219202eb8efe5eab8edcd 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 c821fa277854381e2be0f5d8a9a5963edcd99cf4..1b6db6039516a7eab66694cddd5fb17625bee494 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 f3bda8635520407aa74a2f61f51f88f5cfc6bddc..71e9475330225cfd87bab5c1d12e3f42fe312770 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 6d2f17303083f4da2a7d738f6cb6706dbb19272f..bca1900733794e0cb6c88ac672e61cc7e3125000 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 c79b6c4a43c9839b707cb45fbd04cd04980add67..db05a5bdf575c29c95351c396e6da3f6a0ed16f7 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 492ab14813280e04b0166e56f0ec3b0e1e20f6d4..a7c34b1689e89b5b7b608ae628500ed372fc520a 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 dbc94c21d39f7d6b7db25259ade65a47cd85e9e6..45f368b0a6460a4d1761bfc158eedef2ae6dd873 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 9807d0d18859e6670fb2e1d0d8dd717c88f16a4e..e16aa877b993e2daa3f37ee4c24b56172d563d76 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 ae3a5cdd12ca8b73824a80199e557c97ad8697f8..03ae473536b3b01922037695d6e622a32d45d832 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 ce5e2c972554d6922d3aa6cbfe3536337d07d819..3214ed2254c13723ec7c29bdb2de6e5bde300a2d 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 aee4f0885f3b1d58e88ecdf84df015b4f84bd5b7..0eda70e6f2e66b54a842a77ceb6415683b38f3b8 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',";