View Single Post
  #14  
Old 5th July 2011, 17:52
erosbk erosbk is offline
Senior Member
 
Join Date: Mar 2011
Posts: 337
Thanks: 49
Thanked 36 Times in 30 Posts
Default

I made the script, I can assume that it will work for a multiserver (with one or more ftp/web servers) environment -Debian, pureftpd, log set as stats:-

Only tested with ftp/web server in master server... I will test it in VMs in the next weeks to see if it is working correctly (only thing I need to test, is to add ftp_traffic in master server, give INSERT, UPDATE, SELECT privileges for each slave (or just for ftp slave?) and test, test and test...

Right now, It is just crude code, including this files: require('/usr/local/ispconfig/server/lib/config.inc.php');
require('/usr/local/ispconfig/server/lib/app.inc.php');

But only using a few variables/classes/functions of them...

I don't have enought time to investigate all ispconfig as I wish, so... I need your guidance...

1) Have a look here please if you want to see the "ugly working code" (will be improved soon...)

http://www.tecatest.com.ar/test.txt

2) How can I replace this check? (do I am a FTP server??)

Code:
$myhostname = gethostname();

$conn = mysql_connect($conf['db_host'], $conf['db_user'], $conf['db_password']) or die                      ('Error connecting to mysql');
mysql_select_db($conf['db_database']);
$result = mysql_query("select count(server_id) FROM server WHERE file_server=1 and server_name='$myhostname'");
mysql_close($conn);

$ftpvalid = mysql_fetch_array($result);

if ($ftpvalid[0] > 0) //Do I am a FTP server???, if yes... continues, master or slave is the same

3) I think that ISPConfig3 has some functions to handle update/insert to dbmaster/dblocal... how can I replace this?

Code:
$conn = mysql_connect($conf['dbmaster_host'], $conf['dbmaster_user'], $conf['dbmaster_password']) or die            $
mysql_select_db($conf['dbmaster_database']);
$result = mysql_query("select count(username) from ftp_traffic where username='$ftp_user' and traffic_date='$ftp_dat$
$row = mysql_fetch_array($result);
mysql_close($conn);
if ($row[0] == 0) // No record found, so... insert in master into ftp_traffic
{
        $query = "insert into ftp_traffic values ('$ftp_domain[0]','$ftp_user','$ftp_date',$ftp_type,'$ftp_bytes')";
}
else // Update ftp_traffic in master
{
       $query = "update ftp_traffic set traffic_bytes=traffic_bytes+'$ftp_bytes' where username='$ftp_user' and tra$
}
$conn = mysql_connect($conf['dbmaster_host'], $conf['dbmaster_user'], $conf['dbmaster_password']) or die            $
mysql_select_db($conf['db_database']);
mysql_query($query);
mysql_close($conn);
Reply With Quote