tbrehm
2010-06-30 446416560bbb68f2010b19748ff1a3388aa4a06c
Implemented: FS#1025 - Harddisk Quota Usage
3 files modified
4 files added
269 ■■■■■ changed files
interface/web/sites/lib/lang/en_user_quota_stats_list.lng 8 ●●●●● patch | view | raw | blame | history
interface/web/sites/lib/module.conf.php 5 ●●●●● patch | view | raw | blame | history
interface/web/sites/list/user_quota_stats.list.php 70 ●●●●● patch | view | raw | blame | history
interface/web/sites/templates/user_quota_stats_list.htm 51 ●●●●● patch | view | raw | blame | history
interface/web/sites/user_quota_stats.php 55 ●●●●● patch | view | raw | blame | history
interface/web/sites/web_sites_stats.php 2 ●●●●● patch | view | raw | blame | history
server/mods-available/monitor_core_module.inc.php 78 ●●●●● patch | view | raw | blame | history
interface/web/sites/lib/lang/en_user_quota_stats_list.lng
New file
@@ -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';
?>
interface/web/sites/lib/module.conf.php
@@ -124,6 +124,11 @@
        '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,
interface/web/sites/list/user_quota_stats.list.php
New file
@@ -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'        => "");
?>
interface/web/sites/templates/user_quota_stats_list.htm
New file
@@ -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">&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_system_user"><input type="text" name="search_system_user" value="{tmpl_var name='search_system_user'}" /></td>
            <td class="tbl_col_system_user">&nbsp;</td>
            <td class="tbl_col_system_user">&nbsp;</td>
            <td class="tbl_col_system_user">&nbsp;</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">
                &nbsp;
              </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>
interface/web/sites/user_quota_stats.php
New file
@@ -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();
?>
interface/web/sites/web_sites_stats.php
@@ -58,6 +58,8 @@
}
$list = new list_action;
$list->SQLExtWhere = "type = 'vhost'";
$list->onLoad();
server/mods-available/monitor_core_module.inc.php
@@ -195,6 +195,7 @@
    // 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 @@
        $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;