pinokiod 3.15.1 → 3.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  const axios = require('axios')
2
+ const path = require('path')
2
3
  const fs = require('fs')
3
4
  const semver = require('semver')
5
+ const Util = require('../util')
4
6
 
5
7
  class Caddy {
6
8
  cmd() {
@@ -12,6 +14,7 @@ class Caddy {
12
14
  }
13
15
  async running() {
14
16
  console.log("caddy running check")
17
+ console.log("stack", new Error().stack)
15
18
  try {
16
19
  let response = await axios.get('http://127.0.0.1:2019/config/')
17
20
  return true
@@ -37,6 +40,7 @@ class Caddy {
37
40
  message: `caddy run --watch`,
38
41
  path: this.kernel.homedir,
39
42
  }, (e) => {
43
+ process.stdout.write(e.raw)
40
44
  if (!resolved) {
41
45
  if (/endpoint started/i.test(e.cleaned)) {
42
46
  resolved = true
@@ -50,6 +54,11 @@ class Caddy {
50
54
  }
51
55
  }
52
56
  async install(req, ondata, kernel, id) {
57
+ // let fullpath = path.resolve(kernel.homedir, "ENVIRONMENT")
58
+ // await Util.update_env(fullpath, {
59
+ // PINOKIO_NETWORK_ACTIVE: "1",
60
+ // PINOKIO_HTTPS_ACTIVE: "1"
61
+ // })
53
62
  await this.kernel.bin.exec({
54
63
  message: [
55
64
  "conda clean -y --all",
@@ -103,21 +112,25 @@ class Caddy {
103
112
  }
104
113
  }
105
114
  async installed() {
106
- let version = this.kernel.bin.installed.conda_versions.caddy
107
- let coerced = semver.coerce(version)
108
- let requirement = "<2.10.0"
109
- let satisfied = semver.satisfies(coerced, requirement)
110
- if (!satisfied) {
111
- return false
112
- }
113
- let e = await this.kernel.exists(this.kernel.path("cache/XDG_DATA_HOME/caddy/pki/authorities/local/root.crt"))
114
- if (e) {
115
- if (this.kernel.platform === "win32") {
116
- return this.kernel.bin.installed.conda.has("caddy")
115
+ try {
116
+ let version = this.kernel.bin.installed.conda_versions.caddy
117
+ let coerced = semver.coerce(version)
118
+ let requirement = "<2.10.0"
119
+ let satisfied = semver.satisfies(coerced, requirement)
120
+ if (!satisfied) {
121
+ return false
122
+ }
123
+ let e = await this.kernel.exists(this.kernel.path("cache/XDG_DATA_HOME/caddy/pki/authorities/local/root.crt"))
124
+ if (e) {
125
+ if (this.kernel.platform === "win32") {
126
+ return this.kernel.bin.installed.conda.has("caddy")
127
+ } else {
128
+ return this.kernel.bin.installed.conda.has("caddy") && this.kernel.bin.installed.conda.has("nss")
129
+ }
117
130
  } else {
118
- return this.kernel.bin.installed.conda.has("caddy") && this.kernel.bin.installed.conda.has("nss")
131
+ return false
119
132
  }
120
- } else {
133
+ } catch (e) {
121
134
  return false
122
135
  }
123
136
  }
package/kernel/index.js CHANGED
@@ -3,6 +3,7 @@ const os = require("os")
3
3
  const jsdom = require("jsdom");
4
4
  const randomUseragent = require('random-useragent');
5
5
  const path = require('path')
6
+ const axios = require('axios')
6
7
  const fastq = require('fastq')
7
8
  const fetch = require('cross-fetch');
8
9
  const waitOn = require('wait-on');
@@ -262,38 +263,35 @@ class Kernel {
262
263
  log(data, group, info) {
263
264
  this.log_queue.push({ data, group, info })
264
265
  }
265
- async should_refresh() {
266
- if (this.refresh_cached) {
267
- return this.cached_refresh_value
268
- } else {
269
- let env = await Environment.get(this.homedir)
270
- let peer_active = true
271
- // if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
272
- // By default it should be on.
273
- // It's off if the value is set, and it's 0 or false
274
-
275
- //if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
276
- if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="0" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="false")) {
277
- peer_active = false
278
- }
279
- let https_active = true
280
- //if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="1" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="true")) {
281
- if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="0" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="false")) {
282
- //https_active = true
283
- https_active = false
266
+ async network_active() {
267
+ await this.peer.check(this)
268
+ return this.peer.active
269
+ }
270
+ async network_installed() {
271
+ let installed = await this.bin.check_installed({ name: "caddy" })
272
+ return installed
273
+ }
274
+ async network_running() {
275
+ let installed = await this.network_installed()
276
+ if (installed) {
277
+ try {
278
+ await axios.get(`http://127.0.0.1:2019/config/`, { timeout: 1000 });
279
+ return true;
280
+ } catch (err) {
281
+ return false;
284
282
  }
285
- // console.log("kernel.refresh", { active, notify_peers })
286
-
287
- let caddy_installed = await this.bin.check_installed({ name: "caddy" })
288
- this.refresh_cached = true
289
- this.cached_refresh_value = caddy_installed && https_active
290
- return this.cached_refresh_value
283
+ } else {
284
+ return false
291
285
  }
292
286
  }
293
287
  async refresh(notify_peers) {
294
288
  const ts = Date.now()
295
- let should_refresh = await this.should_refresh()
296
- if (should_refresh) {
289
+ let network_active = await this.network_active()
290
+ if (!network_active) {
291
+ return
292
+ }
293
+ let network_running = await this.network_running()
294
+ if (network_running) {
297
295
 
298
296
 
299
297
  let ts = Date.now()
@@ -803,14 +801,19 @@ class Kernel {
803
801
  // }, 3000)
804
802
 
805
803
  // refresh every 5 second
806
- // if (this.refresh_interval) {
807
- // clearInterval(this.refresh_interval)
808
- // }
809
- this.refresh_cached = false
810
- this.cached_refresh_value = false
811
- this.refresh_interval = setInterval(() => {
812
- this.refresh()
813
- }, 5000)
804
+ if (this.refresh_interval) {
805
+ clearInterval(this.refresh_interval)
806
+ }
807
+ let network_active = await this.network_active()
808
+ if (network_active) {
809
+ this.refresh_interval = setInterval(() => {
810
+ if (this.server_running) {
811
+ this.refresh()
812
+ } else {
813
+ console.log("server not running yet. retry network refresh in 5 secs")
814
+ }
815
+ }, 5000)
816
+ }
814
817
 
815
818
  }
816
819
 
package/kernel/peer.js CHANGED
@@ -25,21 +25,45 @@ class PeerDiscovery {
25
25
  this.socket.send(this.message, 0, this.message.length, this.port, '192.168.1.255');
26
26
  }
27
27
  }
28
- async start(kernel) {
28
+ async check(kernel) {
29
29
  let env = await Environment.get(kernel.homedir)
30
-
31
- // by default expose to the local network
32
- this.active = true
33
- // if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
34
- if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="0" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="false")) {
35
- //if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
36
- this.active = false
30
+ //let peer_active = true
31
+ let peer_active = false
32
+ if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
33
+ //if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="0" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="false")) {
34
+ peer_active = true
37
35
  }
38
-
36
+ //let https_active = true
37
+ let https_active = false
38
+ if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="1" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="true")) {
39
+ //if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="0" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="false")) {
40
+ https_active = true
41
+ //https_active = false
42
+ }
43
+ // console.log("kernel.refresh", { active, notify_peers })
39
44
  this.name = os.userInfo().username
40
45
  if (env && env.PINOKIO_NETWORK_NAME && env.PINOKIO_NETWORK_NAME.length > 0) {
41
46
  this.name = env.PINOKIO_NETWORK_NAME
42
47
  }
48
+ if (peer_active && https_active) {
49
+ this.active = true
50
+ } else {
51
+ this.active = false
52
+ }
53
+ }
54
+ async start(kernel) {
55
+ let env = await Environment.get(kernel.homedir)
56
+
57
+ // by default expose to the local network
58
+ //this.active = true
59
+ // if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
60
+ // if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="0" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="false")) {
61
+ await this.check(kernel)
62
+ console.log({ active: this.active, name: this.name })
63
+ // if (env && env.PINOKIO_NETWORK_ACTIVE && (env.PINOKIO_NETWORK_ACTIVE==="1" || env.PINOKIO_NETWORK_ACTIVE.toLowerCase()==="true")) {
64
+ //// this.active = false
65
+ // this.active = true
66
+ // }
43
67
 
44
68
  if (this.active) {
45
69
  // Listen for incoming pings
package/kernel/procs.js CHANGED
@@ -16,10 +16,11 @@ class Procs {
16
16
  return this.cache[localAddress]
17
17
  }
18
18
  try {
19
- await axios.head(`http://${localAddress}`, { timeout: 1000 });
19
+ await axios.head(`http://${localAddress}`, { timeout: 3000 });
20
20
  this.cache[localAddress] = true
21
21
  return true;
22
22
  } catch (err) {
23
+ // console.log("HEAD ERROR",{ localAddress, err })
23
24
  this.cache[localAddress] = false
24
25
  return false;
25
26
  }
@@ -41,7 +42,6 @@ class Procs {
41
42
  let pids = new Set()
42
43
  let s = stdout.trim()
43
44
  const lines = s.split('\n');
44
-
45
45
  for(let line of lines) {
46
46
  if (isWin) {
47
47
  // Skip headers
@@ -194,11 +194,9 @@ class Procs {
194
194
  }
195
195
  }
196
196
  if (cached) {
197
- // console.log("already cached")
198
197
  cb(this.port_map)
199
198
  return
200
199
  }
201
- // console.log("not cached")
202
200
  const cmd = isWin ? 'tasklist /fo csv /nh' : 'ps -Ao pid,comm';
203
201
  let id = "Procs.getPidToNameMap"
204
202
  let sh = this.kernel.shell.get(id)
@@ -246,8 +244,6 @@ class Procs {
246
244
  this.getPortPidList((portPidList) => {
247
245
  // console.timeEnd(">>>>>>>>GET PORTS " + ts)
248
246
  // console.time(">>>>>>> GET PIDS " + ts)
249
- // console.log({ portPidList })
250
-
251
247
  // if there's any new port, run getPidToNameMap
252
248
 
253
249
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.15.1",
3
+ "version": "3.15.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -1723,9 +1723,7 @@ class Server {
1723
1723
  } else {
1724
1724
  currentIndexPath = "" + i
1725
1725
  }
1726
- console.log(">>", { indexPath, currentIndexPath, i })
1727
1726
  let shell_id = this.get_shell_id(name, currentIndexPath, rendered)
1728
- console.log(">>", { name, shell_id, })
1729
1727
 
1730
1728
 
1731
1729
  // let hash = crypto.createHash('md5').update(JSON.stringify(rendered)).digest('hex')
@@ -4840,7 +4838,7 @@ class Server {
4840
4838
  this.app.post("/network", ex(async (req, res) => {
4841
4839
  if (this.kernel.homedir) {
4842
4840
  let fullpath = path.resolve(this.kernel.homedir, "ENVIRONMENT")
4843
- console.log("req.body", req.body)
4841
+ console.log("POST /network", req.body)
4844
4842
  await Util.update_env(fullpath, req.body)
4845
4843
  res.json({ success: true })
4846
4844
  } else {
@@ -4938,6 +4936,7 @@ class Server {
4938
4936
  await new Promise((resolve, reject) => {
4939
4937
  this.listening = this.server.listen(this.port, () => {
4940
4938
  console.log(`Server listening on port ${this.port}`)
4939
+ this.kernel.server_running = true
4941
4940
  resolve()
4942
4941
  });
4943
4942
  this.httpTerminator = createHttpTerminator({
@@ -875,6 +875,7 @@ if (document.querySelector("#wifi")) {
875
875
  })
876
876
  }
877
877
  <% } %>
878
+ <% if (peer_active) { %>
878
879
  setInterval(() => {
879
880
  fetch("/peer_check").then((res) => {
880
881
  return res.json()
@@ -884,6 +885,7 @@ setInterval(() => {
884
885
  }
885
886
  })
886
887
  }, 2000)
888
+ <% } %>
887
889
  </script>
888
890
  </body>
889
891
  </html>
@@ -226,6 +226,7 @@ document.addEventListener("DOMContentLoaded", async () => {
226
226
  <% } %>
227
227
  <% if (!requirements_pending && !install_required && wait === "caddy") { %>
228
228
  console.log("RESTART")
229
+ alert("RESTART")
229
230
 
230
231
  let r = await fetch("/network", {
231
232
  method: "post",