forked from dtouzeau/artica-1.5
/
mysql.index.php
executable file
·434 lines (335 loc) · 10.9 KB
/
mysql.index.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<?php
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.mysql.inc");
$user=new usersMenus();
if($user->AsSystemAdministrator==false){header('location:users.index.php');exit();}
if(isset($_GET["mysqlstatus"])){echo mysql_status();exit;}
if(isset($_GET["main"])){echo mysql_main_switch();exit;}
if(isset($_GET["mysqlenable"])){echo mysql_enable();exit;}
if(isset($_GET["changemysqlenable"])){mysql_action_enable_change();exit;}
if(isset($_GET["mysql_account"])){testsMysql();exit;}
if($_GET["script"]=="mysql_enabled"){echo js_mysql_enabled();exit;}
if($_GET["script"]=="mysql_save_account"){echo js_mysql_save_account();exit;}
if(isset($_GET["databases_status"])){Database_Status();exit;}
if(isset($_GET["repair-databases"])){repair_database();exit;}
if(isset($_GET["popup"])){popup();exit;}
if(isset($_GET["mysql-settings-popup"])){mysql_settings_js();exit;}
if(isset($_GET["mysql-settings-popup-show"])){echo mysql_settings(true);exit;}
js();
function js(){
$page=CurrentPageName();
$tpl=new templates();
$title=$tpl->_ENGINE_parse_body("{APP_MYSQL_ARTICA}");
$prefix=str_replace(".","_",$page);
if(isset($_GET["account"])){
$ajax="LoadAjax('main_mysql_config','mysql.index.php?main=settings&hostname=')";
}else{
$ajax="LoadAjax('main_mysql_config','mysql.index.php?main=&hostname=')";
}
$html="
var {$prefix}timerID = null;
var {$prefix}timerID1 = null;
var {$prefix}tant=0;
var {$prefix}reste=0;
function {$prefix}demarre(){
{$prefix}tant = {$prefix}tant+1;
{$prefix}reste=5-{$prefix}tant;
if ({$prefix}tant < 5 ) {
{$prefix}timerID = setTimeout(\"{$prefix}demarre()\",3000);
} else {
{$prefix}tant = 0;
{$prefix}ChargeLogs();
{$prefix}demarre(); //la boucle demarre !
}
}
function mystatus(){
if(document.getElementById('mystatus')){
LoadAjax('mystatus','$page?databases_status=yes');
}
}
function {$prefix}ChargeLogs(){
mystatus();
LoadAjax('mysql_status','$page?mysqlstatus=yes');
}
function mystatus(){
if(document.getElementById('mystatus')){
LoadAjax('mystatus','$page?databases_status=yes');
}
}
function {$prefix}SartMysql(){
YahooWin3(700,'$page?popup=yes','$title');
setTimeout('Loadall()',900);
}
function Loadall(){
demarre();
ChargeLogs();
mystatus();
$ajax
LoadAjax('mysql_status','$page?mysqlstatus=yes');
LoadAjax('mysqlenable','$page?mysqlenable=yes');
}
{$prefix}SartMysql()
";
echo $html;
}
function popup(){
$html="
<h1>{APP_MYSQL_ARTICA}</H1><span id='scripts'><script type=\"text/javascript\" src=\"$page?script=load_functions\"></script></span>
<table style='width:100%'>
<tr>
<td width=1% valign='top'>".RoundedLightWhite("<img src='img/bg_mysql.png'style='margin-right:30px;margin-bottom:5px'>")."</td>
<td valign='top'>
<div id='mysql_status'></div>
</td>
</tr>
<tr>
<td colspan=2 valign='top'>
<br>
".RoundedLightWhite("
<table style='width:100%'>
<tr>
<td valign='top'>
<div id='main_mysql_config'></div>
</td>
<td valign='top'>
<div id='mysqlenable'></div>
</td>
</tr>
</table>")."
</td>
</tr>
</table>
" ;
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function mysql_tabs(){
$page=CurrentPageName();
$users=new usersMenus();
$array["settings"]='{settings}';
$array["performances"]='{performances}';
while (list ($num, $ligne) = each ($array) ){
if($_GET["main"]==$num){$class="id=tab_current";}else{$class=null;}
$html=$html . "<li><a href=\"javascript:LoadAjax('main_mysql_config','$page?main=$num&hostname={$_GET["hostname"]}')\" $class>$ligne</a></li>\n";
}
$tpl=new templates();
return $tpl->_ENGINE_parse_body("<div id=tablist>$html</div>");
}
function mysql_status(){
$tpl=new templates();
$ini=new Bs_IniHandler();
$sock=new sockets();
$ini->loadString($sock->getfile('mysqlstatus'));
$status=DAEMON_STATUS_ROUND("ARTICA_MYSQL",$ini,null);
echo $tpl->_ENGINE_parse_body($status);
}
function mysql_main_switch(){
$tab=mysql_tabs();
switch ($_GET["main"]) {
case "settings":echo $tab.mysql_settings();break;
case "performances":echo $tab.mysql_performances();break;
default:echo $tab.mysql_performances();break;
}
}
function mysql_performances(){
$html="
<table style='width:100%'>
<tr>
<td class=legend>
{change_mysql_power}:
</td>
<td>
<input type=button value='{mysql_performance_level} »' OnClick=\"javascript:YahooWin(400,'artica.performances.php?main_config_mysql=yes');\">
</td>
</tr>
<tr>
<td class=legend>
{mysql_repair}:
</td>
<td>
<input type=button value='{mysql_repair} »' OnClick=\"javascript:YahooWin(400,'mysql.index.php?repair-databases=yes','{waiting}...');\">
</td>
</tr>
</table>
<div id='mystatus'></div>
";
$tpl=new templates();
return $tpl->_ENGINE_parse_body($html);
}
function mysql_enable(){
$artica=new artica_general();
$page=CurrentPageName();
$icon=Paragraphe_switch_img('{enable_mysql}',"{enable_mysql_text}","enable_mysql",$artica->EnableMysqlFeatures);
$html="
<div>$icon
<div style='text-align:right;margin-top:5px'><input type='button' OnClick=\"javascript:Loadjs('$page?script=mysql_enabled')\" value='{edit} »'></div>
</div>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function js_mysql_enabled(){
$page=CurrentPageName();
$html="var enable=document.getElementById('enable_mysql').value;
YahooWin(400,'$page?changemysqlenable='+enable);
LoadAjax('mysqlenable','$page?mysqlenable=yes');
";
echo $html;
}
function mysql_action_enable_change(){
$enable=$_GET["changemysqlenable"];
$artica=new artica_general();
$artica->EnableMysqlFeatures=$enable;
if($enable==0){
$main=new main_cf();
$main->save_conf();
$main->save_conf_to_server();
}
$artica->SaveMysqlSettings();
$sock=new sockets();
$datas=$sock->getfile('restartmysql');
$datas=htmlentities($datas);
$tbl=explode("\n",$datas);
$datas='';
while (list ($num, $val) = each ($tbl) ){
$datas=$datas."<div>$val</div>";
}
echo "<div style='width:100%;height:500px;overflow:auto'>$datas</div>";
}
function mysql_settings_js(){
$user=new usersMenus();
if(!$user->AsSystemAdministrator) {
$tpl=new templates();
$text=$tpl->_ENGINE_parse_body('{ERROR_NO_PRIVS}');
$text=replace_accents(html_entity_decode($text));
echo "alert('$text');";
exit;
}
$page=CurrentPageName();
$tpl=new templates();
$title=$tpl->_ENGINE_parse_body('{mysql_account}',"artica.settings.php");
$prefix=str_replace(".","_",$page);
$page=CurrentPageName();
$js="
function {$prefix}LoadMainRI(){
YahooWin3('450','$page?mysql-settings-popup-show=yes','$title');
}
{$prefix}LoadMainRI();
";
echo $js;
}
function mysql_settings($notitle=false){
$user=new usersMenus();
if(!$user->AsArticaAdministrator){
if(!$user->AsSystemAdministrator){
$tpl=new templates();
$text=$tpl->_ENGINE_parse_body('{ERROR_NO_PRIVS} !AsSystemAdministrator');
$text=replace_accents(html_entity_decode($text));
echo "alert('$text');";
exit;
}}
$artica=new artica_general();
$page=CurrentPageName();
if(preg_match('#(.+?):(.*)#',$artica->MysqlAdminAccount,$re)){
$rootm=$re[1];
$pwd=$re[2];
}
$servername=$artica->MysqlServerName;
$html="
<table style='width:100%'>
<tr>
<td align='right' nowrap class=legend>{mysqlserver}:</strong></td>
<td align='left'>" . Field_text('mysqlserver',$servername,'width:90px;padding:3px;font-size:13px',null,null,'')."</td>
</tr>
<tr>
<td align='right' nowrap class=legend>{mysqlroot}:</strong></td>
<td align='left'>" . Field_text('mysqlroot',$rootm,'width:90px;padding:3px;font-size:13px',null,null,'{mysqlroot_text}')."</td>
</tr>
<tr>
<td align='right' nowrap class=legend>{mysqlpass}:</strong></td>
<td align='left'>" . Field_password("mysqlpass",$pwd,"width:90px;padding:3px;font-size:13px")."</td>
</tr>
<tr>
<td colspan=2 align='right'>
<hr>". button("{apply}","Loadjs('$page?script=mysql_save_account')")."
</td>
</tr>
</table>
";
$tpl=new templates();
return $tpl->_ENGINE_parse_body($html,"artica.settings.php");
}
function js_mysql_save_account(){
$page=CurrentPageName();
$html="
var mysqlserver=document.getElementById('mysqlserver').value;
var mysqlroot=escape(document.getElementById('mysqlroot').value);
var mysqlpass=escape(base64_encode(document.getElementById('mysqlpass').value));
YahooWin4(400,'$page?mysql_account='+mysqlroot+'&mysqlpass='+mysqlpass+'&mysqlserver='+mysqlserver);
";
echo $html;
}
function testsMysql(){
$_GET["mysqlpass"]=trim(base64_decode($_GET["mysqlpass"]));
writelogs("testing {$_GET["mysqlserver"]}:3306 with user {$_GET["mysql_account"]} and password \"{$_GET["mysqlpass"]}\"",__FUNCTION__,__FILE__,__LINE__);
$bd=@mysql_connect("{$_GET["mysqlserver"]}:3306",$_GET["mysql_account"],$_GET["mysqlpass"]);
$database=md5('Y-m-d H:i:s');
$tpl=new templates();
if(!$bd){
$errnum=mysql_errno();
$des=mysql_error();
echo "<div style='font-size:12px;color:red;font-weight:bold'>
<p>{connection}:ERR N.$errnum</p> $des
</div>";
exit;
}
$results=@mysql_query("CREATE DATABASE $database");
if(!$bd){
$errnum=mysql_errno();
$des=mysql_error();
echo RoundedLightWhite("<div style='font-size:12px;color:red;font-weight:bold'>
<p>{privileges}:ERR N.$errnum</p> $des
</div>");
exit;
}
$results=@mysql_query("DROP DATABASE $database");
$artica=new artica_general();
$artica->MysqlAdminAccount="{$_GET["mysql_account"]}:{$_GET["mysqlpass"]}";
$artica->MysqlServerName=$_GET["mysqlserver"];
$artica->SaveMysqlSettings();
$mysql=new mysql();
$mysql->mysql_server=$_GET["mysqlserver"];
$mysql->mysql_admin=$_GET["mysql_account"];
$mysql->mysql_password=$_GET["mysqlpass"];
$mysql->hostname=$_GET["mysqlserver"];
$mysql->BuildTables();
$tpl=new templates();
echo RoundedLightWhite($tpl->_ENGINE_parse_body('<div>{success} {edit} {mysql_account}</div>'));
}
function Database_Status(){
$my=new mysql();
$artica_back=$my->DATABASE_STATUS("artica_backup");
$artica_events=$my->DATABASE_STATUS("artica_events");
$tpl=new templates();
echo $tpl->_ENGINE_parse_body("<H5>{databases_status}</H5>$artica_back.$artica_events");
}
function repair_database(){
$sock=new sockets();
$datas=$sock->getfile('MysqlRepairDatabase');
$tb=explode("\n",$datas);
while (list ($num, $ligne) = each ($tb) ){
if(trim($ligne)==null){continue;}
$ligne=htmlentities($ligne);
$dd=$dd."<div><strong style='font-size:12px;color:black'><code>$ligne</code></strong></div>";
}
$dd=RoundedLightWhite($dd);
$html="
<H1>{mysql_repair}</H1>
<div style='width:100%;height:300px;overflow:auto'>$dd</div>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
?>