Shinobi/web/pages/super.ejs

354 lines
16 KiB
Plaintext

<!DOCTYPE html>
<html lang="en">
<head>
<title><%-lang.Superuser%> - <%-lang.Shinobi%></title>
<% window.libURL = originalURL + global.s.checkCorrectPathEnding(config.webPaths.admin) %>
<% include blocks/header-meta.ejs %>
<% include blocks/header-favicon.ejs %>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport' />
<!-- Fonts and icons -->
<link href="<%-window.libURL%>libs/css/montserrat.css" rel="stylesheet" />
<link href="<%-window.libURL%>libs/css/font-awesome.min.css" rel="stylesheet" />
<!-- CSS Files -->
<link rel="stylesheet" href="<%-window.libURL%>libs/css/bootstrap4.min.css" />
<link rel="stylesheet" href="<%-window.libURL%>libs/css/main.dash2.css" />
<link rel="stylesheet" href="<%-window.libURL%>libs/css/pnotify.custom.min.css">
<link rel="stylesheet" href="<%-window.libURL%>libs/css/now-ui-kit.css?v=1.1.0" />
<link rel="stylesheet" href="<%-window.libURL%>libs/css/dash2.basic.css">
<link rel="stylesheet" href="<%-window.libURL%>libs/css/dash2.modal.css">
<link rel="stylesheet" href="<%-window.libURL%>libs/css/dash2.forms.css">
<link rel="stylesheet" href="<%-window.libURL%>libs/css/super-page.css" />
<script src="<%-window.libURL%>libs/js/jquery.min.js"></script>
<script src="<%-window.libURL%>libs/js/jquery-ui.min.js"></script>
<script src="<%-window.libURL%>libs/js/basic.js"></script>
<script src="<%-window.libURL%>libs/js/jquery.serialize.js"></script>
<script src="<%-window.libURL%>libs/js/pnotify.custom.min.js"></script>
<script src="<%-window.libURL%>libs/js/popper.min.js" type="text/javascript"></script>
<script src="<%-window.libURL%>libs/js/bootstrap4.min.js" type="text/javascript"></script>
<script src="<%-window.libURL%>libs/js/dash2.confirm.js" type="text/javascript"></script>
<style>
.form-group label>div:first-child{width:40%}
.list-group li .form-group {margin:0}
a {cursor:pointer}
</style>
<script>
var superApiPrefix = location.search === '?p2p=1' ? (location.pathname.endsWith('/') ? location.pathname : location.pathname) : "<%=originalURL%><%=config.webPaths.superApiPrefix%>"
</script>
<% customAutoLoad.superLibsCss.forEach(function(lib){ %>
<link rel="stylesheet" href="<%-window.libURL%>libs/css/<%-lib%>">
<% }) %>
</head>
<script>$user=<%-JSON.stringify($user)%></script>
<body class="index-page sidebar-collapse bg-hexagon">
<!-- Navbar -->
<nav id="main-nav" class="navbar navbar-expand-lg bg-primary fixed-top" color-on-scroll="400">
<div class="container">
<div class="navbar-translate">
<a tabindex="1" class="navbar-brand logout" style="outline:0" href="/" data-placement="bottom">
<%-lang.superAdminTitle%>
</a>
<button class="navbar-toggler navbar-toggler" type="button" data-toggle="collapse" data-target="#navigation" aria-controls="navigation-index" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-bar bar1"></span>
<span class="navbar-toggler-bar bar2"></span>
<span class="navbar-toggler-bar bar3"></span>
</button>
</div>
<div class="collapse navbar-collapse justify-content-end" id="navigation" data-nav-image="<%-window.libURL%>libs/img/blurred-image-1.jpg">
<ul class="nav navbar-nav navbar-right">
<li class="nav-item">
<a href="javascript:location.href=location.pathname" class="nav-link" class="logout">
<i class="fa fa-sign-out"></i>
<p class="d-lg-none d-xl-none"><%-lang.Logout%></p>
</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- End Navbar -->
<div class="wrapper">
<div class="page-header clear-filter" filter-color="primary">
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="main-card" class="card">
<ul class="nav nav-tabs nav-tabs-neutral justify-content-center bg-primary" id="tablist" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#accounts" role="tab"><%-lang['Accounts']%></a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#config" role="tab"><%-lang['Configuration']%></a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#system" role="tab"><%-lang['Controls and Logs']%></a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#changeSuperPreferences" role="tab"><%-lang['Preferences']%></a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#customAutoLoad" role="tab"><%-lang['Custom Auto Load']%></a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#easyRemoteAccess" role="tab"><%-lang['Easy Remote Access (P2P)']%></a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#superPluginManager" role="tab"><%-lang['Plugin Manager']%></a>
</li>
</ul>
<div class="card-body">
<!-- Tab panes -->
<div class="tab-content text-center">
<div class="tab-pane active" id="accounts" role="tabpanel">
<div class="row">
<div class="col-md-5 text-left">
<% include blocks/heyActivate.ejs %>
<div class="card shadow mb-3">
<pre class="super-system-info card-body mb-0">
</pre>
</div>
</div>
<div class="col-md-7">
<div class="mb-4"><a href="#" class="add btn btn-block btn-default"><i class="fa fa-plus"></i> <%- lang.Add %></a></div>
<div class="form-group-group red p-1" style="max-height:400px;overflow:auto">
<table class="table table-striped m-0"></table>
</div>
</div>
</div>
</div>
<div class="tab-pane text-left" id="config" role="tabpanel">
<% include blocks/superConfigEditor.ejs %>
</div>
<div class="tab-pane text-left" id="system" role="tabpanel">
<% include blocks/superSystemTab.ejs %>
</div>
<div class="tab-pane text-left" id="customAutoLoad" role="tabpanel">
<% include blocks/superCustomAutoLoadManager.ejs %>
</div>
<div class="tab-pane text-left" id="changeSuperPreferences" role="tabpanel">
<% include blocks/changeSuperPreferences.ejs %>
</div>
<div class="tab-pane text-left" id="easyRemoteAccess" role="tabpanel">
<% include blocks/easyRemoteAccess.ejs %>
</div>
<div class="tab-pane text-left" id="superPluginManager" role="tabpanel">
<% include blocks/superPluginManager.ejs %>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row text-center">
<div class="col">
<a href="https://gitlab.com/Shinobi-Systems/Shinobi/commit/<%- currentVersion %>" target="_blank">
<small class="epic-text" style="font-weight: 700;color: #fff;letter-spacing: 2pt;">
Current Version : <%- currentVersion %>
</small>
</a>
</div>
</div>
</div>
</div>
</div>
<div id="temp" style="display:none"></div>
</body>
<% include blocks/confirm.ejs %>
<% customAutoLoad.superPageBlocks.forEach(function(block){ %>
<%- include(block) %>
<% }) %>
<script src="<%-window.libURL%>libs/js/pnotify.custom.min.js" type="text/javascript"></script>
<script><% include ../libs/js/moment.js %></script>
<script src="<%-window.libURL%>libs/js/livestamp.min.js" type="text/javascript"></script>
<script src="<%-window.libURL%>libs/js/socket.io.min.js" type="text/javascript"></script>
<script src="<%-window.libURL%>libs/js/placeholder.js" type="text/javascript"></script>
<script src="<%-window.libURL%>libs/js/now-ui-kit.js?v=1.1.0" type="text/javascript"></script>
<script type="text/javascript">
var lang = <%- JSON.stringify(lang) || {} %>;
PNotify.prototype.options.styling = "fontawesome";
$(document).ready(function() {
// the body of this function is in assets/js/now-ui-kit.js
$('#main-card').css('margin-top',$('#main-nav').height() * 2)
});
function scrollToDownload() {
if ($('.section-download').length != 0) {
$("html, body").animate({
scrollTop: $('.section-download').offset().top
}, 1000);
}
}
</script>
<script>
var loadedUsers = {}
function drawUserList(){
loadedUsers = {}
$('#accounts table').empty()
$.get(superApiPrefix + $user.sessionKey + '/accounts/list/admin',function(data){
$.each(data.users,function(n,v){
loadedUsers[v.ke] = v
$.ccio.tm(0,v,'#accounts table')
})
})
}
function drawSystemLogs(){
$('#logs table').empty()
$.get(superApiPrefix + $user.sessionKey + '/logs',function(data){
if(data.ok){
$.each(data.logs.reverse(),function(n,v){
$.ccio.tm(4,v,'#logs table')
})
}else{
var html = `<div class="mt-3 mb-4"><p><i class="fa fa-4x fa-exclamation-circle text-danger"></i></p><h3>Database is not running or unreachable</h3><p>Please ensure it is started then restart Shinobi.</p><p>By default Shinobi uses <b>MariaDB</b>, an SQL server, as the database engine.</p><p>If you need to install the database files again you may follow <a target="_blank" href="https://shinobi.video/articles/2019-02-22-how-to-install-the-shinobi-database-manually">this article.</a></p></div>`
$('#main-card').html(html)
}
})
}
function drawSystemInfo(){
$.get(superApiPrefix + $user.sessionKey + '/system/info',function(data){
if(data.ok){
$('.super-system-info').html($.ccio.init('jsontoblock',data.info))
}
})
}
$.ccio={accounts:{}};$.ls=localStorage;
if(!$user.lang||$user.lang==''){
$user.lang="<%-config.language%>"
}
switch($user.lang){
case'ar'://Arabic
case'bn'://Bengali
$('body').addClass('right-to-left')
$('.mdl-menu__item').each(function(n,v){
v=$(v).find('i')
v.appendTo(v.parent())
})
break;
}
if(location.search === '?p2p=1'){
$.ccio.ws=io(location.origin,{
path : '/socket.io'
});
}else{
$.ccio.ws=io(location.origin,{
path : tool.checkCorrectPathEnding(location.pathname)+'socket.io'
});
}
$.ccio.cx=function(x){return $.ccio.ws.emit('super',x)}
$.ccio.ws.on('connect',function(d){
$.ccio.cx({f:'init',mail:$user.mail,pass:$user.pass,machineId: `<%- config.machineId %>`})
})
$.ccio.ws.on('f',function(d){
switch(d.f){
case'init_success':
$user.sessionKey = d.superSessionKey
drawUserList()
drawSystemLogs()
drawSystemInfo()
break;
case'log':
$.ccio.tm(4,d.log,'#logs table')
break;
case'save_configuration':
d.msg = 'Saved, Restart Shinobi to apply changes.'
break;
case'save_preferences':
d.msg = 'Saved Preferences'
break;
case'edit_account':
d.msg='Account Edited';
$.each(d.form,function(n,v){
$.ccio.accounts[d.ke][n]=v
})
$('[ke="'+d.ke+'"] .mail').text(d.form.mail)
break;
case'add_account':
d.msg='Account Created';
$.ccio.tm(0,d,'#accounts table')
$.aN.selected = $.ccio.accounts[d.ke]
break;
case'delete_account':
$('#accounts table tr[ke="'+d.ke+'"]').remove()
break;
}
if(d.msg&&typeof d.msg==='string'){
new PNotify({text:d.msg,type:'error'})
}
})
$.ccio.tm=function(x,d,z,k){
var tmp='';if(!d){d={}};if(!k){k={}};
if(d.id&&!d.mid){d.mid=d.id;}
switch(x){
case 0://account row
d.detailsJSON=JSON.parse(d.details);
$.ccio.accounts[d.ke]=d;
tmp+='<tr ke="'+d.ke+'"><td class="text-left pl-3"><span class="mail">'+d.mail+'</span></td><td><span>'+d.ke+'</span></td><td><a tabindex="1" class="permission btn badge badge-sm badge-info m-0"><i class="fa fa-lock"></i></a></td><td><a tabindex="1" class="delete btn badge badge-sm badge-danger m-0"><i class="fa fa-trash-o"></i></a></td></tr>';
break;
case 4://log row, draw to global and monitor
if(!d.time){d.time=$.ccio.init('t')}
tmp+='<tr class="search-row"><td><span title="'+d.time+'" class="livestamp"></span><br><small>'+d.time+'</small><br><small>'+d.mid+'</small></td><td></td><td><pre class="pre-inline">'+$.ccio.init('jsontoblock',d.info)+'</pre></td></tr>'
break;
}
if(z){
$(z).prepend(tmp)
}
switch(x){
case 4:
$.ccio.init('ls')
break;
}
return tmp;
}
$.ccio.init=function(x,d,z,k){
if(!k){k={}};k.tmp='';
switch(x){
case 'ls'://livestamp all
g={e:jQuery('.livestamp')};
g.e.each(function(){g.v=jQuery(this),g.t=g.v.attr('title');if(!g.t){return};g.v.toggleClass('livestamp livestamped').attr('title',$.ccio.init('t',g.t)).livestamp(g.t);})
return g.e
break;
case't'://format time
if(!d){d=new Date();}
return moment(d).format('YYYY-MM-DD HH:mm:ss')
break;
case'jsontoblock'://draw json as block
if(d instanceof Object){
k.tmp+='<ul>'
$.each(d,function(n,v){
k.tmp+='<li>';
k.tmp+='<b>'+n+'</b> : '+$.ccio.init('jsontoblock',v);
k.tmp+='</li>';
})
k.tmp+='</ul>'
}else{
k.tmp+='<span>';
k.tmp+=d;
k.tmp+='</span>';
}
break;
}
return k.tmp;
}
//logs
$.logs={e:$('#logs')}
////
$('body')
.on('click','.logout',function(e){
localStorage.removeItem('ShinobiLogin_'+location.host);location.href='/';
})
</script>
<% include blocks/mainpermissions.ejs %>
<% customAutoLoad.superLibsJs.forEach(function(lib){ %>
<script src="<%-window.libURL%>libs/js/<%-lib%>"></script>
<% }) %>
<% customAutoLoad.superRawJs.forEach(function(scriptData){ %>
<script><%- scriptData %></script>
<% }) %>
</html>