@ -1,49 +1,98 @@
// Load required modules
// Load required modules
// note that for WebXR, e.g SpaSca, https is required, even if using own certifcate
// see how it's done for offline NAF
const http = require ( "http" ) ; // http server core module
const http = require ( "http" ) ; // http server core module
const path = require ( "path" ) ;
const path = require ( "path" ) ;
const express = require ( "express" ) ; // web framework external module
const express = require ( "express" ) ; // web framework external module
const spawn = require ( 'child_process' ) . spawn ;
const { execSync } = require ( 'child_process' ) ;
// Get port or default to 8080
// Get port or default to 8080
const port = process . env . PORT || 8082 ;
const port = process . env . PORT || 8082 ;
// Setup and configure Express http server.
// Setup and configure Express http server.
const app = express ( ) ;
const app = express ( ) ;
app . use ( express . static ( path . resolve ( _ _dirname , ".. " , "examples" ) ) ) ;
app . use ( express . static ( path . resolve ( _ _dirname , "." , "examples" ) ) ) ;
const instructions = `
const instructions = `
/ h o m e / d e c k / . s s h /
/ h o m e / d e c k / . s s h /
trusted context , i . e on closed WiFi and over https , still . could check as bearer
/ h o m e / d e c k / . s s h / c o n f i g
could limit to known IP range or class e . g cat . ssh / config | grep 192.168 . 4. - C 3
could also re - add new entries rather than extend the format
/ h o m e / d e c k / . s s h / a u t h o r i z e d _ k e y s
/ h o m e / d e c k / . s s h / a u t h o r i z e d _ k e y s
/ h o m e / d e c k / . s s h / i d _ r s a _ s t e a m d e c k
/ h o m e / d e c k / . s s h / k n o w n _ h o s t s
/ h o m e / d e c k / . s s h / k n o w n _ h o s t s
/ h o m e / d e c k / . s s h / c o n f i g
/ h o m e / d e c k / . s s h / i d _ r s a _ s t e a m d e c k
/ h o m e / d e c k / . s s h / i d _ r s a _ s t e a m d e c k . p u b
/ h o m e / d e c k / . s s h / i d _ r s a _ s t e a m d e c k . p u b
/ h o m e / d e c k / . s s h / k n o w n _ h o s t s . o l d
trusted context , i . e on closed WiFi , still . check on bearer
/ h o m e / d e c k / s e r v e r . l o c a t e d b
/ h o m e / d e c k / s e r v e r . l o c a t e d b
seems to be plain text with metadata
/ h o m e / d e c k / d e s k t o p . p l o c a t e . d b
/ h o m e / d e c k / d e s k t o p . p l o c a t e . d b
should be queriable via http with json output
seems to be a specific format , binary or maybe compressed
both should be queriable via http with json output
ssh remarkable2 to get drawe io ng previw
ssh remarkable2 to get drawing previe w
conversion should be done , if necessary , on device
conversion should be done , if necessary , on device
for typed text
cat 43 * . rm | sed "s/[^a-zA-z0-9 ]//g" | sed "s/[OT,EC]//g"
util functions
util functions
modify WiFi parameters , including AP if available
modify WiFi parameters , including AP if available
shutdown / reboot
shutdown / reboot
`
`
app . get ( '/spawn' , ( req , res ) => {
app . get ( '/pwa' , ( req , res ) => {
res . json ( spawn ( 'ls' ) )
// for offline use on mobile or VR headset
// should try to sync back when devices connect back
// same when itself connects back to (Internet) own server e.g benetou.fr
// can be cascading or federatede or properly P2P
// responsive programming also, not "just" design
res . redirect ( 'pwa/index.html' )
} )
const utilsCmd = {
'shutdown' : { cmd : 'shutdown -h now' } ,
'listprototypes' : { cmd : 'ls' , context : { cwd : '/home/deck/Prototypes' } ,
// more reliably path.join(__dirname,'')
format : res => res . toString ( ) . split ( '\n' )
} ,
}
app . get ( '/exec' , ( req , res ) => {
if ( ! req . query . cmdName ) {
res . json ( utilsCmd )
} else {
let resultFromExecution = execSync ( utilsCmd [ req . query . cmdName ] . cmd , utilsCmd [ req . query . cmdName ] . context )
let formatter = utilsCmd [ req . query . cmdName ] . format
if ( formatter ) resultFromExecution = formatter ( resultFromExecution )
res . json ( resultFromExecution )
}
} )
// app.get('/interface/unregister', (req, res) => {
// app.get('/interface/register', (req, res) => {
// could be use for e.g reMarkable2, Quest2, etc with specifically accepted or prefered formats
app . get ( '/services/unregister' , ( req , res ) => {
res . json ( { msg : 'not yet implemented' } )
} )
app . get ( '/services/register' , ( req , res ) => {
res . json ( { msg : 'not yet implemented' } )
// example {name:'hmdlink', desc:'share URL between local devices', protocol:'http', port:8082, path: '/hmdlink', url:'http://192.168.4.3:8082/hmdlink'},
} )
} )
app . get ( '/services' , ( req , res ) => {
app . get ( '/services' , ( req , res ) => {
// could be probbed first to check for availability
// should be updated also via register/unregister
res . json ( [
res . json ( [
{ name : 'kiwix' , desc : 'offline Wikipedia, Stackoverflow, etc' , protocol : 'http' , port : 8080 , url : 'http://192.168.4.3:8080' } ,
{ name : 'kiwix' , desc : 'offline Wikipedia, Stackoverflow, etc' , protocol : 'http' , port : 8080 , url : 'http://192.168.4.3:8080' } ,
{ name : 'hmdlink' , desc : 'share URL between local devices' , protocol : 'http' , port : 8082 , path : '/hmdlink' , url : 'http://192.168.4.3:8082/hmdlink' } ,
{ name : 'hmdlink' , desc : 'share URL between local devices' , protocol : 'http' , port : 8082 , path : '/hmdlink' , url : 'http://192.168.4.3:8082/hmdlink' } ,
] )
] )
} )
} )
let dynURL = 'https://192.168.4.1/offline.html'
app . get ( '/hmdlink/set' , ( req , res ) => { // could be a PUT instead
// e.g http://192.168.4.3:8082/hmdlink/set?url=http://192.168.4.3:8082/114df5f8-3921-42f0-81e7-48731b563571.thumbnails/f07120ba-0ca1-429d-869f-c704a52b7aa3.png
dynURL = req . query . url
res . redirect ( dynURL )
} )
app . get ( '/hmdlink' , ( req , res ) => {
app . get ( '/hmdlink' , ( req , res ) => {
res . redirect ( 'https://192.168.4.1/offline.html' )
res . redirect ( dynURL )
} )
} )
app . get ( '/json' , ( req , res ) => {
app . get ( '/json' , ( req , res ) => {
res . json ( instructions . split ( '\n' ) )
res . json ( instructions . split ( '\n' ) )
@ -51,9 +100,19 @@ app.get('/json', (req, res) => {
app . get ( '/' , ( req , res ) => {
app . get ( '/' , ( req , res ) => {
res . send ( instructions )
res . send ( instructions )
} )
} )
app . get ( '/localprototypes' , ( req , res ) => {
res . json ( spawn ( 'find Prototypes/ -iwholename */.git/config | xargs grep git.benetou.fr' ) )
} )
const https = require ( "https" ) ;
const fs = require ( "fs" ) ;
const privateKey = fs . readFileSync ( "naf-key.pem" , "utf8" ) ;
const certificate = fs . readFileSync ( "naf.pem" , "utf8" ) ;
const credentials = { key : privateKey , cert : certificate } ;
const webServer = https . createServer ( credentials , app ) ;
// Start Express http server
// Start Express http server
const webServer = http . createServer ( app ) ;
// const webServer = http.createServer(app);
// Listen on port
// Listen on port
webServer . listen ( port , ( ) => {
webServer . listen ( port , ( ) => {
console . log ( "listening on http://localhost:" + port ) ;
console . log ( "listening on http://localhost:" + port ) ;