From 21fe7f05ddfa675bb77989f56ca9c5d98e20410d Mon Sep 17 00:00:00 2001 From: Kepler Vital Date: Wed, 6 Sep 2023 10:06:46 +0200 Subject: [PATCH] fix: ubuntu network proxy auto config (#23) * fix: network proxy auto config * chore: run linter * chore: bump version --- README.md | 6 ++--- package.json | 2 +- packages/core/package.json | 2 +- packages/daemon/package.json | 4 ++-- packages/daemon/src/platforms/linux/linux.ts | 24 ++++++++++++++++++-- packages/daemon/src/platforms/linux/utils.ts | 6 +++++ packages/server/package.json | 6 ++--- packages/server/src/commons/configs.ts | 2 +- packages/ui/package.json | 6 ++--- packages/ui/src/services/proxy.ts | 2 +- yarn.lock | 16 ++++++------- 11 files changed, 51 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 93fc006..4735a3d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=for-the-badge)](LICENSE) -[![Install MacOS](https://img.shields.io/badge/install-MacOSX-blue.svg?style=for-the-badge&logo=apple)](https://github.com/dfinity/http-proxy/releases/download/0.0.5-alpha/ic-http-proxy-mac-universal-0.0.5-alpha.dmg) -[![Install Windows](https://img.shields.io/badge/install-Windows-blue.svg?style=for-the-badge&logo=windows)](https://github.com/dfinity/http-proxy/releases/download/0.0.5-alpha/ic-http-proxy-win-x64-0.0.5-alpha.exe) -[![Install Debian](https://img.shields.io/badge/install-Debian-blue.svg?style=for-the-badge&logo=debian)](https://github.com/dfinity/http-proxy/releases/download/0.0.5-alpha/ic-http-proxy-linux-arm64-0.0.5-alpha.deb) +[![Install MacOS](https://img.shields.io/badge/install-MacOSX-blue.svg?style=for-the-badge&logo=apple)](https://github.com/dfinity/http-proxy/releases/download/0.0.6-alpha/ic-http-proxy-mac-universal-0.0.6-alpha.dmg) +[![Install Windows](https://img.shields.io/badge/install-Windows-blue.svg?style=for-the-badge&logo=windows)](https://github.com/dfinity/http-proxy/releases/download/0.0.6-alpha/ic-http-proxy-win-x64-0.0.6-alpha.exe) +[![Install Debian](https://img.shields.io/badge/install-Debian-blue.svg?style=for-the-badge&logo=debian)](https://github.com/dfinity/http-proxy/releases/download/0.0.6-alpha/ic-http-proxy-linux-arm64-0.0.6-alpha.deb) # IC HTTP Proxy > This application is currently only a proof of concept implementation and should be used at your own risk. diff --git a/package.json b/package.json index d0d1444..5ebf1b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dfinity/http-proxy", - "version": "0.0.5-alpha", + "version": "0.0.6-alpha", "description": "HTTP Proxy to enable trustless access to the Internet Computer.", "author": "Kepler Vital ", "license": "Apache-2.0", diff --git a/packages/core/package.json b/packages/core/package.json index 21c32f4..9ed113a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@dfinity/http-proxy-core", - "version": "0.0.5-alpha", + "version": "0.0.6-alpha", "description": "Gateway server to enable trustless access to the Internet Computer.", "main": "built/main.js", "types": "built/main.d.ts", diff --git a/packages/daemon/package.json b/packages/daemon/package.json index 9aabeec..5c7756c 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -1,6 +1,6 @@ { "name": "@dfinity/http-proxy-daemon", - "version": "0.0.5-alpha", + "version": "0.0.6-alpha", "description": "Daemon process to enable trustless access to the Internet Computer.", "main": "built/main.js", "types": "built/main.d.ts", @@ -62,7 +62,7 @@ "typescript": "^4.9.5" }, "dependencies": { - "@dfinity/http-proxy-core": "0.0.5-alpha", + "@dfinity/http-proxy-core": "0.0.6-alpha", "http-proxy": "^1.18.1", "node-cache": "^5.1.2", "node-forge": "^1.3.1", diff --git a/packages/daemon/src/platforms/linux/linux.ts b/packages/daemon/src/platforms/linux/linux.ts index 08e140a..a2bfb65 100644 --- a/packages/daemon/src/platforms/linux/linux.ts +++ b/packages/daemon/src/platforms/linux/linux.ts @@ -16,6 +16,7 @@ import { FIREFOX_PROFILES_FOLDER, MOZILLA_CERTIFICATES_FOLDER, ROOT_CA_PATH, + findDbusLaunchPath, findP11KitTrustPath, } from './utils'; @@ -81,12 +82,20 @@ export class LinuxPlatform implements Platform { } private async tooggleNetworkWebProxy(enable: boolean): Promise { + const dconfCachePath = `/home/${this.username}/.cache/dconf`; const pacUrl = `http://${this.configs.pac.host}:${this.configs.pac.port}/proxy.pac`; + if (pathExists(dconfCachePath)) { + await execAsync( + `sudo chown -R "${this.username}":"${this.username}" "${dconfCachePath}"` + ); + } + if (enable) { await execAsync( [ - `su -l ${this.username} -c "gsettings set org.gnome.system.proxy mode 'auto' && gsettings set org.gnome.system.proxy autoconfig-url '${pacUrl}'"`, + `sudo -u "${this.username}" dbus-launch gsettings set org.gnome.system.proxy mode 'auto'`, + `sudo -u "${this.username}" dbus-launch gsettings set org.gnome.system.proxy autoconfig-url '${pacUrl}'`, ].join(' && ') ); @@ -95,7 +104,7 @@ export class LinuxPlatform implements Platform { await execAsync( [ - `su -l ${this.username} -c "gsettings set org.gnome.system.proxy mode 'none'"`, + `sudo -u "${this.username}" dbus-launch gsettings set org.gnome.system.proxy mode 'none'`, ].join(' && ') ); } @@ -153,6 +162,17 @@ export class LinuxPlatform implements Platform { throw new Error('Failed to setup p11-kit dependency'); } } + + const dbusLaunchPath = await findDbusLaunchPath(); + if (!dbusLaunchPath) { + await execAsync(`sudo apt install dbus-x11 -y`); + + const installed = await findDbusLaunchPath(); + + if (!installed) { + throw new Error('Failed to setup dbus-x11 dependency'); + } + } } private async firefoxSetupCertificates(profilesPath: string): Promise { diff --git a/packages/daemon/src/platforms/linux/utils.ts b/packages/daemon/src/platforms/linux/utils.ts index 9847dd0..76c17dc 100644 --- a/packages/daemon/src/platforms/linux/utils.ts +++ b/packages/daemon/src/platforms/linux/utils.ts @@ -13,3 +13,9 @@ export const findP11KitTrustPath = async (): Promise => { return path.length ? path : null; }; + +export const findDbusLaunchPath = async (): Promise => { + const path = await execAsync('which dbus-launch'); + + return path.length ? path : null; +}; diff --git a/packages/server/package.json b/packages/server/package.json index f1c40db..bfc3d82 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@dfinity/http-proxy-server", - "version": "0.0.5-alpha", + "version": "0.0.6-alpha", "description": "Gateway server to enable trustless access to the Internet Computer.", "main": "built/main.js", "types": "built/main.d.ts", @@ -51,8 +51,8 @@ "dependencies": { "@dfinity/agent": "^0.19.0", "@dfinity/candid": "^0.19.0", - "@dfinity/http-proxy-core": "0.0.5-alpha", - "@dfinity/http-proxy-daemon": "0.0.5-alpha", + "@dfinity/http-proxy-core": "0.0.6-alpha", + "@dfinity/http-proxy-daemon": "0.0.6-alpha", "@dfinity/principal": "^0.19.0", "@dfinity/response-verification": "^1.0.2", "http-proxy": "^1.18.1", diff --git a/packages/server/src/commons/configs.ts b/packages/server/src/commons/configs.ts index 2b7aef3..81f710a 100644 --- a/packages/server/src/commons/configs.ts +++ b/packages/server/src/commons/configs.ts @@ -3,7 +3,7 @@ import { EnvironmentConfiguration } from './typings'; const environment: EnvironmentConfiguration = { platform: os.platform(), - userAgent: 'ICHttpProxy/0.0.5-alpha', + userAgent: 'ICHttpProxy/0.0.6-alpha', certificate: { storage: { folder: 'certs', diff --git a/packages/ui/package.json b/packages/ui/package.json index fb66c0f..e254c99 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "@dfinity/http-proxy-ui", - "version": "0.0.5-alpha", + "version": "0.0.6-alpha", "description": "Desktop interface to facilitate user interaction with the HTTP Proxy server.", "main": "built/main.js", "scripts": { @@ -37,8 +37,8 @@ }, "homepage": "https://github.com/dfinity/http-proxy/tree/main/packages/ui#readme", "dependencies": { - "@dfinity/http-proxy-core": "0.0.5-alpha", - "@dfinity/http-proxy-server": "0.0.5-alpha" + "@dfinity/http-proxy-core": "0.0.6-alpha", + "@dfinity/http-proxy-server": "0.0.6-alpha" }, "devDependencies": { "@types/node": "^18.14.0", diff --git a/packages/ui/src/services/proxy.ts b/packages/ui/src/services/proxy.ts index 3b0beba..47c5b3b 100644 --- a/packages/ui/src/services/proxy.ts +++ b/packages/ui/src/services/proxy.ts @@ -57,7 +57,7 @@ export class ProxyService { return isStarted; } - fork(entrypoint, undefined, { + fork(entrypoint, [], { stdio: 'ignore', env: process.env, detached: true, diff --git a/yarn.lock b/yarn.lock index 40e8225..09c750c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -102,7 +102,7 @@ __metadata: languageName: node linkType: hard -"@dfinity/http-proxy-core@0.0.5-alpha, @dfinity/http-proxy-core@workspace:packages/core": +"@dfinity/http-proxy-core@0.0.6-alpha, @dfinity/http-proxy-core@workspace:packages/core": version: 0.0.0-use.local resolution: "@dfinity/http-proxy-core@workspace:packages/core" dependencies: @@ -127,11 +127,11 @@ __metadata: languageName: unknown linkType: soft -"@dfinity/http-proxy-daemon@0.0.5-alpha, @dfinity/http-proxy-daemon@workspace:packages/daemon": +"@dfinity/http-proxy-daemon@0.0.6-alpha, @dfinity/http-proxy-daemon@workspace:packages/daemon": version: 0.0.0-use.local resolution: "@dfinity/http-proxy-daemon@workspace:packages/daemon" dependencies: - "@dfinity/http-proxy-core": 0.0.5-alpha + "@dfinity/http-proxy-core": 0.0.6-alpha "@types/node": ^18.14.0 "@types/node-forge": ^1.3.1 "@types/pako": ^2.0.0 @@ -155,14 +155,14 @@ __metadata: languageName: unknown linkType: soft -"@dfinity/http-proxy-server@0.0.5-alpha, @dfinity/http-proxy-server@workspace:packages/server": +"@dfinity/http-proxy-server@0.0.6-alpha, @dfinity/http-proxy-server@workspace:packages/server": version: 0.0.0-use.local resolution: "@dfinity/http-proxy-server@workspace:packages/server" dependencies: "@dfinity/agent": ^0.19.0 "@dfinity/candid": ^0.19.0 - "@dfinity/http-proxy-core": 0.0.5-alpha - "@dfinity/http-proxy-daemon": 0.0.5-alpha + "@dfinity/http-proxy-core": 0.0.6-alpha + "@dfinity/http-proxy-daemon": 0.0.6-alpha "@dfinity/principal": ^0.19.0 "@dfinity/response-verification": ^1.0.2 "@types/isomorphic-fetch": ^0.0.36 @@ -191,8 +191,8 @@ __metadata: version: 0.0.0-use.local resolution: "@dfinity/http-proxy-ui@workspace:packages/ui" dependencies: - "@dfinity/http-proxy-core": 0.0.5-alpha - "@dfinity/http-proxy-server": 0.0.5-alpha + "@dfinity/http-proxy-core": 0.0.6-alpha + "@dfinity/http-proxy-server": 0.0.6-alpha "@types/node": ^18.14.0 "@typescript-eslint/eslint-plugin": ^5.54.1 "@typescript-eslint/parser": ^5.54.1