Skip to content

Commit

Permalink
Fix scanner output
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanJarv committed Dec 15, 2021
1 parent 70aba1b commit e694e55
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 94 deletions.
37 changes: 4 additions & 33 deletions cdn_proxy/lambdas/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@ import React from 'react';
import {HashRouter, Route, Switch} from 'react-router-dom';
import {LinkContainer} from 'react-router-bootstrap';

import {Nav, Navbar, NavDropdown, Row} from "react-bootstrap";
import {Nav, Navbar, Row} from "react-bootstrap";
import Container from "react-bootstrap/Container";

import './App.css';
import Help from "./Help";
import Scanner from "./Scanner";

// // Example POST method implementation:
// async function proxyReq(url = '', data = {}) {
// // Default options are marked with *
// const response = await fetch(url, {
// method: 'GET',
// headers: {
// 'Cdn-Proxy-Origin': 'www.wikipedia.org',
// 'Cdn-Proxy-Host': 'www.wikipedia.org'
// },
// redirect: 'error', // manual, *follow, error
// });
// return response.json(); // parses JSON response into native JavaScript objects
// }
//
const OurNavBar = (props: any) => (
<Navbar bg="light" expand="lg">
<Container>
Expand All @@ -36,16 +22,6 @@ const OurNavBar = (props: any) => (
<LinkContainer to="/scanner">
<Nav.Link>Scanner</Nav.Link>
</LinkContainer>
<LinkContainer to="/help">
<Nav.Link>Help</Nav.Link>
</LinkContainer>
<NavDropdown title="Dropdown" id="basic-nav-dropdown">
<NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.2">Another action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href="#action/3.4">Separated link</NavDropdown.Item>
</NavDropdown>
</Nav>
</Navbar.Collapse>
</Container>
Expand All @@ -55,14 +31,6 @@ const OurNavBar = (props: any) => (
const OurNavBarRouter = () => (
<HashRouter>
<Switch>
<Route path="/help">
<Row>
<OurNavBar name="Help" />
</Row>
<Row>
<Help/>
</Row>
</Route>
<Route path="/scanner">
<Row>
<OurNavBar name="Scanner" />
Expand All @@ -75,6 +43,9 @@ const OurNavBarRouter = () => (
<Row>
<OurNavBar name="Home" />
</Row>
<Row>
<Help/>
</Row>
</Route>
</Switch>
</HashRouter>
Expand Down
8 changes: 1 addition & 7 deletions cdn_proxy/lambdas/src/CloudFrontScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,17 @@ export class CloudFrontScanner {

scan(
backends: Array<string>,
// onfulfilled?: ((value: Response) => PromiseLike<Response>) | undefined | null,
onfulfilled?: ((value: Response) => any),
onfulfilled?: ((resp: Response) => any),
onrejected?: ((reason: any) => any),
) {
for (const backend of backends) {
this.cdnRequest(backend).then(onfulfilled, onrejected)
}
}

public forEachResult(backends: Array<string>) {

}
}


export function textToIps(input: string): Array<string> {
console.log("textToIps input: " + input)
let addr: Address4 = new Address4(input)

// Not sure why they use BigInt here, more then enough numbers to hold an IPv4 address
Expand Down
53 changes: 21 additions & 32 deletions cdn_proxy/lambdas/src/Scanner.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import React, {ChangeEvent, FormEvent, useState} from "react";
import {Button, Col, Form, Row, Table} from "react-bootstrap";
import React, {ChangeEvent, useState} from "react";
import {Button, Col, Form, Row} from "react-bootstrap";
import Container from "react-bootstrap/Container";
import {CloudFrontScanner, textToIps} from "./CloudFrontScanner";
import BootstrapTable from 'react-bootstrap-table-next';

const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'url',
text: 'URL'
dataField: 'origin',
text: 'Origin'
}, {
dataField: 'result',
text: 'Result'
}];


function Scanner() {
// const [isLoading, setLoading] = useState(false);

const [ipRange, setIpRange] = useState("");
const [scanner,] = useState(new CloudFrontScanner(window.location.hostname));
let [products, setProducts] = useState<Array<{ id: Number, url: string; result: string; }>>([]);
let [products, setProducts] = useState<Array<{ id: Number, origin: string; result: string; }>>([]);


return <Container>
Expand All @@ -31,27 +26,23 @@ function Scanner() {
<Button
variant="primary"
type="submit"
// className="scan-shit"
// disabled={isLoading}
onClick={() => {
scanner.scan(
textToIps(ipRange),
(resp) => {
console.log("response is: " + JSON.stringify(resp));
console.log("products currently is: " + JSON.stringify(products));
setProducts((prev) => {
prev.push({
'id': products.length,
'url': resp.url,
'result': resp.status.toString(),
}); return prev
})
},
(resp) => {
console.log(resp);
}
);
// setLoading(true);
for (const ip of textToIps(ipRange)) {
scanner.cdnRequest(ip).then((resp) => {
setProducts((prev) => {
let prevCopy = prev.slice()
prevCopy.push({
'id': products.length,
'origin': ip,
'result': resp.status.toString(),
}); return prevCopy
})
},
(resp) => {
console.log(resp);
}
);
}
}}
>
Submit
Expand All @@ -63,8 +54,6 @@ function Scanner() {
{/*<Form.Label>IPs to Scan</Form.Label>*/}
<Form.Control type="text" placeholder="IP CIDR" onChange={(e: ChangeEvent<HTMLInputElement>) => {
setIpRange(e.currentTarget.value);
console.log("ipRange: " + ipRange);
console.log("products: " + JSON.stringify(products));
}} />
<Form.Text>
Enter the IP range to scan in CIDR notation.
Expand Down
8 changes: 1 addition & 7 deletions cdn_proxy/lambdas/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
);
15 changes: 0 additions & 15 deletions cdn_proxy/lambdas/src/reportWebVitals.ts

This file was deleted.

0 comments on commit e694e55

Please sign in to comment.