adding net project with addr subproject

This commit is contained in:
brent s 2017-10-05 21:17:04 -04:00
parent 6c2dfce9a7
commit 8aaf23cdac
8 changed files with 112 additions and 0 deletions

7
net/addr/app/__init__.py Normal file
View File

@ -0,0 +1,7 @@
from flask import Flask

app = Flask(__name__, instance_relative_config=True)

from app import views

app.config.from_object('config')

0
net/addr/app/models.py Normal file
View File

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>{% block title %}{% endblock %}</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="https://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
</head>

<body>
<div class="container">
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<!-- the following opens in a new tab/window/whatever. the line after opens in the same tab/window/etc. -->
<!-- <li role="presentation"><a href="https://square-r00t.net/" target="_blank">r00t^2</a></li> -->
<li role="presentation"><a href="https://square-r00t.net/">r00t^2</a></li>
</ul>
</nav>
</div>
{% block body %} {% endblock %}
<footer class="footer">
<p><sub>The code for this page is released under the <a href="https://www.gnu.org/licenses/gpl-3.0.en.html#content">GPL 3.0 License</a>. It can be found <a href="https://git.square-r00t.net/OpTools/tree/net">here</a>.</sub></p>
</footer>
</div>
<!-- /container -->
</body>

</html>

View File

@ -0,0 +1,7 @@
{% extends "base.html" %} {% block title %}r00t^2 Client Info Revealer{% endblock %}{% block body %}
<div class="jumbotron">
<h1>What this is</h1>
<p class="lead">This is a tool to reveal certain information about your connection that the server sees.</p>
</div>
<p>PLACEHOLDER.</p>
{% endblock %}

40
net/addr/app/views.py Normal file
View File

@ -0,0 +1,40 @@
import json
import re
from flask import render_template, make_response, request
from app import app

@app.route('/', methods = ['GET']) #@app.route('/')
def index():
# First we define interactive browsers
_intbrowsers = ('camino', 'chrome', 'firefox', 'galeon', 'kmeleon', 'konqueror',
'links', 'lynx')
# And then we set some parameter options for less typing later on.
_yes = ('y', 'yes', 'true', '1')
_no = ('y', 'no', 'false', '0')
visitor = {'client': {'str': request.user_agent.string,
'browser': request.user_agent.browser,
'os': request.user_agent.platform,
'language': request.user_agent.language,
'to_header': request.user_agent.to_header(),
'version': request.user_agent.version},
'ip': request.remote_addr,
'headers': dict(request.headers)}
# We have to convert these to strings so we can do tuple comparisons on lower()s.
_json = str(request.args.get('json')).lower()
_html = str(request.args.get('html')).lower()
# Handle possibly conflicting options.
# This forces JSON if html=0, and forces HTML if json=0. json= is processed first.
if _json in _no:
_html = '1'
elif _html in _no:
_json = '1'
# Set the tabs for JSON
try:
_tabs = int(request.args.get('tabs'))
except (ValueError, TypeError):
_tabs = None
if (visitor['client']['browser'] in _intbrowsers and _json not in _yes) or (_html in _yes):
return(render_template('index.html', visitor = visitor))
else:
j = json.dumps(visitor, indent = _tabs)
return(j)

5
net/addr/config.py Normal file
View File

@ -0,0 +1,5 @@
# config.py

# Flask debugging - DISABLE FOR PRODUCTION ENVIRONMENTS
DEBUG = True
#DEBUG = False

4
net/addr/run.py Normal file
View File

@ -0,0 +1,4 @@
from app import app

if __name__ == '__main__':
app.run()

18
net/addr/uwsgi.ini Normal file
View File

@ -0,0 +1,18 @@
[uwsgi]
plugin = python
py-autoreload = 1
#uid = http
#gid = http
socket = /run/uwsgi/netinfo.sock
chown-socket = http:http
processes = 4
master = 1
base = /usr/local/lib/optools/net/addr
chdir = %(base)
#mount = /=%(base)/run.py
wsgi-file = %(base)/run.py
chmod-socket = 660
callable = app
cgi-helper =.py=python
logto = /var/log/uwsgi/%n.log
vacuum