From b79e5bbad71dfbf3ae44f13579b2904989aed644 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Apr 2023 02:29:52 -0700 Subject: [PATCH 01/19] test install --- examples/http.js | 37 +++++++++++++++++------------ examples/https.sh | 7 ++++++ examples/install.sh | 41 ++++++++++++++++++++++---------- examples/relay.service | 19 +++++++++++++++ examples/stats.html | 22 +++++++++++++++++ lib/axe.js | 54 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+), 27 deletions(-) create mode 100644 examples/https.sh create mode 100644 examples/relay.service diff --git a/examples/http.js b/examples/http.js index bed7cb9b2..fae4c1de5 100644 --- a/examples/http.js +++ b/examples/http.js @@ -1,27 +1,34 @@ ;(function(){ var cluster = require('cluster'); if(cluster.isMaster){ - return cluster.fork() && cluster.on('exit', function(){ cluster.fork(); require('../lib/crashed'); }); + return cluster.fork() && cluster.on('exit',function(){ cluster.fork(); require('../lib/crashed') }); } - var fs = require('fs'); - var config = { - port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765, - peers: process.env.PEERS && process.env.PEERS.split(',') || [] + var fs = require('fs'), env = process.env; + var GUN = require('../'); // require('gun'); + var opt = { + port: env.PORT || process.argv[2] || 8765, + peers: env.PEERS && env.PEERS.split(',') || [] }; - var Gun = require('../'); // require('gun') - if(process.env.HTTPS_KEY){ - config.key = fs.readFileSync(process.env.HTTPS_KEY); - config.cert = fs.readFileSync(process.env.HTTPS_CERT); - config.server = require('https').createServer(config, Gun.serve(__dirname)); + if(fs.existsSync((opt.home = require('os').homedir())+'/cert.pem')){ + env.HTTPS_KEY = env.HTTPS_KEY || opt.home+'/key.pem'; + env.HTTPS_CERT = env.HTTPS_CERT || opt.home+'/cert.pem'; + } + if(env.HTTPS_KEY){ + opt.port = 443; + opt.key = fs.readFileSync(env.HTTPS_KEY); + opt.cert = fs.readFileSync(env.HTTPS_CERT); + opt.server = require('https').createServer(opt, GUN.serve(__dirname)); + require('http').createServer(function(req, res){ + res.writeHead(301, {"Location": "https://"+req.headers['host']+req.url }); + res.end(); + }).listen(80); } else { - config.server = require('http').createServer(Gun.serve(__dirname)); + opt.server = require('http').createServer(GUN.serve(__dirname)); } - var gun = Gun({web: config.server.listen(config.port), peers: config.peers}); - - console.log('Relay peer started on port ' + config.port + ' with /gun'); - + var gun = GUN({web: opt.server.listen(opt.port), peers: opt.peers}); + console.log('Relay peer started on port ' + opt.port + ' with /gun'); module.exports = gun; }()); \ No newline at end of file diff --git a/examples/https.sh b/examples/https.sh new file mode 100644 index 000000000..532fdcc95 --- /dev/null +++ b/examples/https.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd ~ +git clone https://github.com/acmesh-official/acme.sh.git +bash ~/acme.sh/acme.sh --install -m $EMAIL +bash ~/acme.sh/acme.sh --issue -d $DOMAIN -w $WEB +bash ~/acme.sh/acme.sh --install-cert -d $DOMAIN --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload" \ No newline at end of file diff --git a/examples/install.sh b/examples/install.sh index 79cb2b771..24c0dbe7c 100644 --- a/examples/install.sh +++ b/examples/install.sh @@ -3,6 +3,7 @@ # README # This will install nodejs and npm on your system, # should work on most places other than Windows. +# For it to run on boot as a server, a recent OS is needed. # Set any environment variables before you run this, # like `export RAD=false` to disable storage, or # pass file paths of `HTTPS_CERT` & `HTTPS_KEY`, etc. @@ -12,24 +13,40 @@ # curl -o- https://raw.githubusercontent.com/amark/gun/master/examples/install.sh | bash #debian/ubuntu -su - +cd ~ apt-get install sudo -y sudo apt-get update -y -sudo apt-get install curl git git-core screen -y +sudo apt-get install curl git git-core systemd -y +sudo apt-get install systemctl -y #fedora/openSUSE sudo yum check-update -y -sudo yum install curl git git-core screen -y +sudo yum install curl git git-core systemd -y +sudo yum install curl systemctl -y + +#screen -S install # You can safely CTRL+A+D to escape without stopping the process. `screen -R install` to resume. Stop all with `killall screen`. Note: May need to `sudo apt-get install screen` # install nodejs -git clone http://github.com/isaacs/nave.git -sudo ./nave/nave.sh usemain stable -# If you just want nodejs and npm but not gun, stop here. +git clone https://github.com/isaacs/nave.git +./nave/nave.sh usemain stable -npm install gun -cd ./node_modules/gun +# If you just want nodejs and npm but not gun, stop here. +#npm install gun@latest +#cd ./node_modules/gun +mkdir node_modules +git clone https://github.com/amark/gun.git +cd gun +git pull +git checkout master +git checkout $VERSION +git pull npm install . -# to start the gun examples: -screen -S relay -sudo npm start 80 # change `80` to `443` for https or `8765` for development purposes. -# You can now safely CTRL+A+D to escape without stopping the peer. To stop `killall screen` or `killall node`. +service relay stop >> /dev/null +cp ./examples/relay.service /lib/systemd/system/relay.service +echo $PWD >> /lib/systemd/system/relay.service +echo "fs.file-max = 999999" >> /etc/sysctl.conf +ulimit -u unlimited +sysctl -p /etc/sysctl.conf +systemctl daemon-reload +systemctl enable relay +service relay start \ No newline at end of file diff --git a/examples/relay.service b/examples/relay.service new file mode 100644 index 000000000..43d2f5698 --- /dev/null +++ b/examples/relay.service @@ -0,0 +1,19 @@ +[Unit] +Description=GUN relay +Documentation=https://gun.eco +After=network.target + +[Install] +WantedBy=multi-user.target + +[Service] +Environment=PATH=/usr/bin:/usr/local/bin +LimitNOFILE=infinity +LimitNPROC=infinity +LimitCORE=infinity +StartLimitBurst=999999 +StartLimitIntervalSec=999999 +Restart=always +ExecStart=node examples/http.js 80 +# Environment=NODE_ENV=production +WorkingDirectory= \ No newline at end of file diff --git a/examples/stats.html b/examples/stats.html index 324ff8e67..c87fa4dff 100644 --- a/examples/stats.html +++ b/examples/stats.html @@ -111,6 +111,27 @@ // tbd later return chart; } + ;(function(){ + if('https' != (''+location).slice(0,5) && "localhost" != location.hostname){ + $('body').append(""); + if(/^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|$)){4}$/.test(location.hostname)){ + $('#https').text("Link this IP address to a Domain by adding an `A Record` to your DNS settings that point to `"+ location.hostname +"` (we recommend the `name/host` be any subdomain you want, like `relay`, but if you want the root domain itself to directly point here use `*`). Then come back here on the domain & click this button to generate HTTPS certificates."); + return; + } + $('body').append(""); + $('#https').on('click', function(){ + $(this).text("look at console.log for errors, if none, try https"); + var gun = GUN(location.origin + '/gun'); + if(!$('#email').val()){ + $(this).text("email necessary for certs! Type it in & click here again."); + return; + } + setTimeout(function(){ + gun._.opt.mesh.say({dam: 'service', try: 'https', email: $('#email').val(), domain: location.hostname}); + }, 999); + }); + } + }()); /* Notes to Self about Debugging: 1. Read Disks can spike up to 1min, I suspect other operations are blocking it from resolving as fast as it otherwise would. @@ -122,5 +143,6 @@ 7. Watch out for get/put loops times, maybe indicating (5) issues? */ + \ No newline at end of file diff --git a/lib/axe.js b/lib/axe.js index 1d84382df..36d30e415 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -205,6 +205,60 @@ function start(root){ },1000); }()); + ;(function(){ + var cmd = {}; + mesh.hear['service'] = function(msg, peer){ + if(!require('fs').existsSync('/lib/systemd/system/relay.service')){ + mesh.say({dam: '!', err: "Not serviced."}); + return; + } + try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } + } + cmd.https = function(msg, peer){ var run, log; + if(!(run = require('child_process').execSync)){ return } + if(!msg.email || !msg.domain){ + mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); + return; + } + if(require('fs').existsSync(require('os').homedir()+'/cert.pem')){ + mesh.say({dam: '!', err: 'Cert already exists.'}); + return; + } + var path = require('path').resolve(__dirname, '../examples'); + //log = run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { + require('fs').writeFileSync('../email', msg.email); + log = run("../examples/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { + //log = JSON.stringify({err, stdout, stderr}); + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + //}); + return; + // log = run('curl https://get.acme.sh | /bin/sh -s email='+msg.email); + // mesh.say({dam: '!', log: ''+log}, peer); + // log = run('~/.acme.sh/acme.sh --issue -d '+msg.domain+' -w '+path); + // mesh.say({dam: '!', log: ''+log}, peer); + // log = run('~/.acme.sh/acme.sh --install-cert -d '+msg.domain+' --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload"'); + run("bash "+path+"/upgrade.sh", { + env: { + 'EMAIL': msg.email, + 'WEBROOT': path, + 'DOMAIN': msg.domain + }}, (err, stdout, stderr) => { + log = JSON.stringify({err, stdout, stderr}); + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + }); + } + cmd.update = function(msg, peer){ var run, log; + if(!(run = require('child_process').execSync)){ return } + log = run('../examples/install.sh', {env: {VERSION: msg.version||''}}); + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + } + + cmd.any = function(){}; + }()); + ;(function(){ // THIS IS THE MOB MODULE; //return; // WORK IN PROGRESS, TEST FINALIZED, NEED TO MAKE STABLE. /* From 58f9135f6bf49605d48bb516c7ba0255faca2470 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Apr 2023 03:06:35 -0700 Subject: [PATCH 02/19] again --- README.md | 5 +++-- examples/install.sh | 3 ++- lib/axe.js | 11 +++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 356eef060..3eb99b6f0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ **GUN** is an [ecosystem](https://gun.eco/docs/Ecosystem) of **tools** that let you build [community run](https://www.nbcnews.com/tech/tech-news/these-technologists-think-internet-broken-so-they-re-building-another-n1030136) and [encrypted applications](https://gun.eco/docs/Cartoon-Cryptography) - like an Open Source Firebase or a Decentralized Dropbox. -The [Internet Archive](https://news.ycombinator.com/item?id=17685682) and [100s of other apps](https://github.com/amark/gun/wiki/awesome-gun) run GUN in-production. GUN is also part of [Twitter's Bluesky](https://blueskycommunity.net/) initiative! +The [Internet Archive](https://news.ycombinator.com/item?id=17685682) and [100s of other apps](https://github.com/amark/gun/wiki/awesome-gun) run GUN in-production. GUN was also part of [Twitter's bluesky](https://blueskycommunity.net/) initiative! + Multiplayer by default with realtime p2p state synchronization! + Graph data lets you use key/value, tables, documents, videos, & more! @@ -155,7 +155,8 @@ Thanks to: Hunter Owens, Jacob Millner, Gerrit Balindt, -Gabriel Lemon +Gabriel Lemon, +Murage Martin

- Join others in sponsoring code: https://www.patreon.com/gunDB ! diff --git a/examples/install.sh b/examples/install.sh index 24c0dbe7c..2dc44bef7 100644 --- a/examples/install.sh +++ b/examples/install.sh @@ -11,6 +11,7 @@ # If you are on Windows, http://nodejs.org/download/ has # an installer that will automatically do it for you. # curl -o- https://raw.githubusercontent.com/amark/gun/master/examples/install.sh | bash +# wget -O - https://raw.githubusercontent.com/amark/gun/master/examples/install.sh| bash #debian/ubuntu cd ~ @@ -41,7 +42,7 @@ git checkout $VERSION git pull npm install . -service relay stop >> /dev/null +service relay stop cp ./examples/relay.service /lib/systemd/system/relay.service echo $PWD >> /lib/systemd/system/relay.service echo "fs.file-max = 999999" >> /etc/sysctl.conf diff --git a/lib/axe.js b/lib/axe.js index 36d30e415..44768c15d 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -226,8 +226,8 @@ function start(root){ } var path = require('path').resolve(__dirname, '../examples'); //log = run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { - require('fs').writeFileSync('../email', msg.email); - log = run("../examples/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { + require('fs').writeFileSync(path+'/../email', msg.email); + log = run("bash "+path+"/https.sh", {env:{'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { //log = JSON.stringify({err, stdout, stderr}); mesh.say({dam: '!', log: ''+log}, peer); setTimeout(function(){ process.exit() },999); @@ -249,9 +249,12 @@ function start(root){ setTimeout(function(){ process.exit() },999); }); } - cmd.update = function(msg, peer){ var run, log; + cmd.update = function(msg, peer){ var run, log, pass; + try{ pass = ''+require('fs').readFileSync(require('os').homedir()+'/pass') }catch(e){} + if(!pass || msg.pass != pass){ return } if(!(run = require('child_process').execSync)){ return } - log = run('../examples/install.sh', {env: {VERSION: msg.version||''}}); + var path = require('path').resolve(__dirname, '../examples'); + log = run("bash "+path+"/install.sh", {env: {VERSION: msg.version||''}}); mesh.say({dam: '!', log: ''+log}, peer); setTimeout(function(){ process.exit() },999); } From c9283d8fa6230aca6aa8f346c188c3909485534f Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Apr 2023 03:16:21 -0700 Subject: [PATCH 03/19] bump --- lib/axe.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/axe.js b/lib/axe.js index 44768c15d..47de301bc 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -215,7 +215,7 @@ function start(root){ try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } } cmd.https = function(msg, peer){ var run, log; - if(!(run = require('child_process').execSync)){ return } + if(!(run = require('child_process').exec)){ return } if(!msg.email || !msg.domain){ mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); return; @@ -227,11 +227,11 @@ function start(root){ var path = require('path').resolve(__dirname, '../examples'); //log = run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { require('fs').writeFileSync(path+'/../email', msg.email); - log = run("bash "+path+"/https.sh", {env:{'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { - //log = JSON.stringify({err, stdout, stderr}); - mesh.say({dam: '!', log: ''+log}, peer); - setTimeout(function(){ process.exit() },999); - //}); + run("bash "+path+"/https.sh", {env:{'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(e, out, err){ + log = JSON.stringify({e: e, out: out, err: err}); + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + }); return; // log = run('curl https://get.acme.sh | /bin/sh -s email='+msg.email); // mesh.say({dam: '!', log: ''+log}, peer); @@ -252,11 +252,13 @@ function start(root){ cmd.update = function(msg, peer){ var run, log, pass; try{ pass = ''+require('fs').readFileSync(require('os').homedir()+'/pass') }catch(e){} if(!pass || msg.pass != pass){ return } - if(!(run = require('child_process').execSync)){ return } + if(!(run = require('child_process').exec)){ return } var path = require('path').resolve(__dirname, '../examples'); - log = run("bash "+path+"/install.sh", {env: {VERSION: msg.version||''}}); - mesh.say({dam: '!', log: ''+log}, peer); - setTimeout(function(){ process.exit() },999); + run("bash "+path+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ + log = JSON.stringify({e: e, out: out, err: err}); + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + }); } cmd.any = function(){}; From c6b9fa8d139294c19c0c47bf457bf99e1451ca53 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Apr 2023 03:44:38 -0700 Subject: [PATCH 04/19] back? --- lib/axe.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/axe.js b/lib/axe.js index 47de301bc..75af6d7ea 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -215,7 +215,7 @@ function start(root){ try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } } cmd.https = function(msg, peer){ var run, log; - if(!(run = require('child_process').exec)){ return } + if(!(run = require('child_process').execSync)){ return } if(!msg.email || !msg.domain){ mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); return; @@ -227,11 +227,11 @@ function start(root){ var path = require('path').resolve(__dirname, '../examples'); //log = run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { require('fs').writeFileSync(path+'/../email', msg.email); - run("bash "+path+"/https.sh", {env:{'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(e, out, err){ - log = JSON.stringify({e: e, out: out, err: err}); + log = run("bash "+path+"/https.sh", {env:{'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, function(e, out, err){ + //log = JSON.stringify({e: e, out: out, err: err}); mesh.say({dam: '!', log: ''+log}, peer); setTimeout(function(){ process.exit() },999); - }); + //}); return; // log = run('curl https://get.acme.sh | /bin/sh -s email='+msg.email); // mesh.say({dam: '!', log: ''+log}, peer); From 2afde8db4ab45d4e4b1beed7483696c7811c78b9 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Apr 2023 04:18:46 -0700 Subject: [PATCH 05/19] hmm --- lib/axe.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/axe.js b/lib/axe.js index 75af6d7ea..b930f3302 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -215,7 +215,7 @@ function start(root){ try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } } cmd.https = function(msg, peer){ var run, log; - if(!(run = require('child_process').execSync)){ return } + if(!(run = require('child_process').exec)){ return } if(!msg.email || !msg.domain){ mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); return; @@ -227,11 +227,11 @@ function start(root){ var path = require('path').resolve(__dirname, '../examples'); //log = run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { require('fs').writeFileSync(path+'/../email', msg.email); - log = run("bash "+path+"/https.sh", {env:{'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, function(e, out, err){ - //log = JSON.stringify({e: e, out: out, err: err}); + run("bash "+path+"/https.sh", {env:{'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(e, out, err){ + log = e+"|"+out+"|"+err; mesh.say({dam: '!', log: ''+log}, peer); setTimeout(function(){ process.exit() },999); - //}); + }); return; // log = run('curl https://get.acme.sh | /bin/sh -s email='+msg.email); // mesh.say({dam: '!', log: ''+log}, peer); @@ -255,7 +255,7 @@ function start(root){ if(!(run = require('child_process').exec)){ return } var path = require('path').resolve(__dirname, '../examples'); run("bash "+path+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ - log = JSON.stringify({e: e, out: out, err: err}); + log = e+"|"+out+"|"+err; mesh.say({dam: '!', log: ''+log}, peer); setTimeout(function(){ process.exit() },999); }); From 1ddf797fffcd35549e85d1bba14eccc22d60e337 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Apr 2023 15:42:34 -0700 Subject: [PATCH 06/19] reverse? --- examples/https.sh | 9 ++++++--- lib/axe.js | 17 +++-------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/examples/https.sh b/examples/https.sh index 532fdcc95..6c16e8618 100644 --- a/examples/https.sh +++ b/examples/https.sh @@ -1,7 +1,10 @@ #!/bin/bash +echo $EMAIL +echo $WEBROOT +echo $DOMAIN cd ~ git clone https://github.com/acmesh-official/acme.sh.git -bash ~/acme.sh/acme.sh --install -m $EMAIL -bash ~/acme.sh/acme.sh --issue -d $DOMAIN -w $WEB -bash ~/acme.sh/acme.sh --install-cert -d $DOMAIN --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload" \ No newline at end of file +bash ./acme.sh/acme.sh --install -m $EMAIL +bash ./acme.sh/acme.sh --issue -d $DOMAIN -w $WEBROOT +bash ./acme.sh/acme.sh --install-cert -d $DOMAIN --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload"~ \ No newline at end of file diff --git a/lib/axe.js b/lib/axe.js index b930f3302..128e5a801 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -225,26 +225,15 @@ function start(root){ return; } var path = require('path').resolve(__dirname, '../examples'); - //log = run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { require('fs').writeFileSync(path+'/../email', msg.email); - run("bash "+path+"/https.sh", {env:{'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(e, out, err){ - log = e+"|"+out+"|"+err; - mesh.say({dam: '!', log: ''+log}, peer); - setTimeout(function(){ process.exit() },999); - }); - return; - // log = run('curl https://get.acme.sh | /bin/sh -s email='+msg.email); - // mesh.say({dam: '!', log: ''+log}, peer); - // log = run('~/.acme.sh/acme.sh --issue -d '+msg.domain+' -w '+path); - // mesh.say({dam: '!', log: ''+log}, peer); - // log = run('~/.acme.sh/acme.sh --install-cert -d '+msg.domain+' --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload"'); - run("bash "+path+"/upgrade.sh", { + //log = run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { + run("bash "+path+"/https.sh", { env: { 'EMAIL': msg.email, 'WEBROOT': path, 'DOMAIN': msg.domain }}, (err, stdout, stderr) => { - log = JSON.stringify({err, stdout, stderr}); + log = "|"+err+"|"+stdout+"|"+stderr; mesh.say({dam: '!', log: ''+log}, peer); setTimeout(function(){ process.exit() },999); }); From 48b5a0e765c8e9a64c4eb93dd0b0bd196aa4d58a Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Apr 2023 19:41:34 -0700 Subject: [PATCH 07/19] what about now? --- examples/https.sh | 12 +++++------- lib/axe.js | 16 +++++----------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/examples/https.sh b/examples/https.sh index 6c16e8618..29677875f 100644 --- a/examples/https.sh +++ b/examples/https.sh @@ -1,10 +1,8 @@ #!/bin/bash -echo $EMAIL -echo $WEBROOT -echo $DOMAIN - cd ~ git clone https://github.com/acmesh-official/acme.sh.git -bash ./acme.sh/acme.sh --install -m $EMAIL -bash ./acme.sh/acme.sh --issue -d $DOMAIN -w $WEBROOT -bash ./acme.sh/acme.sh --install-cert -d $DOMAIN --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload"~ \ No newline at end of file +cd ~/acme.sh +./acme.sh --install -m $EMAIL + +bash ~/acme.sh/acme.sh --issue -d $DOMAIN -w $WEB +bash ~/acme.sh/acme.sh --install-cert -d $DOMAIN --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload" \ No newline at end of file diff --git a/lib/axe.js b/lib/axe.js index 128e5a801..5874522e9 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -226,17 +226,11 @@ function start(root){ } var path = require('path').resolve(__dirname, '../examples'); require('fs').writeFileSync(path+'/../email', msg.email); - //log = run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}});//, (err, stdout, stderr) => { - run("bash "+path+"/https.sh", { - env: { - 'EMAIL': msg.email, - 'WEBROOT': path, - 'DOMAIN': msg.domain - }}, (err, stdout, stderr) => { - log = "|"+err+"|"+stdout+"|"+stderr; - mesh.say({dam: '!', log: ''+log}, peer); - setTimeout(function(){ process.exit() },999); - }); + run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(err, stdout, stderr){ + log = "|"+err+"|"+stdout+"|"+stderr; + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + }); } cmd.update = function(msg, peer){ var run, log, pass; try{ pass = ''+require('fs').readFileSync(require('os').homedir()+'/pass') }catch(e){} From 2183e6acdf454cda4211c7d60082e2a266551602 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 25 Apr 2023 20:02:28 -0700 Subject: [PATCH 08/19] log --- lib/axe.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/axe.js b/lib/axe.js index 5874522e9..74a03e609 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -226,10 +226,14 @@ function start(root){ } var path = require('path').resolve(__dirname, '../examples'); require('fs').writeFileSync(path+'/../email', msg.email); - run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(err, stdout, stderr){ - log = "|"+err+"|"+stdout+"|"+stderr; + run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(e, out, err){ + console.log("11111DONE11111"); + log = "|"+e+"|"+out+"|"+err; + console.log("2222DONE222222"); mesh.say({dam: '!', log: ''+log}, peer); + console.log("3333DONE333333"); setTimeout(function(){ process.exit() },999); + console.log("4444DONE444444"); }); } cmd.update = function(msg, peer){ var run, log, pass; From 0e7121b8f42992f7402814a8e0a545d270fd569b Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Wed, 26 Apr 2023 01:13:17 -0700 Subject: [PATCH 09/19] finally! --- examples/stats.html | 4 ++++ lib/axe.js | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/stats.html b/examples/stats.html index c87fa4dff..19026da95 100644 --- a/examples/stats.html +++ b/examples/stats.html @@ -128,6 +128,10 @@ } setTimeout(function(){ gun._.opt.mesh.say({dam: 'service', try: 'https', email: $('#email').val(), domain: location.hostname}); + setTimeout(function(){ + if(gun._.opt.mesh.near){ return } + $('#https').text("It might have worked! try HTTPS!"); + }, 2000); }, 999); }); } diff --git a/lib/axe.js b/lib/axe.js index 74a03e609..c807d16ab 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -227,13 +227,9 @@ function start(root){ var path = require('path').resolve(__dirname, '../examples'); require('fs').writeFileSync(path+'/../email', msg.email); run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(e, out, err){ - console.log("11111DONE11111"); log = "|"+e+"|"+out+"|"+err; - console.log("2222DONE222222"); mesh.say({dam: '!', log: ''+log}, peer); - console.log("3333DONE333333"); setTimeout(function(){ process.exit() },999); - console.log("4444DONE444444"); }); } cmd.update = function(msg, peer){ var run, log, pass; From e15416ff2d6ea26c04f6e5a72c9f1c16518c5b19 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Wed, 26 Apr 2023 01:27:48 -0700 Subject: [PATCH 10/19] longer --- examples/stats.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/stats.html b/examples/stats.html index 19026da95..8223b3c8b 100644 --- a/examples/stats.html +++ b/examples/stats.html @@ -131,7 +131,7 @@ setTimeout(function(){ if(gun._.opt.mesh.near){ return } $('#https').text("It might have worked! try HTTPS!"); - }, 2000); + }, 9000); }, 999); }); } From ca0e7e35ae41b965ba6b94370ec652da8b083974 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Wed, 26 Apr 2023 02:03:32 -0700 Subject: [PATCH 11/19] trim --- lib/axe.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/axe.js b/lib/axe.js index c807d16ab..2456460eb 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -233,8 +233,8 @@ function start(root){ }); } cmd.update = function(msg, peer){ var run, log, pass; - try{ pass = ''+require('fs').readFileSync(require('os').homedir()+'/pass') }catch(e){} - if(!pass || msg.pass != pass){ return } + try{ pass = (''+require('fs').readFileSync(require('os').homedir()+'/pass')).trim() }catch(e){} + if(!pass || (msg.pass||'').trim() != pass){ return } if(!(run = require('child_process').exec)){ return } var path = require('path').resolve(__dirname, '../examples'); run("bash "+path+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ From 8b1f055cd1568fef7bc2eb46152af6001c73d401 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 28 Apr 2023 02:26:16 -0700 Subject: [PATCH 12/19] auto update --- examples/install.sh | 4 ++-- lib/axe.js | 42 +--------------------------------------- lib/service.js | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 lib/service.js diff --git a/examples/install.sh b/examples/install.sh index 2dc44bef7..85c7524e2 100644 --- a/examples/install.sh +++ b/examples/install.sh @@ -36,13 +36,13 @@ git clone https://github.com/isaacs/nave.git mkdir node_modules git clone https://github.com/amark/gun.git cd gun +git checkout . git pull git checkout master git checkout $VERSION git pull npm install . -service relay stop cp ./examples/relay.service /lib/systemd/system/relay.service echo $PWD >> /lib/systemd/system/relay.service echo "fs.file-max = 999999" >> /etc/sysctl.conf @@ -50,4 +50,4 @@ ulimit -u unlimited sysctl -p /etc/sysctl.conf systemctl daemon-reload systemctl enable relay -service relay start \ No newline at end of file +systemctl restart relay \ No newline at end of file diff --git a/lib/axe.js b/lib/axe.js index 2456460eb..a6869dbc0 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -205,47 +205,7 @@ function start(root){ },1000); }()); - ;(function(){ - var cmd = {}; - mesh.hear['service'] = function(msg, peer){ - if(!require('fs').existsSync('/lib/systemd/system/relay.service')){ - mesh.say({dam: '!', err: "Not serviced."}); - return; - } - try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } - } - cmd.https = function(msg, peer){ var run, log; - if(!(run = require('child_process').exec)){ return } - if(!msg.email || !msg.domain){ - mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); - return; - } - if(require('fs').existsSync(require('os').homedir()+'/cert.pem')){ - mesh.say({dam: '!', err: 'Cert already exists.'}); - return; - } - var path = require('path').resolve(__dirname, '../examples'); - require('fs').writeFileSync(path+'/../email', msg.email); - run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(e, out, err){ - log = "|"+e+"|"+out+"|"+err; - mesh.say({dam: '!', log: ''+log}, peer); - setTimeout(function(){ process.exit() },999); - }); - } - cmd.update = function(msg, peer){ var run, log, pass; - try{ pass = (''+require('fs').readFileSync(require('os').homedir()+'/pass')).trim() }catch(e){} - if(!pass || (msg.pass||'').trim() != pass){ return } - if(!(run = require('child_process').exec)){ return } - var path = require('path').resolve(__dirname, '../examples'); - run("bash "+path+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ - log = e+"|"+out+"|"+err; - mesh.say({dam: '!', log: ''+log}, peer); - setTimeout(function(){ process.exit() },999); - }); - } - - cmd.any = function(){}; - }()); + setTimeout(function(){ require('./service')(root) },9); ;(function(){ // THIS IS THE MOB MODULE; //return; // WORK IN PROGRESS, TEST FINALIZED, NEED TO MAKE STABLE. diff --git a/lib/service.js b/lib/service.js new file mode 100644 index 000000000..17e0db21f --- /dev/null +++ b/lib/service.js @@ -0,0 +1,47 @@ +module.exports = function(root){ + var mesh = root.opt.mesh, cmd = {}, run = require('child_process').exec, fs = require('fs'), home = require('os').homedir(), examp = require('path').resolve(__dirname, '../examples'); + mesh.hear['service'] = function(msg, peer){ + if(!fs.existsSync('/lib/systemd/system/relay.service')){ + mesh.say({dam: '!', err: "Not serviced."}); + return; + } + try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } + } + cmd.https = function(msg, peer){ var run, log; + if(!msg.email || !msg.domain){ + mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); + return; + } + if(fs.existsSync(home+'/cert.pem')){ + mesh.say({dam: '!', err: 'Cert already exists.'}); + return; + } + fs.writeFile(examp+'/../email', msg.email, function(){}); + run("bash "+examp+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': examp, 'DOMAIN': msg.domain}}, function(e, out, err){ + log = "|"+e+"|"+out+"|"+err; + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + }); + } + cmd.update = function(msg, peer){ var run, log, pass; + try{ pass = (''+fs.readFileSync(home+'/pass')).trim() }catch(e){} + if(!pass || (msg.pass||'').trim() != pass){ return } + fs.writeFile(examp+'/../updated', +new Date+'', function(){}); + run("bash "+examp+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ + log = e+"|"+out+"|"+err; + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + }); + } + ;(function update(){ var last; + if(!fs.existsSync(home+'/cert.pem')){ return } + setTimeout(update, 1000*60*60*24); + last = root.stats.stay.updated || 0; + if(+new Date - last < 1000*60*60*24*15){ return } + root.stats.stay.updated = +new Date; + run("bash "+examp+"/install.sh", {}, function(){}); + }()); + + cmd.any = function(){}; + +}; \ No newline at end of file From bf1565398b6731444a60d22ef666d0243d9256c5 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 28 Apr 2023 02:53:07 -0700 Subject: [PATCH 13/19] ugh --- lib/service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/service.js b/lib/service.js index 17e0db21f..88076b6ac 100644 --- a/lib/service.js +++ b/lib/service.js @@ -7,7 +7,7 @@ module.exports = function(root){ } try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } } - cmd.https = function(msg, peer){ var run, log; + cmd.https = function(msg, peer){ log; if(!msg.email || !msg.domain){ mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); return; @@ -23,7 +23,7 @@ module.exports = function(root){ setTimeout(function(){ process.exit() },999); }); } - cmd.update = function(msg, peer){ var run, log, pass; + cmd.update = function(msg, peer){ log, pass; try{ pass = (''+fs.readFileSync(home+'/pass')).trim() }catch(e){} if(!pass || (msg.pass||'').trim() != pass){ return } fs.writeFile(examp+'/../updated', +new Date+'', function(){}); From bfedfc027cd9776dfc0b13d39e1e125707f2fa03 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 28 Apr 2023 02:57:08 -0700 Subject: [PATCH 14/19] sleepy ugh --- lib/service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/service.js b/lib/service.js index 88076b6ac..1e964012b 100644 --- a/lib/service.js +++ b/lib/service.js @@ -7,7 +7,7 @@ module.exports = function(root){ } try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } } - cmd.https = function(msg, peer){ log; + cmd.https = function(msg, peer){ var log; if(!msg.email || !msg.domain){ mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); return; @@ -23,7 +23,7 @@ module.exports = function(root){ setTimeout(function(){ process.exit() },999); }); } - cmd.update = function(msg, peer){ log, pass; + cmd.update = function(msg, peer){ var log, pass; try{ pass = (''+fs.readFileSync(home+'/pass')).trim() }catch(e){} if(!pass || (msg.pass||'').trim() != pass){ return } fs.writeFile(examp+'/../updated', +new Date+'', function(){}); From 580058056f8798ff8ac2cbba0266c9471e4aa651 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 28 Apr 2023 03:35:51 -0700 Subject: [PATCH 15/19] reduce? --- examples/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/install.sh b/examples/install.sh index 85c7524e2..2c5dc7027 100644 --- a/examples/install.sh +++ b/examples/install.sh @@ -17,12 +17,12 @@ cd ~ apt-get install sudo -y sudo apt-get update -y -sudo apt-get install curl git git-core systemd -y +sudo apt-get install git git-core systemd -y sudo apt-get install systemctl -y #fedora/openSUSE sudo yum check-update -y -sudo yum install curl git git-core systemd -y -sudo yum install curl systemctl -y +sudo yum install git git-core systemd -y +sudo yum install systemctl -y #screen -S install # You can safely CTRL+A+D to escape without stopping the process. `screen -R install` to resume. Stop all with `killall screen`. Note: May need to `sudo apt-get install screen` From 30eff267ea810f84a0ba3a9c6000475d1e8f8f44 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 28 Apr 2023 04:08:51 -0700 Subject: [PATCH 16/19] nope need curl lol --- examples/install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/install.sh b/examples/install.sh index 2c5dc7027..997d011a1 100644 --- a/examples/install.sh +++ b/examples/install.sh @@ -11,18 +11,18 @@ # If you are on Windows, http://nodejs.org/download/ has # an installer that will automatically do it for you. # curl -o- https://raw.githubusercontent.com/amark/gun/master/examples/install.sh | bash -# wget -O - https://raw.githubusercontent.com/amark/gun/master/examples/install.sh| bash +# wget -O - https://raw.githubusercontent.com/amark/gun/master/examples/install.sh | bash #debian/ubuntu cd ~ apt-get install sudo -y sudo apt-get update -y -sudo apt-get install git git-core systemd -y +sudo apt-get install curl git git-core systemd -y sudo apt-get install systemctl -y #fedora/openSUSE sudo yum check-update -y -sudo yum install git git-core systemd -y -sudo yum install systemctl -y +sudo yum install curl git git-core systemd -y +sudo yum install curl systemctl -y #screen -S install # You can safely CTRL+A+D to escape without stopping the process. `screen -R install` to resume. Stop all with `killall screen`. Note: May need to `sudo apt-get install screen` From 8c4d38e30ea31690cdc2459480c7d9a73596b42b Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 28 Apr 2023 04:13:56 -0700 Subject: [PATCH 17/19] oops --- examples/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/install.sh b/examples/install.sh index 997d011a1..4ec20dd7c 100644 --- a/examples/install.sh +++ b/examples/install.sh @@ -22,7 +22,7 @@ sudo apt-get install systemctl -y #fedora/openSUSE sudo yum check-update -y sudo yum install curl git git-core systemd -y -sudo yum install curl systemctl -y +sudo yum install systemctl -y #screen -S install # You can safely CTRL+A+D to escape without stopping the process. `screen -R install` to resume. Stop all with `killall screen`. Note: May need to `sudo apt-get install screen` From 1304ef90e87f0c17c9d79826e03e78a5c1c7f780 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 28 Apr 2023 15:24:40 -0700 Subject: [PATCH 18/19] reuse --- lib/service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/service.js b/lib/service.js index 1e964012b..7f479c34a 100644 --- a/lib/service.js +++ b/lib/service.js @@ -26,7 +26,7 @@ module.exports = function(root){ cmd.update = function(msg, peer){ var log, pass; try{ pass = (''+fs.readFileSync(home+'/pass')).trim() }catch(e){} if(!pass || (msg.pass||'').trim() != pass){ return } - fs.writeFile(examp+'/../updated', +new Date+'', function(){}); + root.stats.stay.updated = +new Date; run("bash "+examp+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ log = e+"|"+out+"|"+err; mesh.say({dam: '!', log: ''+log}, peer); From 4c01db9a67c85ef6fe41943b2e805485ea0400b6 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Sat, 29 Apr 2023 12:19:21 -0700 Subject: [PATCH 19/19] up mob --- lib/axe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/axe.js b/lib/axe.js index a6869dbc0..a2a7fd2a3 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -221,7 +221,7 @@ function start(root){ The mob threshold might be determined by other factors, like how much RAM or CPU stress we have. */ - opt.mob = opt.mob || parseFloat((opt.env||'').MOB) || 9900; // should be based on ulimit, some clouds as low as 10K. + opt.mob = opt.mob || parseFloat((opt.env||'').MOB) || 999999; // should be based on ulimit, some clouds as low as 10K. // handle rebalancing a mob of peers: root.on('hi', function(peer){