pinokiod 1.3.42 → 1.3.43

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.
@@ -53,6 +53,10 @@ class C {
53
53
  return { uri: cloudflare_url }
54
54
  }
55
55
  async stop (req, ondata, kernel) {
56
+ const message = `cloudflared tunnel --url ${req.params.uri}`
57
+ await kernel.shell.kill({
58
+ id: message
59
+ })
56
60
  }
57
61
  }
58
62
  module.exports = C
package/kernel/shells.js CHANGED
@@ -222,6 +222,7 @@ class Shells {
222
222
  for(let i=0; i<shells.length; i++) {
223
223
  let shell = shells[i]
224
224
  if (shell.id === request.id) {
225
+ console.log("FOUND SHELL TO KILL", shell.id)
225
226
  shell.kill(message, true)
226
227
  }
227
228
  }
@@ -234,6 +235,7 @@ class Shells {
234
235
  for(let i=0; i<shells.length; i++) {
235
236
  let shell = shells[i]
236
237
  if (shell.group === request.group) {
238
+ console.log("kill shell ", request.group, i, shell)
237
239
  shell.kill(message, true)
238
240
  }
239
241
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "1.3.42",
3
+ "version": "1.3.43",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -35,6 +35,7 @@ const Socket = require('./socket')
35
35
  const Kernel = require("../kernel")
36
36
  const packagejson = require("../package.json")
37
37
  const Environment = require("../kernel/environment")
38
+ const Cloudflare = require("../kernel/api/cloudflare")
38
39
  class Server {
39
40
  constructor(config) {
40
41
  this.tabs = {}
@@ -48,6 +49,7 @@ class Server {
48
49
  }
49
50
  this.kernel.version = this.version
50
51
  this.upload = multer();
52
+ this.cf = new Cloudflare()
51
53
 
52
54
  // sometimes the C:\Windows\System32 is not in PATH, need to add
53
55
  let platform = os.platform()
@@ -206,9 +208,33 @@ class Server {
206
208
  await this.renderMenu(uri, name, config, [])
207
209
  }
208
210
  let platform = os.platform()
211
+
212
+
213
+ // get all memory variable stied to the current repository
214
+ let api_path = this.kernel.path("api", name)
215
+ let mem = {}
216
+ for(let type in this.kernel.memory) {
217
+ // type := local|global
218
+ let vars = this.kernel.memory[type]
219
+ for(let k in vars) {
220
+ if (k.includes(api_path)) {
221
+ if (mem[k]) {
222
+ mem[k][type] = vars[k]
223
+ } else {
224
+ mem[k] = {
225
+ [type]: vars[k]
226
+ }
227
+ }
228
+ }
229
+ }
230
+ }
231
+ console.log("M", mem)
232
+
233
+
209
234
  //res.render("browser", {
210
235
  res.render("browser-experimental", {
211
236
  port: this.port,
237
+ mem,
212
238
  type,
213
239
  platform,
214
240
  running:this.kernel.api.running,
@@ -1111,19 +1137,31 @@ class Server {
1111
1137
  // console.log("*******", { filepath, pathComponents, U })
1112
1138
 
1113
1139
  let pinokio_proxy = this.kernel.api.proxies["/"]
1140
+ let pinokio_cloudflare = this.cloudflare_pub
1114
1141
 
1115
1142
  let qr = null
1143
+ let qr_cloudflare = null
1144
+ let home_proxy = null
1116
1145
  if (pinokio_proxy && pinokio_proxy.length > 0) {
1117
1146
  qr = await QRCode.toDataURL(pinokio_proxy[0].proxy)
1147
+ home_proxy = pinokio_proxy[0]
1148
+ }
1149
+
1150
+ if (this.cloudflare_pub) {
1151
+ qr_cloudflare = await QRCode.toDataURL(this.cloudflare_pub)
1118
1152
  }
1119
1153
 
1120
1154
 
1155
+
1121
1156
  console.log("running", JSON.stringify(running, null, 2))
1122
1157
 
1123
1158
 
1124
1159
  res.render("index", {
1125
- proxy: pinokio_proxy[0],
1160
+ home_url: `http://localhost:${this.port}`,
1161
+ proxy: home_proxy,
1162
+ cloudflare_pub: this.cloudflare_pub,
1126
1163
  qr,
1164
+ qr_cloudflare,
1127
1165
  error: error,
1128
1166
  logo: this.logo,
1129
1167
  // memory: mem,
@@ -1819,7 +1857,7 @@ class Server {
1819
1857
  await this.kernel.init({ port: this.port})
1820
1858
 
1821
1859
  // start proxy for Pinokio itself
1822
- await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
1860
+ // await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
1823
1861
 
1824
1862
  // if (!debug) {
1825
1863
  // let logsdir = path.resolve(this.kernel.homedir, "logs")
@@ -2020,6 +2058,58 @@ class Server {
2020
2058
  // }
2021
2059
  })
2022
2060
 
2061
+ this.app.post("/unpublish", async (req, res) => {
2062
+ /*
2063
+ req.body := {
2064
+ type: "local"|"cloudflare"
2065
+ }
2066
+ */
2067
+ if (req.body.type) {
2068
+ if (req.body.type === "local") {
2069
+ await this.kernel.api.stopProxy({
2070
+ uri: `http://127.0.0.1:${this.port}`
2071
+ })
2072
+ } else if (req.body.type === "cloudflare") {
2073
+ console.log("STOP CLOUDFLARE")
2074
+ await this.cf.stop({
2075
+ params: {
2076
+ uri: `http://127.0.0.1:${this.port}`
2077
+ }
2078
+ }, (e) => {
2079
+ process.stdout.write(e.raw)
2080
+ }, this.kernel)
2081
+ this.cloudflare_pub = null
2082
+ }
2083
+ res.json({ success: true })
2084
+ } else {
2085
+ res.json({ error: "type must be 'local' or 'cloudflare'" })
2086
+ }
2087
+ })
2088
+ this.app.post("/publish", async (req, res) => {
2089
+ /*
2090
+ req.body := {
2091
+ type: "local"|"cloudflare"
2092
+ }
2093
+ */
2094
+ if (req.body.type) {
2095
+ if (req.body.type === "local") {
2096
+ await this.kernel.api.startProxy("/", `http://127.0.0.1:${this.port}`, "/")
2097
+ } else if (req.body.type === "cloudflare") {
2098
+ let { uri } = await this.cf.tunnel({
2099
+ params: {
2100
+ uri: `http://127.0.0.1:${this.port}`
2101
+ }
2102
+ }, (e) => {
2103
+ process.stdout.write(e.raw)
2104
+ }, this.kernel)
2105
+ console.log("cloudflare started at " + uri)
2106
+ this.cloudflare_pub = uri
2107
+ }
2108
+ res.json({ success: true })
2109
+ } else {
2110
+ res.json({ error: "type must be 'local' or 'cloudflare'" })
2111
+ }
2112
+ })
2023
2113
  this.app.get("/edit/*", async (req, res) => {
2024
2114
  let pathComponents = req.params[0].split("/")
2025
2115
  let filepath = path.resolve(this.kernel.homedir, req.params[0])
@@ -116,7 +116,7 @@ body main iframe {
116
116
  <script src="/hotkeys.min.js"></script>
117
117
  </head>
118
118
  <body class='<%=theme%>'>
119
- <header class='grabbable'>
119
+ <header class='navheader grabbable'>
120
120
  <h1>
121
121
  <a class='home' href="/"><i class="fa-solid fa-house"></i></a>
122
122
  <% paths.forEach((path) => { %>
@@ -135,12 +135,14 @@ body main iframe {
135
135
  </form>
136
136
  -->
137
137
  <div class='flexible'></div>
138
+ <!--
138
139
  <div class='nav-btns'>
139
140
  <a class='btn2' href='https://discord.gg/TQdNwadtE4' target="_blank"><div><i class="fa-brands fa-discord"></i></div><div>Discord</div></a>
140
141
  <a class='btn2' href='https://twitter.com/cocktailpeanut' target="_blank"><div><i class="fa-brands fa-twitter"></i></div><div>Twitter</div></a>
141
142
  <a class='btn2' href="/?mode=settings"><div><i class="fa-solid fa-gear"></i></div><div>Settings</div></a>
142
143
  </div>
143
144
  <button id='new-window' title='open a new window' class='btn2'><i class="fa-solid fa-plus"></i></button>
145
+ -->
144
146
  </h1>
145
147
  </header>
146
148
  <main>
@@ -65,6 +65,54 @@ header .runner {
65
65
  background: black;
66
66
  color: white;
67
67
  }
68
+ .browser-options-btns {
69
+ display: flex;
70
+ padding-top: 5px;
71
+ }
72
+ .browser-options-row {
73
+ display: flex;
74
+ padding: 5px 0;
75
+ align-items: flex-start;
76
+ }
77
+ .browser-options-row h3 {
78
+ margin: 0;
79
+ }
80
+ .browser-options-row .btn.disabled {
81
+ opacity: 0.7;
82
+ }
83
+ .browser-options-row .btn {
84
+ font-weight: bold;
85
+ width: 100px;
86
+ text-align: center;
87
+ display: block;
88
+ margin-right: 10px;
89
+ flex-shrink: 0;
90
+ padding: 5px;
91
+ }
92
+ .badge {
93
+ font-size: 12px;
94
+ padding: 5px 10px;
95
+ background: rgba(0,0,100,0.1);
96
+ border-radius: 5px;
97
+ display: inline-block;
98
+ margin-top: 5px;
99
+ }
100
+ a.badge {
101
+ color: royalblue;
102
+ text-decoration: none;
103
+ cursor: pointer;
104
+ }
105
+ .badge a {
106
+ color: royalblue;
107
+ text-decoration: none;
108
+ }
109
+ body.dark .btn {
110
+ color: cornflowerblue;
111
+ border: 1px solid rgba(255,255,255,0.15);
112
+ }
113
+ body.dark .badge {
114
+ background: rgba(255,255,255,0.1);
115
+ }
68
116
  @media only screen and (max-width: 480px) {
69
117
  .btn2 {
70
118
  padding: 5px;
@@ -72,6 +120,8 @@ header .runner {
72
120
  }
73
121
  .nav-btns {
74
122
  flex-grow: 1;
123
+ justify-content: center;
124
+ padding: 0;
75
125
  }
76
126
  }
77
127
  </style>
@@ -126,9 +176,10 @@ header .runner {
126
176
  <a class='btn2' href="/?mode=help"><div><i class="fa-regular fa-face-smile"></i></div><div>Community</div></a>
127
177
  <% if (agent === "electron") { %>
128
178
  <a class='btn2' data-filepath="<%=filepath%>"><div><i class="fa-regular fa-folder-open"></i></div><div>Files</div></a>
179
+ <!--
129
180
  <a href="/" target="_blank" class='btn2' features="browser"><div><i class="fa-solid fa-arrow-up-right-from-square"></i></div><div>Popout</div></a>
181
+ -->
130
182
  <% } %>
131
- <a id='wifi' data-proxy="<%=proxy.proxy%>" class='btn2'><div><i class="fa-solid fa-wifi"></i></div><div>WiFi Share</div></a>
132
183
  <!--
133
184
  <a class='btn2' id='report'><div><i class="fa-solid fa-bug"></i></div><div>Report Bug</div></a>
134
185
  <a class='btn2' href='https://discord.gg/TQdNwadtE4' target="_blank"><div><i class="fa-brands fa-discord"></i></div><div>Discord</div></a>
@@ -139,8 +190,8 @@ header .runner {
139
190
  <!--
140
191
  <a class='btn2' id='report'><div><i class="fa-solid fa-question"></i></div><div>Help</div></a>
141
192
  -->
193
+ <button id='new-window' title='open a new window' class='btn2'><div><i class="fa-solid fa-plus"></i></div><div>Window</div></button>
142
194
  </div>
143
- <button id='new-window' title='open a new window' class='btn2'><i class="fa-solid fa-plus"></i></button>
144
195
  <% } %>
145
196
  <!--
146
197
  <a class='nav-button path' href='https://discord.gg/TQdNwadtE4' target="_blank"><i class="fa-brands fa-discord"></i></a>
@@ -173,12 +224,53 @@ header .runner {
173
224
  <div id='terminal' class='hidden'></div>
174
225
  <div class='container'>
175
226
  <% if (ishome) { %>
176
- <!--
177
227
  <div class='browser-options'>
178
- <a href="/" target="_blank" class='btn'><div><i class="fa-solid fa-arrow-up-right-from-square"></i> Open in Browser</div></a>
179
- <a id='wifi' data-proxy="<%=proxy.proxy%>" class='btn'><div><i class="fa-solid fa-wifi"></i> WiFi Sharing</div></a>
228
+ <% if (agent !== "electron") { %>
229
+ <div class='browser-options-row'>
230
+ <a href="/" target="_blank" class='btn' features="browser"><div><i class="fa-solid fa-arrow-up-right-from-square"></i> Offline Web</div></a>
231
+ <div class='flexible'>
232
+ <h3>Instant Launch</h3>
233
+ <div>Launch Pinokio and its apps directly from any web browser at <%=home_url%> (Use Pinokio local apps like regular websites)</div>
234
+ </div>
235
+ </div>
236
+ <% } %>
237
+ <div class='browser-options-row'>
238
+ <% if (proxy) { %>
239
+ <a id='wifi-stop' data-proxy="<%=proxy.proxy%>" class='btn'><div><i class="fa-solid fa-stop"></i> Stop</div></a>
240
+ <div class='flexible'>
241
+ <h3>Local Share</h3>
242
+ <div>Access Pinokio from any device on the same network</div>
243
+ <span class='badge'><i class="fa-solid fa-circle-notch fa-spin"></i> Running at <a href="<%=proxy.proxy%>" target="_blank" features="browser"><%=proxy.proxy%></a></span>
244
+ <a id='wifi-qr' class='badge'><i class="fa-solid fa-qrcode"></i> Scan QR Code</a>
245
+ </div>
246
+ <% } else { %>
247
+ <a id='wifi' class='btn'><div><i class="fa-solid fa-wifi"></i> Start</div></a>
248
+ <a id='wifi-starting' class='btn disabled hidden'><div><i class="fa-solid fa-circle-notch fa-spin"></i> Starting</div></a>
249
+ <div class='flexible'>
250
+ <h3>Local Share</h3>
251
+ <div>Access Pinokio from any device on the same network</div>
252
+ </div>
253
+ <% } %>
254
+ </div>
255
+ <div class='browser-options-row hidden'>
256
+ <% if (cloudflare_pub) { %>
257
+ <a id='cloudflare-stop' class='btn'><div><i class="fa-solid fa-stop"></i> Stop</div></a>
258
+ <div class='flexible'>
259
+ <h3>Public Share</h3>
260
+ <div>Open up your Pinokio server to the open internet (anyone with the URL can access)</div>
261
+ <span class='badge'><i class="fa-solid fa-circle-notch fa-spin"></i> Running at <a href="<%=cloudflare_pub%>" target="_blank" features="browser"><%=cloudflare_pub%></a></span>
262
+ <a id='cloudflare-qr' class='badge'><i class="fa-solid fa-qrcode"></i> Scan QR Code</a>
263
+ </div>
264
+ <% } else { %>
265
+ <a id='cloudflare' class='btn'><div><i class="fa-solid fa-globe"></i> Start</div></a>
266
+ <a id='cloudflare-starting' class='btn disabled hidden'><div><i class="fa-solid fa-circle-notch fa-spin"></i> Starting</div></a>
267
+ <div class='flexible'>
268
+ <h3>Public Share</h3>
269
+ <div>Open up your Pinokio server to the open internet (anyone with the URL can access)</div>
270
+ </div>
271
+ <% } %>
272
+ </div>
180
273
  </div>
181
- -->
182
274
  <% if (running.length > 0) { %>
183
275
  <div class='running-apps'>
184
276
  <div class='header-label'>Running</div>
@@ -707,6 +799,7 @@ document.addEventListener("click", (e) => {
707
799
 
708
800
 
709
801
 
802
+ /*
710
803
  target = (e.target.classList.contains(".btn") ? e.target : e.target.closest(".btn"))
711
804
  if (target) {
712
805
  target.classList.add("clicked")
@@ -717,13 +810,14 @@ document.addEventListener("click", (e) => {
717
810
  target.closest(".line").classList.add("selected")
718
811
  return
719
812
  }
813
+ */
720
814
 
721
815
 
722
816
  })
723
- <% if (qr) { %>
724
- document.querySelector("#wifi").addEventListener("click", async (e) => {
817
+ <% if (proxy) { %>
818
+ document.querySelector("#wifi-qr").addEventListener("click", async (e) => {
725
819
  await Swal.fire({
726
- title: "Wifi Sharing",
820
+ title: "Local Share",
727
821
  customClass: {
728
822
  popup: "min-popup",
729
823
  title: "min-title"
@@ -737,7 +831,93 @@ document.addEventListener("click", (e) => {
737
831
  </div>`
738
832
  })
739
833
  })
834
+ document.querySelector("#wifi-stop").addEventListener("click", async (e) => {
835
+ let res = await fetch("/unpublish", {
836
+ method: "post",
837
+ headers: {
838
+ "Content-Type": "application/json"
839
+ },
840
+ body: JSON.stringify({
841
+ type: "local"
842
+ })
843
+ }).then((res) => {
844
+ return res.json()
845
+ })
846
+ console.log(res)
847
+ location.href = location.href
848
+ })
849
+ <% } %>
850
+ <% if (cloudflare_pub) { %>
851
+ document.querySelector("#cloudflare-qr").addEventListener("click", async (e) => {
852
+ await Swal.fire({
853
+ title: "Public Share",
854
+ customClass: {
855
+ popup: "min-popup",
856
+ title: "min-title"
857
+ },
858
+ showConfirmButton: false,
859
+ html: `<div class='min-modal'>
860
+ <div>Access Pinokio from anywhere</div>
861
+ <div>(powered by cloudflare tunnel)</div>
862
+ <div><img src="<%=qr_cloudflare%>"></div>
863
+ <a href="<%=cloudflare_pub%>" target="_blank"><%=cloudflare_pub%></a>
864
+ </div>`
865
+ })
866
+ })
867
+ document.querySelector("#cloudflare-stop").addEventListener("click", async (e) => {
868
+ let res = await fetch("/unpublish", {
869
+ method: "post",
870
+ headers: {
871
+ "Content-Type": "application/json"
872
+ },
873
+ body: JSON.stringify({
874
+ type: "cloudflare"
875
+ })
876
+ }).then((res) => {
877
+ return res.json()
878
+ })
879
+ console.log(res)
880
+ location.href = location.href
881
+ })
740
882
  <% } %>
883
+ if (document.querySelector("#wifi")) {
884
+ document.querySelector("#wifi").addEventListener("click", async (e) => {
885
+ document.querySelector("#wifi").classList.add("hidden")
886
+ document.querySelector("#wifi-starting").classList.remove("hidden")
887
+ let res = await fetch("/publish", {
888
+ method: "post",
889
+ headers: {
890
+ "Content-Type": "application/json"
891
+ },
892
+ body: JSON.stringify({
893
+ type: "local"
894
+ })
895
+ }).then((res) => {
896
+ return res.json()
897
+ })
898
+ console.log(res)
899
+ location.href = location.href
900
+ })
901
+ }
902
+ if (document.querySelector("#cloudflare")) {
903
+ document.querySelector("#cloudflare").addEventListener("click", async (e) => {
904
+ document.querySelector("#cloudflare").classList.add("hidden")
905
+ document.querySelector("#cloudflare-starting").classList.remove("hidden")
906
+ let res = await fetch("/publish", {
907
+ method: "post",
908
+ headers: {
909
+ "Content-Type": "application/json"
910
+ },
911
+ body: JSON.stringify({
912
+ type: "cloudflare"
913
+ })
914
+ }).then((res) => {
915
+ return res.json()
916
+ })
917
+ console.log(res)
918
+ location.href = location.href
919
+ })
920
+ }
741
921
  <% } %>
742
922
 
743
923
  </script>
@@ -215,7 +215,7 @@ hr {
215
215
  <a class='logo' href="/">dal</a>
216
216
  </nav>
217
217
  -->
218
- <header class='grabbable'>
218
+ <header class='navheader grabbable'>
219
219
  <h1>
220
220
  <a class='home' href="/"><i class="fa-solid fa-house"></i></a>
221
221
  <% paths.forEach((path) => { %>