GUI: Web Server: MySQL Server: add daemon status, add start/stop button (unify to nginx page)

arm-sdk7
pedro 4 years ago
parent c8c904bb4e
commit 6d0706b284

@ -2,6 +2,7 @@
* mysql.c * mysql.c
* *
* Copyright (C) 2014 bwq518, Hyzoom * Copyright (C) 2014 bwq518, Hyzoom
* Fixes/updates (C) 2018 - 2022 pedro
* *
*/ */
@ -22,7 +23,7 @@
#define MYSQL_ANYHOST "/tmp/setanyhost.sql" #define MYSQL_ANYHOST "/tmp/setanyhost.sql"
void start_mysql(void) void start_mysql(int force)
{ {
FILE *fp; FILE *fp;
char pbi[128]; char pbi[128];
@ -34,8 +35,8 @@ void start_mysql(void)
/* make sure its really stop */ /* make sure its really stop */
stop_mysql(); stop_mysql();
/* only if enabled... */ /* only if enabled or forced */
if (!nvram_match("mysql_enable", "1")) if (!nvram_get_int("mysql_enable") && force == 0)
return; return;
if (nvram_match("mysql_binary", "internal")) if (nvram_match("mysql_binary", "internal"))
@ -47,6 +48,7 @@ void start_mysql(void)
if (pbi[strlen(pbi)-1] == '/') if (pbi[strlen(pbi)-1] == '/')
pbi[strlen(pbi) - 1] = '\0'; pbi[strlen(pbi) - 1] = '\0';
splitpath(pbi, basedir, tmp1); splitpath(pbi, basedir, tmp1);
/* Generate download saved path based on USB partition (mysql_dlroot) and directory name (mysql_datadir) */ /* Generate download saved path based on USB partition (mysql_dlroot) and directory name (mysql_datadir) */

@ -584,7 +584,7 @@ extern void start_nginx();
extern void stop_nginx(); extern void stop_nginx();
extern void start_nginxfp(); extern void start_nginxfp();
extern void stop_nginxfp(); extern void stop_nginxfp();
extern void start_mysql(); extern void start_mysql(int force);
extern void stop_mysql(); extern void stop_mysql();
#endif #endif

@ -3233,7 +3233,7 @@ void start_services(void)
start_httpd(); start_httpd();
#ifdef TCONFIG_NGINX #ifdef TCONFIG_NGINX
start_nginx(); start_nginx();
start_mysql(); start_mysql(0);
#endif #endif
start_cron(); start_cron();
start_rstats(0); start_rstats(0);
@ -4097,11 +4097,16 @@ TOP:
if (act_start) start_nginxfp(); if (act_start) start_nginxfp();
goto CLEAR; goto CLEAR;
} }
if (strcmp(service, "mysql") == 0) { if (strncmp(service, "mysql", 5) == 0) {
if (act_stop) stop_mysql(); if (act_stop) stop_mysql();
stop_firewall(); stop_firewall();
start_firewall(); /* always restarted */ start_firewall(); /* always restarted */
if (act_start) start_mysql(); if (act_start) {
if (!(strcmp(service, "mysqlgui") == 0)) /* force (re)start */
start_mysql(1);
else
start_mysql(0);
}
goto CLEAR; goto CLEAR;
} }
#endif #endif

@ -2002,8 +2002,9 @@ table.fields tr td.wwan-parser-view {
margin-bottom: 20px; margin-bottom: 20px;
} }
#_nginxfp_button { #_nginxfp_button,
margin-left: 45px; #_mysql_button {
margin-left: 54px;
} }
textarea.as-script { textarea.as-script {

@ -35,6 +35,7 @@ isup.pptpd = parseInt('<% psup("pptpd"); %>');
/* NGINX-BEGIN */ /* NGINX-BEGIN */
isup.nginx = parseInt('<% psup("nginx"); %>'); isup.nginx = parseInt('<% psup("nginx"); %>');
isup.mysqld = parseInt('<% psup("mysqld"); %>');
/* NGINX-END */ /* NGINX-END */
/* SSH-BEGIN */ /* SSH-BEGIN */

@ -21,9 +21,49 @@
// <% usbdevices(); %> // <% usbdevices(); %>
var ams_link = '&nbsp;&nbsp;<a href="http://'+location.hostname+':'+nvram.nginx_port+'/adminer.php" class="new_window"><i>[Click here to manage MySQL]<\/i><\/a>'; </script>
<script src="isup.jsx?_http_id=<% nv(http_id); %>"></script>
<script>
var up = new TomatoRefresh('isup.jsx?_http_id=<% nv(http_id); %>', '', 5);
up.refresh = function(text) {
isup = {};
try {
eval(text);
}
catch (ex) {
isup = {};
}
show();
}
var changed = 0;
function show() {
E('_mysql_notice').innerHTML = 'MySQL is currently '+(!isup.mysqld ? 'stopped' : 'running')+' ';
E('_mysql_button').value = (isup.mysqld ? 'Stop' : 'Start')+' Now';
E('_mysql_button').setAttribute('onclick', 'javascript:toggle(\'mysql\', '+isup.mysqld+');');
E('_mysql_button').disabled = 0;
}
function toggle(service, isup) {
if (changed && !confirm("There are unsaved changes. Continue anyway?"))
return;
E('_'+service+'_button').disabled = 1;
var fom = E('t_fom');
fom._service.value = service+(isup ? '-stop' : '-start');
fom._nofootermsg.value = 1;
form.submit(fom, 1, 'service.cgi');
}
var ams_link = '&nbsp;&nbsp;<a href="http://'+location.hostname+':'+nvram.nginx_port+'/adminer.php" class="new_window"><i>[Click here to manage MySQL]<\/i><\/a>';
var usb_disk_list = new Array(); var usb_disk_list = new Array();
function refresh_usb_disk() { function refresh_usb_disk() {
var i, j, k, a, b, c, e, s, desc, d, parts, p; var i, j, k, a, b, c, e, s, desc, d, parts, p;
var partcount; var partcount;
@ -73,6 +113,9 @@ function refresh_usb_disk() {
} }
function verifyFields(focused, quiet) { function verifyFields(focused, quiet) {
if (focused)
changed = 1;
var ok = 1; var ok = 1;
var a = E('_f_mysql_enable').checked; var a = E('_f_mysql_enable').checked;
@ -120,10 +163,8 @@ function verifyFields(focused, quiet) {
PR(E('_mysql_username')).style.display = x; PR(E('_mysql_username')).style.display = x;
PR(E('_mysql_passwd')).style.display = x; PR(E('_mysql_passwd')).style.display = x;
var e; var e = E('_mysql_passwd');
e = E('_mysql_passwd'); if (e.value.trim() == '') {
s = e.value.trim();
if (s == '') {
ferror.set(e, 'Password can not be NULL value', quiet); ferror.set(e, 'Password can not be NULL value', quiet);
ok = 0; ok = 0;
} }
@ -143,15 +184,25 @@ function save() {
fom.mysql_init_rootpass.value = fom._f_mysql_init_rootpass.checked ? 1 : 0; fom.mysql_init_rootpass.value = fom._f_mysql_init_rootpass.checked ? 1 : 0;
fom.mysql_allow_anyhost.value = fom._f_mysql_allow_anyhost.checked ? 1 : 0; fom.mysql_allow_anyhost.value = fom._f_mysql_allow_anyhost.checked ? 1 : 0;
if (fom.mysql_enable.value == 0) if (fom.mysql_enable.value)
fom._service.value = 'mysql-stop'; fom._service.value = 'mysqlgui-restart';
else else
fom._service.value = 'mysql-restart'; fom._service.value = 'mysql-stop';
fom._nofootermsg.value = 0;
form.submit('t_fom', 1); form.submit(fom, 1);
changed = 0;
}
function earlyInit() {
show();
verifyFields(null, 1);
} }
function init() { function init() {
up.initPage(250, 5);
eventHandler(); eventHandler();
} }
</script> </script>
@ -170,8 +221,9 @@ function init() {
<!-- / / / --> <!-- / / / -->
<input type="hidden" name="_nextpage" value="mysql.asp"> <input type="hidden" name="_nextpage" value="web-mysql.asp">
<input type="hidden" name="_service" value="mysql-restart"> <input type="hidden" name="_service" value="">
<input type="hidden" name="_nofootermsg" value="">
<input type="hidden" name="mysql_enable"> <input type="hidden" name="mysql_enable">
<input type="hidden" name="mysql_check"> <input type="hidden" name="mysql_check">
<input type="hidden" name="mysql_usb_enable"> <input type="hidden" name="mysql_usb_enable">
@ -181,13 +233,23 @@ function init() {
<!-- / / / --> <!-- / / / -->
<div class="section-title">Status</div>
<div class="section">
<div class="fields">
<span id="_mysql_notice"></span>
<input type="button" id="_mysql_button">
</div>
</div>
<!-- / / / -->
<div class="section-title">Basic Settings<script>W(ams_link);</script></div> <div class="section-title">Basic Settings<script>W(ams_link);</script></div>
<div class="section" id="config-section1"> <div class="section" id="config-section1">
<script> <script>
refresh_usb_disk(); refresh_usb_disk();
createFieldTable('', [ createFieldTable('', [
{ title: 'Enable MySQL server', name: 'f_mysql_enable', type: 'checkbox', value: nvram.mysql_enable == 1 }, { title: 'Enable Server on Start', name: 'f_mysql_enable', type: 'checkbox', value: nvram.mysql_enable == 1 },
{ title: 'MySQL binary path', multi: [ { title: 'MySQL binary path', multi: [
{ name: 'mysql_binary', type: 'select', options: [ { name: 'mysql_binary', type: 'select', options: [
['internal','Internal (/usr/bin)'], ['internal','Internal (/usr/bin)'],
@ -254,6 +316,6 @@ function init() {
</td></tr> </td></tr>
</table> </table>
</form> </form>
<script>verifyFields(null, true);</script> <script>earlyInit();</script>
</body> </body>
</html> </html>

Loading…
Cancel
Save