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.
+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
# 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
+
#
# 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 )
$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);
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);
$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])
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');
exit();
}
-$operators=array( '=','<', '>', '<=', '>=', 'regexp', 'like' );
+$operators=array( '=','<', '>', '<=', '>=', '!=', 'regexp', 'like', 'not like' );
if ($config[sql_type] == 'pg'){
$operators=array( '=','<', '>', '<=', '>=', '~', 'like', '~*', '~~*', '<<=' );
}
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);
$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 == '')
$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';
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);
}
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";
$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";
$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')
$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;
$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']++;
}
}
if ($time)
$str .= "$time seconds, ";
- $str = ereg_replace(', $','',$str);
+ $str = preg_replace('/, $/','',$str);
return $str;
}
}
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);
}
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){
$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;
}
$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;
$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;
$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;
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";
$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";
}
?>
$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;
return '';
case 1:
return '';
- case 3:
+ case 2:
return "LIMIT $limit";
}
}
$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',";