Easy Activation Prompt in Superuser Panel
parent
0543fca04d
commit
ff442ace9f
|
@ -1189,6 +1189,10 @@
|
|||
"Hostname": "Hostname",
|
||||
"Network": "Network",
|
||||
"Notice": "Notice",
|
||||
"Activated": "Activated",
|
||||
"activatedText": "Your Installation has been Activated.",
|
||||
"Not Activated": "Not Activated",
|
||||
"notActivatedText": "Your Installation has failed Activation.",
|
||||
"getUserInfo": "Get User Information",
|
||||
"getAllMonitors": "Get All Monitors",
|
||||
"getAMonitor": "Get a Monitor",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const moment = require('moment');
|
||||
const request = require('request');
|
||||
module.exports = (processCwd) => {
|
||||
const parseJSON = (string) => {
|
||||
var parsed
|
||||
|
@ -78,6 +79,40 @@ module.exports = (processCwd) => {
|
|||
if(!e){e=new Date};if(!x){x='YYYY-MM-DDTHH-mm-ss'};
|
||||
return moment(e).format(x);
|
||||
}
|
||||
const checkSubscription = (subscriptionId,callback) => {
|
||||
function subscriptionFailed(){
|
||||
console.error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
console.error('This Install of Shinobi is NOT Activated')
|
||||
console.error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
s.systemLog('This Install of Shinobi is NOT Activated')
|
||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
console.log('https://licenses.shinobi.video/subscribe')
|
||||
}
|
||||
if(subscriptionId && subscriptionId !== 'sub_XXXXXXXXXXXX'){
|
||||
var url = 'https://licenses.shinobi.video/subscribe/check?subscriptionId=' + subscriptionId
|
||||
request(url,{
|
||||
method: 'GET',
|
||||
timeout: 30000
|
||||
}, function(err,resp,body){
|
||||
var json = s.parseJSON(body)
|
||||
if(err)console.log(err,json)
|
||||
var hasSubcribed = json && !!json.ok
|
||||
callback(hasSubcribed)
|
||||
if(hasSubcribed){
|
||||
s.systemLog('This Install of Shinobi is Activated')
|
||||
if(!json.expired && json.timeExpires){
|
||||
s.systemLog(`This License expires on ${json.timeExpires}`)
|
||||
}
|
||||
}else{
|
||||
subscriptionFailed()
|
||||
}
|
||||
})
|
||||
}else{
|
||||
subscriptionFailed()
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
return {
|
||||
parseJSON: parseJSON,
|
||||
stringJSON: stringJSON,
|
||||
|
@ -89,5 +124,6 @@ module.exports = (processCwd) => {
|
|||
utcToLocal: utcToLocal,
|
||||
localToUtc: localToUtc,
|
||||
formattedTime: formattedTime,
|
||||
checkSubscription: checkSubscription,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
var fs = require('fs');
|
||||
var request = require('request');
|
||||
var moment = require('moment');
|
||||
var crypto = require('crypto');
|
||||
var exec = require('child_process').exec;
|
||||
|
@ -9,6 +8,9 @@ module.exports = function(s,config,lang,io){
|
|||
const {
|
||||
scanForOrphanedVideos
|
||||
} = require('./video/utils.js')(s,config,lang)
|
||||
const {
|
||||
checkSubscription
|
||||
} = require('./basic/utils.js')(process.cwd())
|
||||
return new Promise((resolve, reject) => {
|
||||
var checkedAdminUsers = {}
|
||||
console.log('FFmpeg version : '+s.ffmpegVersion)
|
||||
|
@ -391,41 +393,6 @@ module.exports = function(s,config,lang,io){
|
|||
})
|
||||
}
|
||||
config.userHasSubscribed = false
|
||||
var checkSubscription = function(callback){
|
||||
var subscriptionFailed = function(){
|
||||
console.error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
console.error('This Install of Shinobi is NOT Activated')
|
||||
console.error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
s.systemLog('This Install of Shinobi is NOT Activated')
|
||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
console.log('https://licenses.shinobi.video/subscribe')
|
||||
}
|
||||
if(config.subscriptionId && config.subscriptionId !== 'sub_XXXXXXXXXXXX'){
|
||||
var url = 'https://licenses.shinobi.video/subscribe/check?subscriptionId=' + config.subscriptionId
|
||||
request(url,{
|
||||
method: 'GET',
|
||||
timeout: 30000
|
||||
}, function(err,resp,body){
|
||||
var json = s.parseJSON(body)
|
||||
if(err)console.log(err,json)
|
||||
var hasSubcribed = json && !!json.ok
|
||||
config.userHasSubscribed = hasSubcribed
|
||||
callback(hasSubcribed)
|
||||
if(config.userHasSubscribed){
|
||||
s.systemLog('This Install of Shinobi is Activated')
|
||||
if(!json.expired){
|
||||
s.systemLog(`This License expires on ${json.timeExpires}`)
|
||||
}
|
||||
}else{
|
||||
subscriptionFailed()
|
||||
}
|
||||
})
|
||||
}else{
|
||||
subscriptionFailed()
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
//check disk space every 20 minutes
|
||||
if(config.autoDropCache===true){
|
||||
setInterval(function(){
|
||||
|
@ -444,7 +411,8 @@ module.exports = function(s,config,lang,io){
|
|||
s.preQueries()
|
||||
setTimeout(() => {
|
||||
//check for subscription
|
||||
checkSubscription(function(){
|
||||
checkSubscription(config.subscriptionId,function(hasSubcribed){
|
||||
config.userHasSubscribed = hasSubcribed
|
||||
//check terminal commander
|
||||
checkForTerminalCommands(function(){
|
||||
//load administrators (groups)
|
||||
|
|
|
@ -11,6 +11,9 @@ module.exports = function(s,config,lang,app){
|
|||
updateSystem,
|
||||
getSystemInfo,
|
||||
} = require('./system/utils.js')(config)
|
||||
const {
|
||||
checkSubscription
|
||||
} = require('./basic/utils.js')(process.cwd())
|
||||
/**
|
||||
* API : Superuser : Get Logs
|
||||
*/
|
||||
|
@ -138,6 +141,38 @@ module.exports = function(s,config,lang,app){
|
|||
},res,req)
|
||||
})
|
||||
/**
|
||||
* API : Superuser : Activate Key
|
||||
*/
|
||||
app.post(config.webPaths.superApiPrefix+':auth/system/activate', function (req,res){
|
||||
s.superAuth(req.params,async (resp) => {
|
||||
var endData = {
|
||||
ok : true
|
||||
}
|
||||
const currentConfig = JSON.parse(fs.readFileSync(s.location.config))
|
||||
const subscriptionId = s.getPostData(req,'subscriptionId')
|
||||
if(!subscriptionId){
|
||||
endData.ok = false
|
||||
endData.msg = lang.postDataBroken
|
||||
}else{
|
||||
s.systemLog('conf.json Modified',{
|
||||
by: resp.$user.mail,
|
||||
ip: resp.ip,
|
||||
old: currentConfig
|
||||
})
|
||||
const configError = await modifyConfiguration(Object.assign({
|
||||
subscriptionId: subscriptionId,
|
||||
},currentConfig))
|
||||
if(configError)s.systemLog(configError)
|
||||
s.tx({f:'save_configuration'},'$')
|
||||
}
|
||||
checkSubscription(subscriptionId,function(hasSubcribed){
|
||||
endData.ok = hasSubcribed
|
||||
config.userHasSubscribed = hasSubcribed
|
||||
s.closeJsonResponse(res,endData)
|
||||
})
|
||||
},res,req)
|
||||
})
|
||||
/**
|
||||
* API : Superuser : Get users in system
|
||||
*/
|
||||
app.all([
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<form id="hey-activate" class="card shadow mb-3">
|
||||
<div class="card-header">
|
||||
<%- lang['Not Activated'] %>
|
||||
</div>
|
||||
<div class="card-body" style="min-height:auto">
|
||||
<div class="form-group">
|
||||
<input name="subscriptionId" id="pass" tabindex="2" class="form-control wide-text" placeholder="License Key / Subscription ID">
|
||||
</div>
|
||||
<div class="form-group mb-0">
|
||||
<button class="btn btn-sm btn-round btn-block btn-success" type="submit"><%- lang.Save %></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- <style>
|
||||
#hey-activate {
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: auto;
|
||||
position: fixed;
|
||||
max-width: 400px;
|
||||
padding: 20px;
|
||||
background: rgba(0,0,0,0.7);
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px #333;
|
||||
}
|
||||
</style> -->
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
var heyActivateCard = $('#hey-activate')
|
||||
var heyActivateCardSubmit = heyActivateCard.find('[type="submit"]')
|
||||
heyActivateCard.submit(function(e){
|
||||
e.preventDefault()
|
||||
var formValues = $(this).serializeObject()
|
||||
heyActivateCardSubmit.html(`<i class="fa fa-spinner fa-pulse"></i>`)
|
||||
$.post(superApiPrefix + $user.sessionKey + '/system/activate',{
|
||||
subscriptionId: formValues.subscriptionId
|
||||
},function(data){
|
||||
var noticeTitle = lang['Not Activated']
|
||||
var noticeText = data.msg || lang.notActivatedText
|
||||
var noticeType = 'warning'
|
||||
if(data.ok){
|
||||
noticeTitle = lang.Activated
|
||||
noticeText = lang.activatedText
|
||||
noticeType = 'success'
|
||||
heyActivateCard.remove()
|
||||
}else{
|
||||
heyActivateCardSubmit.html(lang.Save)
|
||||
}
|
||||
new PNotify({
|
||||
title: noticeTitle,
|
||||
text: noticeText,
|
||||
type: noticeType
|
||||
})
|
||||
})
|
||||
return false
|
||||
})
|
||||
})
|
||||
</script>
|
|
@ -19,7 +19,11 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<pre class="super-system-info form-group-group red"></pre>
|
||||
<div class="card shadow mb-3">
|
||||
<pre class="super-system-info card-body mb-0">
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div id="logs" class="col-md-7">
|
||||
<div class="form-group-group red" style="height:400px;overflow:auto">
|
||||
|
|
|
@ -103,7 +103,14 @@
|
|||
<div class="tab-pane active" id="accounts" role="tabpanel">
|
||||
<div class="row">
|
||||
<div class="col-md-5 text-left">
|
||||
<pre class="super-system-info form-group-group red"></pre>
|
||||
<% if(!config.userHasSubscribed){ %>
|
||||
<% 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>
|
||||
|
|
Loading…
Reference in New Issue