forked from dtouzeau/artica-1.5
/
greyhole.php
368 lines (281 loc) · 9.59 KB
/
greyhole.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
if(isset($_GET["verbose"])){$GLOBALS["VERBOSE"]=true;ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',null);ini_set('error_append_string',null);}
include_once(dirname(__FILE__).'/ressources/class.templates.inc');
include_once(dirname(__FILE__).'/ressources/class.tcpip.inc');
include_once(dirname(__FILE__).'/ressources/class.system.network.inc');
include_once(dirname(__FILE__).'/ressources/class.computers.inc');
include_once(dirname(__FILE__).'/ressources/class.autofs.inc');
include_once(dirname(__FILE__).'/ressources/class.samba.inc');
if(posix_getuid()<>0){
$users=new usersMenus();
if((!$users->AsSambaAdministrator) OR (!$users->AsSystemAdministrator)){
$tpl=new templates();
$error=$tpl->_ENGINE_parse_body("{ERROR_NO_PRIVS}");
echo "alert('$error')";
die();
}
}
if(isset($_GET["tabs"])){tabs();exit;}
if(isset($_GET["status"])){status();exit;}
if(isset($_GET["greyhole-status"])){status_service();exit;}
if(isset($_GET["pools"])){pools();exit;}
if(isset($_GET["pools-list"])){pools_list();exit;}
if(isset($_GET["greyhole-pools"])){pools_add();exit;}
if(isset($_GET["logs"])){mounts_events();exit;}
if(isset($_GET["syslog-table"])){mounts_events_query();exit;}
if(isset($_GET["EnableGreyHoleDebug"])){EnableGreyHoleDebugSave();exit;}
js();
function js(){
$page=CurrentPageName();
$html="
function GreyHoleConfigLoad(){
$('#BodyContent').load('$page?tabs=yes');
}
GreyHoleConfigLoad();
";
echo $html;
}
function status_service(){
$sock=new sockets();
$tpl=new templates();
$ini=new Bs_IniHandler();
$page=CurrentPageName();
$ini->loadString(base64_decode($sock->getFrameWork("cmd.php?greyhole-ini-status=yes")));
$status=DAEMON_STATUS_ROUND("APP_GREYHOLE",$ini,null,0);
echo $tpl->_ENGINE_parse_body($status);
}
function tabs(){
$page=CurrentPageName();
$tpl=new templates();
$array["status"]='{status}';
$array["pools"]='{storage_pool}';
$array["shared_folders"]='{shared_folders}';
$array["logs"]='{events}';
while (list ($num, $ligne) = each ($array) ){
if($num=="shared_folders"){
$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"samba.index.php?SharedFoldersList=yes\"><span>$ligne</span></a></li>\n");
continue;
}
$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"$page?$num=yes\"><span>$ligne</span></a></li>\n");
}
echo "
<div id=main_config_greyhole style='width:100%;height:750px;overflow:auto'>
<ul>". implode("\n",$html)."</ul>
</div>
<script>
$(document).ready(function() {
$(\"#main_config_greyhole\").tabs();});
</script>";
}
function pools(){
$page=CurrentPageName();
$tpl=new templates();
$autofs=new autofs();
$hash=$autofs->automounts_Browse();
while (list ($foldername, $ligne) = each ($hash) ){
$array[$ligne["DN"]]="$foldername ({$ligne["SRC"]})";
}
$array[null]="{select}";
$html="
<table style='width:100%' class=form>
<tr>
<td class=legend style='font-size:14px' WIDTH=1% nowrap>{add_storage}:</td>
<td>". Field_array_Hash($array,"pool_to_add",null,"style:font-size:14px;padding:3px")."</td>
<td class=legend style='font-size:14px' width=1%> </td>
</tr>
<tr>
<td class=legend style='font-size:14px' WIDTH=1% nowrap>{maxsize} (Gb):</td>
<td>". Field_text("free_g",2,"font-size:14px;padding:3px;width:60px")."</td>
<td class=legend style='font-size:14px' width=1%>". button("{add}","AddGreholePool()")."</td>
<tr>
<td colspan=3 align='right'><a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('autofs.php');\" style='font-size:13px;text-decoration:underline'><i>{add_mount_point_text}</i></a></td>
</table>
<hr>
<div id='greyhole-pools' style='height:225px'></div>
<script>
var x_AddGreholePool= function (obj) {
var results=obj.responseText;
if(results.length>0){alert(results);return;}
RefreshTab('main_config_greyhole');
}
function AddGreholePool(){
var XHR = new XHRConnection();
var p=document.getElementById('pool_to_add').value;
if(p.length<5){return;}
XHR.appendData('greyhole-pools',document.getElementById('pool_to_add').value);
XHR.appendData('free_g',document.getElementById('free_g').value);
//document.getElementById('greyhole-pools').innerHTML='<center><img src=\"img/wait_verybig.gif\"></center>';
XHR.sendAndLoad('$page', 'GET',x_AddGreholePool);
}
function RefreshPool(){
LoadAjax('greyhole-pools','$page?pools-list=yes');
}
RefreshPool();
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
function pools_add(){
$q=new mysql();
$sql="INSERT IGNORE INTO greyhole_spools (dn,free_g) VALUES('{$_GET["greyhole-pools"]}','{$_GET["free_g"]}');";
$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){echo $q->mysql_error;return;}
}
function pools_list(){
$page=CurrentPageName();
$tpl=new templates();
$autofs=new autofs();
$hash=$autofs->automounts_Browse();
$q=new mysql();
$sql="SELECT * FROM greyhole_spools ORDER BY free_g DESC";
$results=$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){
echo $q->mysql_error;
return null;
}
$html="
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>
<thead class='thead'>
<tr>
<th> </th>
<th>{type}</th>
<th>{local_directory_name}</th>
<th>{source}</th>
<th>{size}</th>
<th> </th>
</tr>
</thead>
<tbody class='tbody'>";
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
$dn=$ligne["dn"];
if($GLOBALS["VERBOSE"]){echo "$dn\n";}
$array=$autofs->hash_by_dn[$dn];
$FOLDER=$array["FOLDER"];
$FS=$array["INFOS"]["FS"];
$SRC=$array["INFOS"]["SRC"];
if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
$color="black";
$delete=imgtootltip("delete-32.png","{delete}","AutoFSUSB('$UUID')");
$html=$html . "
<tr class=$classtr>
<td width=1%><img src='img/usb-32-green.png'></td>
<td width=1% align='center' nowrap><strong style='font-size:14px'><code style='color:$color'>$FS</code></td>
<td width=1% align='left'><strong style='font-size:14px'>$FOLDER</strong></td>
<td width=99% align='left' nowrap><strong style='font-size:14px'>$SRC</strong></td>
<td width=1% align='left'><strong style='font-size:14px'>{$ligne["free_g"]}Gb</strong></td>
<td width=1%>$delete</td>
</tr>";
}
$html=$html."</tbody></table>
<script>
var x_AutoFSUSB= function (obj) {
var tempvalue=obj.responseText;
if(tempvalue.length>0){alert(tempvalue);return;}
YahooWin4Hide();
RefreshTab('main_config_autofs');
}
function AutoFSUSB(key){
var XHR = new XHRConnection();
XHR.appendData('USB_UUID',key);
var localdir=document.getElementById('USB_LOCAL_DIR').value;
if(localdir.length==0){alert('LOCAL DIR !');return;}
XHR.appendData('USB_LOCAL_DIR',document.getElementById('USB_LOCAL_DIR').value);
XHR.sendAndLoad('$page', 'GET',x_AutoFSUSB);
}
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
function status(){
$page=CurrentPageName();
$tpl=new templates();
$sock=new sockets();
$html="
<table style='width:100%'>
<tr>
<td valign='top'>
<div id='greyhole-status'></div>
</td>
<td valign='top' width=99%'>
<div class=explain>{APP_GREYHOLE_TEXT}</div>
</tr>
</table>
<script>
LoadAjax('greyhole-status','$page?greyhole-status=yes');
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
function EnableGreyHoleDebugSave(){
$sock=new sockets();
$sock->SET_INFO("EnableGreyHoleDebug",$_GET["EnableGreyHoleDebug"]);
$sock->getFrameWork("cmd.php?greyhole-restart=yes");
}
function mounts_events(){
$page=CurrentPageName();
$sock=new sockets();
$EnableGreyHoleDebug=$sock->GET_INFO("EnableGreyHoleDebug");
if(!is_numeric($EnableGreyHoleDebug)){$EnableGreyHoleDebug=0;}
$html="
<table style='width:100%' class=form>
<tr>
<td class=legend>{debug}:</td>
<td width=1%>". Field_checkbox("EnableGreyHoleDebug",1,$EnableGreyHoleDebug,"EnableGreyHoleDebugSave()")."</td>
</tr>
</table>
<table style='width:100%'>
<tr>
<td class=legend valign='middle'>{search}:</td>
<td>". Field_text("syslog-search",null,"font-size:13px;padding:3px;",null,null,null,false,"SyslogSearchPress(event)")."</td>
<td align='right' width=1%>". imgtootltip("32-refresh.png","{refresh}","SyslogRefresh()")."</td>
</tr>
</table>
<div style='widht:99%;height:600px;overflow:auto;margin:5px' id='syslog-table'></div>
<script>
var x_EnableGreyHoleDebugSave= function (obj) {
var tempvalue=obj.responseText;
if(tempvalue.length>0){alert(tempvalue);return;}
}
function EnableGreyHoleDebugSave(){
var XHR = new XHRConnection();
if(document.getElementById('EnableGreyHoleDebug').checked){
XHR.appendData('EnableGreyHoleDebug',1);
}else{
XHR.appendData('EnableGreyHoleDebug',0);
}
XHR.sendAndLoad('$page', 'GET',x_EnableGreyHoleDebugSave);
}
function SyslogSearchPress(e){
if(checkEnter(e)){SearchSyslog();}
}
function SearchSyslog(){
var pat=escape(document.getElementById('syslog-search').value);
LoadAjax('syslog-table','$page?syslog-table=yes&search='+pat);
}
function SyslogRefresh(){
SearchSyslog();
}
SearchSyslog();
</script>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function mounts_events_query(){
$pattern=base64_encode($_GET["search"]);
$sock=new sockets();
$array=unserialize(base64_decode($sock->getFrameWork("cmd.php?syslog-query=$pattern&syslog-path=/var/log/greyhole.log")));
if(!is_array($array)){return null;}
$html="<table class=TableView>";
while (list ($key, $line) = each ($array) ){
if($line==null){continue;}
if($tr=="class=oddrow"){$tr=null;}else{$tr="class=oddrow";}
$html=$html."
<tr $tr>
<td><code>$line</cod>
</tr>
";
}
$html=$html."</table>";
echo $html;
}