From: kkalev Date: Mon, 21 Mar 2005 13:16:58 +0000 (+0000) Subject: Create a new function da_sql_limit() and use that to pass LIMIT arguments to the... X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=2471f42f3ae6281af944682614a2dcfc20fd3a3f;p=freeradius-dialup-admin.git Create a new function da_sql_limit() and use that to pass LIMIT arguments to the database layer since the syntax is different between db vendors --- diff --git a/Changelog b/Changelog index 2081bda..6a12acd 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,8 @@ 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 general_sessionclear_method and nasXX_sessionclear_method +* Create a new function da_sql_limit() and use that to pass LIMIT arguments to the database layer + since the syntax is different between db vendors Ver 1.78: * Add a snmp_clearsession which can disconnect a user by using the Cisco AAA Session MIB * Add a configuration directive general_sessionclear_bin diff --git a/htdocs/accounting.php3 b/htdocs/accounting.php3 index 93d80ae..137d05a 100644 --- a/htdocs/accounting.php3 +++ b/htdocs/accounting.php3 @@ -238,7 +238,9 @@ unset($sql_extra_query); if ($config[sql_accounting_extra_query] != '') $sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config); $sql_extra_query = da_sql_escape_string($sql_extra_query); -$query="SELECT $query_view FROM $config[sql_accounting_table] $where $sql_extra_query ORDER BY $order LIMIT $maxresults;"; +$query="SELECT da_sql_limit($maxresults,0,$config) $query_view FROM $config[sql_accounting_table] + $where $sql_extra_query da_sql_limit($maxresults,1,$config) + ORDER BY $order da_sql_limit($maxresults,2,$config);"; echo << diff --git a/htdocs/badusers.php3 b/htdocs/badusers.php3 index 631ecc3..97110fa 100644 --- a/htdocs/badusers.php3 +++ b/htdocs/badusers.php3 @@ -33,7 +33,7 @@ $num = 0; $pagesize = ($pagesize) ? $pagesize : 10; if (!is_numeric($pagesize) && $pagesize != 'all') $pagesize = 10; -$limit = ($pagesize == 'all') ? '' : "LIMIT $pagesize"; +$limit = ($pagesize == 'all') ? '' : "$pagesize"; $selected[$pagesize] = 'selected'; $login = ($login != '') ? $login : 'anyone'; $usercheck = ($login == 'anyone') ? "LIKE '%'" : "= '$login'"; @@ -145,9 +145,9 @@ if ($config[general_restrict_badusers_access] == 'yes'){ $link = @da_sql_pconnect($config); if ($link){ $search = @da_sql_query($link,$config, - "SELECT * FROM $config[sql_badusers_table] + "SELECT da_sql_limit($limit,0,$config) * FROM $config[sql_badusers_table] WHERE username $usercheck $extra_query AND date <= '$now_str' - AND date >= '$prev_str' ORDER BY date $order $limit;"); + AND date >= '$prev_str' da_sql_limit($limit,1,$config) ORDER BY date $order da_sql_limit($limit,2,$config);"); if ($search){ while( $row = @da_sql_fetch_array($search,$config) ){ $num++; diff --git a/htdocs/failed_logins.php3 b/htdocs/failed_logins.php3 index 9aa6c1b..8214265 100644 --- a/htdocs/failed_logins.php3 +++ b/htdocs/failed_logins.php3 @@ -39,7 +39,7 @@ $prev_str = da_sql_escape_string($prev_str); $pagesize = ($pagesize) ? $pagesize : 10; if (!is_numeric($pagesize) && $pagesize != 'all') $pagesize = 10; -$limit = ($pagesize == 'all') ? '' : "LIMIT $pagesize"; +$limit = ($pagesize == 'all') ? '' : "$pagesize"; $selected[$pagesize] = 'selected'; $order = ($order != '') ? $order : $config[general_accounting_info_order]; if ($order != 'desc' && $order != 'asc') @@ -115,13 +115,13 @@ if ($config[sql_accounting_extra_query] != ''){ $link = @da_sql_pconnect($config); if ($link){ $search = @da_sql_query($link,$config, - "SELECT acctstoptime,username,nasipaddress,nasportid,acctterminatecause,callingstationid + "SELECT da_sql_limit($limit,0,$config) acctstoptime,username,nasipaddress,nasportid,acctterminatecause,callingstationid FROM $config[sql_accounting_table] WHERE acctstoptime <= '$now_str' AND acctstoptime >= '$prev_str' AND (acctterminatecause LIKE 'Login-Incorrect%' OR acctterminatecause LIKE 'Invalid-User%' OR - acctterminatecause LIKE 'Multiple-Logins%') $callerid_str $server_str $sql_extra_query - ORDER BY acctstoptime $order $limit;"); + acctterminatecause LIKE 'Multiple-Logins%') $callerid_str $server_str $sql_extra_query da_sql_limit($limit,1,$config) + ORDER BY acctstoptime $order da_sql_limit($limit,2,$config);"); if ($search){ while( $row = @da_sql_fetch_array($search,$config) ){ $num++; diff --git a/htdocs/user_accounting.php3 b/htdocs/user_accounting.php3 index 7742784..3f1c8ce 100644 --- a/htdocs/user_accounting.php3 +++ b/htdocs/user_accounting.php3 @@ -31,7 +31,7 @@ $num = 0; $pagesize = ($pagesize) ? $pagesize : 10; if (!is_numeric($pagesize) && $pagesize != 'all') $pagesize = 10; -$limit = ($pagesize == 'all') ? '' : "LIMIT $pagesize"; +$limit = ($pagesize == 'all') ? '' : "$pagesize"; $selected[$pagesize] = 'selected'; $order = ($order != '') ? $order : $config[general_accounting_info_order]; if ($order != 'desc' && $order != 'asc') @@ -102,9 +102,10 @@ if ($config[sql_accounting_extra_query] != '') $link = @da_sql_pconnect($config); if ($link){ $search = @da_sql_query($link,$config, - "SELECT * FROM $config[sql_accounting_table] + "SELECT da_sql_limit($limit,0,$config) * FROM $config[sql_accounting_table] WHERE username = '$login' AND acctstarttime <= '$now_str' - AND acctstarttime >= '$prev_str' $sql_extra_query ORDER BY acctstarttime $order $limit;"); + AND acctstarttime >= '$prev_str' $sql_extra_query da_sql_limit($limit,1,$config) + ORDER BY acctstarttime $order da_sql_limit($limit,2,$config);"); if ($search){ while( $row = @da_sql_fetch_array($search,$config) ){ $tr_color='white'; diff --git a/htdocs/user_admin.php3 b/htdocs/user_admin.php3 index d98945b..d72ece8 100644 --- a/htdocs/user_admin.php3 +++ b/htdocs/user_admin.php3 @@ -214,9 +214,9 @@ if ($link){ } $search = @da_sql_query($link,$config, - "SELECT * FROM $config[sql_accounting_table] - WHERE username = '$login' AND acctstoptime IS NULL - ORDER BY acctstarttime DESC LIMIT 1;"); + "SELECT da_sql_limit(1,0,$config) * FROM $config[sql_accounting_table] + WHERE username = '$login' AND acctstoptime IS NULL da_sql_limit(1,1,$config) + ORDER BY acctstarttime DESC da_sql_limit(1,2,$config);"); if ($search){ if (@da_sql_num_rows($search,$config)){ $logged_now = 1; @@ -255,9 +255,9 @@ if ($link){ echo "Database query failed: " . da_sql_error($link,$config) . "
\n"; if (! $logged_now){ $search = @da_sql_query($link,$config, - "SELECT * FROM $config[sql_accounting_table] - WHERE username = '$login' AND acctsessiontime != '0' - ORDER BY acctstoptime DESC LIMIT 1;"); + "SELECT da_sql_limit(1,0,$config) * FROM $config[sql_accounting_table] + WHERE username = '$login' AND acctsessiontime != '0' da_sql_limit(1,1,$config) + ORDER BY acctstoptime DESC da_sql_limit(1,2,$config);"); if ($search){ if (@da_sql_num_rows($search,$config)){ $row = @da_sql_fetch_array($search,$config); diff --git a/htdocs/user_stats.php3 b/htdocs/user_stats.php3 index 0ba2b18..d277032 100644 --- a/htdocs/user_stats.php3 +++ b/htdocs/user_stats.php3 @@ -37,7 +37,7 @@ if (!is_numeric($pagesize) && $pagesize != 'all') $pagezise = 10; if ($pagesize > 100) $pagesize = 100; -$limit = ($pagesize == 'all') ? 'LIMIT 100' : "LIMIT $pagesize"; +$limit = ($pagesize == 'all') ? '100' : "$pagesize"; $selected[$pagesize] = 'selected'; $order = ($order) ? $order : $config[general_accounting_info_order]; if ($order != 'desc' && $order != 'asc') @@ -110,9 +110,9 @@ EOM; $link = @da_sql_pconnect($config); if ($link){ $search = @da_sql_query($link,$config, - "SELECT * FROM $config[sql_total_accounting_table] - WHERE acctdate >= '$start' AND acctdate <= '$stop' $server_str $login_str $sql_extra_query - ORDER BY $order_attr $order $limit;"); + "SELECT da_sql_limit($limit,0,$config) * FROM $config[sql_total_accounting_table] + WHERE acctdate >= '$start' AND acctdate <= '$stop' $server_str $login_str $sql_extra_query da_sql_limit($limit,1,$config) + ORDER BY $order_attr $order da_sql_limit($limit,2,$config);"); if ($search){ while( $row = @da_sql_fetch_array($search,$config) ){ diff --git a/lib/sql/drivers/dbx/functions.php3 b/lib/sql/drivers/dbx/functions.php3 index 655aedd..a968fd8 100644 --- a/lib/sql/drivers/dbx/functions.php3 +++ b/lib/sql/drivers/dbx/functions.php3 @@ -1,4 +1,16 @@