git ssb

1+

mixmix / scuttle-shell



Tree: 4a030f061750b955cc3028f04d0cf62248113251

Files: 4a030f061750b955cc3028f04d0cf62248113251 / server.js

4017 bytesRaw
1#! /usr/bin/env node
2
3const fs = require('fs')
4const path = require('path')
5const ssbKeys = require('ssb-keys')
6const minimist = require('minimist')
7const notifier = require('node-notifier')
8const SysTray = require('systray').default
9let tray = {}
10
11function start(appname, customPluginPaths) {
12
13 let argv = process.argv.slice(2)
14 let i = argv.indexOf('--')
15 let conf = argv.slice(i + 1)
16 argv = ~i ? argv.slice(0, i) : argv
17 let ssb_appname = appname ? appname : process.env.ssb_appname
18
19 const config = require('ssb-config/inject')(ssb_appname, minimist(conf))
20
21 const keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
22 if (keys.curve === 'k256') {
23 throw new Error('k256 curves are no longer supported,' +
24 'please delete' + path.join(config.path, 'secret'))
25 }
26
27 const manifestFile = path.join(config.path, 'manifest.json')
28
29 const createSbot = require('scuttlebot')
30 // .use(require('scuttlebot/plugins/plugins'))
31 .use(require('scuttlebot/plugins/master'))
32 .use(require('scuttlebot/plugins/gossip'))
33 .use(require('scuttlebot/plugins/replicate'))
34 .use(require('scuttlebot/plugins/invite'))
35 .use(require('scuttlebot/plugins/local'))
36 .use(require('ssb-about'))
37 .use(require('ssb-backlinks'))
38 .use(require('ssb-blobs'))
39 .use(require('ssb-ebt'))
40 .use(require('ssb-chess-db'))
41 .use(require('ssb-friends'))
42 .use(require('ssb-meme'))
43 .use(require('ssb-names'))
44 .use(require('ssb-ooo'))
45 .use(require('ssb-private'))
46 .use(require('ssb-search'))
47 .use(require('ssb-query'))
48 .use(require('ssb-ws'))
49
50
51 // Custom plugins from json
52 let appManifestFile = path.resolve('scuttleshell.json')
53 if (fs.existsSync(appManifestFile)) {
54 let manifest = JSON.parse(fs.readFileSync(manifestPath))
55 if (manifest.hasOwnProperty('plugins') && Array.isArray(manifest.plugins)) {
56 console.log("loading custom plugins: ", manifest.plugins.join(", "))
57 manifest.plugins.forEach(plugin => createSbot.use(require(plugin)))
58 }
59 }
60
61 if (Array.isArray(customPluginPaths)) {
62 console.log("loading custom plugins: ", customPluginPaths.join(", "))
63 customPluginPaths.forEach(plugin => createSbot.use(require(plugin)))
64 }
65
66 // start server
67
68 config.keys = keys
69 const server = createSbot(config)
70
71 // write RPC manifest to ~/.ssb/manifest.json
72 fs.writeFileSync(manifestFile, JSON.stringify(server.getManifest(), null, 2))
73
74 const icon = fs.readFileSync(path.join(__dirname, `icon.${process.platform === 'win32' ? 'ico' : 'png'}`))
75 tray = new SysTray({
76 menu: {
77 icon: icon.toString('base64'),
78 title: 'Scuttle-Shell',
79 tooltip: 'Secure Scuttlebutt',
80 items: [
81
82 {
83 title: 'Quit',
84 tooltip: 'Stop sbot and quit tray application',
85 checked: false,
86 enabled: true
87 }
88 ]
89 },
90 debug: false,
91 copyDir: true,
92 })
93
94 tray.onClick(action => {
95 switch (action.seq_id) {
96 case 0:
97 console.log("### EXITING IN TWO SECONDS ###")
98
99 notifier.notify({
100 title: 'Secure Scuttlebutt',
101 message: `Secure Scuttlebutt will exit in two seconds...`,
102 icon: path.join(__dirname, "icon.png"),
103 wait: true,
104 id: 0,
105 })
106
107 tray.kill()
108 }
109 })
110
111 tray.onExit((code, signal) => {
112 setTimeout(() =>
113 process.exit(0), 2000)
114 })
115
116}
117
118function stop() {
119 tray.kill()
120}
121
122const getConfig = () => {
123 try {
124 let secret = fs.readFileSync(pathToSecret, "utf8")
125 let keys = JSON.parse(secret.replace(/#[^\n]*/g, ''))
126 let manifest = JSON.parse(fs.readFileSync(path.join(config.path, 'manifest.json')))
127 let remote = "ws://localhost:8989~shs:" + keys.id.substring(1, keys.id.indexOf('.'))
128 return { type: 'config', keys: keys, manifest: manifest, remote: remote, secret: secret }
129 } catch (n) {
130 return { type: 'error', msg: n.message }
131 }
132}
133
134module.exports = { start, stop, getConfig }
135
136if (require.main === module) {
137 var errorLevel = start()
138}

Built with git-ssb-web