-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* use proxy auto configuration settings * adapt daemon to use pac file * specify proxy pac file content type * update version to 0.0.3-alpha
- Loading branch information
1 parent
2bb92a4
commit 0a6c066
Showing
27 changed files
with
230 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@dfinity/http-proxy", | ||
"version": "0.0.2-alpha", | ||
"version": "0.0.3-alpha", | ||
"description": "HTTP Proxy to enable trustless access to the Internet Computer.", | ||
"author": "Kepler Vital <[email protected]>", | ||
"license": "Apache-2.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,25 @@ | ||
import { exec } from 'child_process'; | ||
import { WebProxyConfiguration } from './typings'; | ||
import { PlatformProxyInfo } from '../typings'; | ||
import { execSync } from 'child_process'; | ||
|
||
export const SHELL_SCRIPT_SEPARATOR = ' ; '; | ||
export const CURL_RC_FILE = '.curlrc'; | ||
export const PROXY_GET_SEPARATOR = ':ic-separator:'; | ||
|
||
export const resolveNetworkInfo = async ( | ||
proxy: PlatformProxyInfo | ||
): Promise<Map<string, WebProxyConfiguration>> => { | ||
const ports = await fetchHardwarePorts(); | ||
const networkInfo = new Map<string, WebProxyConfiguration>(); | ||
for (const port of ports) { | ||
const webProxyState = await fetchNetworkWebProxy(port, proxy); | ||
networkInfo.set(port, webProxyState); | ||
export const getActiveNetworkService = (): string | null => { | ||
const networkServices = execSync( | ||
`networksetup -listallnetworkservices | tail -n +2` | ||
) | ||
.toString() | ||
.split('\n'); | ||
for (const networkService of networkServices) { | ||
const assignedIpAddress = execSync( | ||
`networksetup -getinfo "${networkService}" | awk '/^IP address:/{print $3}'` | ||
) | ||
.toString() | ||
.trim(); | ||
if (assignedIpAddress.length > 0) { | ||
return networkService; | ||
} | ||
} | ||
|
||
return networkInfo; | ||
}; | ||
|
||
export const fetchHardwarePorts = async (): Promise<string[]> => { | ||
return new Promise<string[]>((ok, err) => { | ||
exec( | ||
`networksetup -listnetworkserviceorder | grep 'Hardware Port'`, | ||
(error, stdout) => { | ||
if (error) { | ||
return err(error); | ||
} | ||
|
||
const ports = stdout | ||
.split('\n') | ||
.map((line) => { | ||
const [, port] = | ||
line.match(new RegExp(/Hardware Port:\s(.*),.*/)) ?? []; | ||
|
||
return port; | ||
}) | ||
.filter((port) => !!port) as string[]; | ||
|
||
ok(ports); | ||
} | ||
); | ||
}); | ||
}; | ||
|
||
export const fetchNetworkWebProxy = async ( | ||
networkHardwarePort = 'wi-fi', | ||
proxy: PlatformProxyInfo | ||
): Promise<WebProxyConfiguration> => { | ||
return new Promise<WebProxyConfiguration>(async (ok, err) => { | ||
const shellScript = | ||
`networksetup -getwebproxy "${networkHardwarePort}"` + | ||
SHELL_SCRIPT_SEPARATOR + | ||
`echo "${PROXY_GET_SEPARATOR}"` + | ||
SHELL_SCRIPT_SEPARATOR + | ||
`networksetup -getsecurewebproxy "${networkHardwarePort}"`; | ||
|
||
exec(`${shellScript}`, (error, stdout) => { | ||
if (error) { | ||
return err(error); | ||
} | ||
|
||
const [rawHttpProxy, rawHttpsProxy] = stdout.split(PROXY_GET_SEPARATOR); | ||
|
||
const isEnabled = (parts: string[]): boolean => { | ||
const sameProxyHost = parts.some((part) => { | ||
const [, host] = | ||
part.trim().match(new RegExp(/^Server:\s+(.*)/)) ?? []; | ||
return host ? host === proxy.host : false; | ||
}); | ||
const sameProxyPort = parts.some((part) => { | ||
const [, port] = part.trim().match(new RegExp(/^Port:\s+(.*)/)) ?? []; | ||
return port ? Number(port) === proxy.port : false; | ||
}); | ||
const isEnabled = parts.some((part) => { | ||
const [, enabled] = | ||
part.trim().match(new RegExp(/^Enabled:\s+(.*)/)) ?? []; | ||
|
||
return enabled ? enabled.toLowerCase() === 'yes' : false; | ||
}); | ||
|
||
return sameProxyHost && sameProxyPort && isEnabled; | ||
}; | ||
|
||
ok({ | ||
http: { enabled: isEnabled(rawHttpProxy.split('\n')) }, | ||
https: { enabled: isEnabled(rawHttpsProxy.split('\n')) }, | ||
}); | ||
}); | ||
}); | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const PAC_FILE_NAME = 'ic-proxy.pac'; | ||
|
||
export const getProxyAutoConfiguration = ( | ||
proxyHost: string, | ||
proxyPort: number | ||
): string => { | ||
return `function FindProxyForURL(url, host) { | ||
if (url.startsWith("https:") || url.startsWith("http:")) { | ||
return "PROXY ${proxyHost}:${proxyPort}; DIRECT"; | ||
} | ||
return "DIRECT"; | ||
}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.