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
*
* Copyright (C) 2014 bwq518, Hyzoom
* Fixes/updates (C) 2018 - 2022 pedro
*
*/
@ -22,7 +23,7 @@
#define MYSQL_ANYHOST "/tmp/setanyhost.sql"
void start_mysql(void)
void start_mysql(int force)
{
FILE *fp;
char pbi[128];
@ -34,11 +35,11 @@ void start_mysql(void)
/* make sure its really stop */
stop_mysql();
/* only if enabled... */
if (!nvram_match("mysql_enable", "1"))
/* only if enabled or forced */
if (!nvram_get_int("mysql_enable") && force == 0)
return;
if (nvram_match( "mysql_binary", "internal"))
if (nvram_match("mysql_binary", "internal"))
strcpy(pbi, "/usr/bin");
else if (nvram_match("mysql_binary", "optware"))
strcpy(pbi, "/opt/bin");
@ -47,6 +48,7 @@ void start_mysql(void)
if (pbi[strlen(pbi)-1] == '/')
pbi[strlen(pbi) - 1] = '\0';
splitpath(pbi, basedir, tmp1);
/* 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 start_nginxfp();
extern void stop_nginxfp();
extern void start_mysql();
extern void start_mysql(int force);
extern void stop_mysql();
#endif

@ -3233,7 +3233,7 @@ void start_services(void)
start_httpd();
#ifdef TCONFIG_NGINX
start_nginx();
start_mysql();
start_mysql(0);
#endif
start_cron();
start_rstats(0);
@ -4097,11 +4097,16 @@ TOP:
if (act_start) start_nginxfp();
goto CLEAR;
}
if (strcmp(service, "mysql") == 0) {
if (strncmp(service, "mysql", 5) == 0) {
if (act_stop) stop_mysql();
stop_firewall();
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;
}
#endif

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

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

@ -21,9 +21,49 @@
// <% 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();
function refresh_usb_disk() {
var i, j, k, a, b, c, e, s, desc, d, parts, p;
var partcount;
@ -73,6 +113,9 @@ function refresh_usb_disk() {
}
function verifyFields(focused, quiet) {
if (focused)
changed = 1;
var ok = 1;
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_passwd')).style.display = x;
var e;
e = E('_mysql_passwd');
s = e.value.trim();
if (s == '') {
var e = E('_mysql_passwd');
if (e.value.trim() == '') {
ferror.set(e, 'Password can not be NULL value', quiet);
ok = 0;
}
@ -136,22 +177,32 @@ function save() {
return;
var fom = E('t_fom');
fom.mysql_enable.value = fom._f_mysql_enable.checked ? 1 : 0;
fom.mysql_check.value = fom._f_mysql_check.checked ? 1 : 0;
fom.mysql_usb_enable.value = fom._f_mysql_usb_enable.checked ? 1 : 0;
fom.mysql_init_priv.value = fom._f_mysql_init_priv.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;
if (fom.mysql_enable.value == 0)
fom._service.value = 'mysql-stop';
fom.mysql_enable.value = fom._f_mysql_enable.checked ? 1 : 0;
fom.mysql_check.value = fom._f_mysql_check.checked ? 1 : 0;
fom.mysql_usb_enable.value = fom._f_mysql_usb_enable.checked ? 1 : 0;
fom.mysql_init_priv.value = fom._f_mysql_init_priv.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;
if (fom.mysql_enable.value)
fom._service.value = 'mysqlgui-restart';
else
fom._service.value = 'mysql-restart';
fom._service.value = 'mysql-stop';
form.submit('t_fom', 1);
fom._nofootermsg.value = 0;
form.submit(fom, 1);
changed = 0;
}
function earlyInit() {
show();
verifyFields(null, 1);
}
function init() {
up.initPage(250, 5);
eventHandler();
}
</script>
@ -170,8 +221,9 @@ function init() {
<!-- / / / -->
<input type="hidden" name="_nextpage" value="mysql.asp">
<input type="hidden" name="_service" value="mysql-restart">
<input type="hidden" name="_nextpage" value="web-mysql.asp">
<input type="hidden" name="_service" value="">
<input type="hidden" name="_nofootermsg" value="">
<input type="hidden" name="mysql_enable">
<input type="hidden" name="mysql_check">
<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" id="config-section1">
<script>
refresh_usb_disk();
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: [
{ name: 'mysql_binary', type: 'select', options: [
['internal','Internal (/usr/bin)'],
@ -254,6 +316,6 @@ function init() {
</td></tr>
</table>
</form>
<script>verifyFields(null, true);</script>
<script>earlyInit();</script>
</body>
</html>

Loading…
Cancel
Save