diff --git a/interface/web/sites/lib/lang/en_user_quota_stats_list.lng b/interface/web/sites/lib/lang/en_user_quota_stats_list.lng new file mode 100644 index 0000000000000000000000000000000000000000..943c13babc3b469c5ddf7f4c953c3974c60cec04 --- /dev/null +++ b/interface/web/sites/lib/lang/en_user_quota_stats_list.lng @@ -0,0 +1,8 @@ +<?php +$wb["list_head_txt"] = 'Website harddisk quota'; +$wb["domain_txt"] = 'Domain / Website'; +$wb["system_user_txt"] = 'Linux user'; +$wb["used_txt"] = 'Used space'; +$wb["hard_txt"] = 'Hard limit'; +$wb["soft_txt"] = 'Soft limit'; +?> \ No newline at end of file diff --git a/interface/web/sites/lib/module.conf.php b/interface/web/sites/lib/module.conf.php index 3b727ee04c65ac90e8bbbfb608460bc94ad2e8d9..7311d6173f4dabf587eefda2ecd414f5ae55c758 100644 --- a/interface/web/sites/lib/module.conf.php +++ b/interface/web/sites/lib/module.conf.php @@ -124,6 +124,11 @@ $items[] = array( 'title' => 'Web traffic', 'link' => 'sites/web_sites_stats.php', 'html_id' => 'websites_stats'); +$items[] = array( 'title' => 'Website quota (Harddisk)', + 'target' => 'content', + 'link' => 'sites/user_quota_stats.php', + 'html_id' => 'user_quota_stats'); + $module['nav'][] = array( 'title' => 'Statistics', 'open' => 1, diff --git a/interface/web/sites/list/user_quota_stats.list.php b/interface/web/sites/list/user_quota_stats.list.php new file mode 100644 index 0000000000000000000000000000000000000000..a3b58d19c2ff2e42e183a2761ea20f4933f10f5c --- /dev/null +++ b/interface/web/sites/list/user_quota_stats.list.php @@ -0,0 +1,70 @@ +<?php + +/* + Datatypes: + - INTEGER + - DOUBLE + - CURRENCY + - VARCHAR + - TEXT + - DATE +*/ + + + +// Name of the list +$liste["name"] = "user_quota_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"] = "user_quota_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' => ""); + +$liste["item"][] = array( 'field' => "system_user", + 'datatype' => "VARCHAR", + 'formtype' => "TEXT", + 'op' => "like", + 'prefix' => "%", + 'suffix' => "%", + 'width' => "", + 'value' => ""); + + + +?> \ No newline at end of file diff --git a/interface/web/sites/templates/user_quota_stats_list.htm b/interface/web/sites/templates/user_quota_stats_list.htm new file mode 100644 index 0000000000000000000000000000000000000000..acee81043c7b24a799de1e91c83be7e6cd0dd4ca --- /dev/null +++ b/interface/web/sites/templates/user_quota_stats_list.htm @@ -0,0 +1,51 @@ +<h2><tmpl_var name="list_head_txt"></h2> + +<div class="panel panel_list_user_quota_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_system_user" scope="col"><tmpl_var name="system_user_txt"></th> + <th class="tbl_col_system_user" scope="col"><tmpl_var name="used_txt"></th> + <th class="tbl_col_system_user" scope="col"><tmpl_var name="soft_txt"></th> + <th class="tbl_col_system_user" scope="col"><tmpl_var name="hard_txt"></th> + <th class="tbl_col_buttons" scope="col"> </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_system_user"><input type="text" name="search_system_user" value="{tmpl_var name='search_system_user'}" /></td> + <td class="tbl_col_system_user"> </td> + <td class="tbl_col_system_user"> </td> + <td class="tbl_col_system_user"> </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/user_quota_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_system_user"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="system_user"}</a></td> + <td class="tbl_col_used"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="used"}</a></td> + <td class="tbl_col_soft"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="soft"}</a></td> + <td class="tbl_col_hard"><a href="#" onClick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="hard"}</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> diff --git a/interface/web/sites/user_quota_stats.php b/interface/web/sites/user_quota_stats.php new file mode 100644 index 0000000000000000000000000000000000000000..ce2c3bc37c9369c26d1f57261fac9dd0e7345197 --- /dev/null +++ b/interface/web/sites/user_quota_stats.php @@ -0,0 +1,55 @@ +<?php +require_once('../../lib/config.inc.php'); +require_once('../../lib/app.inc.php'); + +/****************************************** +* Begin Form configuration +******************************************/ + +$list_def_file = "list/user_quota_stats.list.php"; + +/****************************************** +* End Form configuration +******************************************/ + +//* Check permissions for module +$app->auth->check_module_permissions('sites'); + +$app->load('listform_actions'); + +$tmp_rec = $app->db->queryOneRecord("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC"); +$monitor_data = unserialize($app->db->unquote($tmp_rec['data'])); + +class list_action extends listform_actions { + + function prepareDataRow($rec) + { + global $app,$monitor_data; + + $rec = $app->listform->decode($rec); + + //* Alternating datarow colors + $this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF'; + $rec['bgcolor'] = $this->DataRowColor; + $username = $rec['system_user']; + + $rec['used'] = $monitor_data['user'][$username]['used']; + $rec['soft'] = $monitor_data['user'][$username]['soft']; + $rec['hard'] = $monitor_data['user'][$username]['hard']; + + if($rec['soft'] == '0K') $rec['soft'] = $app->lng('unlimited'); + if($rec['hard'] == '0K') $rec['hard'] = $app->lng('unlimited'); + + //* The variable "id" contains always the index variable + $rec['id'] = $rec[$this->idx_key]; + return $rec; + } +} + +$list = new list_action; +$list->SQLExtWhere = "type = 'vhost'"; + +$list->onLoad(); + + +?> \ No newline at end of file diff --git a/interface/web/sites/web_sites_stats.php b/interface/web/sites/web_sites_stats.php index b9533e869db80157b099c9d9534581e6fe16f4d2..076858bcb9b14feb9656357e0380dab638a5058b 100644 --- a/interface/web/sites/web_sites_stats.php +++ b/interface/web/sites/web_sites_stats.php @@ -58,6 +58,8 @@ class list_action extends listform_actions { } $list = new list_action; +$list->SQLExtWhere = "type = 'vhost'"; + $list->onLoad(); diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php index da509e6f1113749e080600376273a08867fd7fb9..29dea267ad3d117b18b90e8c8c126f30f735ae4f 100644 --- a/server/mods-available/monitor_core_module.inc.php +++ b/server/mods-available/monitor_core_module.inc.php @@ -195,6 +195,7 @@ class monitor_core_module { // TODO: what monitoring is done should be a config-var function doMonitor() { /* Calls the single Monitoring steps */ + $this->monitorHDQuota(); $this->monitorServer(); $this->monitorOSVer(); $this->monitorIspCVer(); @@ -219,7 +220,84 @@ class monitor_core_module { $this->monitorFail2ban(); $this->monitorSysLog(); } + + function monitorHDQuota() { + global $app; + global $conf; + + /* Initialize data array */ + $data = array(); + + /* the id of the server as int */ + $server_id = intval($conf["server_id"]); + + /** The type of the data */ + $type = 'harddisk_quota'; + + /** The state of the harddisk_quota. */ + $state = 'ok'; + + /** Fetch the data for all users*/ + $dfData = shell_exec("repquota -asu"); + + // split into array + $df = explode("\n", $dfData); + + /* + * ignore the first 5 lines, process the rest + */ + for($i=5; $i <= sizeof($df); $i++) { + if ($df[$i] != '') { + /* + * Make a array of the data + */ + $s = preg_split ("/[\s]+/", $df[$i]); + $username = $s[0]; + $data['user'][$username]['used'] = $s[2]; + $data['user'][$username]['soft'] = $s[3]; + $data['user'][$username]['hard'] = $s[4]; + } + } + + /** Fetch the data for all users*/ + $dfData = shell_exec("repquota -asg"); + + // split into array + $df = explode("\n", $dfData); + /* + * ignore the first 5 lines, process the rest + */ + for($i=5; $i <= sizeof($df); $i++) { + if ($df[$i] != '') { + /* + * Make a array of the data + */ + $s = preg_split ("/[\s]+/", $df[$i]); + $groupname = $s[0]; + $data['group'][$groupname]['used'] = $s[1]; + $data['group'][$groupname]['soft'] = $s[2]; + $data['group'][$groupname]['hard'] = $s[3]; + } + } + + /* + Insert the data into the database + */ + $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . + "VALUES (". + $server_id . ", " . + "'" . $app->dbmaster->quote($type) . "', " . + time() . ", " . + "'" . $app->dbmaster->quote(serialize($data)) . "', " . + "'" . $state . "'" . + ")"; + $app->dbmaster->query($sql); + + /* The new data is written, now we can delete the old one */ + $this->_delOldRecords($type, 4); + } + function monitorServer() { global $app; global $conf;