Start work on proxies
This commit is contained in:
parent
24f893c043
commit
207cdebb2e
7 changed files with 87 additions and 1 deletions
|
@ -34,7 +34,8 @@
|
||||||
"clipboardRead",
|
"clipboardRead",
|
||||||
"notifications",
|
"notifications",
|
||||||
"bookmarks",
|
"bookmarks",
|
||||||
"browserSettings"
|
"browserSettings",
|
||||||
|
"proxy"
|
||||||
],
|
],
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
"build/console.html",
|
"build/console.html",
|
||||||
|
|
|
@ -47,6 +47,8 @@ export default class CommandController {
|
||||||
return this.completionsUseCase.queryBdeleteForce(name, keywords);
|
return this.completionsUseCase.queryBdeleteForce(name, keywords);
|
||||||
case 'set':
|
case 'set':
|
||||||
return this.completionsUseCase.querySet(name, keywords);
|
return this.completionsUseCase.querySet(name, keywords);
|
||||||
|
case 'proxy':
|
||||||
|
return this.completionsUseCase.queryProxy(name, keywords);
|
||||||
}
|
}
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
@ -99,6 +101,8 @@ export default class CommandController {
|
||||||
case 'h':
|
case 'h':
|
||||||
case 'help':
|
case 'help':
|
||||||
return this.commandIndicator.help();
|
return this.commandIndicator.help();
|
||||||
|
case 'proxy':
|
||||||
|
return this.commandIndicator.proxy(keywords);
|
||||||
}
|
}
|
||||||
throw new Error(words[0] + ' command is not defined');
|
throw new Error(words[0] + ' command is not defined');
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,5 @@ export default {
|
||||||
quit: 'Close the current tab',
|
quit: 'Close the current tab',
|
||||||
quitall: 'Close all tabs',
|
quitall: 'Close all tabs',
|
||||||
help: 'Open Vim Vixen help in new tab',
|
help: 'Open Vim Vixen help in new tab',
|
||||||
|
proxy: 'Set a proxy'
|
||||||
} as {[key: string]: string};
|
} as {[key: string]: string};
|
||||||
|
|
|
@ -17,6 +17,17 @@ declare namespace browser.browserSettings.homepageOverride {
|
||||||
function get(param: object): Promise<BrowserSettings>;
|
function get(param: object): Promise<BrowserSettings>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare namespace browser.proxy.settings {
|
||||||
|
|
||||||
|
type BrowserSettings = {
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function get(param: object): Promise<BrowserSettings>;
|
||||||
|
function set(param: object): Promise<any>;
|
||||||
|
function clear(param: object): Promise<any>;
|
||||||
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class BrowserSettingRepository {
|
export default class BrowserSettingRepository {
|
||||||
async getHomepageUrls(): Promise<string[]> {
|
async getHomepageUrls(): Promise<string[]> {
|
||||||
|
@ -24,3 +35,25 @@ export default class BrowserSettingRepository {
|
||||||
return value.split('|').map(urls.normalizeUrl);
|
return value.split('|').map(urls.normalizeUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ProxyRepository {
|
||||||
|
private clearProxySettings(): Promise<any>{
|
||||||
|
return browser.proxy.settings.clear({});
|
||||||
|
}
|
||||||
|
|
||||||
|
private setProxySettings(address: string): Promise<any>{
|
||||||
|
return browser.proxy.settings.set({value: {
|
||||||
|
proxyType: "manual",
|
||||||
|
http: address,
|
||||||
|
httpProxyAll: true
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
set(address: string): Promise<any> {
|
||||||
|
if( address.toLowerCase() == 'none' ){
|
||||||
|
return this.clearProxySettings();
|
||||||
|
}
|
||||||
|
return this.setProxySettings(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import BookmarkRepository from '../repositories/BookmarkRepository';
|
||||||
import ConsoleClient from '../infrastructures/ConsoleClient';
|
import ConsoleClient from '../infrastructures/ConsoleClient';
|
||||||
import ContentMessageClient from '../infrastructures/ContentMessageClient';
|
import ContentMessageClient from '../infrastructures/ContentMessageClient';
|
||||||
import RepeatUseCase from '../usecases/RepeatUseCase';
|
import RepeatUseCase from '../usecases/RepeatUseCase';
|
||||||
|
import { ProxyRepository } from '../repositories/BrowserSettingRepository';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class CommandIndicator {
|
export default class CommandIndicator {
|
||||||
|
@ -22,6 +23,7 @@ export default class CommandIndicator {
|
||||||
private consoleClient: ConsoleClient,
|
private consoleClient: ConsoleClient,
|
||||||
private contentMessageClient: ContentMessageClient,
|
private contentMessageClient: ContentMessageClient,
|
||||||
private repeatUseCase: RepeatUseCase,
|
private repeatUseCase: RepeatUseCase,
|
||||||
|
private proxyRepository: ProxyRepository,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +144,13 @@ export default class CommandIndicator {
|
||||||
return this.helpPresenter.open();
|
return this.helpPresenter.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async proxy(keywords: string): Promise<any> {
|
||||||
|
if (keywords.length === 0) {
|
||||||
|
return this.proxyRepository.set('none');
|
||||||
|
}
|
||||||
|
return this.proxyRepository.set(keywords);
|
||||||
|
}
|
||||||
|
|
||||||
private async urlOrSearch(keywords: string): Promise<any> {
|
private async urlOrSearch(keywords: string): Promise<any> {
|
||||||
let settings = await this.settingRepository.get();
|
let settings = await this.settingRepository.get();
|
||||||
return urls.searchUrl(keywords, settings.search);
|
return urls.searchUrl(keywords, settings.search);
|
||||||
|
|
|
@ -217,4 +217,36 @@ export default class CompletionsUseCase {
|
||||||
url: page.url
|
url: page.url
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async queryProxyItems(name: string, keywords: string) {
|
||||||
|
let proxies = [{
|
||||||
|
caption: "burp",
|
||||||
|
url: "127.0.0.1:8080"
|
||||||
|
},{
|
||||||
|
caption: "none",
|
||||||
|
url: "none"
|
||||||
|
} ].filter(proxy=>{
|
||||||
|
if( keywords == '' ){ return true; }
|
||||||
|
if( proxy.caption.startsWith(keywords) ){ return true; }
|
||||||
|
if( proxy.url.startsWith(keywords) ){ return true; }
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
return proxies;
|
||||||
|
return proxies.map(proxy => ({
|
||||||
|
caption: proxy.caption,
|
||||||
|
content: name + ' ' + proxy.url,
|
||||||
|
url: proxy.url
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
async queryProxy(name: string, keywords: string): Promise<CompletionGroup[]> {
|
||||||
|
let groups: CompletionGroup[] = [];
|
||||||
|
let items = await this.queryProxyItems( name, keywords );
|
||||||
|
groups.push({
|
||||||
|
name: 'Saved Proxies',
|
||||||
|
items: items
|
||||||
|
});
|
||||||
|
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import validate from './validate';
|
||||||
export type SettingsJSON = {
|
export type SettingsJSON = {
|
||||||
keymaps?: KeymapsJSON,
|
keymaps?: KeymapsJSON,
|
||||||
search?: SearchJSON,
|
search?: SearchJSON,
|
||||||
|
//proxies?: ProxiesJSON,
|
||||||
properties?: PropertiesJSON,
|
properties?: PropertiesJSON,
|
||||||
blacklist?: BlacklistJSON,
|
blacklist?: BlacklistJSON,
|
||||||
};
|
};
|
||||||
|
@ -162,5 +163,10 @@ export const DefaultSettingJSONText = `{
|
||||||
]
|
]
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
//"proxies": {
|
||||||
|
// "burp": "127.0.0.1:8080",
|
||||||
|
// "none": "none"
|
||||||
|
//},
|
||||||
|
|
||||||
export const DefaultSetting: Settings =
|
export const DefaultSetting: Settings =
|
||||||
Settings.fromJSON(JSON.parse(DefaultSettingJSONText));
|
Settings.fromJSON(JSON.parse(DefaultSettingJSONText));
|
||||||
|
|
Reference in a new issue