#!/usr/bin/env python
#coding:utf-8
import os
import commands
from flask import Flask, request, redirect,render_template
import urllib
import logging
import re
logging.basicConfig(level=logging.INFO, format='%(levelname)s : %(message)s', filename='/var/log/upload.log')
UPLOAD_FOLDER = '/var/www/html/logfile/now'
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
#app.config['MAX_CONTENT_LENGTH'] = 1 * 1024 * 1024
@app.route("/", methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        #ALL_DATA = eval(request.get_data())
        ALL_DATA = request.get_data()
        ALL_DATA = urllib.unquote(ALL_DATA)
        try:
            meetingid = re.findall(r'meetingid=[0-9]+',ALL_DATA)[0].split('=')[1]
            fileName = re.findall(r'(?<=fileName=).*\d+\.(?:error|log)',ALL_DATA)[0].replace('error','error.log')
        except:
            print ALL_DATA
            return "bad"
            #print ALL_DATA
        PATH = os.path.join(app.config['UPLOAD_FOLDER'],meetingid)
        if not os.path.isdir(PATH):
            os.mkdir(PATH)
        try:
            with open(os.path.join(PATH,fileName),'a') as f:
                f.write(ALL_DATA)
        except IOError:
            os._exit(1)
    return "OK!" 
@app.route("/crossdomain.xml", methods=['GET', 'POST'])
def cross():
    return '''<?xml version="1.0"?>
<cross-domain-policy>
    <allow-access-from domain="*" />
    <allow-access-from domain="www.3mang.com" />
</cross-domain-policy>'''
@app.route("/download",methods=['GET','POST'])
def download():
    if request.method == 'POST':
        os.environ['url']=request.form['url']
        result=commands.getoutput('/usr/local/solr/1.sh $url')
        if re.match(r'.*.zip',result):
            return render_template('download.html',result=result)
        else:
            return render_template('download.html',message=result)
    return render_template('download.html')
@app.route("/todayid",methods=['GET','POST'])
def todayid():
    if request.method == 'POST':
        os.environ['classid']=request.form['classid']
        result=commands.getoutput('/usr/local/solr/2.sh $classid')
        if re.match(r'.*.zip',result):
            return render_template('todayid.html',result=result)
        else:
            return render_template('todayid.html',message=result)
    return render_template('todayid.html')
if __name__ == "__main__":
    logging.info(app.run(host='0.0.0.0', threaded=True,port=13966, debug=False))

results matching ""

    No results matching ""