diff --git a/src/.init.lua b/src/.init.lua
index 2b9e889..98f0cf3 100644
--- a/src/.init.lua
+++ b/src/.init.lua
@@ -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
diff --git a/src/.lua/config.lua b/src/.lua/config.lua
index 0c8f328..3c0c0ec 100644
--- a/src/.lua/config.lua
+++ b/src/.lua/config.lua
@@ -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",
diff --git a/src/.lua/soakbean.lua b/src/.lua/soakbean.lua
index c791513..1b7a5fa 100644
--- a/src/.lua/soakbean.lua
+++ b/src/.lua/soakbean.lua
@@ -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 = {}
diff --git a/src/middleware/httpauth.lua b/src/middleware/httpauth.lua
index 8159002..9b21b23 100644
--- a/src/middleware/httpauth.lua
+++ b/src/middleware/httpauth.lua
@@ -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
diff --git a/src/plugin/archive.lua b/src/plugin/archive.lua
index 96f8e6b..093a043 100644
--- a/src/plugin/archive.lua
+++ b/src/plugin/archive.lua
@@ -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.
NOTE: this only works in server mode. For static website generator-users: see Save Page Now',
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 = {},
diff --git a/src/plugin/clouddrive.lua b/src/plugin/clouddrive.lua
index 985591e..2a56fd4 100644
--- a/src/plugin/clouddrive.lua
+++ b/src/plugin/clouddrive.lua
@@ -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
diff --git a/src/plugin/global.lua b/src/plugin/global.lua
index d4fb046..e30715c 100644
--- a/src/plugin/global.lua
+++ b/src/plugin/global.lua
@@ -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)
diff --git a/src/util/build.sh b/src/util/build.sh
index 95d2602..2a6c569 100755
--- a/src/util/build.sh
+++ b/src/util/build.sh
@@ -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
}
"$@"