* Add an sqlrelay functions file. The user_admin page does not currently work. Lookin...
authorkkalev <kkalev>
Tue, 4 Jan 2005 15:17:28 +0000 (15:17 +0000)
committerkkalev <kkalev>
Tue, 4 Jan 2005 15:17:28 +0000 (15:17 +0000)
* Add sqlrelay support in the scripts. Add a sqlrelay_query script to run sqlrelay commands

dialup_admin/Changelog
dialup_admin/bin/backup_radacct
dialup_admin/bin/clean_radacct
dialup_admin/bin/log_badlogins
dialup_admin/bin/monthly_tot_stats
dialup_admin/bin/sqlrelay_query [new file with mode: 0755]
dialup_admin/bin/tot_stats
dialup_admin/bin/truncate_radacct
dialup_admin/conf/admin.conf
dialup_admin/lib/sql/drivers/sqlrelay/functions.php3 [new file with mode: 0644]

index e4c4a57..b16b7a9 100644 (file)
@@ -11,6 +11,8 @@ Ver 1.78:
 * Fix a problem when reading username.mappings
 * If date calculation fails, abort
 * Add a backup_radacct script
+* Add an sqlrelay functions file. The user_admin page does not currently work. Looking into it.
+* Add sqlrelay support in the scripts. Add a sqlrelay_query script to run sqlrelay commands
 Ver 1.75:
 * A LOT of security related fixes. Now dialupadmin should hopefully be secure enough to
   be accessed by normal users (not administrators).
index 2194f46..de873fd 100755 (executable)
@@ -43,6 +43,7 @@ open TMP, ">/tmp/backup_radacct.query"
 print TMP $query;
 close TMP;
 $comm = "$sqlcmd -B -h $sql_server -u $sql_username $sql_password $sql_database </tmp/backup_radacct.query >$backup_directory/$date3" if ($sql_type eq 'mysql');
-$comm = "$sqlcmd  -U $sql_username -f /tmp/truncate_radacct.query $sql_database >$backup_directory/$date3" if ($sql_type eq 'pg');
+$comm = "$sqlcmd  -U $sql_username -f /tmp/backup_radacct.query $sql_database >$backup_directory/$date3" if ($sql_type eq 'pg');
+$command = "$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' </tmp/backup_radacct.query >$backup_directory/$date3" if ($sql_type eq 'sqlrelay');
 `$comm`;
 `/usr/local/bin/gzip -9 $backup_directory/$date3`;
index c82f664..e1a6607 100755 (executable)
@@ -28,7 +28,9 @@ close CONF;
 die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq '');
 die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd);
 
-$sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+if ($sql_type eq 'mysql'){
+       $sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+}
 $sql_password =~ s/(\W)/\\$1/g;
 
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
@@ -46,4 +48,5 @@ print TMP $query;
 close TMP;
 $command = "$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database </tmp/clean_radacct.query" if ($sql_type eq 'mysql');
 $command = "$sqlcmd  -U $sql_username -f /tmp/clean_radacct.query $sql_database" if ($sql_type eq 'pg');
+$command = "$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' </tmp/clean_radacct.query" if ($sql_type eq 'sqlrelay');
 `$command`;
index 1489f76..408534e 100755 (executable)
@@ -93,7 +93,12 @@ close CLIENTS;
 
 $realm_del = '@' if ($realm_del eq '');
 $realm_for = 'suffix' if ($realm_for eq '');
-$pass = ($sql_password ne '') ? "-p$sql_password" : '';
+if ($sql_type eq 'mysql'){
+       $pass = ($sql_password ne '') ? "-p$sql_password" : '';
+}
+else{
+       $pass = $sql_password;
+}
 $pass =~ s/(\W)/\\$1/g;
 die "SQL server not defined\n" if ($sql_server eq '');
 
@@ -193,6 +198,7 @@ for(;;){
                                        close TMP;
                                        $command = "$sqlcmd -h$server $opt -u$sql_username $pass $sql_database <$tmpfile.$server" if ($sql_type eq 'mysql');
                                        $command = "$sqlcmd  -U $sql_username -f $tmpfile.$server $sql_database" if ($sql_type eq 'pg');
+                                       $command = "$sqlcmd '$server' '$sql_port' '' '$sql_username' '$sql_pass' <$tmpfile.$server" if ($sql_type eq 'sqlrelay');
                                        `$command`;
 
                                        $exit = $? >> 8;
index 015ea50..a1f25f6 100755 (executable)
@@ -29,7 +29,9 @@ close CONF;
 die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq '');
 die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd);
 
-$sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+if ($sql_type eq 'mysql'){
+       $sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+}
 $sql_password =~ s/(\W)/\\$1/g;
 
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
@@ -56,4 +58,5 @@ print TMP $query2;
 close TMP;
 $command = "$sqlcmd -h $sql_server -u $sql_username $sql_password $sql_database </tmp/tot_stats.query" if ($sql_type eq 'mysql');
 $command = "$sqlcmd  -U $sql_username -f /tmp/tot_stats.query $sql_database" if ($sql_type eq 'pg');
+$command = "$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' </tmp/tot_stats.query" if ($sql_type eq 'sqlrelay');
 `$command`;
diff --git a/dialup_admin/bin/sqlrelay_query b/dialup_admin/bin/sqlrelay_query
new file mode 100755 (executable)
index 0000000..65e96b5
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+$sqlrelay = '/usr/bin/query';
+$host=shift;
+$port=shift;
+$socket=shift;
+$user=shift;
+$passwd=shift;
+while(<>){
+       chomp;
+       `$sqlrelay '$host' '$port' '$socket' '$user' '$passwd' '$_'`;
+       $exit = $? >> 8;       
+       if ($exit != 0){
+               exit $exit;
+       }
+}
index 904d89e..0c945ea 100755 (executable)
@@ -28,7 +28,9 @@ close CONF;
 die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq '');
 die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd);
 
-$sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+if ($sql_type eq 'mysql'){
+       $sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+}
 $sql_password =~ s/(\W)/\\$1/g;
 
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
@@ -53,4 +55,5 @@ print TMP $query2;
 close TMP;
 $command = "$sqlcmd -h $sql_server -u $sql_username $sql_password $sql_database </tmp/tot_stats.query" if ($sql_type eq 'mysql');
 $command = "$sqlcmd  -U $sql_username -f /tmp/tot_stats.query $sql_database" if ($sql_type eq 'pg');
+$command = "$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' </tmp/tot_stats.query" if ($sql_type eq 'sqlrelay');
 `$command`;
index 48e2d22..3a09262 100755 (executable)
@@ -28,7 +28,9 @@ close CONF;
 die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq '');
 die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd);
 
-$sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+if ($sql_type eq 'mysql'){
+       $sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+}
 $sql_password =~ s/(\W)/\\$1/g;
 
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
@@ -48,4 +50,5 @@ print TMP $query;
 close TMP;
 $command = "$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database </tmp/truncate_radacct.query" if ($sql_type eq 'mysql');
 $command = "$sqlcmd  -U $sql_username -f /tmp/truncate_radacct.query $sql_database" if ($sql_type eq 'pg');
+$command = "$sqlcmd '$sql_server' '$sql_port' '' '$sql_username' '$sql_password' </tmp/truncate_radacct.query" if ($sql_type eq 'sqlrelay');
 `$command`;
index ca1cf04..7ee4e62 100644 (file)
@@ -225,9 +225,10 @@ ldap_debug: true
 
 
 #
-# can be one of mysql,pg where:
+# can be one of mysql,pg,sqlrelay where:
 # mysq: MySQL database (port 3306)
 # pg: PostgreSQL database (port 5432)
+# sqlrelay: SQL Relay
 #
 sql_type: mysql
 sql_server: localhost
@@ -253,7 +254,7 @@ sql_show_all_groups: true
 #
 # This variable is used by the scripts in the bin folder
 # It should contain the path to the sql binary used to run
-# sql commands (mysql and psql are only supported for now)
+# sql commands (mysql, psql and sqlrelay are only supported for now)
 sql_command: /usr/local/bin/mysql
 #
 # This variable is used by the scripts in the bin folder
diff --git a/dialup_admin/lib/sql/drivers/sqlrelay/functions.php3 b/dialup_admin/lib/sql/drivers/sqlrelay/functions.php3
new file mode 100644 (file)
index 0000000..55ee242
--- /dev/null
@@ -0,0 +1,181 @@
+<?php
+function da_sql_host_connect($server,$config)
+{
+       $retrytime = 0;
+
+       if ($config[sql_use_http_credentials] == 'yes'){
+               global $HTTP_SERVER_VARS;
+               $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
+               $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
+       }
+       else{
+               $SQL_user = $config[sql_username];
+               $SQL_passwd = $config[sql_password];
+       }
+
+       if ($config[sql_connect_timeout] != 0)
+               $retrytime = $config[sql_connect_timeout];
+       if ($config[sql_debug] == 'true')
+               print "<b>DEBUG(SQL,SQLRELAY DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd </b><br>\n";
+       $link[con] = @sqlrcon_alloc($server,$port,'',$SQL_user,$SQL_passwd,$retrytime,1);
+       if ($link[con]){
+               $link[cur] = @sqlrcur_alloc($link[con]);
+               if ($link[cur])
+                       return $link;
+               else
+                       return 0;
+       }
+       else
+               return 0;
+}
+
+function da_sql_connect($config)
+{
+       $retrytime = 0;
+
+       if ($config[sql_use_http_credentials] == 'yes'){
+               global $HTTP_SERVER_VARS;
+               $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
+               $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
+       }
+       else{
+               $SQL_user = $config[sql_username];
+               $SQL_passwd = $config[sql_password];
+       }
+
+       if ($config[sql_connect_timeout] != 0)
+               $retrytime = $config[sql_connect_timeout];
+       if ($config[sql_debug] == 'true')
+               print "<b>DEBUG(SQL,SQLRELAY DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd </b><br>\n";
+       $link[con] = @sqlrcon_alloc($config[sql_server],$config[sql_port],'',$SQL_user,$SQL_passwd,$retrytime,1);
+       if ($link[con]){
+               $link[cur] = @sqlrcur_alloc($link[con]);
+               if ($link[cur])
+                       return $link;
+               else
+                       return 0;
+       }
+       else
+               return 0;
+}
+
+function da_sql_pconnect($config)
+{
+       $retrytime = 0;
+
+
+       if ($config[sql_use_http_credentials] == 'yes'){
+               global $HTTP_SERVER_VARS;
+               $SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
+               $SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
+       }
+       else{
+               $SQL_user = $config[sql_username];
+               $SQL_passwd = $config[sql_password];
+       }
+
+       if ($config[sql_connect_timeout] != 0)
+               $retrytime = $config[sql_connect_timeout];
+       if ($config[sql_debug] == 'true')
+               print "<b>DEBUG(SQL,SQLRELAY DRIVER): Connect: Host=$config[sql_server],Port=$config[sql_port],User=$SQL_user,Password=$SQL_passwd </b><br>\n";
+       $link[con] = sqlrcon_alloc($config[sql_server],$config[sql_port],'',$SQL_user,$SQL_passwd,$retrytime,1);
+       if ($link[con]){
+               sqlrcon_debugOn($link[con]);
+               $link[cur] = sqlrcur_alloc($link[con]);
+               if ($link[cur]){
+                       sqlrcur_setResultSetBufferSize($link[cur], 4);
+                       sqlrcur_lowerCaseColumnNames($link[cur]);
+                       return $link;
+               }
+               else
+                       return false;
+       }
+       else{
+               return false;
+       }
+}
+
+function da_sql_close($link,$config)
+{
+       if (sqlrcur_free($link[cur]))
+               return sqlrcon_free($link[con]);
+       else
+               return 0;
+}
+
+function da_sql_escape_string($string)
+{
+       return addslashes($string);
+}
+
+function da_sql_query($link,$config,$query)
+{
+       if ($config[sql_debug] == 'true')
+               print "<b>DEBUG(SQL,SQLRELAY DRIVER): Query: <i>$query</i></b><br>\n";
+       if (sqlrcur_sendQuery($link[cur],$query)){
+               sqlrcon_endSession($link[con]);
+               $link[count] = sqlrcur_rowCount($link[cur]);
+               return $link;
+       }
+       else{
+               return false;
+       }
+}
+
+function da_sql_num_rows($result,$config)
+{
+       if ($config[sql_debug] == 'true')
+               print "<b>DEBUG(SQL,SQLRELAY DRIVER): Query Result: Num rows:: " . @sqlrcur_rowCount($result[cur]) . "</b><br>\n";
+       return sqlrcur_rowCount($result[cur]);
+       return 0;
+}
+
+function da_sql_fetch_array($result,$config)
+{
+       static $counter = 0;
+       if ($counter < $result[count]){
+               $row = sqlrcur_getRowAssoc($result[cur],$counter);
+               $counter++;
+       }
+       else{
+               $counter = 0;
+               return false;
+       }
+       if ($config[sql_debug] == 'true'){
+               print "<b>DEBUG(SQL,SQLRELAY DRIVER): Query Result: <pre>";
+       }
+       return $row;
+}
+
+function da_sql_affected_rows($link,$result,$config)
+{
+       if ($config[sql_debug] == 'true')
+               print "<b>DEBUG(SQL,SQLRELAY DRIVER): Query Result: Affected rows:: " . @sqlrcur_affectedRows($result[cur]) . "</b><br>\n";
+       return sqlrcur_affectedRows($result[cur]);
+}
+
+function da_sql_list_fields($table,$link,$config)
+{
+       if (sqlrcur_sendQuery($link[cur],"SELECT * FROM $table WHERE  1 = 0;")){
+               sqlrcon_endSession($link[con]);
+               return $link[cur];
+       }
+       else
+               return false;
+}
+
+function da_sql_num_fields($fields,$config)
+{
+       return sqlrcur_colCount($fields);
+}
+
+function da_sql_field_name($fields,$num,$config)
+{
+       return sqlrcur_getColumnName($fields,$num);
+}
+
+function da_sql_error($link,$config)
+{
+       return sqlrcur_errorMessage($link[cur]);
+}
+?>