2021-03-08 18:45:06 +00:00
function topFunction ( ) {
document . body . scrollTop = 0 ; // For Safari
document . documentElement . scrollTop = 0 ; // For Chrome, Firefox, IE and Opera
}
2023-10-24 13:56:37 +00:00
function login _menu ( basic _auth ) {
2021-03-08 18:45:06 +00:00
topFunction ( ) ;
2022-01-11 13:33:30 +00:00
var html = '<h2>Admin Login</h2>' ;
2023-10-24 13:56:37 +00:00
html += '<form id="password_login_form" onsubmit="log_in(' + basic _auth + ');return false">'
2021-03-08 18:45:06 +00:00
2021-10-04 12:26:50 +00:00
2023-10-24 13:56:37 +00:00
if ( ! basic _auth ) {
html += '<div class="form-group newline">' ;
html += '<label for="username" title="The username chosen during first-time setup.">Username:</label>' ;
html += '<input type="text" class="form-control" id="username" value="" placeholder="" minlength=4 autocomplete="on" required />' ;
html += '</div>' ;
html += '<div class="form-group newline">' ;
html += '<label for="password" title="The password chosen during first-time setup.">Password:</label>' ;
html += '<input type="password" class="form-control" id="password" value="" autocomplete="off" required />' ;
html += '</div>' ;
}
2021-03-08 18:45:06 +00:00
2022-01-11 13:33:30 +00:00
html += '<div class="form-group newline">' ;
html += '<div id="password_login_form_error"></div>' ;
html += '</div>' ;
html += '<div class="form-group newline">' ;
2023-10-28 14:43:59 +00:00
html += ` <button type="submit" class="form-control btn" id="log_in_button"><img src=" ${ root } /assets/done.svg" class="btn_logo"><p2>Log in</p2></button> ` ;
2021-03-08 18:45:06 +00:00
html += '</div>' ;
html += '</form>' ;
document . getElementById ( "setup" ) . innerHTML = html ;
}
2023-10-24 13:56:37 +00:00
function log _in ( basic _auth ) {
2022-01-11 13:33:30 +00:00
// Disable button
document . getElementById ( "log_in_button" ) . disabled = true ;
document . getElementById ( "log_in_button" ) . style . opacity = '0.5' ;
// Get variables
2023-10-24 13:56:37 +00:00
if ( ! basic _auth ) {
password = document . getElementById ( 'password' ) . value ;
username = document . getElementById ( 'username' ) . value ;
2022-01-11 13:33:30 +00:00
2023-10-24 13:56:37 +00:00
admin _login _form = { "admin_password" : password , "admin_username" : username } ;
2022-01-11 13:33:30 +00:00
2023-10-24 13:56:37 +00:00
var admin _login _data = JSON . stringify ( admin _login _form ) ;
} else {
var admin _login _data = ""
}
2022-01-11 13:33:30 +00:00
var xhttp = new XMLHttpRequest ( ) ;
xhttp . onreadystatechange = function ( ) {
2022-07-04 15:47:59 +00:00
if ( this . readyState == 4 ) {
2022-01-11 13:33:30 +00:00
try {
var result = JSON . parse ( this . responseText ) ;
} catch ( error ) {
console . log ( 'Failed to parse API response. Response: ' + this . responseText )
document . getElementById ( "log_in_button" ) . disabled = false ;
document . getElementById ( "log_in_button" ) . style . opacity = '1' ;
document . getElementById ( 'password' ) . value = '' ;
2022-07-04 22:11:19 +00:00
return ;
2022-01-11 13:33:30 +00:00
}
if ( result . error ) {
2023-10-25 13:14:02 +00:00
try {
document . getElementById ( "password_login_form_error" ) . innerHTML = result . error ;
document . getElementById ( "log_in_button" ) . disabled = false ;
document . getElementById ( "log_in_button" ) . style . opacity = '1' ;
document . getElementById ( 'password' ) . value = '' ;
} catch ( e ) {
console . log ( "Failed to reset input fields. Error: " + e )
}
2022-01-11 13:33:30 +00:00
} else {
2023-10-25 13:14:02 +00:00
tokenPrefix = "Bearer "
set _cookie ( "wrapperr-admin" , tokenPrefix + result . data , 3 ) ;
2022-01-11 13:33:30 +00:00
location . reload ( ) ;
}
}
} ;
xhttp . withCredentials = true ;
2022-12-03 12:06:48 +00:00
xhttp . open ( "post" , api _url + "login/admin" ) ;
2022-01-11 13:33:30 +00:00
xhttp . send ( admin _login _data ) ;
return ;
}
function set _password _form ( ) {
2021-03-08 18:45:06 +00:00
topFunction ( ) ;
2022-01-11 13:33:30 +00:00
var html = '<h2>Create admin</h2>' ;
html += '<form id="password_form" onsubmit="set_password();return false;">'
2021-03-08 18:45:06 +00:00
2022-01-11 13:33:30 +00:00
html += '<div class="form-group newline">' ;
2021-12-12 16:31:15 +00:00
html += '<label for="username" title="The username needed to log in as administrator and change the config-file remotely.">Set an admin username:</label>' ;
html += '<input type="text" class="form-control" id="username" value="' + username + '" placeholder="" minlength=4 autocomplete="on" required />' ;
2021-10-04 12:26:50 +00:00
html += '</div>' ;
2021-03-08 18:45:06 +00:00
html += '<div class="form-group">' ;
2021-12-12 16:31:15 +00:00
html += '<label for="password" title="The password needed to change the config-file remotely.">Set an admin password:</label>' ;
html += '<input type="password" class="form-control" id="password" value="' + password + '" placeholder="" autocomplete="off" required />' ;
2021-03-08 18:45:06 +00:00
html += '</div>' ;
html += '<div class="form-group">' ;
2021-12-12 16:31:15 +00:00
html += '<label for="password_2" title="The password needed to change the config-file remotely.">Repeat the password:</label>' ;
html += '<input type="password" class="form-control" id="password_2" value="' + password + '" placeholder="" autocomplete="off" required />' ;
2021-03-08 18:45:06 +00:00
html += '</div>' ;
2022-01-11 13:33:30 +00:00
html += '<div class="form-group newline">' ;
html += '<div id="password_form_error"></div>' ;
html += '</div>' ;
html += '<div class="form-group newline">' ;
2023-10-28 14:43:59 +00:00
html += ` <button type="submit" class="form-control btn" id="create_admin_button"><img src=" ${ root } /assets/done.svg" class="btn_logo"><p2>Create account</p2></button> ` ;
2021-03-08 18:45:06 +00:00
html += '</div>' ;
html += '</form>' ;
document . getElementById ( "setup" ) . innerHTML = html ;
}
2022-01-11 13:33:30 +00:00
function set _password ( ) {
// Disable button
document . getElementById ( "create_admin_button" ) . disabled = true ;
document . getElementById ( "create_admin_button" ) . style . opacity = '0.5' ;
// Check password match
if ( document . getElementById ( 'password' ) . value != document . getElementById ( 'password_2' ) . value ) {
alert ( "The passwords must match." ) ;
document . getElementById ( 'password' ) . value = "" ;
document . getElementById ( 'password_2' ) . value = "" ;
document . getElementById ( 'password' ) . focus ( ) ;
document . getElementById ( "create_admin_button" ) . disabled = false ;
document . getElementById ( "create_admin_button" ) . style . opacity = '1' ;
return false ;
} else {
password = document . getElementById ( 'password' ) . value ;
username = document . getElementById ( 'username' ) . value ;
}
2021-03-13 22:55:08 +00:00
2022-07-04 15:47:59 +00:00
admin _create _form = { "admin_password" : password , "admin_username" : username } ;
2022-01-11 13:33:30 +00:00
var admin _create _data = JSON . stringify ( admin _create _form ) ;
var xhttp = new XMLHttpRequest ( ) ;
xhttp . onreadystatechange = function ( ) {
2022-07-04 22:11:19 +00:00
if ( this . readyState == 4 ) {
2022-01-11 13:33:30 +00:00
try {
var result = JSON . parse ( this . responseText ) ;
} catch ( error ) {
console . log ( 'Failed to parse API response. Response: ' + this . responseText )
document . getElementById ( "create_admin_button" ) . disabled = false ;
document . getElementById ( "create_admin_button" ) . style . opacity = '1' ;
2022-07-04 22:11:19 +00:00
return ;
2022-01-11 13:33:30 +00:00
}
if ( result . error ) {
2023-10-25 13:14:02 +00:00
document . getElementById ( "password_form_error" ) . innerHTML = result . error ;
2022-01-11 13:33:30 +00:00
document . getElementById ( "create_admin_button" ) . disabled = false ;
document . getElementById ( "create_admin_button" ) . style . opacity = '1' ;
} else {
location . reload ( ) ;
}
}
} ;
xhttp . withCredentials = true ;
2022-12-03 12:06:48 +00:00
xhttp . open ( "post" , api _url + "create/admin" ) ;
2022-01-11 13:33:30 +00:00
xhttp . send ( admin _create _data ) ;
return ;
}
function update _password _form ( ) {
2021-03-08 18:45:06 +00:00
topFunction ( ) ;
2022-01-11 13:33:30 +00:00
var html = '<div class="form-group newline">' ;
2023-10-28 14:43:59 +00:00
html += ` <button class="form-control btn" name="admin_menu_return_button" id="admin_menu_return_button" onclick="get_config(get_cookie( \' wrapperr-admin \' ));"><img src=" ${ root } /assets/trash.svg" class="btn_logo"></img><p2 id="admin_menu_return_button_text">Return</p2></button> ` ;
2022-01-11 13:33:30 +00:00
html += '</div>' ;
html += '<div class="form-group newline">' ;
html += '<hr>' ;
html += '</div>' ;
html += '<form id="update_password_form" onsubmit="return false;">'
html += '<div class="form-group newline">' ;
html += '<label for="username" title="The username needed to log in as administrator and change the config-file remotely.">Update admin username:</label>' ;
html += '<input type="text" class="form-control" id="username" value="' + username + '" placeholder="" minlength=4 autocomplete="on" required />' ;
html += '</div>' ;
html += '<div class="form-group">' ;
html += '<label for="password" title="The password needed to change the config-file remotely.">Update admin password:</label>' ;
html += '<input type="password" class="form-control" id="password" value="" placeholder="" autocomplete="off" required />' ;
html += '</div>' ;
html += '<div class="form-group">' ;
html += '<label for="password_2" title="The password needed to change the config-file remotely.">Repeat the password:</label>' ;
html += '<input type="password" class="form-control" id="password_2" value="" placeholder="" autocomplete="off" required />' ;
html += '</div>' ;
2023-10-25 13:14:02 +00:00
html += '<div class="form-group newline">' ;
html += '<label for="password_original" title="The current login password.">Current password:</label>' ;
html += '<input type="password" class="form-control" id="password_original" value="" placeholder="" autocomplete="off" required />' ;
html += '</div>' ;
2022-01-11 13:33:30 +00:00
html += '<div class="form-group newline">' ;
html += '<div id="password_form_error"></div>' ;
html += '</div>' ;
html += '<div class="form-group newline">' ;
2023-10-28 14:43:59 +00:00
html += ` <button type="submit" class="form-control btn" onclick="update_password();" id="update_admin_button"><img src=" ${ root } /assets/done.svg" class="btn_logo"><p2>Update account</p2></button> ` ;
2022-01-11 13:33:30 +00:00
html += '</div>' ;
html += '</form>' ;
document . getElementById ( "setup" ) . innerHTML = html ;
}
function update _password ( ) {
// Disable button
document . getElementById ( "update_admin_button" ) . disabled = true ;
document . getElementById ( "update_admin_button" ) . style . opacity = '0.5' ;
// Check password match
if ( document . getElementById ( 'password' ) . value != document . getElementById ( 'password_2' ) . value ) {
alert ( "The passwords must match." ) ;
document . getElementById ( 'password' ) . value = "" ;
document . getElementById ( 'password_2' ) . value = "" ;
document . getElementById ( 'password' ) . focus ( ) ;
document . getElementById ( "update_admin_button" ) . disabled = false ;
document . getElementById ( "update_admin_button" ) . style . opacity = '1' ;
return false ;
} else {
password = document . getElementById ( 'password' ) . value ;
2023-10-25 13:14:02 +00:00
password _original = document . getElementById ( 'password_original' ) . value ;
2022-01-11 13:33:30 +00:00
username = document . getElementById ( 'username' ) . value ;
2021-03-08 18:45:06 +00:00
}
2023-10-25 13:14:02 +00:00
admin _create _form = { "admin_password" : password , "admin_password_original" : password _original , "admin_username" : username } ;
2022-01-11 13:33:30 +00:00
var admin _create _data = JSON . stringify ( admin _create _form ) ;
var xhttp = new XMLHttpRequest ( ) ;
xhttp . onreadystatechange = function ( ) {
2022-07-04 22:11:19 +00:00
if ( this . readyState == 4 ) {
2022-01-11 13:33:30 +00:00
try {
var result = JSON . parse ( this . responseText ) ;
} catch ( error ) {
document . getElementById ( "password_form_error" ) . innerHTML = 'Failed to parse API response.' ;
console . log ( 'Failed to parse API response. Response: ' + this . responseText )
document . getElementById ( "update_admin_button" ) . disabled = false ;
document . getElementById ( "update_admin_button" ) . style . opacity = '1' ;
2022-07-04 22:11:19 +00:00
return ;
2022-01-11 13:33:30 +00:00
}
if ( result . error ) {
2023-10-25 13:14:02 +00:00
document . getElementById ( "password_form_error" ) . innerHTML = result . error ;
2022-01-11 13:33:30 +00:00
document . getElementById ( "update_admin_button" ) . disabled = false ;
document . getElementById ( "update_admin_button" ) . style . opacity = '1' ;
} else {
set _cookie ( "wrapperr-admin" , "" , 1 ) ;
location . reload ( ) ;
}
}
} ;
xhttp . withCredentials = true ;
2022-12-03 12:06:48 +00:00
xhttp . open ( "post" , api _url + "update/admin" ) ;
2022-07-04 15:47:59 +00:00
xhttp . setRequestHeader ( "Content-Type" , "application/json;charset=UTF-8" ) ;
2023-10-25 13:14:02 +00:00
xhttp . setRequestHeader ( "Authorization" , cookie ) ;
2022-01-11 13:33:30 +00:00
xhttp . send ( admin _create _data ) ;
return ;
}
2023-10-28 14:43:59 +00:00
function loadAdminPage ( ) {
2022-01-11 13:33:30 +00:00
2023-10-29 17:03:55 +00:00
var html = `
< div class = "admin-button-group" >
< div class = "form-group" > ` ;
2023-10-28 14:43:59 +00:00
html += ` <button class="form-control btn" onclick="update_password_form()"><img src=" ${ root } /assets/config.svg" class="btn_logo"><p2>Admin settings</p2></button> ` ;
html += ` </div> ` ;
2022-01-11 13:33:30 +00:00
2023-10-28 14:43:59 +00:00
html += ` <div class="form-group"> ` ;
html += ` <button class="form-control btn" name="plex_signout_button" id="plex_signout_button" onclick="sign_out()"><img src=" ${ root } /assets/close.svg" class="btn_logo"></img><p2 id="plex_signout_button_text">Sign Out</p2></button> ` ;
2023-10-29 17:03:55 +00:00
html += ` </div>
< / d i v >
` ;
2022-01-11 13:33:30 +00:00
2023-10-28 14:43:59 +00:00
html += ` <div class="form-group newline"> ` ;
html += ` <hr> ` ;
html += ` </div> ` ;
2022-01-11 13:33:30 +00:00
2023-10-28 14:43:59 +00:00
html += ` <div class="form-group newline"> ` ;
html += ` <button class="form-control btn" onclick="TautulliPageRedirect();" id="set_tautulli_settings"><img src=" ${ root } /assets/config.svg" class="btn_logo"><p2>Tautulli settings</p2></button> ` ;
html += ` </div> ` ;
2022-01-11 13:33:30 +00:00
2023-10-28 14:43:59 +00:00
html += ` <div class="form-group newline"> ` ;
html += ` <button class="form-control btn" onclick="SettingsPageRedirect();" id="set_wrapperr_settings"><img src=" ${ root } /assets/config.svg" class="btn_logo"><p2>Wrapperr settings</p2></button> ` ;
html += ` </div> ` ;
2022-01-11 13:33:30 +00:00
2023-10-28 14:43:59 +00:00
html += ` <div class="form-group newline"> ` ;
html += ` <button class="form-control btn" onclick="CustomizationPageRedirect();" id="set_wrapperr_customization"><img src=" ${ root } /assets/config.svg" class="btn_logo"><p2>Wrapperr customization</p2></button> ` ;
html += ` </div> ` ;
2022-01-11 13:33:30 +00:00
2023-10-28 14:43:59 +00:00
html += ` <div class="form-group newline"> ` ;
html += ` <button class="form-control btn" onclick="CachingPageRedirect();" id="caching_menu"><img src=" ${ root } /assets/download.svg" class="btn_logo"><p2>Caching</p2></button> ` ;
html += ` </div> ` ;
2022-01-11 13:33:30 +00:00
2023-10-28 14:43:59 +00:00
html += ` <div class="form-group newline"> ` ;
html += ` <button class="form-control btn" onclick="LogsPageRedirect();" id="log_menu"><img src=" ${ root } /assets/document.svg" class="btn_logo"><p2>Log</p2></button> ` ;
html += ` </div> ` ;
2022-07-04 15:47:59 +00:00
2023-10-29 17:03:55 +00:00
html += ` <div class="form-group newline"> ` ;
html += ` <button class="form-control btn" onclick="UsersPageRedirect();" id="log_menu"><img src=" ${ root } /assets/users.svg" class="btn_logo"><p2>Users</p2></button> ` ;
html += ` </div> ` ;
2022-01-11 13:33:30 +00:00
document . getElementById ( "setup" ) . innerHTML = html ;
if ( timezone === '' ) {
document . getElementById ( "set_wrapperr_settings" ) . style . border = '0.15em dashed var(--red)' ;
document . getElementById ( "caching_menu" ) . disabled = true ;
document . getElementById ( "caching_menu" ) . style . opacity = '0.5' ;
}
if ( wrapped _start === '' || wrapped _end === '' ) {
document . getElementById ( "set_wrapperr_customization" ) . style . border = '0.15em dashed var(--red)' ;
document . getElementById ( "caching_menu" ) . disabled = true ;
document . getElementById ( "caching_menu" ) . style . opacity = '0.5' ;
}
2022-11-27 17:12:11 +00:00
if ( tautulli [ 0 ] . tautulli _ip === '' || tautulli [ 0 ] . tautulli _apikey === '' || tautulli [ 0 ] . tautulli _length === '' || tautulli [ 0 ] . tautulli _port == 0 || tautulli [ 0 ] . tautulli _length == 0 ) {
2022-01-11 13:33:30 +00:00
document . getElementById ( "set_tautulli_settings" ) . style . border = '0.15em dashed var(--red)' ;
document . getElementById ( "caching_menu" ) . disabled = true ;
document . getElementById ( "caching_menu" ) . style . opacity = '0.5' ;
}
2022-07-04 15:47:59 +00:00
if ( ! use _logs ) {
document . getElementById ( "log_menu" ) . disabled = true ;
document . getElementById ( "log_menu" ) . style . opacity = '0.5' ;
}
2021-12-12 16:31:15 +00:00
}