-
Notifications
You must be signed in to change notification settings - Fork 11
/
amada.clients.php
305 lines (253 loc) · 9.63 KB
/
amada.clients.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
<?php
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.system.network.inc');
include_once('ressources/class.mysql.inc');
$user=new usersMenus();
if($user->AsSystemAdministrator==false){
$tpl=new templates();
echo "alert('". $tpl->javascript_parse_text("{ERROR_NO_PRIVS}")."');";
die();exit();
}
if(isset($_GET["browse-amanda-list"])){clients_list();exit();}
if(isset($_GET["id-js"])){client_js();exit();}
if(isset($_GET["id-popup"])){client_popup();exit;}
if(isset($_POST["ID"])){client_save();exit;}
if(isset($_POST["delete-id"])){client_delete();exit;}
page();
function client_js(){
$page=CurrentPageName();
$tpl=new templates();
$title="{computer}:{add}";
if($_GET["id-js"]>0){
$q=new mysql();
$sql="SELECT hostname FROM amanda_hosts WHERE ID='{$_GET["id-js"]}'";
$ligne=@mysql_fetch_array($q->QUERY_SQL($sql,'artica_backup'));
$title="{$ligne["hostname"]}";
}
$title=$tpl->_ENGINE_parse_body($title);
$html="YahooWin3('550','$page?id-popup={$_GET["id-js"]}','$title')";
echo $html;
}
function client_popup(){
$page=CurrentPageName();
$tpl=new templates();
$id=$_GET["id-popup"];
$button="{add}";
if(!is_numeric($id)){$id=0;}
$q=new mysql();
$sql="SELECT dumpname,comment FROM amanda_dumptype ORDER BY dumpname";
$results=$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){echo "<H2>$q->mysql_error</H2>";}
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
$dumps[$ligne["dumpname"]]=$ligne["comment"];
}
if($id>0){
$q=new mysql();
$sql="SELECT * FROM amanda_hosts WHERE ID='$id'";
$ligne=@mysql_fetch_array($q->QUERY_SQL($sql,'artica_backup'));
$button="{apply}";
}
$dumps["always-full"]="Full dump of this filesystem always";
$dumps["root-tar"]="root partitions dumped with tar";
$dumps["user-tar"]="user partitions dumped with tar";
$dumps["user-tar-span"]="tape-spanning user partitions dumped with tar";
$dumps["high-tar"]="partitions dumped with tar";
$dumps["comp-root-tar"]="Root partitions with compression";
$dumps["comp-user"]="Non-root partitions on reasonably fast machines";
$dumps["comp-user-span"]="Tape-spanning non-root partitions on reasonably fast machines";
$dumps["nocomp-user"]="Non-root partitions on slow machines";
$dumps["comp-root"]="Root partitions with compression";
$dumps["nocomp-root"]="Root partitions without compression";
$dumps["comp-high"]="very important partitions on fast machines";
$dumps["nocomp-high"]="very important partitions on slow machines";
while (list ($num, $ligne_s) = each ($dumps) ){
if($ligne["dumptype"]==$num){$val=1;}else{$val=0;}
$dumptd[]="
<tr>
<td class=legend style='font-size:11px'>$ligne_s</td>
<td>". Field_checkbox("f-$num",1,$val,"EnableDumpStrat('$num')")."</td>
</tr>
";
$dumptdjsoff[]="if(document.getElementById('f-$num')){document.getElementById('f-$num').checked=false;}";
}
if($ligne["dumptype"]==null){$ligne["dumptype"]="high-tar";}
$jsdef="EnableDumpStrat('{$ligne["dumptype"]}');";
$html="
<span id='formAmandaHostCheckID'></span>
<inpuyt type='hidden' id='x_dumptype' value='{$ligne["dumptype"]}'>
<table style='width:100%' class=form>
<tr>
<td class=legend>{hostname}:</td>
<td>". Field_text("x_hostname",$ligne["hostname"],"font-size:14px;padding:3px")."</td>
</tr>
<tr>
<td class=legend>{local_directory}:</td>
<td>". Field_text("x_directory",$ligne["directory"],"font-size:14px;padding:3px")."</td>
</tr>
<tr>
<td class=legend valign='top'>{Amandadumptypes}:</td>
<td><table>".@implode("\n", $dumptd)."</table></td>
</tr>
<tr>
<td colspan=2 align='right'>". button($button,"SaveCLientAmandaCOnf()")."</td>
</tr>
</table>
<script>
function EnableDumpStrat(dump){
".@implode("\n", $dumptdjsoff)."
if(document.getElementById('f-'+dump)){document.getElementById('f-'+dump).checked=true;}
document.getElementById('x_dumptype').value=dump;
}
var x_SaveCLientAmandaCOnf=function(obj){
var tempvalue=obj.responseText;
if(tempvalue.length>3){alert(tempvalue);document.getElementById('formAmandaHostCheckID').innerHTML='';return;}
YahooWin3Hide();
if(document.getElementById('browse-amanda-list')){BrowseAmandaSearch();}
}
function SaveCLientAmandaCOnf(){
var XHR = new XHRConnection();
XHR.appendData('dumptype',document.getElementById('x_dumptype').value);
XHR.appendData('directory',document.getElementById('x_directory').value);
XHR.appendData('hostname',document.getElementById('x_hostname').value);
XHR.appendData('ID','$id');
AnimateDiv('formAmandaHostCheckID');
XHR.sendAndLoad('$page', 'POST',x_SaveCLientAmandaCOnf);
}
$jsdef
</script>";
echo $tpl->_ENGINE_parse_body($html);
}
function client_save(){
$id=$_POST["ID"];
unset($_POST["ID"]);
while (list ($num, $ligne) = each ($_POST) ){
$field[]="`$num`";
$ligne=addslashes($ligne);
$vals[]="'$ligne'";
$upd[]="`$num`='$ligne'";
}
$sql_add="INSERT INTO amanda_hosts (".@implode(",", $field).") VALUES (".@implode(",", $vals).")";
$sql_update="UPDATE amanda_hosts SET " .@implode(",", $upd) ." WHERE ID='{$id}'";;
$sql=$sql_add;
if($id>0){$sql=$sql_update;}
$q=new mysql();
$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){echo $q->mysql_error."\n\n$sql\n";return;}
$sock=new sockets();
$sock->getFrameWork("amanda.php?save-client-config=yes");
}
function page(){
$page=CurrentPageName();
$tpl=new templates();
$sock=new sockets();
$add=Paragraphe("64-net-server-add.png", "{add_computer}", "{add_amanda_computer}","javascript:AmandaComputer(0)");
$html="
<div class=explain>{amanda_computers_explain}</div>
<center>
<table style='width:100%' class=form>
<tr>
<td class=legend>{clients}:</td>
<td>". Field_text("browse-amandac-search",null,"font-size:14px;padding:3px",null,null,null,false,"BrowseAmandaSearchCheck(event)")."</td>
<td>". button("{search}","BrowseSambaSearch()")."</td>
</tr>
</table>
</center>
<div id='browse-amanda-list' style='width:100%;height:450px;overflow:auto;text-align:center'></div>
<script>
function BrowseAmandaSearchCheck(e){
if(checkEnter(e)){BrowseAmandaSearch();}
}
function BrowseAmandaSearch(){
var se=escape(document.getElementById('browse-amandac-search').value);
LoadAjax('browse-amanda-list','$page?browse-amanda-list=yes&search='+se+'&field={$_GET["field"]}');
}
function AmandaComputer(ID){
Loadjs('$page?id-js='+ID);
}
BrowseAmandaSearch();
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
function clients_list(){
$page=CurrentPageName();
$tpl=new templates();
$ldap=new clladp();
$sock=new sockets();
$users=new usersMenus();
$search=$_GET["search"];
$search="*$search*";
$search=str_replace("***","*",$search);
$search=str_replace("**","*",$search);
$search_sql=str_replace("*","%",$search);
$search_sql=str_replace("%%","%",$search_sql);
$search_regex=str_replace(".","\.",$search);
$search_regex=str_replace("*",".*?",$search);
$delete_text=$tpl->javascript_parse_text("{delete}");
$add=imgtootltip("plus-24.png","{add}","AmandaComputer(0)");
$html="<center>
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>
<thead class='thead'>
<tr>
<th width=1%>$add</th>
<th colspan=5>{computers} | $search_regex | $search_sql</th>
</tr>
</thead>
<tbody class='tbody'>";
$q=new mysql();
$sql="SELECT * FROM amanda_hosts WHERE hostname LIKE '$search_sql' ORDER BY hostname";
writelogs("$sql",__FUNCTION__,__FILE__,__LINE__);
$results=$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){echo "<H2>$q->mysql_error</H2>";}
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
$img="computer-32.png";
$warn_text=null;
if($ligne["resolved"]==null){$img="warning-panneau-32.png";$warn_text="<hr>{could_not_find_iphost}";}
if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
$select=imgtootltip("32-parameters.png","{edit}$warn_text","AmandaComputer('{$ligne["ID"]}')");
$select2=imgtootltip($img,"{edit}$warn_text","AmandaComputer('{$ligne["ID"]}')");
$delete=imgtootltip("delete-32.png","{delete}","AmandaComputerDel('{$ligne["ID"]}')");
$color="black";
$href="<a href=\"javascript:blur();\" OnClick=\"javascript:AmandaComputer('{$ligne["ID"]}')\"
style='font-size:14px;font-weight:bold;color:$color;text-decoration:underline'>";
$html=$html."
<tr class=$classtr>
<td width=1%>$select2</td>
<td style='font-size:14px;font-weight:bold;color:$color'>$href{$ligne["hostname"]}</a><div><i style='font-size:10px'>({$ligne["resolved"]})</i></div></a></td>
<td style='font-size:14px;font-weight:bold;color:$color'>{$ligne["directory"]}</a></td>
<td style='font-size:14px;font-weight:bold;color:$color'>{$ligne["dumptype"]}</td>
<td width=1%>$select</td>
<td width=1%>$delete</td>
</tr>
";
}
$html=$html."</table></center>
<script>
var x_AmandaComputerDel=function (obj) {
var results=obj.responseText;
if(results.length>2){alert(results);}
BrowseAmandaSearch();
}
function AmandaComputerDel(ID){
if(confirm('$delete_text ?')){
var XHR = new XHRConnection();
XHR.appendData('delete-id',ID);
AnimateDiv('browse-amanda-list');
XHR.sendAndLoad('$page', 'POST',x_AmandaComputerDel);
}
}
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
function client_delete(){
if(!is_numeric($_POST["ID"])){return;}
$sql="DELETE FROM amanda_hosts WHERE ID='{$_POST["ID"]}'";
$q=new mysql();
$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){echo $q->mysql_error;return;}
$sock=new sockets();
$sock->getFrameWork("amanda.php?save-client-config=yes");
}