archive.org rclone autobackup
This commit is contained in:
parent
9b22ed13b4
commit
64bce9db14
8 changed files with 93 additions and 36 deletions
|
|
@ -105,9 +105,10 @@ end)
|
||||||
|
|
||||||
app --
|
app --
|
||||||
.use( require("middleware/httpauth")({
|
.use( require("middleware/httpauth")({
|
||||||
user = app.opts.admin_user,
|
path = "^/admin",
|
||||||
pass = app.opts.admin_pass,
|
authenticate = function(user,pass,req)
|
||||||
path = "^/admin"
|
return user == app.opts.admin_user and pass == app.opts.admin_pass
|
||||||
|
end
|
||||||
}))
|
}))
|
||||||
.use( require("json").middleware() ) -- try plug'n'play json API middleware
|
.use( require("json").middleware() ) -- try plug'n'play json API middleware
|
||||||
.use( require('page/dir').middleware ) -- directory browser
|
.use( require('page/dir').middleware ) -- directory browser
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ return function(app)
|
||||||
name = "XRForge",
|
name = "XRForge",
|
||||||
baseurl="/",
|
baseurl="/",
|
||||||
hostname="",
|
hostname="",
|
||||||
|
-- the following is being overruled by plugins (but still needed without plugins)
|
||||||
admin_title = "admin panel",
|
admin_title = "admin panel",
|
||||||
admin_subtitle = "Manage your XR experiences here",
|
admin_subtitle = "Manage your XR experiences here",
|
||||||
admin_user = "admin",
|
admin_user = "admin",
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,8 @@ return function(data)
|
||||||
sb.arg = arg
|
sb.arg = arg
|
||||||
sb.bin = arg[-1]:gsub(".*/","")
|
sb.bin = arg[-1]:gsub(".*/","")
|
||||||
sb.bindir = arg[-1]:gsub("/[a-zA-Z0-9-_ ]+.com$","/")
|
sb.bindir = arg[-1]:gsub("/[a-zA-Z0-9-_ ]+.com$","/")
|
||||||
|
sb.host = 'localhost'
|
||||||
|
sb.scheme = 'https'
|
||||||
sb.app = app
|
sb.app = app
|
||||||
sb.data = data
|
sb.data = data
|
||||||
sb.data.url = {}
|
sb.data.url = {}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,10 @@ function Authenticate(opts,realm)
|
||||||
|
|
||||||
-- Basic Auth format is "username:password"
|
-- Basic Auth format is "username:password"
|
||||||
local user, pass = decoded:match("([^:]+):(.*)")
|
local user, pass = decoded:match("([^:]+):(.*)")
|
||||||
if user == opts.user and pass == opts.pass then
|
if (user == opts.user and pass == opts.pass) or
|
||||||
print("info: succesful login for user: "..user)
|
(opts.authenticate and opts.authenticate(user,pass,req) )
|
||||||
|
then
|
||||||
|
print("info: succesful login for adin user: ")
|
||||||
return true -- Access granted
|
return true -- Access granted
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -24,22 +26,23 @@ function Authenticate(opts,realm)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- soakbean middleware functions
|
-- soakbean middleware functions
|
||||||
return function(opts)
|
return function(opts)
|
||||||
|
|
||||||
opts = opts or {
|
opts = opts or {
|
||||||
user = "admin",
|
user = "admin",
|
||||||
pass = "admin",
|
pass = "admin",
|
||||||
path = "^/admin"
|
path = "^/admin"
|
||||||
}
|
}
|
||||||
|
|
||||||
return function(req,res,next)
|
return function(req,res,next)
|
||||||
-- Protect a specific path (e.g., /admin or everything under /private/)
|
-- Protect a specific path (e.g., /admin or everything under /private/)
|
||||||
if req.url:match( opts.path ) then
|
if req.url:match( opts.path ) then
|
||||||
if not Authenticate(opts,"Admin Zone") then
|
if not Authenticate(opts,"Admin Zone") then
|
||||||
print("ERROR")
|
print("AUTH ERROR")
|
||||||
else
|
else
|
||||||
|
req.user = 'admin'
|
||||||
req.authenticated = true
|
req.authenticated = true
|
||||||
req.user = opts.user
|
|
||||||
next()
|
next()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,11 @@ app.on('set', function(k,v)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
app.on('init', function()
|
app.on('init', function()
|
||||||
local me = app.plugin.archive
|
app.plugin.archive.waybackmachine()
|
||||||
if arg[1] == 'server' then
|
end)
|
||||||
local code, pid = unix.fork()
|
|
||||||
-- kill thread when main app gets CTRL-c
|
app.on('autobackup', function()
|
||||||
unix.sigaction(unix.SIGINT, function()
|
app.plugin.archive.waybackmachine()
|
||||||
unix.exit()
|
|
||||||
end)
|
|
||||||
function notify()
|
|
||||||
app.plugin.archive.notify()
|
|
||||||
--notify() -- loop forever
|
|
||||||
end
|
|
||||||
if assert( code) == 0 then notify() end -- go!
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- this registers the plugin UI
|
-- this registers the plugin UI
|
||||||
|
|
@ -32,31 +24,31 @@ local plugin = {
|
||||||
info = 'Notify archive.org to archive experiences.<br><b>NOTE</b>: this only works in server mode. For static website generator-users: see <a href="https://web.archive.org/" target="_blank">Save Page Now</a>',
|
info = 'Notify archive.org to archive experiences.<br><b>NOTE</b>: this only works in server mode. For static website generator-users: see <a href="https://web.archive.org/" target="_blank">Save Page Now</a>',
|
||||||
opts = {
|
opts = {
|
||||||
{
|
{
|
||||||
key='app.opts.plugin_archive_frequency',
|
key='app.opts.plugin_archive_when',
|
||||||
title='Archive frequency',
|
title='When to trigger',
|
||||||
info='when should archive.org check this xrforge?',
|
info='when should archive.org check this xrforge?',
|
||||||
default = "wip beta -v[0-9] customerX",
|
default = "boot",
|
||||||
values={boot="On XRForge start"}
|
values={boot="On start", boot_autobackup="On start + autobackup event"}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key='app.opts.plugin_archive_url',
|
key='app.opts.plugin_archive_url',
|
||||||
title='Startingpoint URL',
|
title='Startingpoint URL',
|
||||||
info='absolute URL which archive.org should start with',
|
info='absolute URL which archive.org (waybackmachine) should start with',
|
||||||
default = "https://localhost:8080/myverse",
|
default = "/myverse",
|
||||||
placeholder = "http://my.org/myverse",
|
placeholder = "/myverse",
|
||||||
values=''
|
values=''
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
notify = function()
|
waybackmachine = function()
|
||||||
|
local url = 'https://web.archive.org/save/'.. app.scheme .. '://' .. app.host .. app.opts.plugin_archive_url
|
||||||
|
print("notifying archive.org: " .. url)
|
||||||
if #app.opts.plugin_archive_url > 0
|
if #app.opts.plugin_archive_url > 0
|
||||||
and not app.opts.plugin_archive_url:match("localhost")
|
and not app.host:match("localhost")
|
||||||
then
|
then
|
||||||
print("notifying archive.org")
|
local ok, headers, body = Fetch('https://web.archive.org/save/'.. app.scheme .. '://' .. app.host .. app.opts.plugin_archive_url )
|
||||||
local ok, headers, body = Fetch('https://web.archive.org/save/'.. app.opts.plugin_archive_url )
|
|
||||||
else
|
else
|
||||||
print("ℹ️ skip notifying archive.org")
|
print("ℹ️ skip notifying archive.org")
|
||||||
end
|
end
|
||||||
unix.exit()
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
url = {},
|
url = {},
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,47 @@ end)
|
||||||
app.on('set', function(k,v)
|
app.on('set', function(k,v)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
app.on('init', function()
|
||||||
|
local me = app.plugin.archive
|
||||||
|
if arg[1] == 'server' then
|
||||||
|
local code, pid = unix.fork()
|
||||||
|
-- kill thread when main app gets CTRL-c
|
||||||
|
unix.sigaction(unix.SIGINT, function()
|
||||||
|
unix.exit()
|
||||||
|
end)
|
||||||
|
function autobackup()
|
||||||
|
if app.opts.plugin_global_backup_trigger == 'daily' then
|
||||||
|
app.pub('autobackup', nil, {})
|
||||||
|
Sleep(60*24) -- 24 hours worth of seconds
|
||||||
|
autobackup() -- recurse forever
|
||||||
|
end
|
||||||
|
unix.exit(0)
|
||||||
|
end
|
||||||
|
if assert( code) == 0 then autobackup() end -- go!
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
app.on('autobackup', function()
|
||||||
|
if util.cmdExist('rclone') then
|
||||||
|
print("running RCLONE cmd sync!")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- this registers the plugin UI
|
-- this registers the plugin UI
|
||||||
local plugin = {
|
local plugin = {
|
||||||
name = 'Cloud drives',
|
name = 'Cloud drives',
|
||||||
info = '',
|
info = '',
|
||||||
infowide = true,
|
infowide = true,
|
||||||
opts = { },
|
opts = {
|
||||||
|
{
|
||||||
|
key='app.opts.plugin_clouddrive_syncpath',
|
||||||
|
title='Autobackup syncpath',
|
||||||
|
info='enter rclone-destination to sync ' .. app.opts.plugin_diskscan_dir .. ' to periodically (rclone) sync to',
|
||||||
|
default = "",
|
||||||
|
placeholder = "archive_org:/my-archive-id",
|
||||||
|
values=''
|
||||||
|
}
|
||||||
|
},
|
||||||
mount = function()
|
mount = function()
|
||||||
if util.cmdExist('rclone') then
|
if util.cmdExist('rclone') then
|
||||||
local me = app.plugin.clouddrive
|
local me = app.plugin.clouddrive
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,22 @@ local plugin = {
|
||||||
info = '',
|
info = '',
|
||||||
ext = {"mp3","wav","ogg","mp4","vtt","md","html","jml","jpg","png","svg"},
|
ext = {"mp3","wav","ogg","mp4","vtt","md","html","jml","jpg","png","svg"},
|
||||||
opts = {
|
opts = {
|
||||||
|
{
|
||||||
|
key='app.opts.admin_user',
|
||||||
|
title='Admin username',
|
||||||
|
info='login for ' .. app.scheme .. '://' .. app.host .. '/admin',
|
||||||
|
default = "admin",
|
||||||
|
placeholder = "admin",
|
||||||
|
values=''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key='app.opts.admin_pass',
|
||||||
|
title='Admin password',
|
||||||
|
info='password for ' .. app.scheme .. '://' .. app.host .. '/admin',
|
||||||
|
default = "admin",
|
||||||
|
placeholder = "admin",
|
||||||
|
values=''
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key='app.opts.plugin_global_title',
|
key='app.opts.plugin_global_title',
|
||||||
title='Title',
|
title='Title',
|
||||||
|
|
@ -126,6 +142,13 @@ local plugin = {
|
||||||
default="Remote / Federated",
|
default="Remote / Federated",
|
||||||
values=''
|
values=''
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key='app.opts.plugin_global_backup_trigger',
|
||||||
|
title='Backup',
|
||||||
|
info='plugins (Archive.org/clouddrive) will receive`autobackup`-event',
|
||||||
|
default = "daily",
|
||||||
|
values={daily="every day",disabled="disabled"}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
middleware = {
|
middleware = {
|
||||||
homepage_2D_or_3D = function(req,res,next)
|
homepage_2D_or_3D = function(req,res,next)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ build(){
|
||||||
|
|
||||||
rebuild(){
|
rebuild(){
|
||||||
cd src
|
cd src
|
||||||
zip -yr ../result/bin/xrforge.com .lua shader img page plugin cmd css .init.lua .args test myverse
|
zip -yr ../result/bin/xrforge.com .lua shader img middlware page plugin cmd css .init.lua .args test myverse
|
||||||
}
|
}
|
||||||
|
|
||||||
"$@"
|
"$@"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue