From e3405791e916d2f7d77e84ec27f2d9d5114eea7a Mon Sep 17 00:00:00 2001 From: kkalev Date: Tue, 4 Jan 2005 15:17:28 +0000 Subject: [PATCH] * 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 --- Changelog | 2 + bin/backup_radacct | 3 +- bin/clean_radacct | 5 +- bin/log_badlogins | 8 +- bin/monthly_tot_stats | 5 +- bin/sqlrelay_query | 15 ++ bin/tot_stats | 5 +- bin/truncate_radacct | 5 +- conf/admin.conf | 5 +- lib/sql/drivers/sqlrelay/functions.php3 | 181 ++++++++++++++++++++++++ 10 files changed, 226 insertions(+), 8 deletions(-) create mode 100755 bin/sqlrelay_query create mode 100644 lib/sql/drivers/sqlrelay/functions.php3 diff --git a/Changelog b/Changelog index e4c4a57..b16b7a9 100644 --- a/Changelog +++ b/Changelog @@ -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). diff --git a/bin/backup_radacct b/bin/backup_radacct index 2194f46..de873fd 100755 --- a/bin/backup_radacct +++ b/bin/backup_radacct @@ -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 $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' $backup_directory/$date3" if ($sql_type eq 'sqlrelay'); `$comm`; `/usr/local/bin/gzip -9 $backup_directory/$date3`; diff --git a/bin/clean_radacct b/bin/clean_radacct index c82f664..e1a6607 100755 --- a/bin/clean_radacct +++ b/bin/clean_radacct @@ -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 > 8; diff --git a/bin/monthly_tot_stats b/bin/monthly_tot_stats index 015ea50..a1f25f6 100755 --- a/bin/monthly_tot_stats +++ b/bin/monthly_tot_stats @@ -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 ){ + chomp; + `$sqlrelay '$host' '$port' '$socket' '$user' '$passwd' '$_'`; + $exit = $? >> 8; + if ($exit != 0){ + exit $exit; + } +} diff --git a/bin/tot_stats b/bin/tot_stats index 904d89e..0c945ea 100755 --- a/bin/tot_stats +++ b/bin/tot_stats @@ -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 DEBUG(SQL,SQLRELAY DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd
\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 "DEBUG(SQL,SQLRELAY DRIVER): Connect: User=$SQL_user,Password=$SQL_passwd
\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 "DEBUG(SQL,SQLRELAY DRIVER): Connect: Host=$config[sql_server],Port=$config[sql_port],User=$SQL_user,Password=$SQL_passwd
\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 "DEBUG(SQL,SQLRELAY DRIVER): Query: $query
\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 "DEBUG(SQL,SQLRELAY DRIVER): Query Result: Num rows:: " . @sqlrcur_rowCount($result[cur]) . "
\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 "DEBUG(SQL,SQLRELAY DRIVER): Query Result:
";
+	}
+	return $row;
+}
+
+function da_sql_affected_rows($link,$result,$config)
+{
+	if ($config[sql_debug] == 'true')
+		print "DEBUG(SQL,SQLRELAY DRIVER): Query Result: Affected rows:: " . @sqlrcur_affectedRows($result[cur]) . "
\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]); +} +?> -- 2.39.5