Skip to content

Commit

Permalink
Rename custom proxies to host proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihildt committed Jan 30, 2024
1 parent 8fb438b commit 5ed2ad2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions src/components/ProxyStatus/ProxyHost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ import useStore from '@/composables/useStore';
const { connection } = useConnection();
const { hostProxySelect, toggleLocations } = useLocations();
const { activeTabProxyEnabled } = useSocksProxy();
const { customProxiesDetails, customProxies, excludedHosts } = useStore();
const { hostProxies, hostProxiesDetails, excludedHosts } = useStore();
const { activeTabHost, activeTab } = useActiveTab();
const customTitle = computed(() => `For this website (${activeTabHost.value})`);
const currentProxyDetails = computed(() => {
return customProxiesDetails.value[activeTabHost.value];
return hostProxiesDetails.value[activeTabHost.value];
});
const isExcluded = computed(() => excludedHosts.value.includes(activeTabHost.value));
const isWireGuard = computed(() => connection.value.protocol?.includes('WireGuard'));
const removeCustomProxy = () => {
const updatedCustomProxies = { ...customProxies.value };
delete updatedCustomProxies[activeTabHost.value];
customProxies.value = updatedCustomProxies;
const removeHostProxy = () => {
const updatedHostProxies = { ...hostProxies.value };
delete updatedHostProxies[activeTabHost.value];
hostProxies.value = updatedHostProxies;
};
const neverProxyHost = () => {
Expand Down Expand Up @@ -102,7 +102,7 @@ const handleHostProxySelect = () => {
v-if="activeTabProxyEnabled"
color="error"
class="flex items-center justify-center"
@click="removeCustomProxy"
@click="removeHostProxy"
>
Disable proxy
</Button>
Expand Down
12 changes: 6 additions & 6 deletions src/composables/useSocksProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import useStore from '@/composables/useStore';

const { activeTabHost } = useActiveTab();
const { connection, updateConnection } = useConnection();
const { globalProxyDetails, globalProxy, customProxies, customProxiesDetails } = useStore();
const { globalProxy, globalProxyDetails, hostProxies, hostProxiesDetails } = useStore();

const globalProxyEnabled = computed(() => globalProxyDetails.value.socksEnabled);
const activeTabProxyEnabled = computed(() =>
Object.keys(customProxies.value).includes(activeTabHost.value),
Object.keys(hostProxies.value).includes(activeTabHost.value),
);

const baseConfig: Partial<ProxyInfo> = {
Expand Down Expand Up @@ -109,7 +109,7 @@ const setHostProxy = (
type: ProxyInfoType.socks,
};

const newCustomProxyDetails: ProxyDetails = {
const newHostProxyDetails: ProxyDetails = {
socksEnabled: true,
protocol: connection.value.protocol,
server: hostname!.replace('socks5-', '')!.replace('.relays.mullvad.net', ''),
Expand All @@ -118,14 +118,14 @@ const setHostProxy = (
proxyDNS: baseConfig.proxyDNS,
};

customProxies.value = { ...customProxies.value, [host]: newHostProxy };
customProxiesDetails.value = { ...customProxiesDetails.value, [host]: newCustomProxyDetails };
hostProxies.value = { ...hostProxies.value, [host]: newHostProxy };
hostProxiesDetails.value = { ...hostProxiesDetails.value, [host]: newHostProxyDetails };
};

const useSocksProxy = () => {
return {
customProxiesDetails,
activeTabProxyEnabled,
hostProxiesDetails,
globalProxyDetails,
globalProxyEnabled,
initGlobalProxy,
Expand Down
18 changes: 9 additions & 9 deletions src/composables/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ import type { HistoricConnectionsMap } from './useHistoricConnections/HistoricCo
import { Country } from './useListProxies';

export type Store = {
customProxies: Ref<ProxyInfoMap>;
proxiesList: Ref<Country[]>;
customProxiesDetails: Ref<ProxyDetailsMap>;
excludedHosts: Ref<string[]>;
hostProxies: Ref<ProxyInfoMap>;
hostProxiesDetails: Ref<ProxyDetailsMap>;
globalProxy: Ref<ProxyInfo>;
globalProxyDetails: Ref<ProxyDetails>; // TODO make sure it always come from the socks-proxies server info
historicConnections: Ref<HistoricConnectionsMap>;
mullvadAccount: Ref<string>;
proxiesList: Ref<Country[]>;
randomProxyActive: Ref<boolean>;
webRTCStatus: Ref<boolean>;
};

const useStore = (): Store => {
const customProxies = useBrowserStorageLocal('customProxies', {});
const customProxiesDetails = useBrowserStorageLocal('customProxiesDetails', {});
const excludedHosts = useBrowserStorageLocal('excludedHosts', []);
const globalProxy = useBrowserStorageLocal('globalProxy', {} as ProxyInfo);
const globalProxyDetails = useBrowserStorageLocal('globalProxyDetails', { socksEnabled: false });
const hostProxies = useBrowserStorageLocal('hostProxies', {});
const hostProxiesDetails = useBrowserStorageLocal('hostProxiesDetails', {});
const historicConnections = useBrowserStorageLocal('connections', {});
const proxiesList = useBrowserStorageLocal('proxiesList', [] as Country[]);
const mullvadAccount = useBrowserStorageLocal('mullvadAccount', '');
const proxiesList = useBrowserStorageLocal('proxiesList', [] as Country[]);
const randomProxyActive = useBrowserStorageLocal('randomProxyActive', false);
const webRTCStatus = useBrowserStorageLocal('webRTCStatus', true);
return {
customProxies,
customProxiesDetails,
excludedHosts,
globalProxy,
globalProxyDetails,
hostProxies,
hostProxiesDetails,
historicConnections,
proxiesList,
mullvadAccount,
proxiesList,
randomProxyActive,
webRTCStatus,
};
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/socksProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ const handleProxyRequest = async (details: browser.proxy._OnRequestDetails) => {
const { globalProxy } = await browser.storage.local.get('globalProxy');
const { globalProxyDetails } = await browser.storage.local.get('globalProxyDetails');
const { excludedHosts } = await browser.storage.local.get('excludedHosts');
const { customProxies } = await browser.storage.local.get('customProxies');
const { hostProxies } = await browser.storage.local.get('hostProxies');

// TODO implement random proxy
const { randomProxyActive } = await browser.storage.local.get('randomProxyActive');

const globalConfigParsed = JSON.parse(globalProxy);
const globalProxyDetailsParsed: ProxyDetails = JSON.parse(globalProxyDetails);
const excludedHostsParsed: string[] = JSON.parse(excludedHosts);
const customProxiesParsed = JSON.parse(customProxies);
const hostProxiesParsed = JSON.parse(hostProxies);
const randomProxyActiveParsed = JSON.parse(randomProxyActive);

const proxiedHosts = Object.keys(customProxiesParsed);
const proxiedHosts = Object.keys(hostProxiesParsed);
const currentHost = getCurrentHost(details);

if (excludedHostsParsed.includes(currentHost) || currentHost.includes('localhost')) {
Expand All @@ -46,9 +46,9 @@ const handleProxyRequest = async (details: browser.proxy._OnRequestDetails) => {
// TODO Warn about ubO or other extension creation DNS leaks
// Maybe check automatically?

console.log(`custom proxy "${currentHost}" used for :`, details.url);
console.log(`host proxy "${currentHost}" used for :`, details.url);
console.log('_____________________________');
return customProxiesParsed[currentHost];
return hostProxiesParsed[currentHost];
} else if (randomProxyActiveParsed) {
console.log('random proxy');
console.log('_____________________________');
Expand Down

0 comments on commit 5ed2ad2

Please sign in to comment.