-
Notifications
You must be signed in to change notification settings - Fork 12
/
automount.restart.php
146 lines (107 loc) · 3.33 KB
/
automount.restart.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
<?php
header("Pragma: no-cache");
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
include_once(dirname(__FILE__) . '/ressources/class.main_cf.inc');
include_once(dirname(__FILE__) . '/ressources/class.ldap.inc');
include_once(dirname(__FILE__) . "/ressources/class.sockets.inc");
include_once(dirname(__FILE__) . "/ressources/class.os.system.inc");
$user=new usersMenus();
if(($user->AsSystemAdministrator==false) OR ($user->AsSambaAdministrator==false)) {
$tpl=new templates();
echo $tpl->_ENGINE_parse_body("alert('{ERROR_NO_PRIVS}');");
die();exit();
}
if(isset($_GET["popup"])){popup();exit;}
if(isset($_GET["logs"])){echo showlogs();exit;}
js();
function js(){
$page=CurrentPageName();
$prefix=str_replace('.','_',$page);
$tpl=new templates();
$title=$tpl->_ENGINE_parse_body('{restart_autofs}');
$html="
var {$prefix}timeout=0;
var {$prefix}timerID = null;
var {$prefix}tant=0;
var {$prefix}reste=0;
function {$prefix}LoadPage(){
RTMMail(550,'$page?popup=yes','$title');
{$prefix}ChargeTimeout();
}
function {$prefix}demarre(){
if(!RTMMailOpen()){return false;}
{$prefix}tant = {$prefix}tant+1;
if ({$prefix}tant <10 ) {
{$prefix}timerID = setTimeout(\"{$prefix}demarre()\",1000);
} else {
if(!RTMMailOpen()){return false;}
{$prefix}tant = 0;
{$prefix}ChargeLogs();
{$prefix}demarre();
}
}
var x_{$prefix}ChargeLogs=function (obj) {
text=obj.responseText;
document.getElementById('AutofsDiv159').innerHTML=text;
}
function {$prefix}ChargeLogs(){
var currentTime = new Date()
var XHR = new XHRConnection();
XHR.appendData('logs','yes');
XHR.appendData('s',currentTime.getTime());
XHR.sendAndLoad('$page', 'GET',x_{$prefix}ChargeLogs);
}
function {$prefix}ChargeTimeout(){
{$prefix}timeout={$prefix}timeout+1;
if({$prefix}timeout>20){
alert('time-out $page');
return false;
}
if(!document.getElementById('AutofsDiv159')){
setTimeout(\"{$prefix}ChargeTimeout()\",900);
return false;
}
{$prefix}timeout=0;
{$prefix}ChargeLogs();
{$prefix}demarre();
}
{$prefix}LoadPage();
";
echo $html;
}
function popup(){
$sock=new sockets();
$sock->getfile('ServiceAutofsRestart');
$logs=showlogs();
$html="<H1>{restart_autofs}</H1>
<table style='width:100%'>
<tr>
<td valign='top' width=1%><img src='img/service-restart-64.png'></td>
<td valign='top'><p class=caption>{restart_autofs_text}</p>
". RoundedLightWhite("<div style='width:100%;height:150px;overflow:auto' id='AutofsDiv159'>$logs</div>")."<td>
</tr>
</table>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function showlogs(){
$tpl=new templates();
if(!is_file('ressources/logs/autofs.restart.log')){
return $tpl->_ENGINE_parse_body('{scheduled}: {please_wait} (nofile)');
}
$text=file_get_contents('ressources/logs/autofs.restart.log');
$datas=explode("\n",$text);
if(!is_array($datas)){
return $tpl->_ENGINE_parse_body('{scheduled}: {please_wait} (noarray)');
}
$ct=0;
while (list($num,$val)=each($datas)){
if(trim($val)==null){continue;}
$ct=$ct+1;
$html=$html . "<div><code>" .htmlspecialchars($val)."</code></div>\n";
}
return $tpl->_ENGINE_parse_body($html);
}
?>