Commit a7333537 authored by mcramer's avatar mcramer

Added: vlogger mysql usage to store traffic reports

Added: interface module web traffic statistics
Fixed: mail_traffic is now reported to master server instead of local
Fixed: GRANTs for slave server database user on master database
parent bb5171da
......@@ -148,5 +148,7 @@ $conf['jailkit']['jk_init'] = 'jk_init.ini';
$conf['jailkit']['jk_chrootsh'] = 'jk_chrootsh.ini';
$conf['jailkit']['jailkit_chroot_app_programs'] = '/usr/bin/groups /usr/bin/id /usr/bin/dircolors /bin/basename /usr/bin/dirname /usr/bin/nano';
//* vlogger
$conf['vlogger']['config_dir'] = '/etc';
?>
\ No newline at end of file
......@@ -148,5 +148,7 @@ $conf['jailkit']['jk_init'] = 'jk_init.ini';
$conf['jailkit']['jk_chrootsh'] = 'jk_chrootsh.ini';
$conf['jailkit']['jailkit_chroot_app_programs'] = '/usr/bin/groups /usr/bin/id /usr/bin/dircolors /bin/basename /usr/bin/dirname /usr/bin/nano';
//* vlogger
$conf['vlogger']['config_dir'] = '/etc';
?>
\ No newline at end of file
......@@ -148,5 +148,7 @@ $conf['jailkit']['jk_init'] = 'jk_init.ini';
$conf['jailkit']['jk_chrootsh'] = 'jk_chrootsh.ini';
$conf['jailkit']['jailkit_chroot_app_programs'] = '/usr/bin/groups /usr/bin/id /usr/bin/dircolors /usr/bin/lesspipe /usr/bin/basename /usr/bin/dirname /usr/bin/nano /usr/bin/pico';
//* vlogger
$conf['vlogger']['config_dir'] = '/etc';
?>
\ No newline at end of file
......@@ -148,5 +148,7 @@ $conf['jailkit']['jk_init'] = 'jk_init.ini';
$conf['jailkit']['jk_chrootsh'] = 'jk_chrootsh.ini';
$conf['jailkit']['jailkit_chroot_app_programs'] = '/usr/bin/groups /usr/bin/id /usr/bin/dircolors /bin/basename /usr/bin/dirname /usr/bin/nano';
//* vlogger
$conf['vlogger']['config_dir'] = '/etc';
?>
\ No newline at end of file
......@@ -97,5 +97,7 @@ $conf['jailkit']['jk_init'] = 'jk_init.ini';
$conf['jailkit']['jk_chrootsh'] = 'jk_chrootsh.ini';
$conf['jailkit']['jailkit_chroot_app_programs'] = '/usr/bin/groups /usr/bin/id /usr/bin/dircolors /usr/bin/lesspipe /usr/bin/basename /usr/bin/dirname /usr/bin/nano /usr/bin/pico';
//* vlogger
$conf['vlogger']['config_dir'] = '/etc';
?>
\ No newline at end of file
......@@ -148,5 +148,8 @@ $conf['jailkit']['jk_init'] = 'jk_init.ini';
$conf['jailkit']['jk_chrootsh'] = 'jk_chrootsh.ini';
$conf['jailkit']['jailkit_chroot_app_programs'] = '/usr/bin/groups /usr/bin/id /usr/bin/dircolors /usr/bin/basename /usr/bin/dirname /usr/bin/nano /usr/bin/pico';
//* vlogger
$conf['vlogger']['config_dir'] = '/etc';
?>
\ No newline at end of file
......@@ -195,6 +195,10 @@ if($install_mode == 'standard') {
swriteln('Configuring Apache');
$inst->configure_apache();
//** Configure vlogger
swriteln('Configuring vlogger');
$inst->configure_vlogger();
//* Configure Firewall
swriteln('Configuring Firewall');
$inst->configure_firewall();
......@@ -359,6 +363,10 @@ if($install_mode == 'standard') {
$conf['services']['web'] = true;
swriteln('Configuring Apache');
$inst->configure_apache();
//** Configure vlogger
swriteln('Configuring vlogger');
$inst->configure_vlogger();
}
//** Configure Firewall
......
......@@ -318,6 +318,21 @@ class installer_base {
if(!$this->dbmaster->query($query)) {
$this->error('Unable to create database user in master database: '.$conf['mysql']['master_ispconfig_user'].' Error: '.$this->dbmaster->errorMessage);
}
$query = "GRANT SELECT, INSERT, UPDATE ON ".$conf['mysql']['master_database'].".`mail_traffic` "
."TO '".$conf['mysql']['master_ispconfig_user']."'@'".$src_host."' "
."IDENTIFIED BY '".$conf['mysql']['master_ispconfig_password']."';";
if(!$this->dbmaster->query($query)) {
$this->error('Unable to create database user in master database: '.$conf['mysql']['master_ispconfig_user'].' Error: '.$this->dbmaster->errorMessage);
}
$query = "GRANT SELECT, INSERT, UPDATE ON ".$conf['mysql']['master_database'].".`web_traffic` "
."TO '".$conf['mysql']['master_ispconfig_user']."'@'".$src_host."' "
."IDENTIFIED BY '".$conf['mysql']['master_ispconfig_password']."';";
if(!$this->dbmaster->query($query)) {
$this->error('Unable to create database user in master database: '.$conf['mysql']['master_ispconfig_user'].' Error: '.$this->dbmaster->errorMessage);
}
}
}
......@@ -856,7 +871,32 @@ class installer_base {
}
public function configure_vlogger()
{
global $conf;
//** Configure vlogger to use traffic logging to mysql (master) db
$configfile = 'vlogger-dbi.conf';
if(is_file($conf["vlogger"]["config_dir"].'/'.$configfile)) copy($conf["vlogger"]["config_dir"].'/'.$configfile,$conf["vlogger"]["config_dir"].'/'.$configfile.'~');
if(is_file($conf["vlogger"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["vlogger"]["config_dir"].'/'.$configfile.'~');
$content = rf("tpl/".$configfile.".master");
if($conf['mysql']['master_slave_setup'] == 'y') {
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['master_ispconfig_user'],$content);
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['master_ispconfig_password'], $content);
$content = str_replace('{mysql_server_database}',$conf['mysql']['master_database'],$content);
$content = str_replace('{mysql_server_ip}',$conf["mysql"]["master_host"],$content);
} else {
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
$content = str_replace('{mysql_server_ip}',$conf["mysql"]["host"],$content);
}
wf($conf["vlogger"]["config_dir"].'/'.$configfile,$content);
exec('chmod 600 '.$conf["vlogger"]["config_dir"].'/'.$configfile);
exec('chown root:root '.$conf["vlogger"]["config_dir"].'/'.$configfile);
}
public function install_ispconfig()
{
global $conf;
......
......@@ -1016,6 +1016,20 @@ CREATE TABLE `web_database` (
) ENGINE=MyISAM AUTO_INCREMENT=1;
-- --------------------------------------------------------
--
-- Table structure for table `web_traffic`
--
CREATE TABLE `web_traffic` (
`hostname` varchar(255) NOT NULL,
`traffic_date` date NOT NULL,
`traffic_bytes` bigint(32) unsigned NOT NULL default '0',
PRIMARY KEY (`hostname`,`traffic_date`)
) ENGINE=MyISAM;
-- --------------------------------------------------------
--
......
......@@ -5,7 +5,7 @@
################################################
LogFormat "%v %h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-Agent}i\"" combined_ispconfig
CustomLog "| /usr/sbin/vlogger -s access.log -t \"%Y%m%d-access.log\" /var/log/ispconfig/httpd" combined_ispconfig
CustomLog "| /usr/local/ispconfig/server/scripts/vlogger -s access.log -t \"%Y%m%d-access.log\" -d \"/etc/vlogger-dbi.conf\" /var/log/ispconfig/httpd" combined_ispconfig
<Directory /var/www/clients>
AllowOverride None
......
dsn DBI:mysql:database={mysql_server_database};host={mysql_server_ip}:3306
user {mysql_server_ispconfig_user}
pass {mysql_server_ispconfig_password}
dump 30
\ No newline at end of file
......@@ -300,6 +300,10 @@ if($reconfigure_services_answer == 'yes') {
//** Configure Apache
swriteln('Configuring Apache');
$inst->configure_apache();
//** Configure vlogger
swriteln('Configuring vlogger');
$inst->configure_vlogger();
}
......
<?php
$wb['list_head_txt'] = 'Web traffic';
$wb['domain_txt'] = 'Domain';
$wb['this_month_txt'] = 'This month';
$wb['last_month_txt'] = 'Last month';
$wb['this_year_txt'] = 'This year';
$wb['last_year_txt'] = 'Last year';
?>
<?php
$wb['list_head_txt'] = 'Web Datenverkehr';
$wb['domain_txt'] = 'Domain';
$wb['this_month_txt'] = 'Diesen Monat';
$wb['last_month_txt'] = 'Letzten Monat';
$wb['this_year_txt'] = 'Dieses Jahr';
$wb['last_year_txt'] = 'Letztes Jahr';
?>
<?php
$wb["list_head_txt"] = 'Web traffic';
$wb["domain_txt"] = 'Domain';
$wb["this_month_txt"] = 'This month';
$wb["last_month_txt"] = 'Last month';
$wb["this_year_txt"] = 'This year';
$wb["last_year_txt"] = 'Last year';
?>
\ No newline at end of file
<?php
$wb['list_head_txt'] = 'Tráfico de xxxx';
$wb['domain_txt'] = 'xxxx';
$wb['this_month_txt'] = 'Este mes';
$wb['last_month_txt'] = 'Último mes';
$wb['this_year_txt'] = 'Este año';
$wb['last_year_txt'] = 'Último año';
?>
<?php
$wb['list_head_txt'] = 'Sähköpostiliikenne';
$wb['domain_txt'] = 'Sähköpostiosoite';
$wb['this_month_txt'] = 'Tässä kuussa';
$wb['last_month_txt'] = 'Viime kuussa';
$wb['this_year_txt'] = 'Tänä vuonna';
$wb['last_year_txt'] = 'Viime vuonna';
?>
<?php
$wb['list_head_txt'] = 'Web traffic';
$wb['domain_txt'] = 'Domain';
$wb['this_month_txt'] = 'This month';
$wb['last_month_txt'] = 'Last month';
$wb['this_year_txt'] = 'This year';
$wb['last_year_txt'] = 'Last year';
?>
<?php
$wb['list_head_txt'] = 'Web traffic';
$wb['domain_txt'] = 'Domain';
$wb['this_month_txt'] = 'This month';
$wb['last_month_txt'] = 'Last month';
$wb['this_year_txt'] = 'This year';
$wb['last_year_txt'] = 'Last year';
?>
<?php
$wb['list_head_txt'] = 'Web verkeer';
$wb['domain_txt'] = 'Domain';
$wb['this_month_txt'] = 'Deze maand';
$wb['last_month_txt'] = 'Laatste maand';
$wb['this_year_txt'] = 'Dit jaar';
$wb['last_year_txt'] = 'Vorig jaar';
?>
<?php
$wb['list_head_txt'] = 'Web трафик';
$wb['domain_txt'] = 'Domain';
$wb['this_month_txt'] = 'Этот месяц';
$wb['last_month_txt'] = 'Последний месяц';
$wb['this_year_txt'] = 'Этот год';
$wb['last_year_txt'] = 'Последний год';
?>
<?php
$wb['list_head_txt'] = 'Web traffic';
$wb['domain_txt'] = 'Domain';
$wb['this_month_txt'] = 'This month';
$wb['last_month_txt'] = 'Last month';
$wb['this_year_txt'] = 'This year';
$wb['last_year_txt'] = 'Last year';
?>
......@@ -20,9 +20,9 @@ $items[] = array( 'title' => "Subdomain",
'link' => 'sites/web_subdomain_list.php');
$items[] = array( 'title' => "Aliasdomain",
'target' => 'content',
'link' => 'sites/web_aliasdomain_list.php');
$items[] = array( 'title' => "Aliasdomain",
'target' => 'content',
'link' => 'sites/web_aliasdomain_list.php');
$module["nav"][] = array( 'title' => 'Websites',
'open' => 1,
......@@ -76,6 +76,21 @@ $module["nav"][] = array( 'title' => 'Database',
'open' => 1,
'items' => $items);
//**** Statistics menu
$items = array();
$items[] = array( 'title' => 'Web traffic',
'target' => 'content',
'link' => 'sites/web_sites_stats.php');
$module['nav'][] = array( 'title' => 'Statistics',
'open' => 1,
'items' => $items);
// clean up
unset($items);
......
<?php
/*
Datatypes:
- INTEGER
- DOUBLE
- CURRENCY
- VARCHAR
- TEXT
- DATE
*/
// Name of the list
$liste["name"] = "web_sites_stats";
// Database table
$liste["table"] = "web_domain";
// Index index field of the database table
$liste["table_idx"] = "domain_id";
// Search Field Prefix
$liste["search_prefix"] = "search_";
// Records per page
$liste["records_per_page"] = 15;
// Script File of the list
$liste["file"] = "web_sites_stats.php";
// Script file of the edit form
$liste["edit_file"] = "web_domain_edit.php";
// Script File of the delete script
$liste["delete_file"] = "web_domain_del.php";
// Paging Template
$liste["paging_tpl"] = "templates/paging.tpl.htm";
// Enable auth
$liste["auth"] = "yes";
/*****************************************************
* Suchfelder
*****************************************************/
$liste["item"][] = array( 'field' => "domain",
'datatype' => "VARCHAR",
'formtype' => "TEXT",
'op' => "like",
'prefix' => "%",
'suffix' => "%",
'width' => "",
'value' => "");
?>
\ No newline at end of file
<h2><tmpl_var name="list_head_txt"></h2>
<p><tmpl_var name="list_desc_txt"></p>
<div class="panel panel_list_web_sites_stats">
<div class="pnl_listarea">
<fieldset><legend><tmpl_var name="list_head_txt"></legend>
<table class="list">
<thead>
<tr>
<th class="tbl_col_domain" scope="col"><tmpl_var name="domain_txt"></th>
<th class="tbl_col_this_month" scope="col"><tmpl_var name="this_month_txt"></th>
<th class="tbl_col_last_month" scope="col"><tmpl_var name="last_month_txt"></th>
<th class="tbl_col_this_year" scope="col"><tmpl_var name="this_year_txt"></th>
<th class="tbl_col_last_year" scope="col"><tmpl_var name="last_year_txt"></th>
<th class="tbl_col_buttons" scope="col">&nbsp;</th>
</tr>
<tr>
<td class="tbl_col_domain"><input type="text" name="search_domain" value="{tmpl_var name='search_domain'}" /></td>
<td class="tbl_col_this_month"></td>
<td class="tbl_col_last_month"></td>
<td class="tbl_col_this_year"></td>
<td class="tbl_col_last_year"></td>
<td class="tbl_col_buttons"><div class="buttons"><button type="button" class="icons16 icoFilter" name="Filter" id="Filter" value="{tmpl_var name="filter_txt"}" onClick="submitForm('pageForm','sites/web_sites_stats.php');"><span>{tmpl_var name="filter_txt"}</span></button></div></td>
</tr>
</thead>
<tbody>
<tmpl_loop name="records">
<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
<td class="tbl_col_domain"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="domain"}</a></td>
<td class="tbl_col_this_month"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_month"} kB</a></td>
<td class="tbl_col_last_month"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_month"} kB</a></td>
<td class="tbl_col_this_year"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_year"} kB</a></td>
<td class="tbl_col_last_year"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_year"} kB</a></td>
<td class="tbl_col_buttons">
<div class="buttons icons16">
</div>
</td>
</tr>
</tmpl_loop>
</tbody>
<tfoot>
<tr>
<td class="tbl_footer tbl_paging" colspan="6"><tmpl_var name="paging"></td>
</tr>
</tfoot>
</table>
</fieldset>
</div>
</div>
<?php
require_once('../../lib/config.inc.php');
require_once('../../lib/app.inc.php');
/******************************************
* Begin Form configuration
******************************************/
$list_def_file = "list/web_sites_stats.list.php";
/******************************************
* End Form configuration
******************************************/
//* Check permissions for module
$app->auth->check_module_permissions('sites');
$app->load('listform_actions');
class list_action extends listform_actions {
function prepareDataRow($rec)
{
global $app;
$rec = $app->listform->decode($rec);
//* Alternating datarow colors
$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
$rec['bgcolor'] = $this->DataRowColor;
//* Set the statistics colums
//** Traffic of the current month
$tmp_year = date('Y');
$tmp_month = date('m');
$tmp_rec = $app->db->queryOneRecord("SELECT SUM(traffic_bytes) as t FROM web_traffic WHERE hostname = '".$rec['domain']."' AND YEAR(traffic_date) = '$tmp_year' AND MONTH(traffic_date) = '$tmp_month'");
$rec['this_month'] = number_format(intval($tmp_rec['t'])/1024, 0, '.', ' ');
//** Traffic of the current year
$tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = '".$rec['domain']."' AND YEAR(traffic_date) = '$tmp_year'");
$rec['this_year'] = number_format(intval($tmp_rec['t'])/1024, 0, '.', ' ');
//** Traffic of the last month
$tmp_year = date('Y',mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
$tmp_month = date('m',mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
$tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = '".$rec['domain']."' AND YEAR(traffic_date) = '$tmp_year' AND MONTH(traffic_date) = '$tmp_month'");
$rec['last_month'] = number_format(intval($tmp_rec['t'])/1024, 0, '.', ' ');
//** Traffic of the last year
$tmp_year = date('Y',mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
$tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = '".$rec['domain']."' AND YEAR(traffic_date) = '$tmp_year'");
$rec['last_year'] = number_format(intval($tmp_rec['t'])/1024, 0, '.', ' ');
//* The variable "id" contains always the index variable
$rec['id'] = $rec[$this->idx_key];
return $rec;
}
}
$list = new list_action;
$list->onLoad();
?>
\ No newline at end of file
......@@ -4,7 +4,7 @@
################################################
LogFormat "%v %h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-Agent}i\"" combined_ispconfig
CustomLog "| /usr/sbin/vlogger -s access.log -t \"%Y%m%d-access.log\" /var/log/ispconfig/httpd" combined_ispconfig
CustomLog "| /usr/local/ispconfig/server/scripts/vlogger -s access.log -t \"%Y%m%d-access.log\" -d \"/etc/vlogger-dbi.conf\" /var/log/ispconfig/httpd" combined_ispconfig
<Directory /var/www/clients>
AllowOverride None
......
......@@ -68,7 +68,7 @@ foreach($records as $rec) {
$tstamp = date("Y-m");
$sql = "SELECT * FROM mail_traffic WHERE month = '$tstamp' AND mailuser_id = ".$rec["mailuser_id"];
$tr = $app->db->queryOneRecord($sql);
$tr = $app->dbmaster->queryOneRecord($sql);
$mail_traffic += $tr["traffic"];
if($tr["traffic_id"] > 0) {
......@@ -76,7 +76,7 @@ foreach($records as $rec) {
} else {
$sql = "INSERT INTO mail_traffic (month,mailuser_id,traffic) VALUES ('$tstamp',".$rec["mailuser_id"].",$mail_traffic)";
}
$app->db->query($sql);
$app->dbmaster->query($sql);
echo $sql;
}
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment