Skip to content

Commit

Permalink
set sni & port
Browse files Browse the repository at this point in the history
  • Loading branch information
ircfspace committed Mar 6, 2024
1 parent 863c73a commit 7c80a43
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const config = {
},
],
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@next/next/no-img-element": "off",
},
Expand Down
78 changes: 74 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@serwist/next": "^8.4.4",
"@serwist/precaching": "^8.4.4",
"@serwist/sw": "^8.4.4",
"axios": "^1.6.7",
"next": "^14.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
15 changes: 15 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ label {
border-radius: 30px;
}

.groupInput {
float: left;
width: 100%;
}
.groupInput label {
float: left;
}
.groupInput label:first-child {
width: calc( 100% - 110px);
}
.groupInput label:last-child {
width: 100px;
float: right;
}

footer {
margin: 50px 0 20px 0;
padding: 10px 0;
Expand Down
22 changes: 22 additions & 0 deletions src/hooks/axiosWithSNI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import axios from 'axios';
import https from 'https';

const axiosWithSNI = (url: string, sni: string, signal: AbortSignal | undefined, timeout: number) => {
let agent = null;
if (sni !== '') {
agent = new https.Agent({
servername: sni,
host: sni
});
}

return axios.create({
baseURL: url,
method: "GET",
signal: signal,
httpsAgent: agent,
timeout: timeout
});
};

export default axiosWithSNI;
36 changes: 33 additions & 3 deletions src/hooks/useIPScanner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { randomizeElements } from "~/helpers/randomizeElements";
import axiosWithSNI from "./axiosWithSNI";

type ValidIP = {
ip: string;
Expand All @@ -15,6 +16,8 @@ export type Settings = {
maxIPCount: number;
maxLatency: number;
ipRegex: string;
sniValue: string;
portValue: number;
};

type SettingKeys = keyof Settings;
Expand Down Expand Up @@ -55,6 +58,8 @@ export const settingsInitialValues: Pick<ScannerStore, SettingKeys> = {
maxIPCount: 5,
maxLatency: 1000,
ipRegex: "",
sniValue: "",
portValue: 80,
};

const initialState: Omit<ScannerStore, FunctionalKeys> = {
Expand Down Expand Up @@ -158,10 +163,25 @@ export const useIPScanner = ({ allIps }: IPScannerProps) => {
}
}

const ports = {
http : [80, 8080, 2052, 2082, 2086, 2095],
https: [443, 8443, 2053, 2083, 2087, 2096],
};

async function testIPs(ipList: string[]) {
let isSSL = false;
if (ports.https.includes(state.portValue)) {
isSSL = true;
}
for (const ip of ipList) {
increaseTestNo();
const url = `http://${ip}/cdn-cgi/trace`;

let url = `http://${ip}`;
let path = `/cdn-cgi/trace`;
if (state.sniValue !== '' && isSSL ) {
url = `https://${ip}`;
path = `/__down`;
}

let testCount = 0;

Expand Down Expand Up @@ -191,8 +211,18 @@ export const useIPScanner = ({ allIps }: IPScannerProps) => {
}

dispatch(newState);

try {

const axiosInstance = axiosWithSNI(url, state.sniValue, controller.signal, timeout);
const response = await axiosInstance.get(path);
testCount++;
} catch (error) {
if (error instanceof Error && !["AbortError", "TypeError"].includes(error.name)) {
testCount++;
}
}

/*try {
await fetch(url, {
signal: controller.signal,
//mode: 'no-cors'
Expand All @@ -203,7 +233,7 @@ export const useIPScanner = ({ allIps }: IPScannerProps) => {
if (error instanceof Error && !["AbortError", "TypeError"].includes(error.name)) {
testCount++;
}
}
}*/
clearTimeout(timeoutId);
}

Expand Down
33 changes: 32 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { allIps } from "~/consts";
import { useUserIPInfo } from "~/hooks/useUserIPInfo";
import { toast } from "react-hot-toast";
import { useEffect, useState } from "react";
import { useRouter } from 'next/router';
//import { useRouter } from 'next/router';
const UserIP = dynamic(() => import("~/components/UserIP"), { ssr: false });

const Home: NextPage = () => {
Expand All @@ -28,6 +28,8 @@ const Home: NextPage = () => {
currentIP,
currentLatency,
ipRegex,
sniValue,
portValue,
maxIPCount,
maxLatency,
scanState,
Expand Down Expand Up @@ -148,6 +150,35 @@ const Home: NextPage = () => {
className="form-control dirLeft"
/>
</label>
<div className="groupInput">
<label>
SNI:
<input
type="text"
id="sni"
value={sniValue}
onChange={(e) =>
setSettings({ sniValue: (e.target.value).replace(/^(https?:\/\/)?/, '') })
}
disabled={isRunning}
className="form-control dirLeft"
/>
</label>
<label>
Port:
<input
type="number"
id="max-latency"
value={(sniValue !== "" ? portValue : 80)}
disabled={isRunning}
onChange={(e) =>
setSettings({ portValue: e.target.valueAsNumber })
}
min={80}
className="form-control dirLeft"
/>
</label>
</div>
<div className="clearfix"></div>
{/*<div className="alert alert-info">
<UserIP
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2017",
"target": "es6",
"types": ["@serwist/next/typings"],
"lib": ["dom", "dom.iterable", "esnext", "webworker"],
"allowJs": true,
Expand Down

0 comments on commit 7c80a43

Please sign in to comment.