2024-04-19 09:32:13 +00:00
var awesome = "/app/static/js/fontawesome.min.js"
2023-09-17 09:42:39 +00:00
var cur _url = window . location . href . split ( '/app/' ) . pop ( ) ;
cur _url = cur _url . split ( '/' ) ;
2024-03-17 06:38:00 +00:00
var add _word = $ ( '#translate' ) . attr ( 'data-add' ) ;
var delete _word = $ ( '#translate' ) . attr ( 'data-delete' ) ;
var cancel _word = $ ( '#translate' ) . attr ( 'data-cancel' ) ;
2018-04-16 07:01:44 +00:00
$ ( function ( ) {
2020-08-07 15:14:59 +00:00
$ ( '#add-group-button' ) . click ( function ( ) {
addGroupDialog . dialog ( 'open' ) ;
} ) ;
2023-02-13 14:45:45 +00:00
var group _tabel _title = $ ( "#group-add-table-overview" ) . attr ( 'title' ) ;
2020-08-07 15:14:59 +00:00
var addGroupDialog = $ ( "#group-add-table" ) . dialog ( {
autoOpen : false ,
resizable : false ,
height : "auto" ,
width : 600 ,
modal : true ,
2023-02-13 14:45:45 +00:00
title : group _tabel _title ,
2020-08-07 15:14:59 +00:00
show : {
effect : "fade" ,
duration : 200
} ,
hide : {
effect : "fade" ,
duration : 200
} ,
buttons : {
"Add" : function ( ) {
addGroup ( this ) ;
2018-07-25 05:25:27 +00:00
} ,
2020-08-07 15:14:59 +00:00
Cancel : function ( ) {
$ ( this ) . dialog ( "close" ) ;
clearTips ( ) ;
}
}
2018-07-25 05:25:27 +00:00
} ) ;
2018-04-16 07:01:44 +00:00
$ ( '#add-user-button' ) . click ( function ( ) {
2018-10-04 04:07:32 +00:00
addUserDialog . dialog ( 'open' ) ;
2018-04-16 07:01:44 +00:00
} ) ;
2023-02-13 14:45:45 +00:00
var user _tabel _title = $ ( "#user-add-table-overview" ) . attr ( 'title' ) ;
2018-10-04 04:07:32 +00:00
var addUserDialog = $ ( "#user-add-table" ) . dialog ( {
2020-08-07 15:14:59 +00:00
autoOpen : false ,
resizable : false ,
height : "auto" ,
width : 600 ,
modal : true ,
2023-02-13 14:45:45 +00:00
title : user _tabel _title ,
2020-08-07 15:14:59 +00:00
show : {
effect : "fade" ,
duration : 200
} ,
hide : {
effect : "fade" ,
duration : 200
} ,
2023-02-13 14:45:45 +00:00
buttons : [ {
text : add _word ,
click : function ( ) {
2020-08-07 15:14:59 +00:00
addUser ( this ) ;
2023-02-13 14:45:45 +00:00
}
} , {
text : cancel _word ,
click : function ( ) {
2020-08-07 15:14:59 +00:00
$ ( this ) . dialog ( "close" ) ;
clearTips ( ) ;
2018-10-04 04:07:32 +00:00
}
2023-02-13 14:45:45 +00:00
} ]
2020-08-07 15:14:59 +00:00
} ) ;
$ ( '#add-server-button' ) . click ( function ( ) {
addServerDialog . dialog ( 'open' ) ;
} ) ;
2023-02-13 14:45:45 +00:00
var server _tabel _title = $ ( "#server-add-table-overview" ) . attr ( 'title' ) ;
2018-10-04 04:07:32 +00:00
var addServerDialog = $ ( "#server-add-table" ) . dialog ( {
2020-08-07 15:14:59 +00:00
autoOpen : false ,
resizable : false ,
height : "auto" ,
width : 600 ,
modal : true ,
2023-02-13 14:45:45 +00:00
title : server _tabel _title ,
2020-08-07 15:14:59 +00:00
show : {
effect : "fade" ,
duration : 200
} ,
hide : {
effect : "fade" ,
duration : 200
} ,
2023-02-13 14:45:45 +00:00
buttons : [ {
text : add _word ,
click : function ( ) {
2020-08-07 15:14:59 +00:00
addServer ( this ) ;
2023-02-13 14:45:45 +00:00
}
} , {
text : cancel _word ,
click : function ( ) {
2020-08-07 15:14:59 +00:00
$ ( this ) . dialog ( "close" ) ;
clearTips ( ) ;
2018-10-03 10:14:57 +00:00
}
2023-02-13 14:45:45 +00:00
} ]
2018-04-16 07:01:44 +00:00
} ) ;
2018-06-24 09:31:28 +00:00
$ ( '#add-ssh-button' ) . click ( function ( ) {
2020-08-07 15:14:59 +00:00
addCredsDialog . dialog ( 'open' ) ;
} ) ;
2023-02-13 14:45:45 +00:00
var ssh _tabel _title = $ ( "#ssh-add-table-overview" ) . attr ( 'title' ) ;
2020-08-07 15:14:59 +00:00
var addCredsDialog = $ ( "#ssh-add-table" ) . dialog ( {
autoOpen : false ,
resizable : false ,
height : "auto" ,
width : 600 ,
modal : true ,
2023-02-13 14:45:45 +00:00
title : ssh _tabel _title ,
2020-08-07 15:14:59 +00:00
show : {
effect : "fade" ,
duration : 200
} ,
hide : {
effect : "fade" ,
duration : 200
} ,
2023-02-13 14:45:45 +00:00
buttons : [ {
text : add _word ,
click : function ( ) {
2020-08-07 15:14:59 +00:00
addCreds ( this ) ;
2023-02-13 14:45:45 +00:00
}
} , {
text : cancel _word ,
click : function ( ) {
2020-08-07 15:14:59 +00:00
$ ( this ) . dialog ( "close" ) ;
clearTips ( ) ;
}
2023-02-13 14:45:45 +00:00
} ]
2018-06-24 09:31:28 +00:00
} ) ;
2018-04-20 04:39:39 +00:00
$ ( "#ajax-users input" ) . change ( function ( ) {
var id = $ ( this ) . attr ( 'id' ) . split ( '-' ) ;
updateUser ( id [ 1 ] )
} ) ;
$ ( "#ajax-users select" ) . on ( 'selectmenuchange' , function ( ) {
var id = $ ( this ) . attr ( 'id' ) . split ( '-' ) ;
updateUser ( id [ 1 ] )
} ) ;
$ ( "#ajax-group input" ) . change ( function ( ) {
var id = $ ( this ) . attr ( 'id' ) . split ( '-' ) ;
updateGroup ( id [ 1 ] )
} ) ;
$ ( "#ajax-servers input" ) . change ( function ( ) {
var id = $ ( this ) . attr ( 'id' ) . split ( '-' ) ;
updateServer ( id [ 1 ] )
} ) ;
$ ( "#ajax-servers select" ) . on ( 'selectmenuchange' , function ( ) {
var id = $ ( this ) . attr ( 'id' ) . split ( '-' ) ;
updateServer ( id [ 1 ] )
} ) ;
2018-05-07 13:24:22 +00:00
$ ( "#ssh_enable_table input" ) . change ( function ( ) {
2018-06-24 09:31:28 +00:00
var id = $ ( this ) . attr ( 'id' ) . split ( '-' ) ;
updateSSH ( id [ 1 ] )
sshKeyEnableShow ( id [ 1 ] )
2018-05-07 13:24:22 +00:00
} ) ;
2018-06-28 05:55:07 +00:00
$ ( "#ssh_enable_table select" ) . on ( 'selectmenuchange' , function ( ) {
var id = $ ( this ) . attr ( 'id' ) . split ( '-' ) ;
updateSSH ( id [ 1 ] )
sshKeyEnableShow ( id [ 1 ] )
} ) ;
2018-06-24 09:31:28 +00:00
$ ( '#new-ssh_enable' ) . click ( function ( ) {
if ( $ ( '#new-ssh_enable' ) . is ( ':checked' ) ) {
2018-05-07 13:24:22 +00:00
$ ( '#ssh_pass' ) . css ( 'display' , 'none' ) ;
} else {
$ ( '#ssh_pass' ) . css ( 'display' , 'block' ) ;
}
} ) ;
2018-06-24 09:31:28 +00:00
if ( $ ( '#new-ssh_enable' ) . is ( ':checked' ) ) {
2018-05-07 13:24:22 +00:00
$ ( '#ssh_pass' ) . css ( 'display' , 'none' ) ;
} else {
$ ( '#ssh_pass' ) . css ( 'display' , 'block' ) ;
}
2021-06-02 07:28:07 +00:00
$ ( "#scan_server" ) . change ( function ( ) {
if ( $ ( '#scan_server' ) . is ( ':checked' ) ) {
$ ( '.services_for_scan' ) . hide ( ) ;
} else {
$ ( '.services_for_scan' ) . show ( ) ;
}
} ) ;
2018-11-08 08:49:03 +00:00
$ ( '#search_ldap_user' ) . click ( function ( ) {
var valid = true ;
2020-07-30 17:28:58 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
allFields = $ ( [ ] ) . add ( $ ( '#new-username' ) ) ;
allFields . removeClass ( "ui-state-error" ) ;
valid = valid && checkLength ( $ ( '#new-username' ) , "user name" , 1 ) ;
2018-11-08 08:49:03 +00:00
user = $ ( '#new-username' ) . val ( )
if ( valid ) {
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/user/ldap/" + $ ( '#new-username' ) . val ( ) ,
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2020-07-30 17:28:58 +00:00
if ( data . indexOf ( 'error:' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
2018-11-08 08:49:03 +00:00
$ ( '#new-email' ) . val ( '' ) ;
2022-04-08 18:08:31 +00:00
$ ( '#new-password' ) . attr ( 'readonly' , false ) ;
$ ( '#new-password' ) . val ( '' ) ;
2018-11-08 08:49:03 +00:00
} else {
var json = $ . parseJSON ( data ) ;
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2023-02-13 14:45:45 +00:00
if ( ! $ ( '#new-username' ) . val ( ) . includes ( '@' ) ) {
$ ( '#new-username' ) . val ( user + '@' + json [ 1 ] ) ;
}
2018-11-08 08:49:03 +00:00
$ ( '#new-email' ) . val ( json [ 0 ] ) ;
2022-04-08 18:08:31 +00:00
$ ( '#new-password' ) . val ( 'aduser' ) ;
$ ( '#new-password' ) . attr ( 'readonly' , true ) ;
}
2018-11-08 08:49:03 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-11-08 08:49:03 +00:00
clearTips ( ) ;
}
} ) ;
2021-02-20 07:47:33 +00:00
$ ( "#tabs ul li" ) . click ( function ( ) {
var activeTab = $ ( this ) . find ( "a" ) . attr ( "href" ) ;
2024-05-03 12:22:58 +00:00
console . log ( activeTab ) ;
2022-06-15 07:34:20 +00:00
var activeTabClass = activeTab . replace ( '#' , '' ) ;
$ ( '.menu li ul li' ) . each ( function ( ) {
$ ( this ) . find ( 'a' ) . css ( 'border-left' , '0px solid var(--right-menu-blue-rolor)' ) ;
$ ( this ) . find ( 'a' ) . css ( 'padding-left' , '20px' )
2023-09-17 09:42:39 +00:00
$ ( this ) . find ( 'a' ) . css ( 'background-color' , '#48505A' ) ;
2022-06-15 07:34:20 +00:00
$ ( this ) . children ( "." + activeTabClass ) . css ( 'padding-left' , '30px' ) ;
$ ( this ) . children ( "." + activeTabClass ) . css ( 'border-left' , '4px solid var(--right-menu-blue-rolor)' ) ;
2023-09-17 09:42:39 +00:00
$ ( this ) . children ( "." + activeTabClass ) . css ( 'background-color' , 'var(--right-menu-blue-rolor)' ) ;
2022-06-15 07:34:20 +00:00
} ) ;
2023-09-17 09:42:39 +00:00
if ( activeTab == '#tools' ) {
2021-02-20 07:47:33 +00:00
loadServices ( ) ;
2024-05-03 12:22:58 +00:00
} else if ( activeTab == '#settings' ) {
loadSettings ( ) ;
2021-02-20 07:47:33 +00:00
} else if ( activeTab == '#updatehapwi' ) {
loadupdatehapwi ( ) ;
} else if ( activeTab == '#openvpn' ) {
loadopenvpn ( ) ;
2024-03-17 06:38:00 +00:00
} else if ( activeTab == '#backup' ) {
loadBackup ( ) ;
2021-02-20 07:47:33 +00:00
}
} ) ;
2018-04-16 07:01:44 +00:00
} ) ;
2021-02-20 07:47:33 +00:00
window . onload = function ( ) {
2022-05-17 09:34:52 +00:00
$ ( '#tabs' ) . tabs ( ) ;
2021-02-20 07:47:33 +00:00
var activeTabIdx = $ ( '#tabs' ) . tabs ( 'option' , 'active' )
2023-09-17 09:42:39 +00:00
if ( cur _url [ 0 ] . split ( '#' ) [ 0 ] == 'admin' ) {
if ( activeTabIdx == 6 ) {
2021-02-20 07:47:33 +00:00
loadServices ( ) ;
2024-05-03 12:22:58 +00:00
} else if ( activeTabIdx == 3 ) {
loadSettings ( ) ;
} else if ( activeTabIdx == 4 ) {
loadBackup ( ) ;
2023-09-17 09:42:39 +00:00
} else if ( activeTabIdx == 7 ) {
2021-02-20 07:47:33 +00:00
loadupdatehapwi ( ) ;
2024-03-17 06:38:00 +00:00
} else if ( activeTabIdx == 8 ) {
2021-02-20 07:47:33 +00:00
loadopenvpn ( ) ;
}
}
}
2020-08-07 15:14:59 +00:00
function addUser ( dialog _id ) {
2018-10-04 04:07:32 +00:00
var valid = true ;
2020-07-30 17:28:58 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
allFields = $ ( [ ] ) . add ( $ ( '#new-username' ) ) . add ( $ ( '#new-password' ) ) . add ( $ ( '#new-email' ) )
allFields . removeClass ( "ui-state-error" ) ;
valid = valid && checkLength ( $ ( '#new-username' ) , "user name" , 1 ) ;
valid = valid && checkLength ( $ ( '#new-password' ) , "password" , 1 ) ;
valid = valid && checkLength ( $ ( '#new-email' ) , "Email" , 1 ) ;
2019-01-05 12:36:59 +00:00
var activeuser = 0 ;
if ( $ ( '#activeuser' ) . is ( ':checked' ) ) {
activeuser = '1' ;
}
2018-10-04 04:07:32 +00:00
if ( valid ) {
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/user/create" ,
2018-10-04 04:07:32 +00:00
data : {
newusername : $ ( '#new-username' ) . val ( ) ,
newpassword : $ ( '#new-password' ) . val ( ) ,
newemail : $ ( '#new-email' ) . val ( ) ,
newrole : $ ( '#new-role' ) . val ( ) ,
2019-01-05 12:36:59 +00:00
activeuser : activeuser ,
2020-08-11 09:54:03 +00:00
page : cur _url [ 0 ] . split ( '#' ) [ 0 ] ,
2019-09-27 19:09:49 +00:00
newgroupuser : $ ( '#new-group' ) . val ( ) ,
token : $ ( '#token' ) . val ( )
2018-10-04 04:07:32 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2020-07-30 17:28:58 +00:00
if ( data . indexOf ( 'error:' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
2018-10-04 04:07:32 +00:00
} else {
2020-05-10 06:17:07 +00:00
var getId = new RegExp ( '[0-9]+' ) ;
var id = data . match ( getId ) ;
2023-09-17 09:42:39 +00:00
common _ajax _action _after _success ( dialog _id , 'user-' + id , 'ajax-users' , data ) ;
2022-04-08 18:08:31 +00:00
}
2018-10-04 04:07:32 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-10-04 04:07:32 +00:00
}
}
2020-08-07 15:14:59 +00:00
function addGroup ( dialog _id ) {
toastr . clear ( ) ;
var valid = true ;
2023-09-17 09:42:39 +00:00
allFields = $ ( [ ] ) . add ( $ ( '#new-group-add' ) ) ;
allFields . removeClass ( "ui-state-error" ) ;
valid = valid && checkLength ( $ ( '#new-group-add' ) , "new group name" , 1 ) ;
if ( valid ) {
$ . ajax ( {
url : "/app/server/group/create" ,
2020-08-07 15:14:59 +00:00
data : {
groupname : $ ( '#new-group-add' ) . val ( ) ,
newdesc : $ ( '#new-desc' ) . val ( ) ,
token : $ ( '#token' ) . val ( )
} ,
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
2020-08-07 15:14:59 +00:00
if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
var getId = new RegExp ( '[0-9]+' ) ;
var id = data . match ( getId ) ;
2023-09-17 09:42:39 +00:00
$ ( 'select:regex(id, group)' ) . append ( '<option value=' + id + '>' + $ ( '#new-group-add' ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
2020-08-07 15:14:59 +00:00
common _ajax _action _after _success ( dialog _id , 'newgroup' , 'ajax-group' , data ) ;
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2020-08-07 15:14:59 +00:00
}
}
function addServer ( dialog _id ) {
2020-07-26 16:26:04 +00:00
toastr . clear ( )
2018-10-04 04:07:32 +00:00
var valid = true ;
2018-10-03 10:14:57 +00:00
var servername = $ ( '#new-server-add' ) . val ( ) ;
var newip = $ ( '#new-ip' ) . val ( ) ;
var newservergroup = $ ( '#new-server-group-add' ) . val ( ) ;
var cred = $ ( '#credentials' ) . val ( ) ;
2021-06-02 07:28:07 +00:00
var scan _server = 0 ;
2018-10-03 10:14:57 +00:00
var typeip = 0 ;
var enable = 0 ;
2020-02-06 22:36:58 +00:00
var haproxy = 0 ;
var nginx = 0 ;
2022-04-15 09:49:00 +00:00
var apache = 0 ;
2020-11-18 04:45:34 +00:00
var firewall = 0 ;
2023-07-03 09:15:39 +00:00
var add _to _smon = 0 ;
2021-06-02 07:28:07 +00:00
if ( $ ( '#scan_server' ) . is ( ':checked' ) ) {
scan _server = '1' ;
}
2018-10-03 10:14:57 +00:00
if ( $ ( '#typeip' ) . is ( ':checked' ) ) {
typeip = '1' ;
}
if ( $ ( '#enable' ) . is ( ':checked' ) ) {
enable = '1' ;
}
2020-02-06 22:36:58 +00:00
if ( $ ( '#haproxy' ) . is ( ':checked' ) ) {
haproxy = '1' ;
}
if ( $ ( '#nginx' ) . is ( ':checked' ) ) {
nginx = '1' ;
}
2022-04-15 09:49:00 +00:00
if ( $ ( '#apache' ) . is ( ':checked' ) ) {
apache = '1' ;
}
2020-11-18 04:45:34 +00:00
if ( $ ( '#firewall' ) . is ( ':checked' ) ) {
firewall = '1' ;
}
2023-07-03 09:15:39 +00:00
if ( $ ( '#add_to_smon' ) . is ( ':checked' ) ) {
add _to _smon = '1' ;
}
2023-09-17 09:42:39 +00:00
allFields = $ ( [ ] ) . add ( $ ( '#new-server-add' ) ) . add ( $ ( '#new-ip' ) ) . add ( $ ( '#new-port' ) )
allFields . removeClass ( "ui-state-error" ) ;
valid = valid && checkLength ( $ ( '#new-server-add' ) , "Hostname" , 1 ) ;
valid = valid && checkLength ( $ ( '#new-ip' ) , "IP" , 1 ) ;
valid = valid && checkLength ( $ ( '#new-port' ) , "Port" , 1 ) ;
2021-06-02 07:28:07 +00:00
if ( cred == null ) {
toastr . error ( 'First select credentials' ) ;
return false ;
}
if ( newservergroup == null ) {
toastr . error ( 'First select a group' ) ;
return false ;
}
2018-10-04 04:07:32 +00:00
if ( valid ) {
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/server/create" ,
2018-10-03 10:14:57 +00:00
data : {
servername : servername ,
newip : newip ,
newport : $ ( '#new-port' ) . val ( ) ,
newservergroup : newservergroup ,
typeip : typeip ,
2020-02-06 22:36:58 +00:00
haproxy : haproxy ,
nginx : nginx ,
2022-04-15 09:49:00 +00:00
apache : apache ,
2020-11-18 04:45:34 +00:00
firewall : firewall ,
2023-07-03 09:15:39 +00:00
add _to _smon : add _to _smon ,
2018-10-03 10:14:57 +00:00
enable : enable ,
2023-09-17 09:42:39 +00:00
slave : $ ( '#slavefor' ) . val ( ) ,
2018-10-03 10:14:57 +00:00
cred : cred ,
2023-06-13 18:32:18 +00:00
page : cur _url [ 0 ] . split ( '#' ) [ 0 ] ,
2018-11-26 12:55:00 +00:00
desc : $ ( '#desc' ) . val ( ) ,
2019-09-27 19:09:49 +00:00
token : $ ( '#token' ) . val ( )
2018-10-03 10:14:57 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2023-04-02 16:58:55 +00:00
if ( data . indexOf ( 'error:' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
2018-10-03 10:14:57 +00:00
} else {
2020-08-07 15:14:59 +00:00
common _ajax _action _after _success ( dialog _id , 'newserver' , 'ajax-servers' , data ) ;
2023-09-17 09:42:39 +00:00
$ ( "input[type=submit], button" ) . button ( ) ;
$ ( "input[type=checkbox]" ) . checkboxradio ( ) ;
$ ( ".controlgroup" ) . controlgroup ( ) ;
$ ( "select" ) . selectmenu ( ) ;
2022-05-05 18:26:14 +00:00
var getId = new RegExp ( 'server-[0-9]+' ) ;
var id = data . match ( getId ) + '' ;
id = id . split ( '-' ) . pop ( ) ;
2023-09-17 09:42:39 +00:00
$ ( 'select:regex(id, git-server)' ) . append ( '<option value=' + id + '>' + $ ( '#hostname-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, backup-server)' ) . append ( '<option value=' + $ ( '#ip-' + id ) . text ( ) + '>' + $ ( '#hostname-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, haproxy_exp_addserv)' ) . append ( '<option value=' + $ ( '#ip-' + id ) . text ( ) + '>' + $ ( '#hostname-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, nginx_exp_addserv)' ) . append ( '<option value=' + $ ( '#ip-' + id ) . text ( ) + '>' + $ ( '#hostname-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, apache_exp_addserv)' ) . append ( '<option value=' + $ ( '#ip-' + id ) . text ( ) + '>' + $ ( '#hostname-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, node_exp_addserv)' ) . append ( '<option value=' + $ ( '#ip-' + id ) . text ( ) + '>' + $ ( '#hostname-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, geoipserv)' ) . append ( '<option value=' + $ ( '#ip-' + id ) . text ( ) + '>' + $ ( '#hostname-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
2023-04-02 16:58:55 +00:00
$ ( 'select:regex(id, haproxyaddserv)' ) . append ( '<option value=' + newip + '>' + servername + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, nginxaddserv)' ) . append ( '<option value=' + newip + '>' + servername + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, apacheaddserv)' ) . append ( '<option value=' + newip + '>' + servername + '</option>' ) . selectmenu ( "refresh" ) ;
after _server _creating ( servername , newip , scan _server ) ;
2018-10-03 10:14:57 +00:00
}
2022-04-08 18:08:31 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-10-03 10:14:57 +00:00
}
}
2023-04-02 16:58:55 +00:00
function after _server _creating ( servername , newip , scan _server ) {
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/create/after" ,
2023-04-02 16:58:55 +00:00
data : {
act : 'after_adding' ,
servername : servername ,
newip : newip ,
scan _server : scan _server ,
token : $ ( '#token' ) . val ( )
} ,
type : "POST" ,
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'You should install lshw on the server' ) != '-1' ) {
toastr . error ( data ) ;
} else if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2023-04-02 16:58:55 +00:00
}
2020-08-07 15:14:59 +00:00
function addCreds ( dialog _id ) {
toastr . clear ( ) ;
var ssh _enable = 0 ;
if ( $ ( '#new-ssh_enable' ) . is ( ':checked' ) ) {
ssh _enable = '1' ;
}
var valid = true ;
2023-09-17 09:42:39 +00:00
allFields = $ ( [ ] ) . add ( $ ( '#new-ssh-add' ) ) . add ( $ ( '#ssh_user' ) )
allFields . removeClass ( "ui-state-error" ) ;
valid = valid && checkLength ( $ ( '#new-ssh-add' ) , "Name" , 1 ) ;
valid = valid && checkLength ( $ ( '#ssh_user' ) , "Credentials" , 1 ) ;
if ( valid ) {
2020-08-07 15:14:59 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/ssh/create" ,
2020-08-07 15:14:59 +00:00
data : {
new _ssh : $ ( '#new-ssh-add' ) . val ( ) ,
new _group : $ ( '#new-sshgroup' ) . val ( ) ,
ssh _user : $ ( '#ssh_user' ) . val ( ) ,
ssh _pass : $ ( '#ssh_pass' ) . val ( ) ,
ssh _enable : ssh _enable ,
2020-08-11 09:54:03 +00:00
page : cur _url [ 0 ] . split ( '#' ) [ 0 ] ,
2020-08-07 15:14:59 +00:00
token : $ ( '#token' ) . val ( )
} ,
type : "POST" ,
success : function ( data ) {
if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
2021-02-03 19:25:37 +00:00
var group _name = getGroupNameById ( $ ( '#new-sshgroup' ) . val ( ) ) ;
2020-08-07 15:14:59 +00:00
var getId = new RegExp ( 'ssh-table-[0-9]+' ) ;
var id = data . match ( getId ) + '' ;
id = id . split ( '-' ) . pop ( ) ;
2023-09-17 09:42:39 +00:00
common _ajax _action _after _success ( dialog _id , 'ssh-table-' + id , 'ssh_enable_table' , data ) ;
2020-08-07 15:14:59 +00:00
$ ( 'select:regex(id, credentials)' ) . append ( '<option value=' + id + '>' + $ ( '#new-ssh-add' ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
2023-09-17 09:42:39 +00:00
$ ( 'select:regex(id, ssh-key-name)' ) . append ( '<option value=' + $ ( '#new-ssh-add' ) . val ( ) + '_' + group _name + '>' + $ ( '#new-ssh-add' ) . val ( ) + '_' + group _name + '</option>' ) . selectmenu ( "refresh" ) ;
2020-08-07 15:14:59 +00:00
$ ( "input[type=submit], button" ) . button ( ) ;
$ ( "input[type=checkbox]" ) . checkboxradio ( ) ;
$ ( "select" ) . selectmenu ( ) ;
}
}
} ) ;
}
}
2021-02-03 19:25:37 +00:00
function getGroupNameById ( group _id ) {
var group _name = ''
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/user/group/name/" + group _id ,
2021-02-03 19:25:37 +00:00
async : false ,
2024-04-19 09:32:13 +00:00
2021-02-03 19:25:37 +00:00
success : function ( data ) {
if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
group _name = data ;
}
}
} ) ;
return group _name ;
}
2018-06-24 09:31:28 +00:00
function sshKeyEnableShow ( id ) {
$ ( '#ssh_enable-' + id ) . click ( function ( ) {
if ( $ ( '#ssh_enable-' + id ) . is ( ':checked' ) ) {
$ ( '#ssh_pass-' + id ) . css ( 'display' , 'none' ) ;
} else {
$ ( '#ssh_pass-' + id ) . css ( 'display' , 'block' ) ;
}
} ) ;
if ( $ ( '#ssh_enable-' + id ) . is ( ':checked' ) ) {
$ ( '#ssh_pass-' + id ) . css ( 'display' , 'none' ) ;
} else {
$ ( '#ssh_pass-' + id ) . css ( 'display' , 'block' ) ;
}
}
2018-05-10 17:25:45 +00:00
function confirmDeleteUser ( id ) {
$ ( "#dialog-confirm" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 400 ,
modal : true ,
2023-02-14 16:46:41 +00:00
title : delete _word + " " + $ ( '#login-' + id ) . val ( ) + "?" ,
buttons : [ {
text : delete _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
removeUser ( id ) ;
}
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ]
2018-05-10 17:25:45 +00:00
} ) ;
}
function confirmDeleteGroup ( id ) {
$ ( "#dialog-confirm" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 400 ,
modal : true ,
2023-02-14 16:46:41 +00:00
title : delete _word + " " + $ ( '#name-' + id ) . val ( ) + "?" ,
buttons : [ {
text : delete _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
removeGroup ( id ) ;
}
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ]
2018-05-10 17:25:45 +00:00
} ) ;
}
function confirmDeleteServer ( id ) {
2023-02-13 14:45:45 +00:00
$ ( "#dialog-confirm" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 400 ,
2024-03-17 06:38:00 +00:00
modal : true ,
title : delete _word + " " + $ ( '#hostname-' + id ) . val ( ) + "?" ,
buttons : [ {
text : delete _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
removeServer ( id ) ;
}
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ]
} ) ;
}
function confirmDeleteSsh ( id ) {
$ ( "#dialog-confirm" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 400 ,
modal : true ,
title : delete _word + " " + $ ( '#ssh_name-' + id ) . val ( ) + "?" ,
buttons : [ {
text : delete _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
removeSsh ( id ) ;
}
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ]
} ) ;
2022-05-05 18:26:14 +00:00
}
2019-02-04 06:37:41 +00:00
function cloneServer ( id ) {
$ ( "#add-server-button" ) . trigger ( "click" ) ;
if ( $ ( '#enable-' + id ) . is ( ':checked' ) ) {
$ ( '#enable' ) . prop ( 'checked' , true )
} else {
$ ( '#enable' ) . prop ( 'checked' , false )
}
if ( $ ( '#typeip-' + id ) . is ( ':checked' ) ) {
$ ( '#typeip' ) . prop ( 'checked' , true )
} else {
$ ( '#typeip' ) . prop ( 'checked' , false )
}
2020-02-06 22:36:58 +00:00
if ( $ ( '#haproxy-' + id ) . is ( ':checked' ) ) {
$ ( '#haproxy' ) . prop ( 'checked' , true )
2019-02-04 06:37:41 +00:00
} else {
2020-02-06 22:36:58 +00:00
$ ( '#haproxy' ) . prop ( 'checked' , false )
2019-02-04 06:37:41 +00:00
}
2020-02-06 22:36:58 +00:00
if ( $ ( '#nginx-' + id ) . is ( ':checked' ) ) {
$ ( '#nginx' ) . prop ( 'checked' , true )
2019-02-04 06:37:41 +00:00
} else {
2020-02-06 22:36:58 +00:00
$ ( '#nginx' ) . prop ( 'checked' , false )
2019-02-04 06:37:41 +00:00
}
$ ( '#enable' ) . checkboxradio ( "refresh" ) ;
$ ( '#typeip' ) . checkboxradio ( "refresh" ) ;
2020-02-06 22:36:58 +00:00
$ ( '#haproxy' ) . checkboxradio ( "refresh" ) ;
$ ( '#nginx' ) . checkboxradio ( "refresh" ) ;
2019-02-04 06:37:41 +00:00
$ ( '#new-server-add' ) . val ( $ ( '#hostname-' + id ) . val ( ) )
$ ( '#new-ip' ) . val ( $ ( '#ip-' + id ) . val ( ) )
$ ( '#new-port' ) . val ( $ ( '#port-' + id ) . val ( ) )
$ ( '#desc' ) . val ( $ ( '#desc-' + id ) . val ( ) )
$ ( '#slavefor' ) . val ( $ ( '#slavefor-' + id + ' option:selected' ) . val ( ) ) . change ( )
$ ( '#slavefor' ) . selectmenu ( "refresh" ) ;
$ ( '#credentials' ) . val ( $ ( '#credentials-' + id + ' option:selected' ) . val ( ) ) . change ( )
$ ( '#credentials' ) . selectmenu ( "refresh" ) ;
2023-09-20 10:11:10 +00:00
if ( cur _url [ 0 ] . indexOf ( 'admin' ) != '-1' ) {
2019-10-09 06:35:35 +00:00
$ ( '#new-server-group-add' ) . val ( $ ( '#servergroup-' + id + ' option:selected' ) . val ( ) ) . change ( )
$ ( '#new-server-group-add' ) . selectmenu ( "refresh" ) ;
}
2019-02-04 06:37:41 +00:00
}
2018-04-16 07:01:44 +00:00
function removeUser ( id ) {
2023-09-17 09:42:39 +00:00
$ ( "#user-" + id ) . css ( "background-color" , "#f2dede" ) ;
$ . ajax ( {
url : "/app/user/delete/" + id ,
2024-04-19 09:32:13 +00:00
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data == "ok" ) {
$ ( "#user-" + id ) . remove ( ) ;
2020-08-07 17:02:02 +00:00
} else if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
toastr . error ( data ) ;
2018-05-10 17:25:45 +00:00
}
2022-04-08 18:08:31 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-05-10 17:25:45 +00:00
}
2018-04-16 07:01:44 +00:00
function removeServer ( id ) {
2023-09-17 09:42:39 +00:00
$ ( "#server-" + id ) . css ( "background-color" , "#f2dede" ) ;
$ . ajax ( {
url : "/app/server/delete/" + id ,
2024-04-19 09:32:13 +00:00
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data == "Ok" ) {
$ ( "#server-" + id ) . remove ( ) ;
2020-08-08 06:26:43 +00:00
} else if ( data . indexOf ( 'error: ' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
2020-08-07 17:02:02 +00:00
toastr . error ( data ) ;
2020-08-08 06:26:43 +00:00
} else if ( data . indexOf ( 'warning: ' ) != '-1' ) {
toastr . clear ( ) ;
toastr . warning ( data ) ;
2018-05-10 17:25:45 +00:00
}
2022-04-08 18:08:31 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-05-10 17:25:45 +00:00
}
2018-04-16 07:01:44 +00:00
function removeGroup ( id ) {
2023-09-17 09:42:39 +00:00
$ ( "#group-" + id ) . css ( "background-color" , "#f2dede" ) ;
$ . ajax ( {
url : "/app/server/group/delete/" + id ,
2024-04-19 09:32:13 +00:00
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data == "ok" ) {
$ ( "#group-" + id ) . remove ( ) ;
$ ( 'select:regex(id, group) option[value=' + id + ']' ) . remove ( ) ;
2018-05-10 17:25:45 +00:00
$ ( 'select:regex(id, group)' ) . selectmenu ( "refresh" ) ;
2020-08-07 17:02:02 +00:00
} else if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
toastr . error ( data ) ;
2018-05-10 17:25:45 +00:00
}
2022-04-08 18:08:31 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-05-10 17:25:45 +00:00
}
2018-06-24 09:31:28 +00:00
function removeSsh ( id ) {
$ ( "#ssh-table-" + id ) . css ( "background-color" , "#f2dede" ) ;
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/ssh/delete/" + id ,
2024-04-19 09:32:13 +00:00
2018-06-24 09:31:28 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2023-09-17 09:42:39 +00:00
if ( data == "ok" ) {
2018-06-24 09:31:28 +00:00
$ ( "#ssh-table-" + id ) . remove ( ) ;
$ ( 'select:regex(id, credentials) option[value=' + id + ']' ) . remove ( ) ;
$ ( 'select:regex(id, credentials)' ) . selectmenu ( "refresh" ) ;
2020-08-07 17:02:02 +00:00
} else if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
toastr . error ( data ) ;
2018-06-24 09:31:28 +00:00
}
2022-04-08 18:08:31 +00:00
}
} ) ;
2018-06-24 09:31:28 +00:00
}
2018-04-16 07:01:44 +00:00
function updateUser ( id ) {
2020-07-26 16:26:04 +00:00
toastr . remove ( ) ;
2018-11-26 12:55:00 +00:00
cur _url [ 0 ] = cur _url [ 0 ] . split ( '#' ) [ 0 ]
2020-05-10 06:17:07 +00:00
var usergroup = Cookies . get ( 'group' ) ;
2023-09-17 09:42:39 +00:00
var role = $ ( '#role-' + id ) . val ( ) ;
2019-01-05 12:36:59 +00:00
var activeuser = 0 ;
2023-09-17 09:42:39 +00:00
if ( $ ( '#activeuser-' + id ) . is ( ':checked' ) ) {
2019-01-05 12:36:59 +00:00
activeuser = '1' ;
}
2023-09-17 09:42:39 +00:00
if ( role == null && role !== undefined ) {
2024-05-13 09:08:51 +00:00
toastr . warning ( 'You cannot edit superAdmin user' ) ;
2021-08-24 10:12:52 +00:00
return false ;
}
toastr . remove ( ) ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/user/update" ,
2018-04-16 07:01:44 +00:00
data : {
2023-09-17 09:42:39 +00:00
updateuser : $ ( '#login-' + id ) . val ( ) ,
email : $ ( '#email-' + id ) . val ( ) ,
2021-08-24 10:12:52 +00:00
role : role ,
2018-09-28 16:10:01 +00:00
usergroup : usergroup ,
2019-01-05 12:36:59 +00:00
activeuser : activeuser ,
2019-09-27 19:09:49 +00:00
id : id ,
token : $ ( '#token' ) . val ( )
2018-04-16 07:01:44 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2020-08-07 17:02:02 +00:00
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
2018-04-20 04:39:39 +00:00
} else {
2020-07-26 16:26:04 +00:00
toastr . remove ( ) ;
2023-09-17 09:42:39 +00:00
$ ( "#user-" + id ) . addClass ( "update" , 1000 ) ;
setTimeout ( function ( ) {
$ ( "#user-" + id ) . removeClass ( "update" ) ;
} , 2500 ) ;
2018-04-16 07:01:44 +00:00
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-04-16 07:01:44 +00:00
}
function updateGroup ( id ) {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/server/group/update" ,
2018-04-16 07:01:44 +00:00
data : {
2023-09-17 09:42:39 +00:00
updategroup : $ ( '#name-' + id ) . val ( ) ,
descript : $ ( '#descript-' + id ) . val ( ) ,
2019-09-27 19:09:49 +00:00
id : id ,
token : $ ( '#token' ) . val ( )
2018-04-16 07:01:44 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2020-08-07 17:02:02 +00:00
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
2018-04-20 04:39:39 +00:00
} else {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
$ ( "#group-" + id ) . addClass ( "update" , 1000 ) ;
setTimeout ( function ( ) {
$ ( "#group-" + id ) . removeClass ( "update" ) ;
} , 2500 ) ;
$ ( 'select:regex(id, group) option[value=' + id + ']' ) . remove ( ) ;
$ ( 'select:regex(id, group)' ) . append ( '<option value=' + id + '>' + $ ( '#name-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
2018-04-16 07:01:44 +00:00
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-04-16 07:01:44 +00:00
}
function updateServer ( id ) {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2022-04-08 18:08:31 +00:00
let typeip = 0 ;
let enable = 0 ;
let firewall = 0 ;
let protected _serv = 0 ;
2023-09-17 09:42:39 +00:00
if ( $ ( '#typeip-' + id ) . is ( ':checked' ) ) {
2018-04-17 20:06:18 +00:00
typeip = '1' ;
}
2023-09-17 09:42:39 +00:00
if ( $ ( '#enable-' + id ) . is ( ':checked' ) ) {
2018-04-19 05:22:44 +00:00
enable = '1' ;
}
2023-09-17 09:42:39 +00:00
if ( $ ( '#firewall-' + id ) . is ( ':checked' ) ) {
2020-11-18 04:45:34 +00:00
firewall = '1' ;
}
2023-09-17 09:42:39 +00:00
if ( $ ( '#protected-' + id ) . is ( ':checked' ) ) {
2021-05-16 05:27:47 +00:00
protected _serv = '1' ;
}
2023-09-17 09:42:39 +00:00
var servergroup = $ ( '#servergroup-' + id + ' option:selected' ) . val ( ) ;
2023-09-20 13:43:15 +00:00
if ( cur _url [ 0 ] . indexOf ( 'servers#' ) != '-1' ) {
2023-09-17 09:42:39 +00:00
servergroup = $ ( '#new-server-group-add' ) . val ( ) ;
2018-07-25 05:25:27 +00:00
}
2023-09-17 09:42:39 +00:00
$ . ajax ( {
2023-09-19 11:14:46 +00:00
url : "/app/server/update" ,
2018-04-16 07:01:44 +00:00
data : {
2023-09-17 09:42:39 +00:00
updateserver : $ ( '#hostname-' + id ) . val ( ) ,
port : $ ( '#port-' + id ) . val ( ) ,
2018-07-25 05:25:27 +00:00
servergroup : servergroup ,
2018-04-17 20:06:18 +00:00
typeip : typeip ,
2020-11-18 04:45:34 +00:00
firewall : firewall ,
2018-04-19 05:22:44 +00:00
enable : enable ,
2023-09-17 09:42:39 +00:00
slave : $ ( '#slavefor-' + id + ' option:selected' ) . val ( ) ,
cred : $ ( '#credentials-' + id + ' option:selected' ) . val ( ) ,
2018-07-23 07:08:43 +00:00
id : id ,
2023-09-17 09:42:39 +00:00
desc : $ ( '#desc-' + id ) . val ( ) ,
2021-05-16 05:27:47 +00:00
protected : protected _serv ,
2019-09-27 19:09:49 +00:00
token : $ ( '#token' ) . val ( )
2018-04-16 07:01:44 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2020-08-07 17:02:02 +00:00
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
2018-04-20 04:39:39 +00:00
} else {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
$ ( "#server-" + id ) . addClass ( "update" , 1000 ) ;
setTimeout ( function ( ) {
$ ( "#server-" + id ) . removeClass ( "update" ) ;
} , 2500 ) ;
2018-04-16 07:01:44 +00:00
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-04-21 14:40:59 +00:00
}
2018-04-26 13:03:48 +00:00
function uploadSsh ( ) {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
if ( $ ( "#ssh-key-name option:selected" ) . val ( ) == "------" || $ ( '#ssh_cert' ) . val ( ) == '' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( 'All fields must be completed' ) ;
2018-09-14 14:15:17 +00:00
} else {
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/server/ssh/upload" ,
2018-09-14 14:15:17 +00:00
data : {
ssh _cert : $ ( '#ssh_cert' ) . val ( ) ,
name : $ ( '#ssh-key-name' ) . val ( ) ,
2024-02-04 07:28:17 +00:00
pass : $ ( '#ssh-key-pass' ) . val ( ) ,
2018-09-14 14:15:17 +00:00
token : $ ( '#token' ) . val ( )
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'danger' ) != '-1' || data . indexOf ( 'unique' ) != '-1' || data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else if ( data . indexOf ( 'success' ) != '-1' ) {
toastr . clear ( ) ;
toastr . success ( data )
} else {
toastr . error ( 'Something wrong, check and try again' ) ;
}
2018-09-14 14:15:17 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-09-14 14:15:17 +00:00
}
2018-05-07 13:24:22 +00:00
}
2018-06-24 09:31:28 +00:00
function updateSSH ( id ) {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2018-05-07 13:24:22 +00:00
var ssh _enable = 0 ;
2023-09-17 09:42:39 +00:00
if ( $ ( '#ssh_enable-' + id ) . is ( ':checked' ) ) {
2018-05-07 13:24:22 +00:00
ssh _enable = '1' ;
}
2023-09-17 09:42:39 +00:00
var group = $ ( '#sshgroup-' + id ) . val ( ) ;
2023-09-20 10:11:10 +00:00
if ( cur _url [ 0 ] . indexOf ( 'servers' ) != '-1' ) {
2023-09-17 09:42:39 +00:00
group = $ ( '#new-server-group-add' ) . val ( ) ;
2020-04-06 16:38:58 +00:00
}
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/server/ssh/update" ,
2018-05-07 13:24:22 +00:00
data : {
2023-09-17 09:42:39 +00:00
name : $ ( '#ssh_name-' + id ) . val ( ) ,
2020-04-06 16:38:58 +00:00
group : group ,
2018-05-07 13:24:22 +00:00
ssh _enable : ssh _enable ,
2023-09-17 09:42:39 +00:00
ssh _user : $ ( '#ssh_user-' + id ) . val ( ) ,
ssh _pass : $ ( '#ssh_pass-' + id ) . val ( ) ,
2019-09-27 19:09:49 +00:00
id : id ,
token : $ ( '#token' ) . val ( )
2018-05-07 13:24:22 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2020-08-07 17:02:02 +00:00
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
2018-05-07 13:24:22 +00:00
} else {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
$ ( "#ssh-table-" + id ) . addClass ( "update" , 1000 ) ;
setTimeout ( function ( ) {
$ ( "#ssh-table-" + id ) . removeClass ( "update" ) ;
} , 2500 ) ;
$ ( 'select:regex(id, credentials) option[value=' + id + ']' ) . remove ( ) ;
$ ( 'select:regex(id, ssh-key-name) option[value=' + $ ( '#ssh_name-' + id ) . val ( ) + ']' ) . remove ( ) ;
$ ( 'select:regex(id, credentials)' ) . append ( '<option value=' + id + '>' + $ ( '#ssh_name-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
$ ( 'select:regex(id, ssh-key-name)' ) . append ( '<option value=' + $ ( '#ssh_name-' + id ) . val ( ) + '>' + $ ( '#ssh_name-' + id ) . val ( ) + '</option>' ) . selectmenu ( "refresh" ) ;
2018-05-07 13:24:22 +00:00
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2018-05-07 19:09:56 +00:00
}
2018-07-24 04:08:06 +00:00
function showApacheLog ( serv ) {
2023-09-17 09:42:39 +00:00
var rows = $ ( '#rows' ) . val ( ) ;
var grep = $ ( '#grep' ) . val ( ) ;
var exgrep = $ ( '#exgrep' ) . val ( ) ;
var hour = $ ( '#time_range_out_hour' ) . val ( ) ;
var minute = $ ( '#time_range_out_minut' ) . val ( ) ;
var hour1 = $ ( '#time_range_out_hour1' ) . val ( ) ;
var minute1 = $ ( '#time_range_out_minut1' ) . val ( ) ;
var url = "/app/logs/apache_internal/" + serv + "/" + rows ;
2018-05-07 19:09:56 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : url ,
2018-05-07 19:09:56 +00:00
data : {
2023-09-17 09:42:39 +00:00
rows : rows ,
2018-07-24 04:08:06 +00:00
serv : serv ,
2019-09-29 20:16:24 +00:00
grep : grep ,
2020-06-15 17:29:49 +00:00
exgrep : exgrep ,
2019-09-29 20:16:24 +00:00
hour : hour ,
2023-09-17 09:42:39 +00:00
minute : minute ,
2019-09-29 20:16:24 +00:00
hour1 : hour1 ,
2023-09-17 09:42:39 +00:00
minute1 : minute1 ,
2018-06-01 12:27:58 +00:00
token : $ ( '#token' ) . val ( )
2018-05-07 19:09:56 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2018-05-07 19:09:56 +00:00
success : function ( data ) {
$ ( "#ajax" ) . html ( data ) ;
2022-04-08 18:08:31 +00:00
}
2018-05-07 19:09:56 +00:00
} ) ;
2018-10-01 16:51:37 +00:00
}
function checkSshConnect ( ip ) {
2024-02-17 12:28:34 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/check/ssh/" + ip ,
2024-04-19 09:32:13 +00:00
2024-02-17 12:28:34 +00:00
success : function ( data ) {
2020-07-30 17:28:58 +00:00
if ( data . indexOf ( 'error:' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data )
2024-02-17 12:28:34 +00:00
} else if ( data . indexOf ( 'failed' ) != '-1' ) {
2021-07-21 04:57:58 +00:00
toastr . error ( data )
2024-02-17 12:28:34 +00:00
} else if ( data . indexOf ( 'Errno' ) != '-1' ) {
2021-08-15 09:02:12 +00:00
toastr . error ( data )
2018-10-01 16:51:37 +00:00
} else {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
toastr . success ( 'Connect is accepted' ) ;
2018-10-01 16:51:37 +00:00
}
2022-04-08 18:08:31 +00:00
}
2024-02-17 12:28:34 +00:00
} ) ;
2019-09-26 15:48:56 +00:00
}
function openChangeUserPasswordDialog ( id ) {
changeUserPasswordDialog ( id ) ;
}
2021-08-15 09:02:12 +00:00
function openChangeUserServiceDialog ( id ) {
changeUserServiceDialog ( id ) ;
}
2019-09-26 15:48:56 +00:00
function changeUserPasswordDialog ( id ) {
2023-02-13 14:45:45 +00:00
var cancel _word = $ ( '#translate' ) . attr ( 'data-cancel' ) ;
var superAdmin _pass = $ ( '#translate' ) . attr ( 'data-superAdmin_pass' ) ;
var change _word = $ ( '#translate' ) . attr ( 'data-change2' ) ;
var password _word = $ ( '#translate' ) . attr ( 'data-password' ) ;
2022-11-03 08:45:50 +00:00
if ( $ ( '#role-' + id + ' option:selected' ) . val ( ) == 'Select a role' ) {
2023-02-13 14:45:45 +00:00
toastr . warning ( superAdmin _pass ) ;
2022-11-03 08:45:50 +00:00
return false ;
}
2019-09-26 15:48:56 +00:00
$ ( "#user-change-password-table" ) . dialog ( {
2023-09-17 09:42:39 +00:00
autoOpen : true ,
resizable : false ,
height : "auto" ,
width : 600 ,
modal : true ,
title : change _word + " " + $ ( '#login-' + id ) . val ( ) + " " + password _word ,
show : {
effect : "fade" ,
duration : 200
} ,
hide : {
effect : "fade" ,
duration : 200
} ,
buttons : [ {
text : change _word ,
click : function ( ) {
changeUserPassword ( id , $ ( this ) ) ;
}
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
$ ( '#missmatchpass' ) . hide ( ) ;
}
} ]
} ) ;
2019-09-26 15:48:56 +00:00
}
function changeUserPassword ( id , d ) {
var pass = $ ( '#change-password' ) . val ( ) ;
var pass2 = $ ( '#change2-password' ) . val ( ) ;
2023-09-17 09:42:39 +00:00
if ( pass != pass2 ) {
2019-09-26 15:48:56 +00:00
$ ( '#missmatchpass' ) . show ( ) ;
} else {
$ ( '#missmatchpass' ) . hide ( ) ;
2020-07-30 17:28:58 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/user/password" ,
2019-09-26 15:48:56 +00:00
data : {
updatepassowrd : pass ,
2019-09-27 19:09:49 +00:00
id : id ,
token : $ ( '#token' ) . val ( )
2019-09-26 15:48:56 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2020-07-30 17:28:58 +00:00
if ( data . indexOf ( 'error:' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
2019-09-26 15:48:56 +00:00
} else {
2020-07-26 16:26:04 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
$ ( "#user-" + id ) . addClass ( "update" , 1000 ) ;
setTimeout ( function ( ) {
$ ( "#user-" + id ) . removeClass ( "update" ) ;
} , 2500 ) ;
d . dialog ( "close" ) ;
2019-09-26 15:48:56 +00:00
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2019-09-26 15:48:56 +00:00
}
2020-05-10 06:17:07 +00:00
}
2021-08-15 09:02:12 +00:00
function changeUserServiceDialog ( id ) {
2023-02-13 14:45:45 +00:00
var cancel _word = $ ( '#translate' ) . attr ( 'data-cancel' ) ;
var manage _word = $ ( '#translate' ) . attr ( 'data-manage' ) ;
var services _word = $ ( '#translate' ) . attr ( 'data-services3' ) ;
var save _word = $ ( '#translate' ) . attr ( 'data-save' ) ;
var superAdmin _services = $ ( '#translate' ) . attr ( 'data-superAdmin_services' ) ;
2023-09-17 09:42:39 +00:00
if ( $ ( '#role-' + id + ' option:selected' ) . val ( ) == 'Select a role' ) {
2023-02-13 14:45:45 +00:00
toastr . warning ( superAdmin _services ) ;
2022-11-03 08:45:50 +00:00
return false ;
}
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/user/services/" + id ,
2024-04-19 09:32:13 +00:00
2023-09-17 09:42:39 +00:00
success : function ( data ) {
2021-08-15 09:02:12 +00:00
if ( data . indexOf ( 'danger' ) != '-1' ) {
toastr . error ( data ) ;
} else {
toastr . clear ( ) ;
$ ( '#change-user-service-form' ) . html ( data ) ;
2023-09-17 09:42:39 +00:00
$ ( "#change-user-service-dialog" ) . dialog ( {
2021-08-15 09:02:12 +00:00
resizable : false ,
height : "auto" ,
2023-03-04 07:42:26 +00:00
width : 700 ,
2021-08-15 09:02:12 +00:00
modal : true ,
2023-09-17 09:42:39 +00:00
title : manage _word + " " + $ ( '#login-' + id ) . val ( ) + " " + services _word ,
2023-02-13 14:45:45 +00:00
buttons : [ {
text : save _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
2021-08-15 09:02:12 +00:00
changeUserServices ( id ) ;
}
2023-02-13 14:45:45 +00:00
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ]
2021-08-15 09:02:12 +00:00
} ) ;
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2021-08-15 09:02:12 +00:00
}
2023-03-04 07:42:26 +00:00
function changeUserServices ( user _id ) {
var jsonData = { } ;
jsonData [ user _id ] = { } ;
$ ( '#checked_services tbody tr' ) . each ( function ( ) {
var this _id = $ ( this ) . attr ( 'id' ) . split ( '-' ) [ 1 ] ;
jsonData [ user _id ] [ this _id ] = { }
} ) ;
2021-08-15 09:02:12 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/user/services/" + user _id ,
2021-08-15 09:02:12 +00:00
data : {
2023-03-04 07:42:26 +00:00
jsonDatas : JSON . stringify ( jsonData ) ,
changeUserServicesUser : $ ( '#login-' + user _id ) . val ( ) ,
2021-08-15 09:02:12 +00:00
token : $ ( '#token' ) . val ( )
} ,
type : "POST" ,
success : function ( data ) {
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'Failed' ) != '-1' ) {
toastr . error ( data ) ;
} else {
2023-03-04 07:42:26 +00:00
$ ( "#user-" + user _id ) . addClass ( "update" , 1000 ) ;
2021-08-15 09:02:12 +00:00
setTimeout ( function ( ) {
2023-03-04 07:42:26 +00:00
$ ( "#user-" + user _id ) . removeClass ( "update" ) ;
2021-08-15 09:02:12 +00:00
} , 2500 ) ;
}
}
} ) ;
}
2023-03-04 07:42:26 +00:00
function addServiceToUser ( service _id ) {
var service _name = $ ( '#add_service-' + service _id ) . attr ( 'data-service_name' ) ;
var service _word = $ ( '#translate' ) . attr ( 'data-service' ) ;
var length _tr = $ ( '#checked_services tbody tr' ) . length ;
var tr _class = 'odd' ;
if ( length _tr % 2 != 0 ) {
tr _class = 'even' ;
}
var html _tag = '<tr class="' + tr _class + '" id="remove_service-' + service _id + '" data-service_name="' + service _name + '">' +
'<td class="padding20" style="width: 100%;">' + service _name + '</td>' +
2023-03-04 12:42:26 +00:00
'<td><span class="add_user_group" onclick="removeServiceFromUser(' + service _id + ')" title="' + delete _word + ' ' + service _word + '">-</span></td></tr>' ;
2023-03-04 07:42:26 +00:00
$ ( '#add_service-' + service _id ) . remove ( ) ;
$ ( "#checked_services tbody" ) . append ( html _tag ) ;
}
function removeServiceFromUser ( service _id ) {
var service _name = $ ( '#remove_service-' + service _id ) . attr ( 'data-service_name' ) ;
var service _word = $ ( '#translate' ) . attr ( 'data-service' ) ;
var length _tr = $ ( '#all_services tbody tr' ) . length ;
var tr _class = 'odd' ;
if ( length _tr % 2 != 0 ) {
tr _class = 'even' ;
}
var html _tag = '<tr class="' + tr _class + '" id="add_service-' + service _id + '" data-service_name="' + service _name + '">' +
'<td class="padding20" style="width: 100%;">' + service _name + '</td>' +
'<td><span class="add_user_group" onclick="addServiceToUser(' + service _id + ')" title="' + add _word + ' ' + service _word + '">+</span></td></tr>' ;
$ ( '#remove_service-' + service _id ) . remove ( ) ;
$ ( "#all_services tbody" ) . append ( html _tag ) ;
2020-05-12 18:57:05 +00:00
}
function confirmAjaxServiceAction ( action , service ) {
2024-02-16 06:50:27 +00:00
let cancel _word = $ ( '#translate' ) . attr ( 'data-cancel' ) ;
let action _word = $ ( '#translate' ) . attr ( 'data-' + action ) ;
2020-05-12 18:57:05 +00:00
$ ( "#dialog-confirm-services" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 400 ,
modal : true ,
2023-03-03 20:03:41 +00:00
title : action _word + " " + service + "?" ,
buttons : [ {
text : action _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
2024-02-16 06:50:27 +00:00
ajaxActionServices ( action , service ) ;
2023-03-03 20:03:41 +00:00
}
} , {
text : cancel _word ,
click : function ( ) {
2020-05-12 18:57:05 +00:00
$ ( this ) . dialog ( "close" ) ;
}
2023-03-03 20:03:41 +00:00
} ]
2020-05-12 18:57:05 +00:00
} ) ;
}
2024-02-16 06:50:27 +00:00
function ajaxActionServices ( action , service ) {
2020-05-12 18:57:05 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/admin/tools/action/" + service + "/" + action ,
2020-05-12 18:57:05 +00:00
success : function ( data ) {
2021-02-20 07:47:33 +00:00
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'Failed' ) != '-1' ) {
toastr . error ( data ) ;
2022-04-27 18:10:26 +00:00
} else if ( data . indexOf ( 'warning: ' ) != '-1' ) {
toastr . warning ( data ) ;
2021-02-20 07:47:33 +00:00
} else {
2023-09-17 09:42:39 +00:00
window . history . pushState ( "services" , "services" , cur _url [ 0 ] . split ( "#" ) [ 0 ] + "#tools" ) ;
2021-04-16 14:09:51 +00:00
toastr . success ( 'The ' + service + ' has been ' + action + 'ed' ) ;
2021-02-20 07:47:33 +00:00
loadServices ( ) ;
}
2020-05-12 18:57:05 +00:00
} ,
error : function ( ) {
alert ( w . data _error ) ;
2022-04-08 18:08:31 +00:00
}
2020-05-12 18:57:05 +00:00
} ) ;
2020-09-24 05:01:48 +00:00
}
2022-06-16 19:58:01 +00:00
function updateService ( service , action = 'update' ) {
2020-09-24 05:01:48 +00:00
$ ( "#ajax-update" ) . html ( '' )
2021-05-16 05:27:47 +00:00
$ ( "#ajax-update" ) . html ( wait _mess ) ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/admin/tools/update/" + service ,
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'Complete!' ) != '-1' || data . indexOf ( 'Unpacking' ) != '-1' ) {
2020-09-24 05:01:48 +00:00
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
toastr . success ( service + ' has been ' + action + 'ed' ) ;
2022-06-18 07:49:42 +00:00
} else if ( data . indexOf ( 'Unauthorized' ) != '-1' || data . indexOf ( 'Status code: 401' ) != '-1' ) {
2020-09-24 05:01:48 +00:00
toastr . clear ( ) ;
2023-09-20 10:11:10 +00:00
toastr . error ( 'It looks like there is no authorization in the Roxy-WI repository. Your subscription may have expired or there is no subscription. How to get the <b><a href="https://roxy-wi.org/pricing" title="Pricing" target="_blank">subscription</a></b>' ) ;
2020-09-24 05:01:48 +00:00
} else if ( data . indexOf ( 'but not installed' ) != '-1' ) {
toastr . clear ( ) ;
2022-06-16 19:58:01 +00:00
toastr . error ( 'There is setting for Roxy-WI repository, but Roxy-WI is installed without repository. Please reinstall with package manager' ) ;
2022-06-18 07:49:42 +00:00
} else if ( data . indexOf ( 'No Match for argument' ) != '-1' || data . indexOf ( 'Unable to find a match' ) != '-1' ) {
2020-09-24 05:01:48 +00:00
toastr . clear ( ) ;
2023-09-20 10:11:10 +00:00
toastr . error ( 'It seems like Roxy-WI repository is not set. Please read docs for <b><a href="https://roxy-wi.org/updates">detail</a></b>' ) ;
2020-09-24 05:01:48 +00:00
} else if ( data . indexOf ( 'password for' ) != '-1' ) {
toastr . clear ( ) ;
2023-09-20 10:11:10 +00:00
toastr . error ( 'It seems like apache user needs to be add to sudoers. Please read docs for <b><a href="https://roxy-wi.org/installation#ansible">detail</a></b>' ) ;
2020-09-24 05:01:48 +00:00
} else if ( data . indexOf ( 'No packages marked for update' ) != '-1' ) {
toastr . clear ( ) ;
2021-06-02 07:28:07 +00:00
toastr . info ( 'It seems like the lastest version Roxy-WI is installed' ) ;
2020-09-24 05:01:48 +00:00
} else if ( data . indexOf ( 'Connection timed out' ) != '-1' ) {
toastr . clear ( ) ;
2021-06-02 07:28:07 +00:00
toastr . error ( 'Cannot connect to Roxy-WI repository. Connection timed out' ) ;
2020-09-24 05:01:48 +00:00
} else if ( data . indexOf ( '--disable' ) != '-1' ) {
toastr . clear ( ) ;
2020-11-19 20:11:08 +00:00
toastr . error ( 'It seems like there is a problem with repositories' ) ;
2020-09-24 05:01:48 +00:00
} else if ( data . indexOf ( 'Error: Package' ) != '-1' ) {
toastr . clear ( ) ;
toastr . error ( data ) ;
} else if ( data . indexOf ( 'conflicts with file from' ) != '-1' ) {
toastr . clear ( ) ;
toastr . error ( data ) ;
2022-06-18 07:49:42 +00:00
} else if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'Failed' ) != '-1' ) {
toastr . error ( data ) ;
2023-10-24 19:21:19 +00:00
} else if ( data . indexOf ( '0 upgraded, 0 newly installed' ) != '-1' ) {
toastr . info ( 'There is no a new version of ' + service ) ;
} else {
toastr . clear ( ) ;
toastr . success ( service + ' has been ' + action + 'ed' ) ;
2020-09-24 05:01:48 +00:00
}
2021-02-20 07:47:33 +00:00
$ ( "#ajax-update" ) . html ( '' ) ;
loadupdatehapwi ( ) ;
2023-10-16 15:35:26 +00:00
loadServices ( ) ;
2023-08-03 06:56:25 +00:00
show _version ( ) ;
2020-09-24 05:01:48 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2020-10-09 15:56:16 +00:00
}
function confirmDeleteOpenVpnProfile ( id ) {
$ ( "#dialog-confirm" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 400 ,
modal : true ,
title : "Are you sure you want to delete profile " + id + "?" ,
buttons : {
"Delete" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
removeOpenVpnProfile ( id ) ;
} ,
Cancel : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
}
} ) ;
}
function removeOpenVpnProfile ( id ) {
2023-09-17 09:42:39 +00:00
$ ( "#" + id ) . css ( "background-color" , "#f2dede" ) ;
$ . ajax ( {
url : "/app/admin/openvpn/delete" ,
2020-10-09 15:56:16 +00:00
data : {
openvpndel : id ,
token : $ ( '#token' ) . val ( )
} ,
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data == "ok" ) {
$ ( "#" + id ) . remove ( ) ;
2020-10-09 15:56:16 +00:00
} else if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'unique' ) != '-1' ) {
toastr . error ( data ) ;
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2020-10-09 15:56:16 +00:00
}
function uploadOvpn ( ) {
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
if ( $ ( "#ovpn_upload_name" ) . val ( ) == '' || $ ( '#ovpn_upload_file' ) . val ( ) == '' ) {
2020-10-09 15:56:16 +00:00
toastr . error ( 'All fields must be completed' ) ;
} else {
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/admin/openvpn/upload" ,
2020-10-09 15:56:16 +00:00
data : {
uploadovpn : $ ( '#ovpn_upload_file' ) . val ( ) ,
ovpnname : $ ( '#ovpn_upload_name' ) . val ( ) ,
token : $ ( '#token' ) . val ( )
} ,
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'danger' ) != '-1' || data . indexOf ( 'unique' ) != '-1' || data . indexOf ( 'error:' ) != '-1' ) {
2020-10-09 15:56:16 +00:00
toastr . error ( data ) ;
} else if ( data . indexOf ( 'success' ) != '-1' ) {
toastr . clear ( ) ;
2023-12-16 07:15:59 +00:00
toastr . success ( data ) ;
location . reload ( ) ;
2020-10-09 15:56:16 +00:00
} else {
toastr . error ( 'Something wrong, check and try again' ) ;
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2020-10-09 15:56:16 +00:00
}
}
function OpenVpnSess ( id , action ) {
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/admin/openvpn/" + action + "/" + id ,
2020-10-09 15:56:16 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'danger' ) != '-1' || data . indexOf ( 'unique' ) != '-1' || data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else if ( data . indexOf ( 'success' ) != '-1' ) {
toastr . clear ( ) ;
toastr . success ( data )
location . reload ( )
} else {
toastr . error ( 'Something wrong, check and try again' ) ;
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2020-11-02 17:01:08 +00:00
}
2023-09-17 09:42:39 +00:00
function viewFirewallRules ( ip ) {
2020-11-19 20:11:08 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/firewall/" + ip ,
2024-04-19 09:32:13 +00:00
2020-11-19 20:11:08 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
2021-01-22 04:01:08 +00:00
if ( data . indexOf ( 'danger' ) != '-1' || data . indexOf ( 'unique' ) != '-1' || data . indexOf ( 'error: ' ) != '-1' ) {
2020-11-19 20:11:08 +00:00
toastr . error ( data ) ;
} else {
toastr . clear ( ) ;
$ ( "#firewall_rules_body" ) . html ( data ) ;
$ ( "#firewall_rules" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 860 ,
modal : true ,
title : "Firewall rules" ,
buttons : {
Close : function ( ) {
$ ( this ) . dialog ( "close" ) ;
$ ( "#firewall_rules_body" ) . html ( '' ) ;
}
}
} ) ;
}
}
} ) ;
}
2024-05-03 12:22:58 +00:00
function loadSettings ( ) {
$ . ajax ( {
url : "/app/admin/settings" ,
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
$ ( '#settings' ) . html ( data ) ;
$ . getScript ( awesome ) ;
$ ( "input[type=checkbox]" ) . checkboxradio ( ) ;
$ ( "select" ) . selectmenu ( ) ;
}
}
} ) ;
}
2021-02-20 07:47:33 +00:00
function loadServices ( ) {
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/admin/tools" ,
2021-02-20 07:47:33 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'danger' ) != '-1' || data . indexOf ( 'unique' ) != '-1' || data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
$ ( '#ajax-services-body' ) . html ( data ) ;
$ . getScript ( awesome ) ;
}
}
} ) ;
}
function loadupdatehapwi ( ) {
$ . ajax ( {
2023-09-30 08:48:54 +00:00
url : "/app/admin/update" ,
2021-02-20 07:47:33 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'danger' ) != '-1' || data . indexOf ( 'unique' ) != '-1' || data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
$ ( '#ajax-updatehapwi-body' ) . html ( data ) ;
}
}
} ) ;
}
2023-10-16 15:35:26 +00:00
function checkUpdateRoxy ( ) {
$ . ajax ( {
url : "/app/admin/update/check" ,
success : function ( data ) {
loadupdatehapwi ( ) ;
}
} ) ;
}
2021-02-20 07:47:33 +00:00
function loadopenvpn ( ) {
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/admin/openvpn" ,
2021-02-20 07:47:33 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'group_error' ) == '-1' && data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
$ ( '#openvpn' ) . html ( data ) ;
$ . getScript ( awesome ) ;
}
}
} ) ;
}
2021-12-03 10:39:15 +00:00
function updateServerInfo ( ip , id ) {
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/system_info/update/" + ip + "/" + id ,
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'error_code' ) != '-1' ) {
toastr . error ( data ) ;
} else {
$ ( "#server_info-" + id ) . html ( data ) ;
$ ( '#server_info-' + id ) . show ( ) ;
$ ( '#server_info_link-' + id ) . attr ( 'title' , 'Hide System info' ) ;
$ . getScript ( awesome ) ;
2021-12-03 10:39:15 +00:00
}
2023-09-17 09:42:39 +00:00
}
} ) ;
2021-12-03 10:39:15 +00:00
}
function showServerInfo ( id , ip ) {
2023-02-17 17:21:19 +00:00
var close _word = $ ( '#translate' ) . attr ( 'data-close' ) ;
var server _info = $ ( '#translate' ) . attr ( 'data-server_info' ) ;
2023-01-24 07:34:14 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/system_info/get/" + ip + "/" + id ,
2023-01-24 07:34:14 +00:00
success : function ( data ) {
data = data . replace ( /\s+/g , ' ' ) ;
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'error_code' ) != '-1' ) {
toastr . error ( data ) ;
} else {
$ ( "#server-info" ) . html ( data ) ;
$ ( "#dialog-server-info" ) . dialog ( {
resizable : false ,
height : "auto" ,
2023-02-17 17:21:19 +00:00
width : 1000 ,
2023-01-24 07:34:14 +00:00
modal : true ,
2023-02-17 17:21:19 +00:00
title : server _info + " (" + ip + ")" ,
buttons : [ {
text : close _word ,
click : function ( ) {
2023-01-24 07:34:14 +00:00
$ ( this ) . dialog ( "close" ) ;
}
2023-02-17 17:21:19 +00:00
} ]
2023-01-24 07:34:14 +00:00
} ) ;
$ . getScript ( awesome ) ;
2021-12-03 10:39:15 +00:00
}
2023-01-24 07:34:14 +00:00
}
2023-09-17 09:42:39 +00:00
} ) ;
2021-12-03 10:39:15 +00:00
}
2023-02-13 14:45:45 +00:00
function serverIsUp ( server _ip , server _id ) {
2023-04-02 16:58:55 +00:00
var cur _url = window . location . href . split ( '/' ) . pop ( ) ;
if ( cur _url . split ( '#' ) [ 1 ] == 'servers' ) {
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/check/server/" + server _ip ,
// data: {
// token: $('#token').val()
// },
// type: "POST",
2023-04-02 16:58:55 +00:00
success : function ( data ) {
data = data . replace ( /^\s+|\s+$/g , '' ) ;
if ( data . indexOf ( 'up' ) != '-1' ) {
$ ( '#server_status-' + server _id ) . removeClass ( 'serverNone' ) ;
$ ( '#server_status-' + server _id ) . removeClass ( 'serverDown' ) ;
$ ( '#server_status-' + server _id ) . addClass ( 'serverUp' ) ;
$ ( '#server_status-' + server _id ) . attr ( 'title' , 'Server is reachable' ) ;
} else if ( data . indexOf ( 'down' ) != '-1' ) {
$ ( '#server_status-' + server _id ) . removeClass ( 'serverNone' ) ;
$ ( '#server_status-' + server _id ) . removeClass ( 'serverUp' ) ;
$ ( '#server_status-' + server _id ) . addClass ( 'serverDown' ) ;
$ ( '#server_status-' + server _id ) . attr ( 'title' , 'Server is unreachable' ) ;
} else {
$ ( '#server_status-' + server _id ) . removeClass ( 'serverDown' ) ;
$ ( '#server_status-' + server _id ) . removeClass ( 'serverUp' ) ;
$ ( '#server_status-' + server _id ) . addClass ( 'serverNone' ) ;
$ ( '#server_status-' + server _id ) . attr ( 'title' , 'Cannot get server status' ) ;
}
2023-02-13 14:45:45 +00:00
}
2023-04-02 16:58:55 +00:00
} ) ;
}
2023-02-13 14:45:45 +00:00
}
2023-03-03 20:03:41 +00:00
function confirmChangeGroupsAndRoles ( user _id ) {
var cancel _word = $ ( '#translate' ) . attr ( 'data-cancel' ) ;
var action _word = $ ( '#translate' ) . attr ( 'data-save' ) ;
var user _groups _word = $ ( '#translate' ) . attr ( 'data-user_groups' ) ;
2023-09-17 09:42:39 +00:00
var username = $ ( '#login-' + user _id ) . val ( ) ;
2023-03-03 20:03:41 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/user/groups/" + user _id ,
2024-04-19 09:32:13 +00:00
2023-03-03 20:03:41 +00:00
success : function ( data ) {
$ ( "#groups-roles" ) . html ( data ) ;
$ ( "#groups-roles" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 700 ,
modal : true ,
2023-03-04 07:42:26 +00:00
title : user _groups _word + ' ' + username ,
2023-03-03 20:03:41 +00:00
buttons : [ {
text : action _word ,
click : function ( ) {
saveGroupsAndRoles ( user _id ) ;
$ ( this ) . dialog ( "close" ) ;
}
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ]
} ) ;
}
} ) ;
}
function addGroupToUser ( group _id ) {
var group _name = $ ( '#add_group-' + group _id ) . attr ( 'data-group_name' ) ;
2023-03-04 12:42:26 +00:00
var group2 _word = $ ( '#translate' ) . attr ( 'data-group2' ) ;
var length _tr = $ ( '#all_groups tbody tr' ) . length ;
2024-05-13 09:08:51 +00:00
const roles = { 1 : 'superAdmin' , 2 : 'admin' , 3 : 'user' , 4 : 'guest' } ;
2023-03-04 12:42:26 +00:00
var options _roles = '' ;
for ( const [ role _id , role _name ] of Object . entries ( roles ) ) {
options _roles += '<option value="' + role _id + '">' + role _name + '</option>' ;
}
var tr _class = 'odd' ;
if ( length _tr % 2 != 0 ) {
tr _class = 'even' ;
}
var html _tag = '<tr class="' + tr _class + '" id="remove_group-' + group _id + '" data-group_name="' + group _name + '">\n' +
' <td class="padding20" style="width: 50%;">' + group _name + '</td>\n' +
' <td style="width: 50%;">\n' +
' <select id="add_role-' + group _id + '">' + options _roles + '</select></td>\n' +
' <td><span class="remove_user_group" onclick="removeGroupFromUser(' + group _id + ')" title="' + delete _word + ' ' + group2 _word + '">-</span></td></tr>'
$ ( '#add_group-' + group _id ) . remove ( ) ;
$ ( "#checked_groups tbody" ) . append ( html _tag ) ;
2023-03-03 20:03:41 +00:00
}
function removeGroupFromUser ( group _id ) {
var group _name = $ ( '#remove_group-' + group _id ) . attr ( 'data-group_name' ) ;
2023-03-04 07:42:26 +00:00
var add _word = $ ( '#translate' ) . attr ( 'data-add' ) ;
var group2 _word = $ ( '#translate' ) . attr ( 'data-group2' ) ;
var length _tr = $ ( '#all_groups tbody tr' ) . length ;
var tr _class = 'odd' ;
if ( length _tr % 2 != 0 ) {
tr _class = 'even' ;
}
var html _tag = '<tr class="' + tr _class + '" id="add_group-' + group _id + '" data-group_name=' + group _name + '>\n' +
' <td class="padding20" style="width: 100%">' + group _name + '</td>\n' +
2023-03-04 12:42:26 +00:00
' <td><span class="add_user_group" title="' + add _word + ' ' + group2 _word + '" onclick="addGroupToUser(' + group _id + ')">+</span></td></tr>'
2023-03-04 07:42:26 +00:00
$ ( '#remove_group-' + group _id ) . remove ( ) ;
$ ( "#all_groups tbody" ) . append ( html _tag ) ;
2023-03-03 20:03:41 +00:00
}
function saveGroupsAndRoles ( user _id ) {
var length _tr = $ ( '#checked_groups tbody tr' ) . length ;
var jsonData = { } ;
jsonData [ user _id ] = { } ;
$ ( '#checked_groups tbody tr' ) . each ( function ( ) {
var this _id = $ ( this ) . attr ( 'id' ) . split ( '-' ) [ 1 ] ;
2023-09-17 09:42:39 +00:00
var role _id = $ ( '#add_role-' + this _id ) . val ( ) ;
2023-03-03 20:03:41 +00:00
jsonData [ user _id ] [ this _id ] = { 'role_id' : role _id } ;
} ) ;
2023-10-04 18:58:39 +00:00
for ( const [ key , value ] of Object . entries ( jsonData ) ) {
if ( Object . keys ( value ) . length === 0 ) {
toastr . error ( 'error: User must have at least one group' ) ;
return false ;
}
}
2023-03-03 20:03:41 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/user/groups/save" ,
2023-03-03 20:03:41 +00:00
data : {
2023-09-17 09:42:39 +00:00
changeUserGroupsUser : $ ( '#login-' + user _id ) . val ( ) ,
2023-03-03 20:03:41 +00:00
jsonDatas : JSON . stringify ( jsonData ) ,
token : $ ( '#token' ) . val ( )
} ,
type : "POST" ,
success : function ( data ) {
if ( data . indexOf ( 'error: ' ) != '-1' ) {
toastr . warning ( data ) ;
} else {
2023-09-17 09:42:39 +00:00
$ ( "#user-" + user _id ) . addClass ( "update" , 1000 ) ;
setTimeout ( function ( ) {
$ ( "#user-" + user _id ) . removeClass ( "update" ) ;
} , 2500 ) ;
2023-03-03 20:03:41 +00:00
}
}
} ) ;
}
2023-04-02 16:58:55 +00:00
function openChangeServerServiceDialog ( server _id ) {
var cancel _word = $ ( '#translate' ) . attr ( 'data-cancel' ) ;
var action _word = $ ( '#translate' ) . attr ( 'data-save' ) ;
var user _groups _word = $ ( '#translate' ) . attr ( 'data-user_groups' ) ;
2023-09-17 09:42:39 +00:00
var hostname = $ ( '#hostname-' + server _id ) . val ( ) ;
2023-04-02 16:58:55 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : "/app/server/services/" + server _id ,
// data: {
// token: $('#token').val()
// },
// type: "GET",
2023-04-02 16:58:55 +00:00
success : function ( data ) {
$ ( "#groups-roles" ) . html ( data ) ;
$ ( "#groups-roles" ) . dialog ( {
resizable : false ,
height : "auto" ,
width : 700 ,
modal : true ,
title : user _groups _word + ' ' + hostname ,
buttons : [ {
text : action _word ,
click : function ( ) {
changeServerServices ( server _id ) ;
$ ( this ) . dialog ( "close" ) ;
}
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ]
} ) ;
}
} ) ;
}
function addServiceToServer ( service _id ) {
var service _name = $ ( '#add_service-' + service _id ) . attr ( 'data-service_name' ) ;
var service _word = $ ( '#translate' ) . attr ( 'data-service' ) ;
var length _tr = $ ( '#checked_services tbody tr' ) . length ;
var tr _class = 'odd' ;
if ( length _tr % 2 != 0 ) {
tr _class = 'even' ;
}
var html _tag = '<tr class="' + tr _class + '" id="remove_service-' + service _id + '" data-service_name="' + service _name + '">' +
'<td class="padding20" style="width: 100%;">' + service _name + '</td>' +
'<td><span class="add_user_group" onclick="removeServiceFromUser(' + service _id + ')" title="' + delete _word + ' ' + service _word + '">-</span></td></tr>' ;
$ ( '#add_service-' + service _id ) . remove ( ) ;
$ ( "#checked_services tbody" ) . append ( html _tag ) ;
}
function removeServiceFromServer ( service _id ) {
var service _name = $ ( '#remove_service-' + service _id ) . attr ( 'data-service_name' ) ;
var service _word = $ ( '#translate' ) . attr ( 'data-service' ) ;
var length _tr = $ ( '#all_services tbody tr' ) . length ;
var tr _class = 'odd' ;
if ( length _tr % 2 != 0 ) {
tr _class = 'even' ;
}
var html _tag = '<tr class="' + tr _class + '" id="add_service-' + service _id + '" data-service_name="' + service _name + '">' +
'<td class="padding20" style="width: 100%;">' + service _name + '</td>' +
'<td><span class="add_user_group" onclick="addServiceToUser(' + service _id + ')" title="' + add _word + ' ' + service _word + '">+</span></td></tr>' ;
$ ( '#remove_service-' + service _id ) . remove ( ) ;
$ ( "#all_services tbody" ) . append ( html _tag ) ;
}
function changeServerServices ( server _id ) {
var jsonData = { } ;
$ ( '#checked_services tbody tr' ) . each ( function ( ) {
var this _id = $ ( this ) . attr ( 'id' ) . split ( '-' ) [ 1 ] ;
jsonData [ this _id ] = 1
} ) ;
$ ( '#all_services tbody tr' ) . each ( function ( ) {
var this _id = $ ( this ) . attr ( 'id' ) . split ( '-' ) [ 1 ] ;
jsonData [ this _id ] = 0
} ) ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : "/app/server/services/" + server _id ,
2023-04-02 16:58:55 +00:00
data : {
jsonDatas : JSON . stringify ( jsonData ) ,
2023-09-17 09:42:39 +00:00
changeServerServicesServer : $ ( '#hostname-' + server _id ) . val ( ) ,
2023-04-02 16:58:55 +00:00
token : $ ( '#token' ) . val ( )
} ,
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
2023-04-02 16:58:55 +00:00
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'Failed' ) != '-1' ) {
toastr . error ( data ) ;
} else {
$ ( "#server-" + server _id ) . addClass ( "update" , 1000 ) ;
setTimeout ( function ( ) {
$ ( "#server-" + server _id ) . removeClass ( "update" ) ;
} , 2500 ) ;
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2023-04-02 16:58:55 +00:00
}