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 --
|
||||
.use( require("middleware/httpauth")({
|
||||
user = app.opts.admin_user,
|
||||
pass = app.opts.admin_pass,
|
||||
path = "^/admin"
|
||||
path = "^/admin",
|
||||
authenticate = function(user,pass,req)
|
||||
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('page/dir').middleware ) -- directory browser
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ return function(app)
|
|||
name = "XRForge",
|
||||
baseurl="/",
|
||||
hostname="",
|
||||
-- the following is being overruled by plugins (but still needed without plugins)
|
||||
admin_title = "admin panel",
|
||||
admin_subtitle = "Manage your XR experiences here",
|
||||
admin_user = "admin",
|
||||
|
|
|
|||
|
|
@ -330,6 +330,8 @@ return function(data)
|
|||
sb.arg = arg
|
||||
sb.bin = arg[-1]:gsub(".*/","")
|
||||
sb.bindir = arg[-1]:gsub("/[a-zA-Z0-9-_ ]+.com$","/")
|
||||
sb.host = 'localhost'
|
||||
sb.scheme = 'https'
|
||||
sb.app = app
|
||||
sb.data = data
|
||||
sb.data.url = {}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ function Authenticate(opts,realm)
|
|||
|
||||
-- Basic Auth format is "username:password"
|
||||
local user, pass = decoded:match("([^:]+):(.*)")
|
||||
if user == opts.user and pass == opts.pass then
|
||||
print("info: succesful login for user: "..user)
|
||||
if (user == opts.user and pass == opts.pass) or
|
||||
(opts.authenticate and opts.authenticate(user,pass,req) )
|
||||
then
|
||||
print("info: succesful login for adin user: ")
|
||||
return true -- Access granted
|
||||
end
|
||||
end
|
||||
|
|
@ -24,22 +26,23 @@ function Authenticate(opts,realm)
|
|||
return false
|
||||
end
|
||||
|
||||
|
||||
-- soakbean middleware functions
|
||||
return function(opts)
|
||||
|
||||
opts = opts or {
|
||||
user = "admin",
|
||||
pass = "admin",
|
||||
path = "^/admin"
|
||||
}
|
||||
|
||||
return function(req,res,next)
|
||||
-- Protect a specific path (e.g., /admin or everything under /private/)
|
||||
if req.url:match( opts.path ) then
|
||||
if not Authenticate(opts,"Admin Zone") then
|
||||
print("ERROR")
|
||||
print("AUTH ERROR")
|
||||
else
|
||||
req.user = 'admin'
|
||||
req.authenticated = true
|
||||
req.user = opts.user
|
||||
next()
|
||||
end
|
||||
else
|
||||
|
|
|
|||
|
|
@ -11,19 +11,11 @@ app.on('set', function(k,v)
|
|||
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 notify()
|
||||
app.plugin.archive.notify()
|
||||
--notify() -- loop forever
|
||||
end
|
||||
if assert( code) == 0 then notify() end -- go!
|
||||
end
|
||||
app.plugin.archive.waybackmachine()
|
||||
end)
|
||||
|
||||
app.on('autobackup', function()
|
||||
app.plugin.archive.waybackmachine()
|
||||
end)
|
||||
|
||||
-- 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>',
|
||||
opts = {
|
||||
{
|
||||
key='app.opts.plugin_archive_frequency',
|
||||
title='Archive frequency',
|
||||
key='app.opts.plugin_archive_when',
|
||||
title='When to trigger',
|
||||
info='when should archive.org check this xrforge?',
|
||||
default = "wip beta -v[0-9] customerX",
|
||||
values={boot="On XRForge start"}
|
||||
default = "boot",
|
||||
values={boot="On start", boot_autobackup="On start + autobackup event"}
|
||||
},
|
||||
{
|
||||
key='app.opts.plugin_archive_url',
|
||||
title='Startingpoint URL',
|
||||
info='absolute URL which archive.org should start with',
|
||||
default = "https://localhost:8080/myverse",
|
||||
placeholder = "http://my.org/myverse",
|
||||
info='absolute URL which archive.org (waybackmachine) should start with',
|
||||
default = "/myverse",
|
||||
placeholder = "/myverse",
|
||||
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
|
||||
and not app.opts.plugin_archive_url:match("localhost")
|
||||
and not app.host:match("localhost")
|
||||
then
|
||||
print("notifying archive.org")
|
||||
local ok, headers, body = Fetch('https://web.archive.org/save/'.. app.opts.plugin_archive_url )
|
||||
local ok, headers, body = Fetch('https://web.archive.org/save/'.. app.scheme .. '://' .. app.host .. app.opts.plugin_archive_url )
|
||||
else
|
||||
print("ℹ️ skip notifying archive.org")
|
||||
end
|
||||
unix.exit()
|
||||
end,
|
||||
|
||||
url = {},
|
||||
|
|
|
|||
|
|
@ -11,12 +11,47 @@ end)
|
|||
app.on('set', function(k,v)
|
||||
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
|
||||
local plugin = {
|
||||
name = 'Cloud drives',
|
||||
info = '',
|
||||
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()
|
||||
if util.cmdExist('rclone') then
|
||||
local me = app.plugin.clouddrive
|
||||
|
|
|
|||
|
|
@ -48,6 +48,22 @@ local plugin = {
|
|||
info = '',
|
||||
ext = {"mp3","wav","ogg","mp4","vtt","md","html","jml","jpg","png","svg"},
|
||||
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',
|
||||
title='Title',
|
||||
|
|
@ -126,6 +142,13 @@ local plugin = {
|
|||
default="Remote / Federated",
|
||||
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 = {
|
||||
homepage_2D_or_3D = function(req,res,next)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ build(){
|
|||
|
||||
rebuild(){
|
||||
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