Esempio n. 1
0
 def _archives():
     rpm = flask.Blueprint("archives", __name__)
     AutoIndex(rpm,
               browse_root=path.join(
                   self.app_repo_config.artifacts_directory,
                   'archives'))
     self.register_blueprint(rpm, url_prefix="/archives")
Esempio n. 2
0
def main():
    config = configparser.ConfigParser()

    # INI file validation.
    try:
        with open('log_access.ini') as f:
            config.read('log_access.ini')
    except IOError:
        print("log_access.ini doesn't exist. Hence taking a default dict."
              " with path : /var/log/redant and port : 5000")
        config = {"serverdata": {"path": "/var/log/redant", "port": 5000}}

    # Path extraction and validation.
    try:
        ppath = config['serverdata']['path']
    except Exception as KeyError:
        print("Key error in path. Defaulting to /var/log/redant as log path.")
        ppath = "/var/log/redant"

    # Port extraction and validation.
    try:
        fport = int(config['serverdata']['port'])
    except Exception as KeyError:
        print("Key error in port. Defaulting to 5000.")
        fport = 5000
    except Exception as ValueError:
        print("Value error in port. Defaulting to 5000.")
        fport = 5000

    app = Flask(__name__)
    AutoIndex(app, browse_root=ppath)
    app.run(host='0.0.0.0', port=fport)
Esempio n. 3
0
def start_server(port, directory):
    print("Starting server normal")
    # output_file.write("Starting server normal")
    os.chdir(directory)
    app = Flask("Files")
    AutoIndex(app, browse_root=os.path.curdir)
    port = int(port)
    try:
        app.run(port=port)
    finally:
        print("Closing Server")
Esempio n. 4
0
def start_server_tor(port, directory, output_fileer):
    print("Starting server TOR")
    os.chdir(directory)
    app = Flask(__name__)
    AutoIndex(app, browse_root=os.path.curdir)
    print('Connecting to tor')
    with Controller.from_port() as controller:
        controller.authenticate()
        response = controller.create_ephemeral_hidden_service(
            {80: 5000}, await_publication=True)
        print("%s.onion" % response.service_id)
        output_fileer = str(output_fileer)
        output_fileer = output_fileer.replace("\\\\", "/")
        print(output_fileer)
        temp = open(output_fileer, "w")
        temp.write("%s.onion" % response.service_id)
        temp.close()
        try:
            app.run()
        finally:
            print("Stopping server")
Esempio n. 5
0
 def _python():
     rpm = flask.Blueprint("python", __name__)
     AutoIndex(rpm,
               browse_root=path.join(
                   self.app_repo_config.artifacts_directory, 'python'))
     self.register_blueprint(rpm, url_prefix="/python")
Esempio n. 6
0
              WHERE filename = ?'''
    cur = conn.cursor()
    cur.execute(sql, comic)
    conn.commit()


def init_db():
    sql = '''CREATE TABLE comics(filename TEXT,status INT,page INT)'''
    conn = create_connection(db_file)
    cur = conn.cursor()
    cur.execute(sql)
    conn.commit()


ppath = "/comics/"  # update your own parent directory here
files_index = AutoIndex(app, ppath, add_url_rules=False)
files_index.add_icon_rule('contrast.png', rule=is_comic_reading)
files_index.add_icon_rule('tick.png', rule=is_comic_read)
db_file = r"/usr/src/app/sqlite.db"


@app.route('/')
@app.route('/index')
def index():
    if not os.path.isfile(db_file):
        init_db()
    # TODO : List currently reading comics
    return render_template('index.html', comics=get_reading_comics())


@app.route('/update_path')
Esempio n. 7
0
#!/usr/bin/python3
import json, os, yaml, time, sys
from flask import Flask, render_template
from flask_autoindex import AutoIndex

start_time = time.time()

with open("settings.yml", "r") as file:
    settings = yaml.load(file, Loader=yaml.FullLoader)


app = Flask(__name__)

AutoIndex(app,browse_root=settings['files_path'])

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html', 404)

if settings['status_path'] != "OFF":
    @app.route(settings['status_path'])
    def status():
        return render_template("status.html", version=settings['version'], uptime=time.time()-start_time)


if __name__ == "__main__":
    app.run()
import os.path
from flask import Flask, escape, request, send_from_directory
from flask_autoindex import AutoIndex
from environs import Env
import subprocess
import demjson
import requests
import tempfile
import json
from flask_cors import CORS
env = Env()
env.read_env()

app = Flask(__name__)
CORS(app)
AutoIndex(app, browse_root=os.path.curdir)


def form_to_ini(form):
    """Take the form submitted and convert it to an INI file."""
    ini_dict = {}

    for k in form.keys():
        v = form[k]
        sec_key = k.split(':')
        if len(sec_key) != 2:
            continue
        if not sec_key[0] in ini_dict:
            ini_dict[sec_key[0]] = {sec_key[1]: v}
        else:
            ini_dict[sec_key[0]][sec_key[1]] = v
Esempio n. 9
0
from flask import render_template, flash, redirect, url_for, request
from flask_login import login_user, logout_user, current_user, login_required
from werkzeug.urls import url_parse
from app import app, db
from app.forms import LoginForm, RegistrationForm
from app.models import User
import os
import os.path
from flask_autoindex import AutoIndex

files_index = AutoIndex(app,
                        os.path.curdir + '/app/zapis',
                        add_url_rules=False)


@app.route('/asd')
@app.route('/asd <path:path>')
def autoindex(path='.'):
    return files_index.render_autoindex(path)


@app.route('/')
@app.route('/index')
@login_required
def index():
    posts = [{
        'author': {
            'username': '******'
        },
        'body': 'Beautiful day in Portland!'
    }, {
Esempio n. 10
0
                last_name='toilet',
                email='*****@*****.**',
                password='******',
                is_authenticated='False')

    db.session.add(user)
    db.session.add(admin)
    db.session.commit()
    print('Database seeded.')


# db_create()
# db_seed()
# db_drop()

files_index = AutoIndex(app, browse_root=os.path.curdir, add_url_rules=False)


# Custom indexing
@app.route('/dir')
@app.route('/dir/<path:path>')
def autoindex(path='.'):
    return files_index.render_autoindex(path)


@app.errorhandler(404)
def page_not_found(error):
    print(basedir)
    template = '''
    <h1>That page doesn't exist.</h1>
    <h3>%s Not found</h3>''' % (urllib.parse.unquote(request.url))
Esempio n. 11
0
import os
import tarfile
from flask import Flask, request, flash, redirect, render_template
from flask import Blueprint
from flask_autoindex import AutoIndex
import shutil
from werkzeug.utils import secure_filename

app = Flask(__name__)
app.config.from_object('tarhosting.config')
app.secret_key = app.config['SECRET_KEY']

auto_index = AutoIndex(app,
                       browse_root=app.config['STATIC_DIR'],
                       add_url_rules=False)


@app.route("/")
def index():
    return render_template('index.html', URL=request.url)


@app.route('/browse')
@app.route('/browse/')
@app.route('/browse/<path:path>')
def autoindex(path='.'):
    return auto_index.render_autoindex(path)


@app.route('/deploy/<path:name>', methods=['POST'])
def deploy(name):
Esempio n. 12
0
# Create flask app
application = Flask(__name__, static_folder="static")

# Load the default configuration
application.config.from_object("config.DefaultConfig")

# Define the database object which is imported
# by modules and controllers
db = SQLAlchemy(application)

# Authetication scheme
auth = HTTPTokenAuth(scheme="Token")

# Listing reports directory
autoindex = AutoIndex(application,
                      browse_root=Files.REPORTS_FOLDER,
                      add_url_rules=False)


@auth.verify_token
def verify_token(token):
    """
    Verify token for authentication
    :param token: Token used by client
    :return: Boolean
    """

    if token in AppTokens.tokens:
        g.current_user = AppTokens.tokens[token]
        return True
    return False
Esempio n. 13
0
from flask import *
from flask_autoindex import AutoIndex
from werkzeug.utils import secure_filename
import os, json
with open('backend/path.json', 'r') as f:
    k = json.loads(f.read())


UPLOAD_FOLDER = k['path']
# pls change this, thanks!
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}


app = Flask(__name__)
AutoIndex(app, browse_root=UPLOAD_FOLDER)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.secret_key = 'super secret key'
app.config['SESSION_TYPE'] = 'filesystem'
def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
    x = request.args.get('path')
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
                    help="Sets the path for the Private Key",
                    default="privkey.key")

args = parser.parse_args()

UPLOAD_FOLDER = args.folder

app = Flask(__name__, static_url_path=UPLOAD_FOLDER)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.secret_key = 'super secret key'
app.config['SESSION_TYPE'] = 'filesystem'
if args.ssl:
    context = ssl.SSLContext()
    context.load_cert_chain(args.fullchain, args.privkey)

AutoIndex(app, browse_root=app.config['UPLOAD_FOLDER'])
logging.basicConfig(filename='filebrowser.log', level=logging.DEBUG)
log = logging.getLogger('pydrop')


@app.route("/", defaults={'path': ''}, methods=['GET', 'POST'])
@app.route('/<path:path>', methods=['GET', 'POST'])
def index(path):
    if request.method == 'POST':
        if request.files['file'].filename != '':
            file = request.files['file']
            save_path = os.path.join(
                os.path.join(app.config['UPLOAD_FOLDER'], path),
                secure_filename(file.filename))

            current_chunk = int(request.form['dzchunkindex'])
Esempio n. 15
0
from flask import *
from . import login_manager
from .models import db, User
from flask_autoindex import AutoIndex

import json

# Blueprint configuration.
main_bp = Blueprint('main_bp',
                    __name__,
                    template_folder='templates',
                    static_folder='static')

# assets config - locally uploaded.
assets_files_index = AutoIndex(
    main_bp, 'flask_internals/', add_url_rules=False)


@main_bp.route('/<path:path>')
def autoindex(path='.'):
    """
    Serving /css, images/, and /js paths 
    """
    return assets_files_index.render_autoindex('static/assets/' + path)


@main_bp.route('/')
@main_bp.route('/index.html')
def load_index():
    return render_template('index.html')
Esempio n. 16
0
 def _directory_index():
     packages = flask.Blueprint("packages", __name__)
     AutoIndex(packages,
               browse_root=self.app_repo_config.packages_directory)
     self.register_blueprint(packages, url_prefix="/packages")
Esempio n. 17
0
# ----------------------------------------------------------------#
# file serving related
# defining the root folder to allow looking
# just into it
root1 = get_config("base_path")

#------------------------------------------------------------------#
# FLASK related

#-------------------------------------------------#
# creating app
app = Flask(__name__)
# allowing different origins to communicate with it
cors = CORS(app, resources={r"/*": {"origins": "*"}})
AutoIndex(app, browse_root=root1)


#-------------------------------------------------#
# route to VIEW docs and folders in the shared folder
@app.route("/docs_view/", methods=["GET"])
@app.route('/docs_view/<path:path>', methods=["GET"])
def get_dir(**kwargs):
    # using **kwargs allows having any argument with any name
    # also allows having no arguments (needed to access most
    # exterior folder)
    # creating a list of the args given (only 1 or 0 in this case)
    # to use them later on as path

    relative_path = list(kwargs.items())