-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TorBot GUI #152
TorBot GUI #152
Changes from 23 commits
d69ade6
cfdb4c3
e055ab1
d43521a
81a3316
6d54348
e119490
d52b5a6
30b82d7
d725b11
06ef3be
36f0f86
941e8fe
66b1376
2a08689
dc5636b
540e68e
a143d36
9bbe784
0c14198
d8c42f8
f994c3c
31ba103
f5a3b14
9b1ff79
200917d
85cc2aa
9265007
aa70a9a
43dd359
1989da5
622a931
54515e9
71594bf
e9032c7
e33e272
fcf739d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
flake8: | ||
enabled: true | ||
enabled: true | ||
eslint: | ||
enbaled: true | ||
config_file: ./ui/.eslintrc.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if [ -f ../torBot.py ]; then | ||
python3 ../torBot.py --server | ||
fi | ||
if [ -f torBot.py ]; then | ||
python3 torBot.py --server | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import requests | ||
|
||
proxies = { | ||
'http': 'socks5h://localhost:9050', | ||
'https': 'socks5h://localhost:9050' | ||
} | ||
session = requests.session() | ||
session.proxies = proxies | ||
def proxyGET(url, headers=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
if headers: | ||
return session.get(url, headers=headers) | ||
else: | ||
return session.get(url) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line at end of file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
""" | ||
Module contains WebSocket server | ||
""" | ||
|
||
# Built-in Imports | ||
import asyncio | ||
import json | ||
import logging | ||
|
||
# Third Party Imports | ||
import tldextract | ||
import websockets | ||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
# Local Imports | ||
from .link import LinkNode | ||
from .proxy import proxyGET | ||
|
||
|
||
logging.basicConfig( | ||
format='%(asctime)s %(levelname)-8s %(message)s', | ||
level=logging.INFO, | ||
datefmt='%Y-%m-%d %H:%M:%S') | ||
async def handle_msg(websocket, path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
""" | ||
Handles incoming WebSocket messages from front-end. | ||
The appropriate action is taken based on the message. | ||
|
||
Args: | ||
websocket (websockets.protocol): websocket connection being used | ||
path (string): contains origin of websocket message | ||
""" | ||
msg = await websocket.recv() | ||
data = json.loads(msg) # Load JSON response from front-end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at least two spaces before inline comment |
||
url = data['url'] | ||
# action determines what we will do with the url | ||
action = data['action'] | ||
if action == 'get_links': | ||
links = get_links(url) | ||
# If get_links returns an exception then send an error as a response | ||
if isinstance(links, Exception): | ||
error_msg = str(links) | ||
logging.error(error_msg) | ||
error = json.dumps({'error': error_msg}) | ||
await websocket.send(error) | ||
else: | ||
for link in links: | ||
response = json.dumps({'link': link}) | ||
await websocket.send(response) | ||
|
||
def get_links(url): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
""" | ||
Get links from url | ||
|
||
Args: | ||
url (string): url to get links from | ||
Returns: | ||
links (list): list containing links | ||
""" | ||
ext = tldextract.extract(url) | ||
use_tor = ext.domain == 'onion' or ext.suffix == 'onion' | ||
try: | ||
if use_tor: | ||
response = proxyGET(url) | ||
else: | ||
response = requests.get(url) | ||
except Exception as err: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||
return err | ||
soup = BeautifulSoup(response.text, 'html.parser') | ||
anchor_tags = soup.find_all('a') | ||
links = list() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. local variable 'links' is assigned to but never used |
||
for anchor in anchor_tags: | ||
link = anchor.get('href') | ||
if link and LinkNode.valid_link(link): | ||
links.append(link) | ||
return links | ||
|
||
def start_wsserver(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
""" | ||
Starts WebSocketServer | ||
""" | ||
print('Starting WSServer on address localhost:8080') | ||
start_server = websockets.serve(handle_msg, 'localhost', '8080') | ||
asyncio.get_event_loop().run_until_complete(start_server) | ||
asyncio.get_event_loop().run_forever() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ pyinstaller==3.4.0 | |
ete3==3.1.1 | ||
PyQt5==5.11.3 | ||
validators==0.12.2 | ||
websockets==7.0.0 | ||
tldextract==2.2.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"browser": true, | ||
"commonjs": true, | ||
"es6": true | ||
}, | ||
"extends": ["plugin:react/recommended","eslint:recommended"], | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"react" | ||
], | ||
"rules": { | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "torbot", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"electron-reload-webpack-plugin": "^2.0.4", | ||
"extract-text-webpack-plugin": "^4.0.0-beta.0", | ||
"react": "^16.6.0", | ||
"react-dom": "^16.6.0", | ||
"react-scripts": "2.0.5" | ||
}, | ||
"scripts": { | ||
"start": "webpack --mode development --watch", | ||
"build": "webpack --mode production", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject", | ||
"electron": "electron ." | ||
}, | ||
"homepage": "./", | ||
"main": "src/electron-main.js", | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
], | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.1.0", | ||
"babel-eslint": "^10.0.1", | ||
"babel-loader": "^8.0.4", | ||
"css-loader": "^1.0.1", | ||
"electron": "^3.0.8", | ||
"electron-connect": "^0.6.3", | ||
"electron-reload": "^1.2.5", | ||
"eslint": "^5.9.0", | ||
"eslint-config-prettier": "^3.3.0", | ||
"eslint-plugin-prettier": "^3.0.0", | ||
"eslint-plugin-react": "^7.11.1", | ||
"html-webpack-plugin": "^3.2.0", | ||
"mini-css-extract-plugin": "^0.4.4", | ||
"prettier": "^1.15.2", | ||
"webpack-cli": "^3.1.2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'import' is only available in ES6 (use 'esversion: 6'). |
||
import Home from './components/home'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'import' is only available in ES6 (use 'esversion: 6'). |
||
import './app.css'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'import' is only available in ES6 (use 'esversion: 6'). |
||
|
||
class App extends React.Component { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'class' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
render() { | ||
return <Home/>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected an assignment or function call and instead saw an expression. |
||
} | ||
} | ||
|
||
export default App; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'export' is only available in ES6 (use 'esversion: 6'). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (150 > 79 characters)