forked from robhost/UPDIAN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
328 lines (232 loc) · 9.74 KB
/
index.php
File metadata and controls
328 lines (232 loc) · 9.74 KB
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
<?php
/*
UPDIAN - UpdateDebian v0.4
Minimalistic Debian Package Upgrade Tool with Web-Frontend by Robert Klikics, RobHost GmbH [rk@robhost.de], 2007-2012
License: GPL
Web: http://robhost.de/updian
File: index.php - web frontend
Usage: open firefox/chrome/safari/lynx/whatever and call http://yourdomain/updian/ ;-)
*/
// no-cache header
header("Expires: -1");
header("Cache-Control: post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
?>
<html>
<head>
<title>Updian</title>
<script language="JavaScript">
function ask(url, txt) {
if( confirm(txt) ) window.location = url;
}
function doIt() {
if( confirm('This runs the given command on ALL your machines!\nAre you sure?') ) document.f1.submit();
}
</script>
<style>
body, td { font: 12px verdana, arial; }
h1 { font: 24px verdana, arial; }
A:link {text-decoration: none; color: dodgerblue}
A:visited {text-decoration: none; color: dodgerblue}
A:active {color: dodgerblue}
A:hover {text-decoration: underline; color: dodgerblue}
.whiteTR {background: #fff;}
.greyTR {background: #cecece;}
</style>
<meta http-equiv="pragma" content="no-cache">
<body>
<h1>Updian - UpdateDebian v0.4</h1>
<h4>by <a href="http://www.robhost.de/updian/">RobHost GmbH</a>, 2007-<?=date(Y)?></h4>
hr>
<a href="index.php">Home</a> - <a href="index.php?act=queue">Queue</a> - <a href='index.php?act=servers'>Servers</a> - <a href='index.php?act=logs'>Logs</a> - <a href="index.php?act=ssh">Multi-SSH</a>
<hr>
<?php
include 'config.php';
// multi-ssh
if($_REQUEST[act] == "ssh") {
echo "<h2>Multi-SSH</h1>";
if( file_exists($data_dir."multissh.txt") ) {
echo "multissh.txt exists, please run cron_updates.php or wait till the next cron-run..";
echo "<br><br>Pending command:<br><i>";
readfile($data_dir."multissh.txt");
exit;
}
if( isset($_POST[run]) ) {
if(empty($_POST[cmd])) die("No cmd given ..");
$res = escapeshellcmd($_POST['cmd']);
// write statusfile in $data_dir
$fp = fopen($data_dir."multissh.txt", "w");
fwrite($fp, $res, strlen($res));
fclose($fp);
echo "Saved! Now please run cron_updates.php as root or wait till the next cron-run.<br>The output will be logged (see <i>Logs</i>).<br><br>The command was:<br><br><i>$res</i><br><br>";
die("<br><br></body></html>");
}
echo "With <i>Multi-SSH</i> you can run any shell-command <b>once</b> on <b>all</b> your machines!";
echo "<br><br>";
echo "<form action='index.php' method='post' name='f1'>\n";
echo "<input type='hidden' name='act' value='ssh'>\n";
echo "<input type='hidden' name='run' value='1'>\n";
echo "The command:<br><input type='text' name='cmd' size='50'>\n";
echo "<input type='button' value='run command' onClick='javascript:doIt()'>";
die("<br><br></body></html>");
}
// show|edit server-list
if($_REQUEST[act] == "servers") {
if( isset($_POST[save]) ) {
// save new $cfg_file
$fp = fopen($cfg_file, "w") or die("Could not open $cfg_file for writing ...");
$postdata = trim($_POST[txt]) . "\n";
@fwrite($fp, $postdata, strlen($postdata));
@fclose($fp);
}
#$cmd = "cat $cfg_file";
#$srv = `$cmd`;
#$row = count( file($cfg_file) ); // calculate rows for textarea
$file = file($cfg_file);
$row = count($file) + 2;
$srvs = '';
sort($file);
foreach($file as $srv) {
if( trim($srv) == "") {
continue;
}
$srvs.= $srv;
}
$srvs.= "\n";
echo "<h3>View/Edit <i>$cfg_file</i>:</h3>(one host per line, optional :portnumber after hostname if SSH not on 22)<br><br>";
echo "<form action='index.php' method='post'>\n";
echo "<input type='hidden' name='act' value='servers'>\n";
echo "<input type='hidden' name='save' value='1'>\n";
echo "<textarea style='border:1px solid black;padding:5px;' name='txt' rows='$row' cols='50'>$srvs</textarea>\n";
echo "<br><br><input type='submit' value='Save to $cfg_file'>\n";
echo "</form>\n";
die("<br><br></body></html>");
}
// add to queue
if($_GET[act] == "add") {
if( $_GET[all_servers] == 1 ) {
// add ALL
$dir = opendir($data_dir);
while (false !== ($file = readdir($dir))) {
if ($file == "." || $file == "..") continue;
if($file == "statfile") continue;
if($file == "statfile_upd") continue;
if(!file_exists($todo_dir.$file)) touch($todo_dir.$file);
}
} else {
touch($todo_dir.$_GET[srv].".txt"); // add unique server
}
}
// view logs
if($_GET[act] == "logs") {
if( isset($_GET[del]) ) {
// del all?
if($_GET[del] == "all") {
$dir = opendir($log_path);
while (false !== ($file = readdir($dir))) {
if ($file == "." || $file == "..") continue;
@unlink($log_path.$file);
}
} else {
// del unique logfile
@unlink($log_path.$_GET[del]);
}
}
$dir = opendir($log_path);
$cnt = 0;
$logs = array();
echo "<h3>Logfiles</h3>";
echo "<table width='600' cellspacing='0' cellpadding='2'>\n";
while (false !== ($file = readdir($dir))) {
if ($file == "." || $file == "..") continue;
$logs[] = $file;
$cnt++;
}
sort($logs);
foreach($logs as $files) {
if(preg_match("/checkrestart/", $files))
$col = "yellow";
else
$col = "";
echo "<tr onmouseover=\"this.className='greyTR';\" onmouseout=\"this.className='whiteTR';\"><td><a href='".$log_path_rel.$files."'><span style='background:$col'>$files</a> </td><td>".date("M d, H:i", filemtime($log_path.$files))."</td><td align='right'><a href='javascript:ask(\"index.php?act=logs&del=$files\", \"Delete $files?\")'>delete</a></td></tr>\n";
}
echo "</table>";
if(!$cnt) echo "Logdir is empty ...";
if($cnt) echo "<br><br><a href='javascript:ask(\"index.php?act=logs&del=all\",\"Really?\")'>Delete ALL logs</a>";
die("<br/><br/></body></html>");
}
// show queue
if($_GET[act] == "queue") {
// are we going to del a server from the queue?
if( isset($_GET[del]) ) {
@unlink($todo_dir.$_GET[del].".txt");
}
// show servers in $todo_dir
echo "UpdateCronjob last runtime: ".date ("F d Y H:i.", @filemtime($data_dir."statfile_upd"));
echo "<br>";
echo "<h3>Servers in queue - will be updated on next cron-run</h3>";
echo "<table width='600' cellspacing='0' cellpadding='2'>\n";
$dir = opendir($todo_dir);
$cnt = 0;
$que = array();
while (false !== ($file = readdir($dir))) {
if ($file == "." || $file == "..") continue;
$file = preg_replace("/\.txt$/", "", $file);
$que[] = "<tr onmouseover=\"this.className='greyTR';\" onmouseout=\"this.className='whiteTR';\"><td>" . $file."</td><td>queued: ".date("M d, H:i", filemtime($todo_dir.$file.".txt"))."</td><td align='right'><a href='javascript:ask(\"index.php?act=queue&del=$file\", \"Delete $file from queue?\")'>delete</a></td></tr>";
$cnt++;
}
sort($que);
foreach($que as $que_entry) {
echo $que_entry;
}
echo "</table>";
if(!$cnt) echo "Currently no servers in queue ...";
die("</body></html>");
}
// print info on index page
echo "Data collected on: ".date ("F d Y H:i.",@filemtime($data_dir."statfile"))."<br>";
echo "<h3>Updates available:</h3>";
$dir = opendir($data_dir);
$mcnt = 0;
$_html = array();
$_tmp_html = '';
echo "<table width='600' cellspacing='0' cellpadding='2'>\n";
// get info for all servers from datadir
while (false !== ($file = readdir($dir))) {
if ($file == "." || $file == "..") continue;
if($file == "statfile") continue;
if($file == "statfile_upd") continue;
if($file == "multissh.txt") continue;
$cnt = count( file($data_dir.$file) );
$file = preg_replace("/\.txt$/", "", $file);
$_tmp_html = "\n<tr onmouseover=\"this.className='greyTR';\" onmouseout=\"this.className='whiteTR';\"><td>$file</td><td align='center'><a href='index.php?act=show&srv=$file#updates' title='show packages'>$cnt updates</a></td><td align='right'>";
if(!file_exists($todo_dir.$file.".txt")) $_tmp_html.= "<a href='javascript:ask(\"index.php?act=add&srv=$file\", \"Install updates for $file when install-cronjob runs next time?\")'>add to queue</a>";
else $_tmp_html.= "queued";
$_tmp_html.= '</td></tr>';
$_html[] = $_tmp_html;
$mcnt++;
}
sort($_html);
foreach($_html as $line) {
echo $line;
}
echo "</table>";
if($cnt) echo "<br><br><li><a href='javascript:ask(\"index.php?act=add&all_servers=1\",\"Add all updates on all $mcnt servers to the queue?\")'>Add all $mcnt servers to install-queue</a>";
if(!$cnt) echo "Currently no pending updates ...";
echo "<br><a name='updates'></a>";
// show off updates
if($_GET[act] == "show") {
$toshow = $data_dir.$_GET[srv].".txt";
$content = `cat $toshow`;
echo "<h3>Updates for $_GET[srv]";
if(!file_exists($todo_dir.$_GET[srv].".txt")) echo " [ <a href='javascript:ask(\"index.php?act=add&srv=$_GET[srv]\", \"Install updates for $_GET[srv] when install-cronjob runs next time?\")'>add to install-queue</a> ]</h3>";
else echo "</h3>";
$content = preg_replace("/Inst |base|updates/", "", $content);
echo nl2br($content);
echo "<br><br><li><a href='javascript:scroll(0,0)'>top</a><br><br>";
}
clearstatcache();
?>
</body>
</html>