Skip to content

Commit 4464165

Browse files
committed
Implemented: FS#1025 - Harddisk Quota Usage
1 parent 0f7d3e2 commit 4464165

File tree

7 files changed

+269
-0
lines changed

7 files changed

+269
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
$wb["list_head_txt"] = 'Website harddisk quota';
3+
$wb["domain_txt"] = 'Domain / Website';
4+
$wb["system_user_txt"] = 'Linux user';
5+
$wb["used_txt"] = 'Used space';
6+
$wb["hard_txt"] = 'Hard limit';
7+
$wb["soft_txt"] = 'Soft limit';
8+
?>

interface/web/sites/lib/module.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
'link' => 'sites/web_sites_stats.php',
125125
'html_id' => 'websites_stats');
126126

127+
$items[] = array( 'title' => 'Website quota (Harddisk)',
128+
'target' => 'content',
129+
'link' => 'sites/user_quota_stats.php',
130+
'html_id' => 'user_quota_stats');
131+
127132

128133
$module['nav'][] = array( 'title' => 'Statistics',
129134
'open' => 1,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/*
4+
Datatypes:
5+
- INTEGER
6+
- DOUBLE
7+
- CURRENCY
8+
- VARCHAR
9+
- TEXT
10+
- DATE
11+
*/
12+
13+
14+
15+
// Name of the list
16+
$liste["name"] = "user_quota_stats";
17+
18+
// Database table
19+
$liste["table"] = "web_domain";
20+
21+
// Index index field of the database table
22+
$liste["table_idx"] = "domain_id";
23+
24+
// Search Field Prefix
25+
$liste["search_prefix"] = "search_";
26+
27+
// Records per page
28+
$liste["records_per_page"] = 15;
29+
30+
// Script File of the list
31+
$liste["file"] = "user_quota_stats.php";
32+
33+
// Script file of the edit form
34+
$liste["edit_file"] = "web_domain_edit.php";
35+
36+
// Script File of the delete script
37+
$liste["delete_file"] = "web_domain_del.php";
38+
39+
// Paging Template
40+
$liste["paging_tpl"] = "templates/paging.tpl.htm";
41+
42+
// Enable auth
43+
$liste["auth"] = "yes";
44+
45+
46+
/*****************************************************
47+
* Suchfelder
48+
*****************************************************/
49+
50+
$liste["item"][] = array( 'field' => "domain",
51+
'datatype' => "VARCHAR",
52+
'formtype' => "TEXT",
53+
'op' => "like",
54+
'prefix' => "%",
55+
'suffix' => "%",
56+
'width' => "",
57+
'value' => "");
58+
59+
$liste["item"][] = array( 'field' => "system_user",
60+
'datatype' => "VARCHAR",
61+
'formtype' => "TEXT",
62+
'op' => "like",
63+
'prefix' => "%",
64+
'suffix' => "%",
65+
'width' => "",
66+
'value' => "");
67+
68+
69+
70+
?>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<h2><tmpl_var name="list_head_txt"></h2>
2+
3+
<div class="panel panel_list_user_quota_stats">
4+
5+
<div class="pnl_listarea">
6+
<fieldset><legend><tmpl_var name="list_head_txt"></legend>
7+
<table class="list">
8+
<thead>
9+
<tr>
10+
<th class="tbl_col_domain" scope="col"><tmpl_var name="domain_txt"></th>
11+
<th class="tbl_col_system_user" scope="col"><tmpl_var name="system_user_txt"></th>
12+
<th class="tbl_col_system_user" scope="col"><tmpl_var name="used_txt"></th>
13+
<th class="tbl_col_system_user" scope="col"><tmpl_var name="soft_txt"></th>
14+
<th class="tbl_col_system_user" scope="col"><tmpl_var name="hard_txt"></th>
15+
<th class="tbl_col_buttons" scope="col">&nbsp;</th>
16+
</tr>
17+
<tr>
18+
<td class="tbl_col_domain"><input type="text" name="search_domain" value="{tmpl_var name='search_domain'}" /></td>
19+
<td class="tbl_col_system_user"><input type="text" name="search_system_user" value="{tmpl_var name='search_system_user'}" /></td>
20+
<td class="tbl_col_system_user">&nbsp;</td>
21+
<td class="tbl_col_system_user">&nbsp;</td>
22+
<td class="tbl_col_system_user">&nbsp;</td>
23+
<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>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
<tmpl_loop name="records">
28+
<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
29+
<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>
30+
<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>
31+
<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>
32+
<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>
33+
<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>
34+
<td class="tbl_col_buttons">
35+
<div class="buttons icons16">
36+
&nbsp;
37+
</div>
38+
</td>
39+
</tr>
40+
</tmpl_loop>
41+
</tbody>
42+
<tfoot>
43+
<tr>
44+
<td class="tbl_footer tbl_paging" colspan="6"><tmpl_var name="paging"></td>
45+
</tr>
46+
</tfoot>
47+
</table>
48+
</fieldset>
49+
</div>
50+
51+
</div>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
require_once('../../lib/config.inc.php');
3+
require_once('../../lib/app.inc.php');
4+
5+
/******************************************
6+
* Begin Form configuration
7+
******************************************/
8+
9+
$list_def_file = "list/user_quota_stats.list.php";
10+
11+
/******************************************
12+
* End Form configuration
13+
******************************************/
14+
15+
//* Check permissions for module
16+
$app->auth->check_module_permissions('sites');
17+
18+
$app->load('listform_actions');
19+
20+
$tmp_rec = $app->db->queryOneRecord("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC");
21+
$monitor_data = unserialize($app->db->unquote($tmp_rec['data']));
22+
23+
class list_action extends listform_actions {
24+
25+
function prepareDataRow($rec)
26+
{
27+
global $app,$monitor_data;
28+
29+
$rec = $app->listform->decode($rec);
30+
31+
//* Alternating datarow colors
32+
$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
33+
$rec['bgcolor'] = $this->DataRowColor;
34+
$username = $rec['system_user'];
35+
36+
$rec['used'] = $monitor_data['user'][$username]['used'];
37+
$rec['soft'] = $monitor_data['user'][$username]['soft'];
38+
$rec['hard'] = $monitor_data['user'][$username]['hard'];
39+
40+
if($rec['soft'] == '0K') $rec['soft'] = $app->lng('unlimited');
41+
if($rec['hard'] == '0K') $rec['hard'] = $app->lng('unlimited');
42+
43+
//* The variable "id" contains always the index variable
44+
$rec['id'] = $rec[$this->idx_key];
45+
return $rec;
46+
}
47+
}
48+
49+
$list = new list_action;
50+
$list->SQLExtWhere = "type = 'vhost'";
51+
52+
$list->onLoad();
53+
54+
55+
?>

interface/web/sites/web_sites_stats.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ function prepareDataRow($rec)
5858
}
5959

6060
$list = new list_action;
61+
$list->SQLExtWhere = "type = 'vhost'";
62+
6163
$list->onLoad();
6264

6365

server/mods-available/monitor_core_module.inc.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ function get_distname() {
195195
// TODO: what monitoring is done should be a config-var
196196
function doMonitor() {
197197
/* Calls the single Monitoring steps */
198+
$this->monitorHDQuota();
198199
$this->monitorServer();
199200
$this->monitorOSVer();
200201
$this->monitorIspCVer();
@@ -219,7 +220,84 @@ function doMonitor() {
219220
$this->monitorFail2ban();
220221
$this->monitorSysLog();
221222
}
223+
224+
function monitorHDQuota() {
225+
global $app;
226+
global $conf;
227+
228+
/* Initialize data array */
229+
$data = array();
230+
231+
/* the id of the server as int */
232+
$server_id = intval($conf["server_id"]);
233+
234+
/** The type of the data */
235+
$type = 'harddisk_quota';
236+
237+
/** The state of the harddisk_quota. */
238+
$state = 'ok';
239+
240+
/** Fetch the data for all users*/
241+
$dfData = shell_exec("repquota -asu");
242+
243+
// split into array
244+
$df = explode("\n", $dfData);
245+
246+
/*
247+
* ignore the first 5 lines, process the rest
248+
*/
249+
for($i=5; $i <= sizeof($df); $i++) {
250+
if ($df[$i] != '') {
251+
/*
252+
* Make a array of the data
253+
*/
254+
$s = preg_split ("/[\s]+/", $df[$i]);
255+
$username = $s[0];
256+
$data['user'][$username]['used'] = $s[2];
257+
$data['user'][$username]['soft'] = $s[3];
258+
$data['user'][$username]['hard'] = $s[4];
259+
}
260+
}
261+
262+
/** Fetch the data for all users*/
263+
$dfData = shell_exec("repquota -asg");
264+
265+
// split into array
266+
$df = explode("\n", $dfData);
222267

268+
/*
269+
* ignore the first 5 lines, process the rest
270+
*/
271+
for($i=5; $i <= sizeof($df); $i++) {
272+
if ($df[$i] != '') {
273+
/*
274+
* Make a array of the data
275+
*/
276+
$s = preg_split ("/[\s]+/", $df[$i]);
277+
$groupname = $s[0];
278+
$data['group'][$groupname]['used'] = $s[1];
279+
$data['group'][$groupname]['soft'] = $s[2];
280+
$data['group'][$groupname]['hard'] = $s[3];
281+
}
282+
}
283+
284+
/*
285+
Insert the data into the database
286+
*/
287+
$sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " .
288+
"VALUES (".
289+
$server_id . ", " .
290+
"'" . $app->dbmaster->quote($type) . "', " .
291+
time() . ", " .
292+
"'" . $app->dbmaster->quote(serialize($data)) . "', " .
293+
"'" . $state . "'" .
294+
")";
295+
$app->dbmaster->query($sql);
296+
297+
/* The new data is written, now we can delete the old one */
298+
$this->_delOldRecords($type, 4);
299+
}
300+
223301
function monitorServer() {
224302
global $app;
225303
global $conf;

0 commit comments

Comments
 (0)