started to make a docker service of it
This commit is contained in:
parent
fffb354d7c
commit
a69f12ec07
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ build
|
|||||||
data
|
data
|
||||||
dist
|
dist
|
||||||
venv/
|
venv/
|
||||||
|
/.idea/
|
||||||
|
|||||||
@ -1 +1,7 @@
|
|||||||
.
|
Flask
|
||||||
|
requests
|
||||||
|
flask-restplus
|
||||||
|
Werkzeug==0.16.1
|
||||||
|
dataclasses
|
||||||
|
pyyaml
|
||||||
|
graphviz
|
||||||
1
setup.py
1
setup.py
@ -23,6 +23,7 @@ setup(
|
|||||||
install_requires=[
|
install_requires=[
|
||||||
'pyyaml',
|
'pyyaml',
|
||||||
'graphviz',
|
'graphviz',
|
||||||
|
|
||||||
],
|
],
|
||||||
license='GPLv3',
|
license='GPLv3',
|
||||||
keywords='cable connector hardware harness wiring wiring-diagram wiring-harness',
|
keywords='cable connector hardware harness wiring wiring-diagram wiring-harness',
|
||||||
|
|||||||
53
src/Dockerfile
Normal file
53
src/Dockerfile
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
############################################################
|
||||||
|
# Dockerfile to build Flask App
|
||||||
|
# Based on
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
# Set the base image
|
||||||
|
FROM debian:latest
|
||||||
|
|
||||||
|
# File Author / Maintainer
|
||||||
|
MAINTAINER Jürgen Key
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y apache2 \
|
||||||
|
libapache2-mod-wsgi-py3 \
|
||||||
|
build-essential \
|
||||||
|
python3 \
|
||||||
|
python3-dev\
|
||||||
|
python3-pip \
|
||||||
|
joe \
|
||||||
|
graphviz \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& apt-get autoremove \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Copy over and install the requirements
|
||||||
|
COPY ../requirements.txt /var/www/apache-flask/app/requirements.txt
|
||||||
|
RUN pip3 install -r /var/www/apache-flask/app/requirements.txt
|
||||||
|
|
||||||
|
# Copy over the apache configuration file and enable the site
|
||||||
|
COPY ./apache-flask.conf /etc/apache2/sites-available/apache-flask.conf
|
||||||
|
RUN a2ensite apache-flask
|
||||||
|
RUN a2enmod headers
|
||||||
|
|
||||||
|
# Copy over the wsgi file
|
||||||
|
COPY ./apache-flask.wsgi /var/www/apache-flask/apache-flask.wsgi
|
||||||
|
|
||||||
|
COPY ./run.py /var/www/apache-flask/run.py
|
||||||
|
COPY ./app /var/www/apache-flask/app/
|
||||||
|
COPY ./wirewiz /var/www/apache-flask/wirewiz/
|
||||||
|
COPY ./static /var/www/apache-flask/static/
|
||||||
|
|
||||||
|
RUN a2dissite 000-default.conf
|
||||||
|
RUN a2ensite apache-flask.conf
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
WORKDIR /var/www/apache-flask
|
||||||
|
|
||||||
|
# CMD ["/bin/bash"]
|
||||||
|
CMD /usr/sbin/apache2ctl -D FOREGROUND
|
||||||
|
# The commands below get apache running but there are issues accessing it online
|
||||||
|
# The port is only available if you go to another port first
|
||||||
|
# ENTRYPOINT ["/sbin/init"]
|
||||||
|
# CMD ["/usr/sbin/apache2ctl"]
|
||||||
38
src/apache-flask.conf
Normal file
38
src/apache-flask.conf
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# -*- apache -*-
|
||||||
|
|
||||||
|
<VirtualHost *:80>
|
||||||
|
|
||||||
|
# Python application integration
|
||||||
|
WSGIDaemonProcess /apache-flask processes=4 threads=20 python-path=/var/www/apache-flask/:/usr/bin/python3
|
||||||
|
WSGIProcessGroup /apache-flask
|
||||||
|
WSGIScriptAlias / /var/www/apache-flask/apache-flask.wsgi
|
||||||
|
|
||||||
|
<Directory "/var/www/apache-flask/wirewiz/">
|
||||||
|
Header set Access-Control-Allow-Origin "*"
|
||||||
|
WSGIProcessGroup /apache-flask
|
||||||
|
WSGIApplicationGroup %{GLOBAL}
|
||||||
|
Options +ExecCGI
|
||||||
|
Order deny,allow
|
||||||
|
Allow from all
|
||||||
|
</Directory>
|
||||||
|
<Directory "/var/www/apache-flask/app/">
|
||||||
|
Header set Access-Control-Allow-Origin "*"
|
||||||
|
WSGIProcessGroup /apache-flask
|
||||||
|
WSGIApplicationGroup %{GLOBAL}
|
||||||
|
Options +ExecCGI
|
||||||
|
Order deny,allow
|
||||||
|
Allow from all
|
||||||
|
</Directory>
|
||||||
|
Alias /static /var/www/apache-flask/wirewiz/static
|
||||||
|
<Directory /var/www/apache-flask/wirewiz/static/>
|
||||||
|
Order allow,deny
|
||||||
|
Allow from all
|
||||||
|
</Directory>
|
||||||
|
# ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||||
|
ErrorLog /dev/stderr
|
||||||
|
LogLevel warn
|
||||||
|
# CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||||
|
TransferLog /dev/stdout
|
||||||
|
CustomLog /dev/stdout combined
|
||||||
|
|
||||||
|
</VirtualHost>
|
||||||
10
src/app/__init__.py
Normal file
10
src/app/__init__.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from flask import Flask, Blueprint
|
||||||
|
from flask_restplus import Api
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
blueprint = Blueprint('api', __name__, url_prefix='')
|
||||||
|
api = Api(blueprint, doc='/doc/', version='1.0', title='WireWiz server',
|
||||||
|
description='WireViz is a tool for easily documenting cables, wiring harnesses and connector pinouts. It takes plain text, YAML-formatted files as input and produces beautiful graphical output (SVG, PNG, ...) thanks to GraphViz. It handles automatic BOM (Bill of Materials) creation and has a lot of extra features.',)
|
||||||
|
app.register_blueprint(blueprint)
|
||||||
|
# app.config.from_object('config')
|
||||||
|
from app import server
|
||||||
49
src/app/server.py
Normal file
49
src/app/server.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
from flask import send_file
|
||||||
|
from flask import request, jsonify, send_file, make_response
|
||||||
|
from app import app, api
|
||||||
|
import os
|
||||||
|
from flask_restplus import Resource, reqparse
|
||||||
|
import werkzeug
|
||||||
|
import tempfile
|
||||||
|
from wireviz import wireviz
|
||||||
|
|
||||||
|
file_upload = reqparse.RequestParser()
|
||||||
|
file_upload.add_argument('yml_file',
|
||||||
|
type=werkzeug.datastructures.FileStorage,
|
||||||
|
location='files',
|
||||||
|
required=True,
|
||||||
|
help='YAML file')
|
||||||
|
#curl -X POST "http://localhost:5000/wirewiz/" -H "Content-Type: multipart/form-data" -F "yml_file=@/home/elbosso/Desktop/demo01.yml;type=application/x-yaml"
|
||||||
|
ns = api.namespace('', description='wirewiz server')
|
||||||
|
@ns.route('/wirewiz/')
|
||||||
|
class Render(Resource):
|
||||||
|
@api.expect(file_upload)
|
||||||
|
@ns.produces(['image/png', 'image/svg+xml'])
|
||||||
|
def post(self):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
args = file_upload.parse_args()
|
||||||
|
try:
|
||||||
|
file_temp=tempfile.TemporaryFile()
|
||||||
|
args['yml_file'].save(file_temp)
|
||||||
|
file_temp.seek(0)
|
||||||
|
yaml_input = file_temp.read().decode()
|
||||||
|
file_out=tempfile.NamedTemporaryFile()
|
||||||
|
fon="%s%s" % (file_out.name, '.png')
|
||||||
|
outputname = "%s%s" % (fon, '.png')
|
||||||
|
mimetype='image/png'
|
||||||
|
if request.headers["accept"] == "image/svg+xml":
|
||||||
|
fon="%s%s" % (file_out.name, '.svg')
|
||||||
|
outputname="%s%s" % (fon, '.svg')
|
||||||
|
mimetype='image/svg+xml'
|
||||||
|
wireviz.parse(yaml_input, file_out=fon)
|
||||||
|
return send_file(outputname,
|
||||||
|
as_attachment=True,
|
||||||
|
attachment_filename=outputname,
|
||||||
|
mimetype=mimetype)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return make_response(jsonify({
|
||||||
|
'message': 'internal error',
|
||||||
|
'exception': str(e)
|
||||||
|
}), 500)
|
||||||
90
src/static/index.html
Normal file
90
src/static/index.html
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<title>RFC 3161 Timestamp Server</title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
|
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3-theme-teal.css">
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- Header -->
|
||||||
|
<header class="w3-container w3-theme w3-padding" id="myHeader">
|
||||||
|
<!--i onclick="w3_open()" class="fa fa-bars w3-xlarge w3-button w3-theme"></i-->
|
||||||
|
<div class="w3-center">
|
||||||
|
<h4>by Jürgen "EL BOSSO" Key</h4>
|
||||||
|
<h1 class="w3-xxxlarge w3-animate-bottom">RFC 3161 Timestamp Server</h1>
|
||||||
|
<div class="w3-padding-16">
|
||||||
|
<a class="w3-btn w3-large w3-theme-dark w3-hover-teal" href="https://github.com/elbosso/rfc3161timestampingserver">Visit project website!</a>
|
||||||
|
</div>
|
||||||
|
<div class="w3-padding-16">
|
||||||
|
<a class="w3-btn w3-large w3-theme-dark w3-hover-teal" href="https://elbosso.github.io">Visit authors website!</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="w3-row-padding w3-margin-top">
|
||||||
|
<div class="w3-twothird">
|
||||||
|
<div class="w3-card w3-container" style="min-height:500px">
|
||||||
|
<h3>Usage</h3>
|
||||||
|
<p>The OpenSSL configuration provided as ressource can be used with
|
||||||
|
<a href="https://www.openssl.org/" rel="nofollow">OpenSSL</a> to create a certificate
|
||||||
|
request like so:</p>
|
||||||
|
<div class="w3-panel w3-leftbar w3-sand w3-tiny w3-mono">openssl ts -query -config tsa.conf -cert -sha512 -data <path>/<some_file> -no_nonce -out <request_path>/<request>.tsq</div>
|
||||||
|
<p>This request can be sent using a HTTP POST request as multipart form data
|
||||||
|
(for example from a file upload form inside a web page):</p>
|
||||||
|
<div class="w3-panel w3-leftbar w3-sand w3-tiny w3-mono">curl -F "tsq=@<request>.tsq" http://<host>:<port>/ ><reply>.tsr</div>
|
||||||
|
<p>The file <em>reply.tsr</em> contains the timestamp. Alternatively,
|
||||||
|
this also works with a POST request containing the timestamp query in
|
||||||
|
the body of said request having the correct mime-type:</p>
|
||||||
|
<div class="w3-panel w3-leftbar w3-sand w3-tiny w3-mono">curl -H "Content-Type: application/timestamp-query" --data-binary '@<request>.tsq' http://<host>:<port>/ ><reply>.tsr</div>
|
||||||
|
<p>The content of the timestamp (useful for ascertaining the time and date
|
||||||
|
for example) can be displayed for example with the help of
|
||||||
|
OpenSSL command line tools like so:</p>
|
||||||
|
<div class="w3-panel w3-leftbar w3-sand w3-tiny w3-mono">openssl ts -config tsa.conf -reply -in <reply>.tsr -text</div>
|
||||||
|
<p>To verify the timestamp, OpenSSL can help too:</p>
|
||||||
|
<div class="w3-panel w3-leftbar w3-sand w3-tiny w3-mono">openssl ts -verify -config tsa.conf -queryfile <request>.tsq -in <reply>.tsr -CAfile chain.pem</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w3-third" style="min-height:500px">
|
||||||
|
<div class="w3-card-padding w3-container" >
|
||||||
|
<h3>Ressources</h3>
|
||||||
|
<p><a href="/tsa.crt">Timestamping Authority (TSA) Certificate</a></p>
|
||||||
|
<p><a href="/chain.pem">Certificate Chain for TSA</a></p>
|
||||||
|
<p><a href="/tsa.conf">OpenSSL configuration for client operations</a></p>
|
||||||
|
<p></p>
|
||||||
|
</div>
|
||||||
|
<div class="w3-card-padding w3-container">
|
||||||
|
<h3>Search timestamp...</h3>
|
||||||
|
<form action="/query" method="post">
|
||||||
|
<div class="w3-row-padding w3-tiny w3-margin-top"><textarea rows="3" style="width: 100%; height: 100%" name="msgDigestHex"></textarea></div>
|
||||||
|
<div class="w3-row-padding w3-margin-top"><input type="submit" title="Find..." value="Find..."/></div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="w3-card-padding w3-container">
|
||||||
|
<h3>Request timestamp...</h3>
|
||||||
|
<form action="/" method="post" enctype="multipart/form-data">
|
||||||
|
<div class="w3-row-padding w3-margin-top"><input name="tsq" type="file" accept="application/timestamp-query"></div>
|
||||||
|
<div class="w3-row-padding w3-margin-top"><input type="submit" title="Request Timestamp" value="Request Timestamp"/></div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<footer class="w3-container w3-theme-dark">
|
||||||
|
<!--h3>Footer</h3-->
|
||||||
|
<p>Powered by <a href="https://www.w3schools.com/w3css/default.asp" target="_blank">w3.css</a></p>
|
||||||
|
<!--div style="position:relative;bottom:55px;" class="w3-tooltip w3-right">
|
||||||
|
Go To Top
|
||||||
|
<a class="w3-text-white" href="#myHeader">
|
||||||
|
<i class="fa fa-chevron-circle-up"></i></a>
|
||||||
|
</div>
|
||||||
|
<p>Remember to check out our <a href="w3css_references.asp" class="w3-btn w3-theme" target="_blank">W3.CSS Reference</a></p-->
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user