1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <mysql/mysql.h>
#include <stdio.h>
#include <time.h>
main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
MYSQL updatesec;
char *server = "127.0.0.1";
char *user = "xxx";
char *password = "xxxxxxx";
char *database = "xxxxx";
time_t timestamp,t;
char diff;
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}
query="select * from radacct where AcctInputOctets != '0' and AcctOutputOctets != '0' and AcctStopTime = '0000-00-00 00:00:00'";
while (1)
{
printf("\n --- Waiting 5 Secondes --- \n");
sleep (5);
/* send SQL query */
if (mysql_query(conn, "select * from radacct where AcctInputOctets != '0' and AcctOutputOctets != '0' and AcctStopTime = '0000-00-00 00:00:00'"))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}
printf ("SQL Request : %s\n",query);
res = mysql_use_result(conn);
timestamp = time (NULL);
printf ("Current Date in Sec = %i\n",timestamp);
while ((row = mysql_fetch_row(res)) != NULL)
{
//DEBUG
printf("Username = %s \n", row[3]);
printf ("timestamp = %lu\n",timestamp);
printf ("updatetime = %s\n",row[25]);
diff = timestamp - row[25];
printf ("Diff : %u secondes !\n",diff);
// Fin DEBUG
if (row[25] < diff)
{
printf ("\nAbout To Update %s from RadAcct\n",row[3]);
}
else
{
printf ("Nobody to Update ! \n");
}
}
mysql_free_result(res);
//}
}
} |
Partager