pinokiod 8.3.1 → 8.3.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.
package/server/index.js CHANGED
@@ -29,6 +29,7 @@ const serveIndex = require('./serveIndex')
29
29
  const registerFileRoutes = require('./routes/files')
30
30
  const registerAppRoutes = require('./routes/apps')
31
31
  const registerConnectRoutes = require('./routes/connect')
32
+ const registerGithubAuthRoutes = require('./routes/github_auth')
32
33
  const ServerAutolaunch = require('./autolaunch')
33
34
  const Git = require("../kernel/git")
34
35
  const TerminalApi = require('../kernel/api/terminal')
@@ -1622,144 +1623,9 @@ class Server {
1622
1623
  const connection = await this.get_github_connection()
1623
1624
  return connection.display
1624
1625
  }
1625
- async get_legacy_github_hosts() {
1626
- let hosts = ""
1627
- let hosts_file = this.kernel.path("config/gh/hosts.yml")
1628
- let e = await this.exists(hosts_file)
1629
- if (e) {
1630
- hosts = await fs.promises.readFile(hosts_file, "utf8")
1631
- if (hosts.startsWith("{}")) {
1632
- hosts = ""
1633
- }
1634
- }
1635
- return hosts
1636
- }
1637
- github_command_env(interactive = false) {
1638
- const env = this.kernel && this.kernel.envs
1639
- ? { ...this.kernel.envs }
1640
- : (this.kernel && this.kernel.bin && typeof this.kernel.bin.envs === 'function'
1641
- ? this.kernel.bin.envs(process.env)
1642
- : { ...process.env })
1643
-
1644
- if (interactive) {
1645
- delete env.GCM_INTERACTIVE
1646
- delete env.GIT_TERMINAL_PROMPT
1647
- delete env.GIT_ASKPASS
1648
- delete env.SSH_ASKPASS
1649
- } else {
1650
- Object.assign(env, NON_INTERACTIVE_GIT_ENV)
1651
- }
1652
-
1653
- return env
1654
- }
1655
- async github_gcm(args, options = {}) {
1656
- return new Promise((resolve, reject) => {
1657
- execFile(
1658
- 'git',
1659
- ['credential-manager', 'github', ...args],
1660
- {
1661
- cwd: this.kernel.homedir,
1662
- env: this.github_command_env(Boolean(options.interactive)),
1663
- timeout: Number.isFinite(options.timeout) ? options.timeout : 15000,
1664
- maxBuffer: 1024 * 1024,
1665
- },
1666
- (error, stdout, stderr) => {
1667
- if (error) {
1668
- error.stderr = stderr
1669
- reject(error)
1670
- return
1671
- }
1672
- resolve(stdout || "")
1673
- }
1674
- )
1675
- })
1676
- }
1626
+ // GitHub login state, read from the token Pinokio stored (kernel/github_auth.js).
1677
1627
  async get_github_connection(options = {}) {
1678
- if (this._githubConnectionPromise) {
1679
- return this._githubConnectionPromise
1680
- }
1681
-
1682
- this._githubConnectionPromise = (async () => {
1683
- const legacyHosts = await this.get_legacy_github_hosts()
1684
- let accounts = []
1685
- let gcmError = null
1686
-
1687
- try {
1688
- const stdout = await this.github_gcm(['list'], {
1689
- timeout: Number.isFinite(options.timeout) ? options.timeout : 10000
1690
- })
1691
- accounts = stdout
1692
- .split(/\r?\n/)
1693
- .map((line) => line.trim())
1694
- .filter(Boolean)
1695
- } catch (error) {
1696
- gcmError = error && (error.stderr || error.message) ? String(error.stderr || error.message).trim() : String(error)
1697
- }
1698
-
1699
- const display = accounts.length > 0
1700
- ? accounts.map((account) => `github.com: ${account}`).join("\n")
1701
- : ""
1702
-
1703
- return {
1704
- accounts,
1705
- legacyHosts,
1706
- display,
1707
- connected: accounts.length > 0,
1708
- provider: accounts.length > 0 ? "gcm" : null,
1709
- gcmError,
1710
- }
1711
- })()
1712
-
1713
- try {
1714
- return await this._githubConnectionPromise
1715
- } finally {
1716
- this._githubConnectionPromise = null
1717
- }
1718
- }
1719
- github_login_params() {
1720
- const doneMarker = "PINOKIO_GITHUB_LOGIN_DONE"
1721
- const delimiter = this.kernel.platform === "win32" ? " && " : " ; "
1722
- const doneCommand = this.kernel.platform === "win32"
1723
- ? "echo P^INOKIO_GITHUB_LOGIN_DONE"
1724
- : "(GCM_DONE=INOKIO_GITHUB_LOGIN_DONE; printf 'P%s\\n' \"$GCM_DONE\")"
1725
- const loginCommand = [
1726
- "git credential-manager github login --device --force",
1727
- doneCommand
1728
- ].join(" && ")
1729
-
1730
- return {
1731
- doneMarker,
1732
- message: [
1733
- "git config --global --replace-all credential.helper manager",
1734
- "git config --global --replace-all credential.gitHubAuthModes oauth",
1735
- "git config --global --replace-all credential.namespace pinokio",
1736
- "git config --global --replace-all credential.https://github.com.helper manager",
1737
- "git config --global --replace-all credential.https://github.com.provider github",
1738
- loginCommand
1739
- ].join(delimiter)
1740
- }
1741
- }
1742
- github_logout_command(connection) {
1743
- const accounts = connection && Array.isArray(connection.accounts) ? connection.accounts : []
1744
- const safeAccounts = accounts.filter((account) => /^[A-Za-z0-9._-]+$/.test(account))
1745
- if (safeAccounts.length === 0) {
1746
- return null
1747
- }
1748
- const delimiter = this.kernel.platform === "win32" ? " && " : " ; "
1749
- return safeAccounts.map((account) => `git credential-manager github logout ${account}`).join(delimiter)
1750
- }
1751
- async github_logout_params(connection) {
1752
- const hadLegacyAuth = Boolean(connection && connection.legacyHosts && connection.legacyHosts.length > 0)
1753
- if (hadLegacyAuth) {
1754
- await this.clear_legacy_github_auth()
1755
- }
1756
- return {
1757
- hadLegacyAuth,
1758
- message: this.github_logout_command(connection)
1759
- }
1760
- }
1761
- async clear_legacy_github_auth() {
1762
- await fs.promises.rm(this.kernel.path("config/gh/hosts.yml"), { force: true }).catch(() => {})
1628
+ return this.kernel.githubAuth.connection(options)
1763
1629
  }
1764
1630
  async current_urls(current_path) {
1765
1631
  return {}
@@ -12904,6 +12770,18 @@ class Server {
12904
12770
  getProviderConnection: (provider, options) => this.kernel.connect.connected(provider, options)
12905
12771
  })
12906
12772
  /*
12773
+ GET /github/login => GitHub device login page (replaces Git Credential Manager)
12774
+ */
12775
+ registerGithubAuthRoutes(this.app, {
12776
+ auth: this.kernel.githubAuth,
12777
+ getPageContext: (req) => ({
12778
+ portal: this.portal,
12779
+ logo: this.logo,
12780
+ theme: this.theme,
12781
+ agent: req.agent
12782
+ })
12783
+ })
12784
+ /*
12907
12785
  * GET /connect/x
12908
12786
  * GET /connect/discord
12909
12787
  */
@@ -13565,8 +13443,8 @@ class Server {
13565
13443
  let hosts = githubConnection.display
13566
13444
 
13567
13445
  let items
13568
- if (githubConnection.connected) {
13569
- // logged in => display logout
13446
+ if (githubConnection.saved) {
13447
+ // Pinokio has a login saved => display logout (a login from outside Pinokio cannot be removed here)
13570
13448
  items = [{
13571
13449
  icon: "fa-solid fa-circle-xmark",
13572
13450
  title: "Logout",
@@ -13637,57 +13515,7 @@ class Server {
13637
13515
  res.json({ success: true })
13638
13516
 
13639
13517
  }))
13640
- this.app.get("/github/status", ex(async (req, res) => {
13641
- let id = "gh_status"
13642
- let params = new URLSearchParams()
13643
- let message = "git credential-manager github list"
13644
- params.set("message", encodeURIComponent(message))
13645
- params.set("path", this.kernel.homedir)
13646
- // params.set("kill", "/Logged in/i")
13647
- params.set("kill_message", "Click to return home")
13648
- params.set("callback", encodeURIComponent("/github"))
13649
- params.set("target", "_top")
13650
- params.set("id", id)
13651
- let url = `/shell/${id}?${params.toString()}`
13652
- res.redirect(url)
13653
- }))
13654
- this.app.get("/github/logout", ex(async (req, res) => {
13655
- let id = "gh_logout"
13656
- let params = new URLSearchParams()
13657
- const githubConnection = await this.get_github_connection()
13658
- let { hadLegacyAuth, message } = await this.github_logout_params(githubConnection)
13659
- if (!message && hadLegacyAuth) {
13660
- res.redirect("/github")
13661
- return
13662
- }
13663
- if (!message) {
13664
- message = "git credential-manager github list"
13665
- }
13666
- params.set("message", encodeURIComponent(message))
13667
- params.set("path", this.kernel.homedir)
13668
- // params.set("kill", "/Logged in/i")
13669
- // params.set("kill_message", "Click to return home")
13670
- params.set("callback", encodeURIComponent("/github"))
13671
- params.set("id", id)
13672
- params.set("target", "_top")
13673
- let url = `/shell/${id}?${params.toString()}`
13674
- res.redirect(url)
13675
- }))
13676
- this.app.get("/github/login", ex(async (req, res) => {
13677
- let id = "gh_login"
13678
- this.kernel.shell.kill({ id: `shell/${id}` })
13679
- let params = new URLSearchParams()
13680
- const { doneMarker, message } = this.github_login_params()
13681
- params.set("message", encodeURIComponent(message))
13682
- params.set("input", true)
13683
- params.set("path", this.kernel.homedir)
13684
- params.set("kill", `/${doneMarker}/`)
13685
- params.set("callback", encodeURIComponent("/github"))
13686
- params.set("id", id)
13687
- params.set("target", "_top")
13688
- let url = `/shell/${id}?${params.toString()}`
13689
- res.redirect(url)
13690
- }))
13518
+ // /github/login and /github/logout are served by routes/github_auth.js
13691
13519
  this.app.get("/terminals/gemini/fork", ex(async (req, res) => {
13692
13520
  const source = typeof req.query.source === "string" ? req.query.source.trim() : ""
13693
13521
  const expectedSessionId = typeof req.query.expected_session_id === "string" ? req.query.expected_session_id.trim() : ""
@@ -0,0 +1,43 @@
1
+ // GitHub login routes (device flow), backed by kernel/github_auth.js.
2
+ //
3
+ // GET /github/login login page: shows the device code and waits
4
+ // POST /github/login/start asks GitHub for a device code and starts polling
5
+ // GET /github/login/status { connected, saved, login, display, source, session }
6
+ // GET /github/logout removes the stored token and returns to /github
7
+ module.exports = function registerGithubAuthRoutes(app, options = {}) {
8
+ const auth = options.auth
9
+ const getPageContext = options.getPageContext || (() => ({}))
10
+ const noStore = (res) => res.set("Cache-Control", "no-store")
11
+
12
+ app.get("/github/login", (req, res) => {
13
+ res.render("github_login", getPageContext(req))
14
+ })
15
+
16
+ app.post("/github/login/start", async (req, res) => {
17
+ noStore(res)
18
+ try {
19
+ const session = await auth.startLogin()
20
+ res.json({ status: "ok", login: session })
21
+ } catch (error) {
22
+ res.json({ status: "error", error: error && error.message ? error.message : String(error) })
23
+ }
24
+ })
25
+
26
+ app.get("/github/login/status", async (req, res) => {
27
+ noStore(res)
28
+ try {
29
+ res.json(await auth.status())
30
+ } catch (error) {
31
+ res.json({ connected: false, error: error && error.message ? error.message : String(error) })
32
+ }
33
+ })
34
+
35
+ app.get("/github/logout", async (req, res) => {
36
+ try {
37
+ await auth.logout()
38
+ res.redirect("/github")
39
+ } catch (error) {
40
+ res.status(500).type("text").send(`GitHub logout failed: ${error && error.message ? error.message : error}`)
41
+ }
42
+ })
43
+ }
@@ -159,6 +159,7 @@ document.addEventListener('DOMContentLoaded', function() {
159
159
  <div class='anywhere-card'>
160
160
  <h2>Remote access is off</h2>
161
161
  <p>Turn it on to access this Pinokio from another device. Nothing is exposed to the public internet: only devices signed in to your own Tailscale account can connect.</p>
162
+ <p>Tailscale is bundled with Pinokio. It's <a href='https://tailscale.com/pricing' target='_blank' rel='noopener'>free for personal use</a> and its core is open source. You sign in with a personal account you already have, such as Google, Apple, GitHub or Microsoft. <a href='https://tailscale.com/kb/1151/what-is-tailscale' target='_blank' rel='noopener'>What is Tailscale?</a></p>
162
163
  <p><button class='anywhere-btn' data-action='start'><i class="fa-solid fa-power-off"></i> Turn on</button></p>
163
164
  </div>
164
165
  </div>
@@ -155,7 +155,7 @@
155
155
  const connectionLabel = isGithubConnected ? "Connected" : "Not connected";
156
156
  const connectionIcon = isGithubConnected ? "fa-solid fa-circle-check" : "fa-regular fa-circle";
157
157
  const connectionDetail = isGithubConnected
158
- ? "Git Credential Manager is ready for GitHub operations inside Pinokio."
158
+ ? "Git and gh inside Pinokio use this login for GitHub operations."
159
159
  : "Connect GitHub to clone private repositories and publish from Pinokio.";
160
160
  %>
161
161
  <body class="<%= theme %> main-sidebar-page task-launcher-page task-page setup-page github-page" data-agent="<%= agent %>" data-page="github-config">
@@ -172,7 +172,7 @@
172
172
  <p class="task-description">Connect GitHub for private repositories and publishing, then set the identity Git writes on commits.</p>
173
173
  <div class="task-badge-row task-header-badges">
174
174
  <span class="task-badge <%= isGithubConnected ? 'task-badge-accent' : 'task-badge-neutral' %>"><%= connectionLabel %></span>
175
- <span class="task-badge task-badge-neutral">Git Credential Manager</span>
175
+ <span class="task-badge task-badge-neutral">GitHub device login</span>
176
176
  <span class="task-badge task-badge-neutral">~/pinokio/gitconfig</span>
177
177
  </div>
178
178
  </div>