2024-08-02 09:50:02 +00:00
var cur _url = window . location . href . split ( '/' ) . pop ( ) ;
2023-09-17 09:42:39 +00:00
cur _url = cur _url . split ( '/' ) ;
2018-05-02 11:11:22 +00:00
var intervalId ;
2020-09-15 05:56:43 +00:00
function validateEmail ( email ) {
const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ ;
return re . test ( email ) ;
}
2024-05-30 18:10:42 +00:00
function ValidateIPaddress ( ipaddress ) {
if ( /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ . test ( ipaddress ) ) {
2024-08-02 09:50:02 +00:00
return true
2024-05-30 18:10:42 +00:00
}
2024-08-02 09:50:02 +00:00
return false
2024-05-30 18:10:42 +00:00
}
2024-06-16 09:27:47 +00:00
var select _server = translate _div . attr ( 'data-select_server' ) ;
2024-05-30 18:10:42 +00:00
function checkIsServerFiled ( select _id , message = select _server ) {
if ( $ ( select _id ) . val ( ) == null || $ ( select _id ) . val ( ) == '' ) {
toastr . warning ( message ) ;
return false ;
}
return true ;
}
2020-12-01 04:31:50 +00:00
function escapeHtml ( unsafe ) {
return unsafe
. replace ( /&/g , "&" )
. replace ( /</g , "<" )
. replace ( />/g , ">" )
. replace ( /"/g , """ )
. replace ( /'/g , "'" ) ;
}
2024-06-16 09:27:47 +00:00
var wait _mess _word = translate _div . attr ( 'data-wait_mess' ) ;
2023-02-13 14:45:45 +00:00
var wait _mess = '<div class="alert alert-warning">' + wait _mess _word + '</div>'
2021-08-15 09:02:12 +00:00
function show _current _page ( id ) {
id . parent ( ) . css ( 'display' , 'contents' ) ;
id . parent ( ) . css ( 'font-size' , '13px' ) ;
id . parent ( ) . css ( 'top' , '0' ) ;
id . parent ( ) . css ( 'left' , '0' ) ;
id . parent ( ) . children ( ) . css ( 'margin-left' , '-20px' ) ;
id . parent ( ) . find ( 'a' ) . css ( 'padding-left' , '20px' ) ;
2024-08-02 09:50:02 +00:00
id . find ( 'a' ) . css ( 'border-left' , '4px solid var(--color-wanring) !important' ) ;
id . find ( 'a' ) . css ( 'background-color' , 'var(--color-gray-dark-alpha) !important' ) ;
2021-08-15 09:02:12 +00:00
}
2019-09-20 06:42:19 +00:00
$ ( function ( ) {
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
let link = $ ( this ) . find ( 'a' ) . attr ( 'href' ) ;
let link2 = link . split ( '#' ) [ 1 ] ;
let link3 = link . split ( '/' ) [ 2 ] ;
let link4 = link . split ( '/' ) [ 3 ] ;
// if (cur_url[1] == null) {
// cur_url[1] = 'haproxy';
// }
let full _uri = window . location . pathname
let full _uri1 = window . location . hash
let full _uri2 = cur _url [ 0 ] + '/' + cur _url [ 1 ] + '/' + cur _url [ 2 ]
let full _uri3 = link2 + '/' + link3 + '/' + link4
// console.log(link)
// console.log(window.location.hash)
let params = new URL ( document . location . toString ( ) ) . searchParams ;
// console.log(params.get("service"))
// console.log(link)
// console.log(full_uri)
// console.log(full_uri1)
// console.log(full_uri + "/" + full_uri1)
// if (full_uri1 === '/service/haproxy') {
// console.log(full_uri)
// console.log(full_uri1)
// }
if ( full _uri === link ) {
2023-09-17 09:42:39 +00:00
show _current _page ( $ ( this ) )
2024-08-02 09:50:02 +00:00
// } else if (window.location.pathname.indexOf('add/haproxy#') != '-1' && link.indexOf('add/haproxy#proxy') != '-1') {
// show_current_page($(this))
} else if ( link === full _uri + full _uri1 ) {
2023-09-17 09:42:39 +00:00
show _current _page ( $ ( this ) )
2024-08-02 09:50:02 +00:00
// } else if (link === '/admin#servers' && full_uri1 === '#servers') {
// show_current_page($(this))
// } else if (link === '/admin#ssh' && full_uri1 === '#ssh') {
// show_current_page($(this))
// } else if (link === '/add/haproxy#proxy' && full_uri1 === '#proxy') {
// show_current_page($(this))
} else if ( link === '/add/haproxy#ssl' && full _uri1 === '#ssl' && params . get ( "service" ) != 'nginx' ) {
2023-09-17 09:42:39 +00:00
show _current _page ( $ ( this ) )
2024-08-02 09:50:02 +00:00
} else if ( link === '/add/haproxy#ssl' && full _uri1 === '#ssl' && params . get ( "service" ) === 'nginx' ) {
2023-09-17 09:42:39 +00:00
show _current _page ( $ ( this ) )
2024-08-02 09:50:02 +00:00
} else if ( full _uri === 'add/haproxy?service=nginx#ssl' && cur _url [ 1 ] . split ( '?' ) [ 1 ] === 'service=nginx#ssl' && full _uri1 === 'add/haproxy?service=nginx#ssl' ) {
2023-09-17 09:42:39 +00:00
show _current _page ( $ ( this ) )
2024-08-02 09:50:02 +00:00
} else if ( full _uri === 'add/haproxy?service=apache#ssl' && cur _url [ 1 ] . split ( '?' ) [ 1 ] === 'service=apache#ssl' && full _uri1 === 'add/haproxy?service=apache#ssl' ) {
2022-08-02 08:53:32 +00:00
show _current _page ( $ ( this ) )
2020-07-15 04:16:31 +00:00
}
2019-09-20 06:42:19 +00:00
} ) ;
} ) ;
2018-07-23 07:08:43 +00:00
jQuery . expr [ ':' ] . regex = function ( elem , index , match ) {
var matchParams = match [ 3 ] . split ( ',' ) ,
validLabels = /^(data|css):/ ,
attr = {
2024-02-16 06:50:27 +00:00
method : matchParams [ 0 ] . match ( validLabels ) ?
2018-07-23 07:08:43 +00:00
matchParams [ 0 ] . split ( ':' ) [ 0 ] : 'attr' ,
property : matchParams . shift ( ) . replace ( validLabels , '' )
} ,
regexFlags = 'ig' ,
regex = new RegExp ( matchParams . join ( '' ) . replace ( /^\s+|\s+$/g , '' ) , regexFlags ) ;
return regex . test ( jQuery ( elem ) [ attr . method ] ( attr . property ) ) ;
}
2020-12-15 06:34:02 +00:00
if ( localStorage . getItem ( 'restart' ) ) {
2024-08-02 09:50:02 +00:00
let ip _for _restart = localStorage . getItem ( 'restart' ) ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/service/check-restart/" + ip _for _restart ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
if ( data . indexOf ( 'ok' ) != '-1' ) {
2022-07-06 08:51:02 +00:00
var apply _div = $ . find ( "#apply_div" ) ;
apply _div = apply _div [ 0 ] . id ;
2018-08-28 10:45:09 +00:00
$ ( "#apply" ) . css ( 'display' , 'block' ) ;
2023-09-17 09:42:39 +00:00
$ ( '#' + apply _div ) . css ( 'width' , '850px' ) ;
2022-07-06 09:04:05 +00:00
ip _for _restart = escapeHtml ( ip _for _restart ) ;
2024-08-02 09:50:02 +00:00
if ( cur _url [ 0 ] === "service" ) {
2023-09-17 09:42:39 +00:00
$ ( '#' + apply _div ) . css ( 'width' , '650px' ) ;
$ ( '#' + apply _div ) . addClass ( "alert-one-row" ) ;
$ ( '#' + apply _div ) . html ( "You have made changes to the server: " + ip _for _restart + ". Changes will take effect only after<a id='" + ip _for _restart + "' class='restart' title='Restart HAproxy service' onclick=\"confirmAjaxAction('restart', 'hap', '" + ip _for _restart + "')\">restart</a><a href='#' title='close' id='apply_close' style='float: right'><b>X</b></a>" ) ;
2018-08-28 10:45:09 +00:00
} else {
2023-09-17 09:42:39 +00:00
$ ( '#' + apply _div ) . html ( "You have made changes to the server: " + ip _for _restart + ". Changes will take effect only after restart. <a href='service' title='Overview'>Go to the HAProxy Overview page and restart</a><a href='#' title='close' id='apply_close' style='float: right'><b>X</b></a>" ) ;
2018-08-28 10:45:09 +00:00
}
2024-06-16 09:27:47 +00:00
$ . getScript ( overview ) ;
2018-08-28 10:45:09 +00:00
}
2023-09-17 09:42:39 +00:00
}
} ) ;
2018-08-28 10:45:09 +00:00
}
2018-04-11 03:30:46 +00:00
$ ( document ) . ajaxSend ( function ( event , request , settings ) {
NProgress . start ( ) ;
} ) ;
$ ( document ) . ajaxComplete ( function ( event , request , settings ) {
NProgress . done ( ) ;
} ) ;
2024-08-02 09:50:02 +00:00
$ . ajaxSetup ( {
headers : { "X-CSRF-TOKEN" : csrf _token } ,
} ) ;
2024-07-16 05:45:28 +00:00
$ ( document ) . ajaxError ( function myErrorHandler ( event , xhr , ajaxOptions , thrownError ) {
if ( xhr . status != 401 ) {
toastr . error ( xhr . responseJSON . error ) ;
}
} ) ;
2018-04-09 10:27:01 +00:00
function showStats ( ) {
2023-09-17 09:42:39 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/stats/view/" + $ ( "#service" ) . val ( ) + "/" + $ ( "#serv" ) . val ( ) ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
2020-11-02 17:01:08 +00:00
if ( data . indexOf ( 'error:' ) != '-1' && data . indexOf ( 'Internal error:' ) == '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax" ) . html ( data ) ;
2024-08-02 09:50:02 +00:00
window . history . pushState ( "Stats" , "Stats" , "/stats/" + $ ( "#service" ) . val ( ) + "/" + $ ( "#serv" ) . val ( ) ) ;
2020-07-26 16:26:04 +00:00
wait ( ) ;
}
2023-09-17 09:42:39 +00:00
}
} ) ;
2019-09-08 10:07:58 +00:00
}
function openStats ( ) {
2024-08-02 09:50:02 +00:00
let serv = $ ( "#serv" ) . val ( ) ;
let service _url = cur _url [ 4 ] ;
let url = "/stats/" + service _url + "/" + serv
let win = window . open ( url , '_blank' ) ;
2019-09-08 10:07:58 +00:00
win . focus ( ) ;
2018-04-09 10:27:01 +00:00
}
2019-09-15 11:51:09 +00:00
function openVersions ( ) {
2024-08-02 09:50:02 +00:00
let serv = $ ( "#serv" ) . val ( ) ;
let service _url = cur _url [ 4 ] ;
let url = "/config/versions/" + service _url + "/" + serv
let win = window . open ( url , "_self" ) ;
2023-09-17 09:42:39 +00:00
win . focus ( ) ;
}
function openSection ( ) {
2024-08-02 09:50:02 +00:00
let serv = $ ( "#serv" ) . val ( ) ;
let section = $ ( "#section" ) . val ( ) ;
let url = "/config/section/haproxy/" + serv + "/" + section ;
let win = window . open ( url , "_self" ) ;
2019-09-15 11:51:09 +00:00
win . focus ( ) ;
}
2018-04-09 10:27:01 +00:00
function showLog ( ) {
2023-09-17 09:42:39 +00:00
var waf = cur _url [ 2 ] ;
2022-03-02 20:09:39 +00:00
var file = $ ( '#log_files' ) . val ( ) ;
2023-09-20 10:11:10 +00:00
var serv = $ ( "#serv" ) . val ( ) ;
if ( ( file === undefined || file === null ) && ( waf == '' || waf === undefined ) ) {
2022-08-02 08:53:32 +00:00
var file _from _get = findGetParameter ( 'file' ) ;
if ( file _from _get === undefined || file _from _get === null ) {
toastr . warning ( 'Select a log file first' )
return false ;
} else {
file = file _from _get ;
}
2018-08-17 11:55:17 +00:00
}
2023-09-20 10:11:10 +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 service = $ ( '#service' ) . val ( ) ;
2020-07-02 14:44:13 +00:00
if ( service == 'None' ) {
service = 'haproxy' ;
}
2023-09-17 09:42:39 +00:00
if ( waf ) {
2024-08-02 09:50:02 +00:00
var url = "/logs/" + service + "/waf/" + serv + "/" + rows ;
2023-09-17 09:42:39 +00:00
waf = 1 ;
} else {
2024-08-02 09:50:02 +00:00
var url = "/logs/" + service + "/" + serv + "/" + rows ;
2023-09-17 09:42:39 +00:00
}
2018-04-09 10:27:01 +00:00
$ . ajax ( {
2023-09-17 09:42:39 +00:00
url : url ,
2018-04-09 10:27:01 +00:00
data : {
2021-08-08 13:02:00 +00:00
show _log : rows ,
2018-08-17 11:55:17 +00:00
waf : waf ,
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 ,
2022-03-02 20:09:39 +00:00
file : file ,
} ,
type : "POST" ,
success : function ( data ) {
toastr . clear ( ) ;
$ ( "#ajax" ) . html ( data ) ;
2022-09-28 14:18:53 +00:00
}
2022-03-02 20:09:39 +00:00
} ) ;
}
function showRemoteLogFiles ( ) {
let serv = $ ( '#serv' ) . val ( ) ;
if ( serv === undefined || serv === null ) {
toastr . warning ( 'Select a server firts' ) ;
return false ;
}
var rows = $ ( '#rows' ) . val ( )
var grep = $ ( '#grep' ) . val ( )
var exgrep = $ ( '#exgrep' ) . val ( )
var hour = $ ( '#time_range_out_hour' ) . val ( )
2023-09-17 09:42:39 +00:00
var minute = $ ( '#time_range_out_minut' ) . val ( )
2022-03-02 20:09:39 +00:00
var hour1 = $ ( '#time_range_out_hour1' ) . val ( )
2023-09-17 09:42:39 +00:00
var minute1 = $ ( '#time_range_out_minut1' ) . val ( )
2022-03-02 20:09:39 +00:00
var service = $ ( '#service' ) . val ( )
if ( service == 'None' ) {
service = 'haproxy' ;
}
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/logs/" + service + "/" + serv ,
2022-03-02 20:09:39 +00:00
data : {
serv : $ ( "#serv" ) . val ( ) ,
2018-04-09 10:27:01 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2018-04-11 03:30:46 +00:00
success : function ( data ) {
2022-03-02 20:09:39 +00:00
if ( data . indexOf ( 'error:' ) != '-1' || data . indexOf ( 'ls: cannot access' ) != '-1' ) {
2020-07-26 16:26:04 +00:00
toastr . error ( data ) ;
} else {
toastr . clear ( ) ;
2022-03-02 20:09:39 +00:00
$ ( "#remote_log_files" ) . html ( data ) ;
2024-06-16 09:27:47 +00:00
$ . getScript ( configShow ) ;
2020-07-26 16:26:04 +00:00
}
2022-03-02 20:09:39 +00:00
}
2018-04-11 03:30:46 +00:00
} ) ;
2022-03-02 20:09:39 +00:00
2018-04-11 03:30:46 +00:00
}
2022-01-16 13:50:53 +00:00
function clearAllAjaxFields ( ) {
2018-09-27 04:28:10 +00:00
$ ( "#ajax" ) . empty ( ) ;
2020-11-18 04:45:34 +00:00
$ ( '.alert' ) . remove ( ) ;
2020-08-09 07:18:30 +00:00
try {
myCodeMirror . toTextArea ( ) ;
} catch ( e ) {
console . log ( e )
}
$ ( "#saveconfig" ) . remove ( ) ;
$ ( "h4" ) . remove ( ) ;
2018-09-27 04:28:10 +00:00
$ ( "#ajax-compare" ) . empty ( ) ;
$ ( "#config" ) . empty ( ) ;
2022-01-16 13:50:53 +00:00
}
function showMap ( ) {
clearAllAjaxFields ( ) ;
$ ( '#ajax-config_file_name' ) . empty ( ) ;
2018-04-11 03:30:46 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/map/haproxy/" + $ ( "#serv" ) . val ( ) + '/show' ,
2018-04-10 03:58:56 +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 ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax" ) . html ( data ) ;
2024-08-02 09:50:02 +00:00
window . history . pushState ( "Show Map" , "Show Map" , '/config/map/' + $ ( "#service" ) . val ( ) + '/' + $ ( "#serv" ) . val ( ) ) ;
2020-07-26 16:26:04 +00:00
}
2022-09-28 14:18:53 +00:00
}
2018-04-10 03:58:56 +00:00
} ) ;
}
function showCompare ( ) {
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/compare/" + $ ( "#service" ) . val ( ) + "/" + $ ( "#serv" ) . val ( ) + "/show" ,
2018-04-10 03:58:56 +00:00
data : {
left : $ ( '#left' ) . val ( ) ,
2018-06-01 12:27:58 +00:00
right : $ ( "#right" ) . val ( ) ,
2018-04-10 03:58:56 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2018-04-09 10:27:01 +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 ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax" ) . html ( data ) ;
}
2022-09-28 14:18:53 +00:00
}
2018-04-11 09:27:57 +00:00
} ) ;
}
function showCompareConfigs ( ) {
2022-01-16 13:50:53 +00:00
clearAllAjaxFields ( ) ;
$ ( '#ajax-config_file_name' ) . empty ( ) ;
2018-04-11 09:27:57 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/compare/" + $ ( "#service" ) . val ( ) + "/" + $ ( "#serv" ) . val ( ) + "/files" ,
2023-09-17 09:42:39 +00:00
type : "GET" ,
2018-04-11 09:27:57 +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 ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax-compare" ) . html ( data ) ;
$ ( "input[type=submit], button" ) . button ( ) ;
$ ( "select" ) . selectmenu ( ) ;
2024-08-02 09:50:02 +00:00
window . history . pushState ( "Show compare config" , "Show compare config" , '/config/compare/' + $ ( "#service" ) . val ( ) + '/' + $ ( "#serv" ) . val ( ) ) ;
2020-07-26 16:26:04 +00:00
}
}
2018-04-10 06:10:07 +00:00
} ) ;
}
function showConfig ( ) {
2024-08-02 09:50:02 +00:00
let service = $ ( '#service' ) . val ( ) ;
let config _file = $ ( '#config_file_name' ) . val ( )
let config _file _name = encodeURI ( config _file ) ;
if ( service === 'nginx' || service === 'apache' ) {
if ( config _file === undefined || config _file === null ) {
2023-09-17 09:42:39 +00:00
config _file _name = cur _url [ 4 ]
2024-08-02 09:50:02 +00:00
if ( config _file _name === '' ) {
toastr . warning ( 'Select a config file first' ) ;
2023-09-17 09:42:39 +00:00
return false ;
} else {
showConfigFiles ( true ) ;
}
2022-03-02 20:09:39 +00:00
}
}
2022-01-16 13:50:53 +00:00
clearAllAjaxFields ( ) ;
2018-04-10 06:10:07 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/" + service + "/show" ,
2018-04-10 06:10:07 +00:00
data : {
serv : $ ( "#serv" ) . val ( ) ,
2020-04-16 13:30:51 +00:00
service : service ,
2023-09-17 09:42:39 +00:00
config _file _name : config _file _name
2018-04-10 06:10:07 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2018-04-10 06:10:07 +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 ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax" ) . html ( data ) ;
2024-06-16 09:27:47 +00:00
$ . getScript ( configShow ) ;
2024-08-02 09:50:02 +00:00
window . history . pushState ( "Show config" , "Show config" , "/config/" + service + "/" + $ ( "#serv" ) . val ( ) + "/show/" + config _file _name ) ;
2020-07-26 16:26:04 +00:00
}
2022-09-28 14:18:53 +00:00
}
2018-04-09 10:27:01 +00:00
} ) ;
}
2023-09-17 09:42:39 +00:00
function showConfigFiles ( not _redirect = false ) {
2022-01-16 13:50:53 +00:00
var service = $ ( '#service' ) . val ( ) ;
2023-09-17 09:42:39 +00:00
var server _ip = $ ( "#serv" ) . val ( ) ;
2022-01-16 13:50:53 +00:00
clearAllAjaxFields ( ) ;
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/" + service + "/show-files" ,
2022-01-16 13:50:53 +00:00
data : {
2023-09-17 09:42:39 +00:00
serv : server _ip ,
service : service
2022-01-16 13:50:53 +00:00
} ,
type : "POST" ,
success : function ( data ) {
if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax-config_file_name" ) . html ( data ) ;
2022-04-27 18:10:26 +00:00
if ( findGetParameter ( 'findInConfig' ) === null ) {
2023-09-17 09:42:39 +00:00
if ( not _redirect ) {
2024-08-02 09:50:02 +00:00
window . history . pushState ( "Show config" , "Show config" , "/config/" + service + "/" + server _ip + "/show-files" ) ;
2023-09-17 09:42:39 +00:00
}
2022-04-27 18:10:26 +00:00
}
2022-01-16 13:50:53 +00:00
}
}
} ) ;
}
function showConfigFilesForEditing ( ) {
2024-08-02 09:50:02 +00:00
let service = $ ( '#service' ) . val ( ) ;
let server _ip = $ ( "#serv" ) . val ( ) ;
let config _file _name = findGetParameter ( 'config_file_name' )
if ( service === 'nginx' || service === 'apache' ) {
2022-01-16 13:50:53 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/" + service + "/" + server _ip + "/edit/" + config _file _name ,
2022-01-16 13:50:53 +00:00
type : "POST" ,
success : function ( data ) {
if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax-config_file_name" ) . html ( data ) ;
}
}
} ) ;
}
}
2018-05-05 12:54:33 +00:00
function showUploadConfig ( ) {
2024-08-02 09:50:02 +00:00
let service = $ ( '#service' ) . val ( ) ;
let configver = $ ( '#configver' ) . val ( ) ;
let serv = $ ( "#serv" ) . val ( )
2018-05-05 12:54:33 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/" + service + "/show" ,
2018-05-05 12:54:33 +00:00
data : {
2020-02-02 14:23:00 +00:00
serv : serv ,
2023-09-17 09:42:39 +00:00
configver : configver
2018-05-05 12:54:33 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2018-05-05 12:54:33 +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 ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax" ) . html ( data ) ;
2024-08-02 09:50:02 +00:00
window . history . pushState ( "Show config" , "Show config" , "/config/versions/" + service + "/" + serv + "/" + configver ) ;
2024-06-16 09:27:47 +00:00
$ . getScript ( configShow ) ;
2020-07-26 16:26:04 +00:00
}
2022-09-28 14:18:53 +00:00
}
2018-05-05 12:54:33 +00:00
} ) ;
}
2021-10-18 15:57:49 +00:00
function showListOfVersion ( for _delver ) {
2024-08-02 09:50:02 +00:00
let cur _url = window . location . href . split ( '/' ) . pop ( ) ;
2023-09-17 09:42:39 +00:00
cur _url = cur _url . split ( '/' ) ;
2024-08-02 09:50:02 +00:00
let service = $ ( '#service' ) . val ( ) ;
let serv = $ ( "#serv" ) . val ( ) ;
let configver = cur _url [ 4 ] ;
2022-01-16 13:50:53 +00:00
clearAllAjaxFields ( ) ;
2021-10-18 15:57:49 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/version/" + service + "/list" ,
2021-10-18 15:57:49 +00:00
data : {
serv : serv ,
configver : configver ,
2023-09-17 09:42:39 +00:00
for _delver : for _delver
2021-10-18 15:57:49 +00:00
} ,
type : "POST" ,
success : function ( data ) {
if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
toastr . clear ( ) ;
$ ( "#config_version_div" ) . html ( data ) ;
$ ( "input[type=checkbox]" ) . checkboxradio ( ) ;
2024-08-02 09:50:02 +00:00
window . history . pushState ( "Show config" , "Show config" , "/config/versions/" + service + "/" + serv ) ;
2021-10-18 15:57:49 +00:00
}
}
} ) ;
}
2020-03-05 18:56:13 +00:00
function findGetParameter ( parameterName ) {
2024-08-02 09:50:02 +00:00
let result = null ,
2020-03-05 18:56:13 +00:00
tmp = [ ] ;
2024-08-02 09:50:02 +00:00
let items = location . search . substr ( 1 ) . split ( "&" ) ;
for ( let index = 0 ; index < items . length ; index ++ ) {
2020-03-05 18:56:13 +00:00
tmp = items [ index ] . split ( "=" ) ;
if ( tmp [ 0 ] === parameterName ) result = decodeURIComponent ( tmp [ 1 ] ) ;
}
return result ;
}
2018-04-21 14:40:59 +00:00
function viewLogs ( ) {
2024-08-02 09:50:02 +00:00
let viewlogs = $ ( '#viewlogs' ) . val ( ) ;
if ( viewlogs === '------' || viewlogs === null ) { return false ; }
if ( viewlogs === 'roxy-wi.error.log' || viewlogs === 'roxy-wi.access.log' || viewlogs === 'fail2ban.log' ) {
2023-09-20 13:43:15 +00:00
showApacheLog ( viewlogs ) ;
2018-07-24 04:08:06 +00:00
} else {
2024-08-02 09:50:02 +00:00
let rows = $ ( '#rows' ) . val ( ) ;
let grep = $ ( '#grep' ) . val ( ) ;
let exgrep = $ ( '#exgrep' ) . val ( ) ;
let hour = $ ( '#time_range_out_hour' ) . val ( ) ;
let minute = $ ( '#time_range_out_minut' ) . val ( ) ;
let hour1 = $ ( '#time_range_out_hour1' ) . val ( ) ;
let minute1 = $ ( '#time_range_out_minut1' ) . val ( ) ;
let type = findGetParameter ( 'type' )
2020-03-05 18:56:13 +00:00
if ( viewlogs == null ) {
viewlogs = findGetParameter ( 'viewlogs' )
2022-09-28 14:18:53 +00:00
}
2024-08-02 09:50:02 +00:00
let url = "/logs/internal/" + viewlogs + "/" + rows ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
url : url ,
2018-07-24 04:08:06 +00:00
data : {
2020-03-05 18:56:13 +00:00
viewlogs : viewlogs ,
2023-09-17 09:42:39 +00:00
serv : viewlogs ,
2019-09-29 20:16:24 +00:00
rows : rows ,
grep : grep ,
2020-06-15 17:29:49 +00:00
exgrep : exgrep ,
2019-09-29 20:16:24 +00:00
hour : hour ,
2023-09-20 13:43:15 +00:00
minute : minute ,
2019-09-29 20:16:24 +00:00
hour1 : hour1 ,
2023-09-20 13:43:15 +00:00
minute1 : minute1 ,
2018-07-24 04:08:06 +00:00
} ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
2022-02-16 07:46:30 +00:00
$ ( "#ajax" ) . html ( data ) ;
2022-09-28 14:18:53 +00:00
}
2018-07-24 04:08:06 +00:00
} ) ;
}
2018-04-21 14:40:59 +00:00
}
2018-01-25 09:04:57 +00:00
$ ( function ( ) {
2023-08-03 06:56:25 +00:00
$ ( 'a' ) . click ( function ( e ) {
try {
var cur _path = window . location . pathname ;
var attr = $ ( this ) . attr ( 'href' ) ;
2024-08-02 09:50:02 +00:00
if ( cur _path == '/add/haproxy' || cur _path == '/add/nginx' || cur _path == '/admin' || cur _path == '/install' || cur _path == '/runtimeapi' ) {
2023-08-03 06:56:25 +00:00
if ( typeof attr !== typeof undefined && attr !== false ) {
$ ( 'title' ) . text ( $ ( this ) . attr ( 'title' ) ) ;
history . pushState ( { } , '' , $ ( this ) . attr ( 'href' ) ) ;
if ( $ ( this ) . attr ( 'href' ) . split ( '#' ) [ 0 ] && $ ( this ) . attr ( 'href' ) . split ( '#' ) [ 0 ] != cur _path ) {
window . history . go ( )
}
}
}
} catch ( err ) {
console . log ( err ) ;
}
} ) ;
2020-07-26 16:26:04 +00:00
toastr . options . closeButton = true ;
toastr . options . progressBar = true ;
toastr . options . positionClass = 'toast-bottom-full-width' ;
toastr . options . timeOut = 25000 ;
toastr . options . extendedTimeOut = 50000 ;
2019-12-27 04:31:09 +00:00
$ ( '#errorMess' ) . click ( function ( ) {
$ ( '#error' ) . remove ( ) ;
} ) ;
2018-04-11 03:30:46 +00:00
$ ( "#serv" ) . on ( 'selectmenuchange' , function ( ) {
$ ( "#show" ) . css ( "pointer-events" , "inherit" ) ;
$ ( "#show" ) . css ( "cursor" , "pointer" ) ;
} ) ;
if ( $ ( "#serv option:selected" ) . val ( ) == "Choose server" ) {
$ ( "#show" ) . css ( "pointer-events" , "none" ) ;
$ ( "#show" ) . css ( "cursor" , "not-allowed" ) ;
}
2018-01-25 09:04:57 +00:00
$ ( "#tabs" ) . tabs ( ) ;
$ ( "select" ) . selectmenu ( ) ;
2022-09-28 14:18:53 +00:00
2022-11-20 07:48:15 +00:00
$ ( "[title]" ) . tooltip ( {
"content" : function ( ) {
return $ ( this ) . attr ( "data-help" ) ;
2023-04-02 16:58:55 +00:00
} ,
show : { "delay" : 1000 }
2022-11-20 07:48:15 +00:00
} ) ;
2018-01-25 09:04:57 +00:00
$ ( "input[type=submit], button" ) . button ( ) ;
2018-02-07 04:39:42 +00:00
$ ( "input[type=checkbox]" ) . checkboxradio ( ) ;
2018-02-17 17:20:30 +00:00
$ ( ".controlgroup" ) . controlgroup ( ) ;
2022-09-28 14:18:53 +00:00
2019-09-26 15:48:56 +00:00
$ ( "#hide_menu" ) . click ( function ( ) {
$ ( ".top-menu" ) . hide ( "drop" , "fast" ) ;
2019-10-18 17:23:35 +00:00
$ ( ".container" ) . css ( "max-width" , "100%" ) ;
$ ( ".footer" ) . css ( "max-width" , "97%" ) ;
2019-09-26 15:48:56 +00:00
$ ( ".container" ) . css ( "margin-left" , "1%" ) ;
$ ( ".footer" ) . css ( "margin-left" , "1%" ) ;
$ ( ".show_menu" ) . show ( ) ;
$ ( "#hide_menu" ) . hide ( ) ;
2020-11-04 12:28:51 +00:00
sessionStorage . setItem ( 'hide_menu' , 'hide' ) ;
2019-09-26 15:48:56 +00:00
} ) ;
$ ( "#show_menu" ) . click ( function ( ) {
$ ( ".top-menu" ) . show ( "drop" , "fast" ) ;
2019-10-05 20:41:07 +00:00
$ ( ".container" ) . css ( "max-width" , "100%" ) ;
$ ( ".footer" ) . css ( "max-width" , "100%" ) ;
2019-09-26 15:48:56 +00:00
$ ( ".container" ) . css ( "margin-left" , "207px" ) ;
$ ( ".footer" ) . css ( "margin-left" , "207px" ) ;
$ ( ".show_menu" ) . hide ( ) ;
$ ( "#hide_menu" ) . show ( ) ;
2020-11-04 12:28:51 +00:00
sessionStorage . setItem ( 'hide_menu' , 'show' ) ;
} ) ;
var hideMenu = sessionStorage . getItem ( 'hide_menu' ) ;
2019-09-26 15:48:56 +00:00
if ( hideMenu == "show" ) {
$ ( ".top-menu" ) . show ( "drop" , "fast" ) ;
2019-10-05 20:41:07 +00:00
$ ( ".container" ) . css ( "max-width" , "100%" ) ;
2019-09-26 15:48:56 +00:00
$ ( ".container" ) . css ( "margin-left" , "207px" ) ;
2019-11-09 08:44:45 +00:00
$ ( ".footer" ) . css ( "margin-left" , "207px" ) ;
$ ( ".footer" ) . css ( "max-width" , "100%" ) ;
$ ( "#hide_menu" ) . show ( ) ;
$ ( ".show_menu" ) . hide ( ) ;
2019-09-26 15:48:56 +00:00
}
if ( hideMenu == "hide" ) {
$ ( ".top-menu" ) . hide ( ) ;
2019-10-18 17:23:35 +00:00
$ ( ".container" ) . css ( "max-width" , "97%" ) ;
2019-09-26 15:48:56 +00:00
$ ( ".container" ) . css ( "margin-left" , "1%" ) ;
2019-11-09 08:44:45 +00:00
$ ( ".footer" ) . css ( "margin-left" , "1%" ) ;
$ ( ".footer" ) . css ( "max-width" , "97%" ) ;
2019-09-26 15:48:56 +00:00
$ ( ".show_menu" ) . show ( ) ;
2019-11-09 08:44:45 +00:00
$ ( "#hide_menu" ) . hide ( ) ;
2022-09-28 14:18:53 +00:00
}
2018-05-18 18:09:14 +00:00
var now = new Date ( Date . now ( ) ) ;
2019-09-29 20:16:24 +00:00
if ( $ ( '#time_range_out_hour' ) . val ( ) != '' && $ ( '#time_range_out_hour' ) . val ( ) != 'None' ) {
var date1 = parseInt ( $ ( '#time_range_out_hour' ) . val ( ) , 10 ) * 60 + parseInt ( $ ( '#time_range_out_minut' ) . val ( ) , 10 )
} else {
2022-04-27 18:10:26 +00:00
var date1 = now . getHours ( ) * 60 - 3 * 60 ;
2019-09-29 20:16:24 +00:00
}
if ( $ ( '#time_range_out_hour' ) . val ( ) != '' && $ ( '#time_range_out_hour' ) . val ( ) != 'None' ) {
var date2 = parseInt ( $ ( '#time_range_out_hour1' ) . val ( ) , 10 ) * 60 + parseInt ( $ ( '#time_range_out_minut1' ) . val ( ) , 10 )
} else {
var date2 = now . getHours ( ) * 60 + now . getMinutes ( ) ;
}
2022-09-28 14:18:53 +00:00
$ ( "#time-range" ) . slider ( {
2018-05-18 18:09:14 +00:00
range : true ,
min : 0 ,
max : 1440 ,
step : 15 ,
values : [ date1 , date2 ] ,
slide : function ( e , ui ) {
var hours = Math . floor ( ui . values [ 0 ] / 60 ) ;
var minutes = ui . values [ 0 ] - ( hours * 60 ) ;
if ( hours . toString ( ) . length == 1 ) hours = '0' + hours ;
if ( minutes . toString ( ) . length == 1 ) minutes = '0' + minutes ;
2022-09-28 14:18:53 +00:00
2018-05-18 18:09:14 +00:00
var hours1 = Math . floor ( ui . values [ 1 ] / 60 ) ;
var minutes1 = ui . values [ 1 ] - ( hours1 * 60 ) ;
2018-03-30 06:26:22 +00:00
2018-05-18 18:09:14 +00:00
if ( hours1 . toString ( ) . length == 1 ) hours1 = '0' + hours1 ;
if ( minutes1 . toString ( ) . length == 1 ) minutes1 = '0' + minutes1 ;
2019-09-29 20:16:24 +00:00
if ( $ ( '#time_range_out_hour' ) . val ( ) != '' && $ ( '#time_range_out_hour' ) . val ( ) != 'None' ) {
$ ( '#time_range_out_hour' ) . val ( hours ) ;
}
if ( $ ( '#time_range_out_minut' ) . val ( ) != '' && $ ( '#time_range_out_minut' ) . val ( ) != 'None' ) {
$ ( '#time_range_out_minut' ) . val ( minutes ) ;
}
if ( $ ( '#time_range_out_hour1' ) . val ( ) != '' && $ ( '#time_range_out_hour1' ) . val ( ) != 'None' ) {
$ ( '#time_range_out_hour1' ) . val ( hours1 ) ;
}
if ( $ ( '#time_range_out_minut1' ) . val ( ) != '' && $ ( '#time_range_out_minut1' ) . val ( ) != 'None' ) {
$ ( '#time_range_out_minut1' ) . val ( minutes1 ) ;
}
2018-05-18 18:09:14 +00:00
}
} ) ;
2018-06-29 06:07:24 +00:00
var date1 _hours = Math . floor ( date1 / 60 ) ;
var date2 _hours = date1 _hours + 1 ;
2018-07-05 07:03:26 +00:00
var date2 _minute = now . getMinutes ( )
2018-06-29 06:07:24 +00:00
if ( date1 _hours <= 9 ) date1 _hours = '0' + date1 _hours ;
if ( date2 _hours <= 9 ) date2 _hours = '0' + date2 _hours ;
2018-07-05 07:03:26 +00:00
if ( date2 _minute <= 9 ) date2 _minute = '0' + date2 _minute ;
2019-09-29 20:16:24 +00:00
if ( $ ( '#time_range_out_hour' ) . val ( ) != '' && $ ( '#time_range_out_hour' ) . val ( ) != 'None' ) {
$ ( '#time_range_out_hour' ) . val ( $ ( '#time_range_out_hour' ) . val ( ) ) ;
} else {
$ ( '#time_range_out_hour' ) . val ( date1 _hours ) ;
}
if ( $ ( '#time_range_out_minut' ) . val ( ) != '' && $ ( '#time_range_out_minut' ) . val ( ) != 'None' ) {
$ ( '#time_range_out_minut' ) . val ( $ ( '#time_range_out_minut' ) . val ( ) ) ;
} else {
$ ( '#time_range_out_minut' ) . val ( '00' ) ;
}
if ( $ ( '#time_range_out_hour1' ) . val ( ) != '' && $ ( '#time_range_out_hour1' ) . val ( ) != 'None' ) {
$ ( '#time_range_out_hour1' ) . val ( $ ( '#time_range_out_hour1' ) . val ( ) ) ;
} else {
$ ( '#time_range_out_hour1' ) . val ( date2 _hours ) ;
}
if ( $ ( '#time_range_out_minut1' ) . val ( ) != '' && $ ( '#time_range_out_minut1' ) . val ( ) != 'None' ) {
$ ( '#time_range_out_minut1' ) . val ( $ ( '#time_range_out_minut1' ) . val ( ) ) ;
} else {
$ ( '#time_range_out_minut1' ) . val ( date2 _minute ) ;
}
2024-08-02 09:50:02 +00:00
$ ( '#auth' ) . submit ( function ( ) {
let next _url = findGetParameter ( 'next' ) ;
let json _data = {
"login" : $ ( '#login' ) . val ( ) ,
"pass" : $ ( '#pass' ) . val ( ) ,
"next" : next _url
}
$ . ajax ( {
url : "/login" ,
data : JSON . stringify ( json _data ) ,
contentType : "application/json; charset=utf-8" ,
2019-12-04 13:38:07 +00:00
type : "POST" ,
2024-08-02 09:50:02 +00:00
statusCode : {
401 : function ( xhr ) {
2020-01-18 23:50:43 +00:00
$ ( '.alert' ) . show ( ) ;
2024-08-02 09:50:02 +00:00
if ( xhr . responseText . indexOf ( 'disabled' ) != '-1' ) {
$ ( '.alert' ) . html ( 'Your login is disabled' )
} else {
$ ( '.alert' ) . html ( 'Login or password is incorrect' ) ;
ban ( ) ;
}
}
} ,
success : function ( data ) {
if ( data . status === 'failed' ) {
if ( data . error . indexOf ( 'disabled' ) != '-1' ) {
$ ( '.alert' ) . show ( ) ;
$ ( '.alert' ) . html ( data . error ) ;
} else {
$ ( '.alert' ) . show ( ) ;
$ ( '.alert' ) . html ( data . error ) ;
ban ( ) ;
}
2023-09-17 09:42:39 +00:00
} else {
2023-10-16 15:35:26 +00:00
sessionStorage . removeItem ( 'check-service' ) ;
2024-08-02 09:50:02 +00:00
window . location . replace ( data . next _url ) ;
2022-09-28 14:18:53 +00:00
}
2018-07-18 13:14:03 +00:00
}
2024-08-02 09:50:02 +00:00
} ) ;
2019-09-26 15:48:56 +00:00
return false ;
2018-07-18 05:46:37 +00:00
} ) ;
2020-07-05 06:59:51 +00:00
$ ( '#show_log_form' ) . submit ( function ( ) {
2023-09-17 09:42:39 +00:00
showLog ( ) ;
2020-07-05 06:59:51 +00:00
return false ;
} ) ;
2023-09-17 09:42:39 +00:00
$ ( '#show_internal_log_form' ) . submit ( function ( ) {
viewLogs ( ) ;
return false ;
} ) ;
2024-08-02 09:50:02 +00:00
let cur _url = window . location . href . split ( '/' ) . pop ( ) ;
cur _url = cur _url . split ( '#' ) ;
2023-09-17 09:42:39 +00:00
if ( cur _url [ 0 ] . indexOf ( 'install' ) != '-1' ) {
$ ( ".installproxy" ) . on ( "click" , function ( ) {
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'installproxy' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
$ ( "#tabs" ) . tabs ( "option" , "active" , 0 ) ;
} ) ;
$ ( ".installmon" ) . on ( "click" , function ( ) {
2019-09-20 06:42:19 +00:00
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'instalmon' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
$ ( "#tabs" ) . tabs ( "option" , "active" , 1 ) ;
} ) ;
$ ( ".installgeo" ) . on ( "click" , function ( ) {
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'installgeo' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
$ ( "#tabs" ) . tabs ( "option" , "active" , 2 ) ;
} ) ;
}
2024-05-03 12:22:58 +00:00
if ( cur _url [ 0 ] . indexOf ( 'admin' ) != '-1' ) {
2023-09-17 09:42:39 +00:00
$ ( ".users" ) . on ( "click" , function ( ) {
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'users' ) ;
2018-09-29 05:23:01 +00:00
} ) ;
2023-09-17 09:42:39 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 0 ) ;
} ) ;
2024-08-02 09:50:02 +00:00
$ ( ".servers" ) . on ( "click" , function ( ) {
2024-05-03 12:22:58 +00:00
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'servers' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
2024-05-03 12:22:58 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 1 ) ;
} ) ;
2024-08-02 09:50:02 +00:00
$ ( ".ssh" ) . on ( "click" , function ( ) {
2024-05-03 12:22:58 +00:00
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'ssh' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
2024-05-03 12:22:58 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 2 ) ;
} ) ;
$ ( ".settings" ) . on ( "click" , function ( ) {
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'settings' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
2024-05-03 12:22:58 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 3 ) ;
loadSettings ( ) ;
} ) ;
$ ( ".backup" ) . on ( "click" , function ( ) {
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'backup' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
2024-05-03 12:22:58 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 4 ) ;
loadBackup ( ) ;
} ) ;
2024-08-02 09:50:02 +00:00
$ ( ".groups" ) . on ( "click" , function ( ) {
2024-05-03 12:22:58 +00:00
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'groups' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
2024-05-03 12:22:58 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 5 ) ;
} ) ;
$ ( ".tools" ) . on ( "click" , function ( ) {
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'tools' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
2024-05-03 12:22:58 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 6 ) ;
loadServices ( ) ;
} ) ;
$ ( ".updatehapwi" ) . on ( "click" , function ( ) {
$ ( '.menu li ul li' ) . each ( function ( ) {
2024-08-02 09:50:02 +00:00
activeSubMenu ( $ ( this ) , 'updatehapwi' ) ;
2023-09-17 09:42:39 +00:00
} ) ;
2024-05-03 12:22:58 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 7 ) ;
loadupdatehapwi ( ) ;
} ) ;
2018-09-28 16:10:01 +00:00
}
2021-07-05 14:51:05 +00:00
$ ( '.copyToClipboard' ) . hover ( function ( ) {
2024-06-16 09:27:47 +00:00
$ . getScript ( overview ) ;
2021-07-05 14:51:05 +00:00
} ) ;
$ ( '.copyToClipboard' ) . click ( function ( ) {
let str = $ ( this ) . attr ( 'data-copy' ) ;
const el = document . createElement ( 'textarea' ) ;
el . value = str ;
el . setAttribute ( 'readonly' , '' ) ;
el . style . position = 'absolute' ;
el . style . left = '-9999px' ;
document . body . appendChild ( el ) ;
el . select ( ) ;
document . execCommand ( 'copy' ) ;
document . body . removeChild ( el ) ;
} )
2018-05-12 15:49:24 +00:00
} ) ;
2024-08-02 09:50:02 +00:00
function activeSubMenu ( sub _menu , sub _menu _class ) {
sub _menu . find ( 'a' ) . css ( 'padding-left' , '20px' ) ;
sub _menu . find ( 'a' ) . css ( 'border-left' , '0px solid var(--right-menu-blue-rolor)' ) ;
sub _menu . find ( 'a' ) . css ( 'background-color' , '#48505A' ) ;
sub _menu . children ( "." + sub _menu _class ) . css ( 'padding-left' , '30px' ) ;
sub _menu . children ( "." + sub _menu _class ) . css ( 'border-left' , '4px solid var(--color-wanring) !important' ) ;
sub _menu . children ( "." + sub _menu _class ) . css ( 'background-color' , 'var(--color-gray-dark-alpha) !important' ) ;
}
function saveUserSettings ( user _id ) {
2023-04-02 16:58:55 +00:00
if ( $ ( '#disable_alerting' ) . is ( ':checked' ) ) {
2021-02-03 19:25:37 +00:00
localStorage . removeItem ( 'disabled_alert' ) ;
2023-04-02 16:58:55 +00:00
} else {
localStorage . setItem ( 'disabled_alert' , '1' ) ;
2021-02-03 19:25:37 +00:00
}
2024-08-02 09:50:02 +00:00
changeCurrentGroupF ( user _id ) ;
2021-02-03 19:25:37 +00:00
}
2019-09-11 06:05:57 +00:00
function sleep ( ms ) {
2019-10-25 07:18:57 +00:00
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
2019-09-11 06:05:57 +00:00
}
2024-05-03 12:22:58 +00:00
function getRandomArbitrary ( min , max ) {
return Math . random ( ) * ( max - min ) + min ;
}
2019-09-11 06:05:57 +00:00
async function ban ( ) {
2024-08-02 09:50:02 +00:00
$ ( '#login' ) . attr ( 'disabled' , 'disabled' ) ;
$ ( '#pass' ) . attr ( 'disabled' , 'disabled' ) ;
$ ( "input[type=submit], button" ) . button ( 'disable' ) ;
2023-09-17 09:42:39 +00:00
$ ( '#wrong-login' ) . show ( ) ;
2019-09-11 06:05:57 +00:00
$ ( '#ban_10' ) . show ( ) ;
2024-08-02 09:50:02 +00:00
$ ( '#ban_timer' ) . text ( 10 ) ;
2022-09-28 14:18:53 +00:00
2019-09-11 06:05:57 +00:00
let i = 10 ;
while ( i > 0 ) {
i -- ;
await sleep ( 1000 ) ;
2024-08-02 09:50:02 +00:00
$ ( '#ban_timer' ) . text ( i ) ;
}
2022-09-28 14:18:53 +00:00
2024-08-02 09:50:02 +00:00
$ ( '#login' ) . removeAttr ( 'disabled' ) ;
$ ( '#pass' ) . removeAttr ( 'disabled' ) ;
$ ( "input[type=submit], button" ) . button ( 'enable' ) ;
2019-09-11 06:05:57 +00:00
$ ( '#ban_10' ) . hide ( ) ;
2022-09-28 14:18:53 +00:00
}
2018-05-12 15:49:24 +00:00
function replace _text ( id _textarea , text _var ) {
var str = $ ( id _textarea ) . val ( ) ;
var len = str . length ;
var len _var = text _var . length ;
var beg = str . indexOf ( text _var ) ;
var end = beg + len _var
var text _val = str . substring ( 0 , beg ) + str . substring ( end , len ) ;
$ ( id _textarea ) . text ( text _val ) ;
2018-06-29 06:07:24 +00:00
}
2019-12-01 17:15:09 +00:00
function createHistroy ( ) {
2021-01-09 15:42:08 +00:00
if ( localStorage . getItem ( 'history' ) === null ) {
2023-09-17 09:42:39 +00:00
var get _history _array = [ 'login' , 'login' , 'login' ] ;
2021-01-09 15:42:08 +00:00
localStorage . setItem ( 'history' , JSON . stringify ( get _history _array ) ) ;
2019-12-01 17:15:09 +00:00
}
}
2022-09-28 14:18:53 +00:00
function listHistroy ( ) {
2021-01-09 15:42:08 +00:00
var browse _history = JSON . parse ( localStorage . getItem ( 'history' ) ) ;
2019-12-01 17:15:09 +00:00
var history _link = '' ;
var title = [ ]
var link _text = [ ]
2023-10-03 19:56:34 +00:00
var cur _path = window . location . pathname ;
2019-12-01 17:15:09 +00:00
for ( let i = 0 ; i < browse _history . length ; i ++ ) {
if ( i == 0 ) {
browse _history [ 0 ] = browse _history [ 1 ] ;
}
2020-07-15 04:16:31 +00:00
if ( i == 1 ) {
2019-12-01 17:15:09 +00:00
browse _history [ 1 ] = browse _history [ 2 ]
}
if ( i == 2 ) {
2023-10-03 19:56:34 +00:00
browse _history [ 2 ] = cur _path
2019-12-01 17:15:09 +00:00
}
2020-07-02 14:44:13 +00:00
$ ( function ( ) {
2019-12-01 17:15:09 +00:00
$ ( '.menu li ul li' ) . each ( function ( ) {
var link1 = $ ( this ) . find ( 'a' ) . attr ( 'href' ) ;
2023-10-03 19:56:34 +00:00
if ( browse _history [ i ] . replace ( /\/$/ , "" ) == link1 ) {
2020-07-30 05:36:29 +00:00
title [ i ] = $ ( this ) . find ( 'a' ) . attr ( 'title' ) ;
link _text [ i ] = $ ( this ) . find ( 'a' ) . text ( ) ;
history _link = '<li><a href="' + browse _history [ i ] + '" title="' + title [ i ] + '">' + link _text [ i ] + '</a></li>'
2023-10-03 19:56:34 +00:00
$ ( '#browse_history' ) . append ( history _link ) ;
2019-12-01 17:15:09 +00:00
}
} ) ;
} ) ;
}
2021-01-09 15:42:08 +00:00
localStorage . setItem ( 'history' , JSON . stringify ( browse _history ) ) ;
2019-12-01 17:15:09 +00:00
}
2023-10-03 19:56:34 +00:00
createHistroy ( ) ;
listHistroy ( ) ;
2020-05-10 06:17:07 +00:00
2024-08-02 09:50:02 +00:00
function changeCurrentGroupF ( user _id ) {
2023-09-17 09:42:39 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/user/" + user _id + "/groups/" + $ ( '#newCurrentGroup' ) . val ( ) ,
contentType : "application/json; charset=utf-8" ,
type : "PATCH" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
2024-08-02 09:50:02 +00:00
if ( data . error === 'failed' ) {
toastr . error ( data . error ) ;
2021-01-02 16:36:43 +00:00
} else {
toastr . clear ( ) ;
location . reload ( ) ;
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2020-07-02 14:44:13 +00:00
}
2020-08-02 18:24:09 +00:00
function updateTips ( t ) {
var tips = $ ( ".validateTips" ) ;
tips . text ( t ) . addClass ( "alert-warning" ) ;
2021-08-11 05:37:36 +00:00
tips . text ( t ) . addClass ( "alert-one-row" ) ;
2020-08-02 18:24:09 +00:00
}
function clearTips ( ) {
var tips = $ ( ".validateTips" ) ;
2021-08-11 05:37:36 +00:00
tips . html ( 'Fields marked "<span class="need-field">*</span>" are required' ) . removeClass ( "alert-warning" ) ;
2020-08-02 18:24:09 +00:00
allFields = $ ( [ ] ) . add ( $ ( '#new-server-add' ) ) . add ( $ ( '#new-ip' ) ) . add ( $ ( '#new-port' ) ) . add ( $ ( '#new-username' ) ) . add ( $ ( '#new-password' ) )
allFields . removeClass ( "ui-state-error" ) ;
}
function checkLength ( o , n , min ) {
if ( o . val ( ) . length < min ) {
o . addClass ( "ui-state-error" ) ;
2022-05-12 06:42:16 +00:00
updateTips ( "Field " + n + " is required" ) ;
2020-08-02 18:24:09 +00:00
return false ;
} else {
return true ;
}
2020-08-25 12:38:49 +00:00
}
2020-10-02 12:39:00 +00:00
$ ( function ( ) {
ion . sound ( {
sounds : [
{
name : "bell_ring" ,
} ,
{
name : "glass" ,
volume : 1 ,
} ,
{
name : "alert_sound" ,
volume : 0.3 ,
preload : false
}
] ,
volume : 0.5 ,
2024-08-02 09:50:02 +00:00
path : "/static/js/sounds/" ,
2020-10-02 12:39:00 +00:00
preload : true
} ) ;
} ) ;
2022-03-15 09:51:03 +00:00
let socket = new ReconnectingWebSocket ( "wss://" + window . location . host , null , { maxReconnectAttempts : 20 , reconnectInterval : 3000 } ) ;
socket . onopen = function ( e ) {
console . log ( "[open] Connection is established with " + window . location . host ) ;
getAlerts ( ) ;
} ;
function getAlerts ( ) {
2024-08-02 09:50:02 +00:00
socket . send ( "alert_group " + $ ( '#user_group_socket' ) . val ( ) + " " + $ ( '#user_id_socket' ) . val ( ) ) ;
2022-03-15 09:51:03 +00:00
}
socket . onmessage = function ( event ) {
2024-08-02 09:50:02 +00:00
var cur _url = window . location . href . split ( '/' ) . pop ( ) ;
2024-01-09 06:55:19 +00:00
cur _url = cur _url . split ( '/' ) ;
if ( cur _url != 'login' && localStorage . getItem ( 'disabled_alert' ) === null ) {
2022-03-15 09:51:03 +00:00
data = event . data . split ( ";" ) ;
for ( i = 0 ; i < data . length ; i ++ ) {
if ( data [ i ] . indexOf ( 'error:' ) != '-1' || data [ i ] . indexOf ( 'alert' ) != '-1' || data [ i ] . indexOf ( 'FAILED' ) != '-1' ) {
if ( data [ i ] . indexOf ( 'error: database is locked' ) == '-1' ) {
toastr . error ( data [ i ] ) ;
ion . sound . play ( "bell_ring" ) ;
2020-10-02 12:39:00 +00:00
}
2022-03-15 09:51:03 +00:00
} else if ( data [ i ] . indexOf ( 'info: ' ) != '-1' ) {
toastr . info ( data [ i ] ) ;
ion . sound . play ( "glass" ) ;
} else if ( data [ i ] . indexOf ( 'success: ' ) != '-1' ) {
toastr . success ( data [ i ] ) ;
ion . sound . play ( "glass" ) ;
} else if ( data [ i ] . indexOf ( 'warning: ' ) != '-1' ) {
toastr . warning ( data [ i ] ) ;
ion . sound . play ( "bell_ring" ) ;
2023-01-17 18:23:53 +00:00
} else if ( data [ i ] . indexOf ( 'critical: ' ) != '-1' ) {
toastr . error ( data [ i ] ) ;
ion . sound . play ( "bell_ring" ) ;
2020-10-02 12:39:00 +00:00
}
2022-03-15 09:51:03 +00:00
}
2020-10-02 12:39:00 +00:00
}
2022-03-15 09:51:03 +00:00
} ;
socket . onclose = function ( event ) {
if ( event . wasClean ) {
console . log ( ` [close] Соединение закрыто чисто, код= ${ event . code } причина= ${ event . reason } ` ) ;
} else {
console . log ( '[close] Соединение прервано' ) ;
}
} ;
socket . onerror = function ( error ) {
console . log ( ` [error] ${ error . message } ` ) ;
} ;
2022-02-16 07:46:30 +00:00
function changePassword ( ) {
2022-11-09 16:47:59 +00:00
$ ( "#user-change-password-table" ) . dialog ( {
autoOpen : true ,
resizable : false ,
height : "auto" ,
width : 600 ,
modal : true ,
title : "Change password" ,
show : {
effect : "fade" ,
duration : 200
} ,
hide : {
effect : "fade" ,
duration : 200
} ,
buttons : {
"Change" : function ( ) {
changeUserPasswordItOwn ( $ ( this ) ) ;
2022-02-16 07:46:30 +00:00
} ,
2022-11-09 16:47:59 +00:00
Cancel : function ( ) {
$ ( this ) . dialog ( "close" ) ;
$ ( '#missmatchpass' ) . hide ( ) ;
2022-02-16 07:46:30 +00:00
}
2022-11-09 16:47:59 +00:00
}
} ) ;
2022-02-16 07:46:30 +00:00
}
function changeUserPasswordItOwn ( d ) {
var pass = $ ( '#change-password' ) . val ( ) ;
var pass2 = $ ( '#change2-password' ) . val ( ) ;
2023-09-17 09:42:39 +00:00
if ( pass != pass2 ) {
2022-02-16 07:46:30 +00:00
$ ( '#missmatchpass' ) . show ( ) ;
} else {
$ ( '#missmatchpass' ) . hide ( ) ;
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/user/password" ,
data : JSON . stringify ( { 'pass' : pass } ) ,
2022-02-16 07:46:30 +00:00
type : "POST" ,
2024-08-02 09:50:02 +00:00
contentType : "application/json; charset=utf-8" ,
2023-09-17 09:42:39 +00:00
success : function ( data ) {
2024-06-19 17:52:24 +00:00
if ( data . status === 'failed' ) {
toastr . error ( data . error ) ;
2022-02-16 07:46:30 +00:00
} else {
toastr . clear ( ) ;
2023-09-17 09:42:39 +00:00
d . dialog ( "close" ) ;
2022-02-16 07:46:30 +00:00
}
}
2023-09-17 09:42:39 +00:00
} ) ;
2022-02-16 07:46:30 +00:00
}
}
2022-04-27 18:10:26 +00:00
function findInConfig ( words ) {
2022-03-02 20:09:39 +00:00
clearAllAjaxFields ( ) ;
2023-09-17 09:42:39 +00:00
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/config/" + $ ( "#service" ) . val ( ) + "/find-in-config" ,
2023-09-17 09:42:39 +00:00
data : {
serv : $ ( "#serv" ) . val ( ) ,
words : words
} ,
type : "POST" ,
success : function ( data ) {
if ( data . indexOf ( 'error:' ) != '-1' ) {
toastr . error ( data ) ;
} else {
toastr . clear ( ) ;
$ ( "#ajax" ) . html ( data ) ;
2022-03-02 20:09:39 +00:00
}
2023-09-17 09:42:39 +00:00
}
} ) ;
2022-03-02 20:09:39 +00:00
}
2022-04-27 18:10:26 +00:00
function waitForElm ( selector ) {
2023-09-17 09:42:39 +00:00
return new Promise ( resolve => {
if ( document . querySelector ( selector ) ) {
return resolve ( document . querySelector ( selector ) ) ;
}
2022-04-27 18:10:26 +00:00
2023-09-17 09:42:39 +00:00
const observer = new MutationObserver ( mutations => {
if ( document . querySelector ( selector ) ) {
resolve ( document . querySelector ( selector ) ) ;
observer . disconnect ( ) ;
}
} ) ;
2022-04-27 18:10:26 +00:00
2023-09-17 09:42:39 +00:00
observer . observe ( document . body , {
childList : true ,
subtree : true
} ) ;
} ) ;
2022-04-27 18:10:26 +00:00
}
2022-06-02 09:08:37 +00:00
function randomIntFromInterval ( min , max ) {
return Math . floor ( Math . random ( ) * ( max - min + 1 ) + min )
}
2022-06-15 07:34:20 +00:00
const removeEmptyLines = str => str . split ( /\r?\n/ ) . filter ( line => line . trim ( ) !== '' ) . join ( '\n' ) ;
function returnNiceCheckingConfig ( data ) {
if ( data . indexOf ( 'sudo: firewall-cmd: command not found' ) != '-1' ) {
data = data . replaceAll ( 'sudo: firewall-cmd: command not found\n' , '' ) ;
data = data . replaceAll ( 'sudo: firewall-cmd: command not found' , '' ) ;
toastr . warning ( 'The Firewalld service is not enabled. You should disable this setting for this server or enable the firewalld service on the server.' )
}
data = data . replaceAll ( 'Configuration file is valid' , '' ) ;
data = data . replaceAll ( 'Warnings were found.' , '' ) ;
data = data . replaceAll ( 'nginx: the configuration file /etc/nginx/nginx.conf syntax is ok' , '' ) ;
data = data . replaceAll ( 'nginx: configuration file /etc/nginx/nginx.conf test is successful' , '' ) ;
data = data . replaceAll ( 'Syntax OK' , '' ) ;
output = data . split ( '<br>' )
2022-07-15 18:55:54 +00:00
var alerts = [ ] ;
var alert _warning = '' ;
2022-07-16 07:09:34 +00:00
var alert _warning2 = '' ;
2022-07-15 18:55:54 +00:00
var alert _error = '' ;
2022-07-16 07:09:34 +00:00
var second _alert = false ;
2022-06-15 07:34:20 +00:00
alerts . push ( output [ 0 ] + '\n' + output [ 1 ] ) ;
2022-07-16 07:09:34 +00:00
var server _name = output [ 0 ] ;
var server _name2 = '' ;
2022-06-15 07:34:20 +00:00
try {
for ( var i = 0 ; i < output . length ; i ++ ) {
if ( i > 1 ) {
if ( output [ i ] !== undefined ) {
alerts . push ( output [ i ] )
}
}
}
} catch ( err ) {
console . log ( err ) ;
}
alerts . forEach ( ( element ) => {
2024-03-01 08:40:58 +00:00
if ( element . indexOf ( 'error: ' ) != '-1' || element . indexOf ( 'Fatal' ) != '-1' || element . indexOf ( 'Error' ) != '-1' || element . indexOf ( 'failed ' ) != '-1' || element . indexOf ( 'emerg] ' ) != '-1' || element . indexOf ( 'Syntax error ' ) != '-1' || element . indexOf ( 'Parsing' ) != '-1' || element . indexOf ( 'Unknown' ) != '-1' ) {
2022-10-30 17:22:05 +00:00
alert _error = alert _error + element ;
2022-06-15 07:34:20 +00:00
return
}
if ( element . indexOf ( '[WARNING]' ) != '-1' || element . indexOf ( '[ALER]' ) != '-1' || element . indexOf ( '[warn]' ) != '-1' ) {
element = removeEmptyLines ( element ) ;
2022-07-16 07:09:34 +00:00
if ( second _alert == false ) {
alert _warning = alert _warning + element ;
} else {
alert _warning2 = alert _warning2 + element ;
2022-10-30 17:22:05 +00:00
server _name = 'Master server:' ;
server _name2 = 'Slave server:' ;
2022-07-16 07:09:34 +00:00
}
}
if ( second _alert && output . length > 4 && output [ 1 ] . indexOf ( '[NOTICE]' ) == '-1' ) {
2022-10-30 17:22:05 +00:00
server _name = 'Master server:' ;
server _name2 = 'Slave server:' ;
2022-07-16 07:09:34 +00:00
}
if ( element . length === 0 ) {
second _alert = true ;
2022-06-15 07:34:20 +00:00
}
2022-07-16 07:09:34 +00:00
2022-06-15 07:34:20 +00:00
} )
2022-07-16 07:09:34 +00:00
if ( alert _error ) {
toastr . error ( server _name + '<pre style="padding: 0; margin: 0;">' + alert _error + '</pre>' ) ;
2022-07-15 18:55:54 +00:00
toastr . info ( 'Config not applied' ) ;
2022-07-16 07:09:34 +00:00
} else if ( alert _warning ) {
toastr . warning ( server _name + '<pre style="padding: 0; margin: 0;">' + alert _warning + '</pre>' ) ;
toastr . success ( '<b>' + server _name + ' Configuration file is valid</b>' ) ;
} else {
toastr . success ( '<b>' + server _name + ' Configuration file is valid</b>' ) ;
}
if ( alert _warning2 ) {
toastr . warning ( server _name2 + '<pre style="padding: 0; margin: 0;">' + alert _warning2 + '</pre>' ) ;
toastr . success ( '<b>' + server _name2 + ' Configuration file is valid</b>' ) ;
} else if ( server _name2 ) {
toastr . success ( '<b>' + server _name2 + ' Configuration file is valid</b>' ) ;
2022-07-15 18:55:54 +00:00
}
2022-06-15 07:34:20 +00:00
}
2022-09-02 14:12:28 +00:00
function show _version ( ) {
NProgress . configure ( { showSpinner : false } ) ;
$ . ajax ( {
2024-08-02 09:50:02 +00:00
url : "/internal/show_version" ,
2022-09-02 14:12:28 +00:00
success : function ( data ) {
$ ( '#version' ) . html ( data ) ;
var showUpdates = $ ( "#show-updates" ) . dialog ( {
autoOpen : false ,
width : 600 ,
modal : true ,
title : 'There is a new Roxy-WI version' ,
buttons : {
Close : function ( ) {
$ ( this ) . dialog ( "close" ) ;
clearTips ( ) ;
}
}
} ) ;
$ ( '#show-updates-button' ) . click ( function ( ) {
showUpdates . dialog ( 'open' ) ;
} ) ;
}
} ) ;
NProgress . configure ( { showSpinner : true } ) ;
}
2022-11-09 19:05:47 +00:00
function statAgriment ( ) {
2024-08-02 09:50:02 +00:00
var cur _url = window . location . href . split ( '/' ) . pop ( ) ;
2024-01-09 06:55:19 +00:00
cur _url = cur _url . split ( '/' ) ;
if ( localStorage . getItem ( 'statistic' ) == null && cur _url != 'login' ) {
2022-11-09 19:05:47 +00:00
var titles = new Map ( )
var body = new Map ( )
var yes _ans = new Map ( )
var no _ans = new Map ( )
2022-11-09 19:54:35 +00:00
var ver _question = randomIntFromInterval ( 1 , 2 ) ;
2022-11-09 19:05:47 +00:00
titles . set ( 1 , 'Help us improve Roxy-WI' ) ;
titles . set ( 2 , 'Data collection agreement' ) ;
body . set ( 1 , 'We want to improve the user experience by collecting anonymous statistics. No marketing.' ) ;
body . set ( 2 , 'We’ d like to improve your experience in Roxy-WI, so we ask for statistics collection. No personal data is collected.' ) ;
yes _ans . set ( 1 , 'Yes' ) ;
yes _ans . set ( 2 , 'Agree and help the Roxy-WI team' ) ;
no _ans . set ( 1 , 'No' ) ;
no _ans . set ( 2 , 'Disagree' ) ;
$ ( "#statistic" ) . dialog ( {
autoOpen : true ,
resizable : false ,
height : "auto" ,
width : 600 ,
modal : true ,
2022-11-09 19:22:08 +00:00
title : titles . get ( ver _question ) ,
2022-11-09 19:05:47 +00:00
show : {
effect : "fade" ,
duration : 200
} ,
hide : {
effect : "fade" ,
duration : 200
} ,
buttons : [ {
"id" : "statYesBut" ,
text : "Yes" ,
click : function ( ) {
localStorage . setItem ( 'statistic' , '1' ) ;
$ ( this ) . dialog ( "close" ) ;
sendGet ( 'page/ans/1/' + ver _question ) ;
statAgriment ( ) ;
} ,
} , {
"id" : "statNoBut" ,
text : "No" ,
click : function ( ) {
localStorage . setItem ( 'statistic' , '0' ) ;
$ ( this ) . dialog ( "close" ) ;
sendGet ( 'page/ans/0/' + ver _question ) ;
}
} ]
} ) ;
$ ( "#statYesBut" ) . html ( '<span class="ui-button-text">' + yes _ans . get ( ver _question ) + '</span>' ) ;
$ ( "#statNoBut" ) . html ( '<span class="ui-button-text">' + no _ans . get ( ver _question ) + '</span>' ) ;
$ ( "#statistic-body" ) . html ( body . get ( ver _question ) ) ;
2022-11-09 16:47:59 +00:00
}
if ( localStorage . getItem ( 'statistic' ) == 1 ) {
2022-11-09 19:54:35 +00:00
cur _url = btoa ( cur _url ) ;
2022-11-09 19:05:47 +00:00
sendGet ( '/page/send/' + cur _url ) ;
2022-11-09 16:47:59 +00:00
}
}
2022-11-28 07:47:18 +00:00
function startIntro ( intro ) {
intro = intro . setOptions ( { 'exitOnOverlayClick' : false } ) ;
var intro _url = cur _url [ 0 ] . split ( '#' ) [ 0 ] ;
var intro _history = { } ;
intro . onbeforechange ( function ( targetElement ) {
2022-11-28 07:52:23 +00:00
if ( intro _url == 'users.py' && this . _currentStep == 3 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 1 ) ;
} else if ( intro _url == 'users.py' && this . _currentStep == 4 ) {
2022-11-28 07:47:18 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 2 ) ;
2022-11-28 07:52:23 +00:00
} else if ( intro _url == 'users.py' && this . _currentStep == 6 ) {
2022-11-28 07:47:18 +00:00
$ ( "#tabs" ) . tabs ( "option" , "active" , 3 ) ;
2022-11-28 07:52:23 +00:00
} else if ( intro _url == 'users.py' && this . _currentStep == 7 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 4 ) ;
} else if ( intro _url == 'users.py' && this . _currentStep == 9 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 6 ) ;
} else if ( intro _url == 'users.py' && this . _currentStep == 10 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 7 ) ;
} else if ( intro _url == 'users.py' && this . _currentStep == 12 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 8 ) ;
2022-11-28 07:47:18 +00:00
}
if ( intro _url == 'servers.py' && this . _currentStep == 5 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 1 ) ;
} else if ( intro _url == 'servers.py' && this . _currentStep == 13 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 2 ) ;
} else if ( intro _url == 'servers.py' && this . _currentStep == 16 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 6 ) ;
} else if ( intro _url == 'servers.py' && this . _currentStep == 18 ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 7 ) ;
}
} ) ;
intro . onbeforeexit ( function ( ) {
if ( localStorage . getItem ( 'intro' ) === null ) {
intro _history [ intro _url ] = '1' ;
localStorage . setItem ( 'intro' , JSON . stringify ( intro _history ) ) ;
} else {
intro _history = localStorage . getItem ( 'intro' ) ;
intro _history = JSON . parse ( intro _history ) ;
intro _history [ intro _url ] = '1' ;
localStorage . setItem ( 'intro' , JSON . stringify ( intro _history ) ) ;
}
} ) ;
intro . onexit ( function ( ) {
sendGet ( 'intro/' + intro _url + '/' + this . _currentStep ) ;
} ) ;
if ( localStorage . getItem ( 'intro' ) === null ) {
if ( intro _url . split ( '#' ) [ 0 ] == 'users.py' || intro _url . split ( '#' ) [ 0 ] == 'servers.py' ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 0 ) ;
}
intro . start ( ) ;
} else {
intro _history = localStorage . getItem ( 'intro' ) ;
intro _history = JSON . parse ( intro _history ) ;
if ( intro _history [ intro _url ] != '1' ) {
if ( intro _url . split ( '#' ) [ 0 ] == 'users.py' || intro _url . split ( '#' ) [ 0 ] == 'servers.py' ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , 0 ) ;
}
intro . start ( ) ;
}
}
}
document . addEventListener ( "DOMContentLoaded" , function ( event ) {
2024-01-09 06:55:19 +00:00
statAgriment ( ) ;
2022-11-28 07:47:18 +00:00
} ) ;
2022-11-09 19:05:47 +00:00
function sendGet ( page ) {
var xmlHttp = new XMLHttpRequest ( ) ;
var theUrl = 'https://roxy-wi.org/' + page ;
xmlHttp . open ( "GET" , theUrl , true ) ; // true for asynchronous
xmlHttp . send ( null ) ;
}
2022-11-20 07:48:15 +00:00
function show _pretty _ansible _error ( data ) {
try {
data = data . split ( 'error: ' ) ;
var p _err = JSON . parse ( data [ 1 ] ) ;
return p _err [ 'msg' ] ;
} catch ( e ) {
return data ;
}
}
2022-12-24 11:13:10 +00:00
function openTab ( tabId ) {
$ ( "#tabs" ) . tabs ( "option" , "active" , tabId ) ;
}
2023-04-02 16:58:55 +00:00
function showPassword ( input ) {
var x = document . getElementById ( input ) ;
if ( x . type === "password" ) {
x . type = "text" ;
} else {
x . type = "password" ;
}
}
2024-03-01 08:40:58 +00:00
function removeData ( ) {
let chart ;
for ( let i = 0 ; i < charts . length ; i ++ ) {
chart = charts [ i ] ;
chart . destroy ( ) ;
}
}
2024-03-18 09:54:27 +00:00
function common _ajax _action _after _success ( dialog _id , new _group , ajax _append _id , data ) {
toastr . clear ( ) ;
$ ( "#" + ajax _append _id ) . append ( data ) ;
$ ( "." + new _group ) . addClass ( "update" , 1000 ) ;
$ . getScript ( awesome ) ;
clearTips ( ) ;
$ ( dialog _id ) . dialog ( "close" ) ;
setTimeout ( function ( ) {
$ ( "." + new _group ) . removeClass ( "update" ) ;
} , 2500 ) ;
}
2024-08-02 09:50:02 +00:00
function getAllGroups ( ) {
let groups = '' ;
$ . ajax ( {
url : "/server/groups" ,
contentType : "application/json; charset=utf-8" ,
async : false ,
success : function ( data ) {
groups = data ;
}
} ) ;
return groups ;
}
function openUserSettings ( user _id ) {
if ( localStorage . getItem ( 'disabled_alert' ) == '1' ) {
$ ( '#disable_alerting' ) . prop ( 'checked' , false ) . checkboxradio ( 'refresh' ) ;
} else {
$ ( '#disable_alerting' ) . prop ( 'checked' , true ) . checkboxradio ( 'refresh' ) ;
}
$ . ajax ( {
url : "/user/group" ,
success : function ( data ) {
if ( data . indexOf ( 'danger' ) != '-1' ) {
$ ( "#ajax" ) . html ( data ) ;
} else {
$ ( '#show-user-settings-group' ) . html ( data ) ;
$ ( "select" ) . selectmenu ( ) ;
}
}
} ) ;
let user _settings _tabel _title = $ ( "#show-user-settings-table" ) . attr ( 'title' ) ;
let change _pass _word = $ ( '#translate' ) . attr ( 'data-change' ) + ' ' + $ ( '#translate' ) . attr ( 'data-password' )
let showUserSettings = $ ( "#show-user-settings" ) . dialog ( {
autoOpen : false ,
width : 600 ,
modal : true ,
title : user _settings _tabel _title ,
buttons : [ {
text : save _word ,
click : function ( ) {
saveUserSettings ( user _id ) ;
$ ( this ) . dialog ( "close" ) ;
}
} , {
text : change _pass _word ,
click : function ( ) {
changePassword ( ) ;
$ ( this ) . dialog ( "close" ) ;
}
} , {
text : cancel _word ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ]
} ) ;
showUserSettings . dialog ( 'open' ) ;
}
function generateSelect ( select _id , option _value , option _name , is _selected = '' ) {
$ ( select _id ) . append ( '<option value="' + option _value + '" ' + is _selected + '>' + option _name + '</option>' ) ;
}