Example #1
0
def show(req):
    return wsgi_util.render_template_2(
        "22.html",
        PLT_M=platform.processor(),
        CPU_F=str(psutil.cpu_freq()),
        CPU_P=str(psutil.cpu_percent(percpu=True)),
        MEM_T='{:,}'.format(psutil.virtual_memory().total),
        MEM_U='{:,}'.format(psutil.virtual_memory().used))
Example #2
0
def show(req):

    room = ""
    user = ""
    content = ""
    passwd = ""
    fbtoken = ""
    orders = ""
    session = sessionmaker(bind=wsgi_util.dbengine)()
    Base.metadata.create_all(wsgi_util.dbengine)
    if req.method == 'POST':
        if "fbtoken" in req.form:
            fbtoken = secure_filename(
                req.form["fbtoken"])  #Firebase_Token_keep
        if 'room' in req.form:
            room = req.form['room'].translate(
                str.maketrans("", "", "\"\'\\/<>%`?;"))  #Not_secure_filename!
        if 'user' in req.form:
            user = req.form['user'].translate(
                str.maketrans("", "", "\"\'\\/<>%`?;"))  #Not_secure_filename!
        if 'content' in req.form:
            content = req.form['content'].translate(
                str.maketrans("\"\'\\/<>%`?;",
                              '””¥_〈〉%”?;'))  #Not_secure_filename!
        if 'pass' in req.form:
            passwd = secure_filename(req.form['pass'])
        if "remark" in req.form and secure_filename(
                req.form["remark"]) == "True":
            session.add(
                table(room=room,
                      user=user,
                      content=content,
                      trip=hashlib.sha256(passwd.encode('utf-8')).hexdigest(),
                      date=datetime.now(
                          pytz.UTC).strftime("%Y/%m/%d %H:%M:%S %f (UTC)")))
        if "clear" in req.form and secure_filename(
                req.form["clear"]) == "True":
            session.query(table).filter(
                table.trip == hashlib.sha256(
                    passwd.encode('utf-8')).hexdigest(),
                table.room == room).delete()
    #show chat thread
    for order in session.query(table).filter(table.room == room):
        orders += "<tr><td>" + order.user + "</td>"
        orders += "<td>" + order.content + "</td>"
        orders+="<td style=\"font-size: 12px;\">"+order.trip[:16]+"<br>"+order.trip[16:32]+\
        "<br>"+order.trip[32:48]+"<br>"+order.trip[48:64]+"</td>"
        orders += "<td style=\"font-size: 12px;\">" + order.date + "</td></tr>"

    session.commit()
    session.close()

    return wsgi_util.render_template_2("tptef.html",
                                       ORDERS=orders,
                                       ROOM=room,
                                       USER=user,
                                       PASS=passwd)
Example #3
0
def show(req):
    if not os.path.exists(DataDir):os.mkdir(DataDir)
    passwd=""
    #GET
    if req.args.get('dl')!=None:
        target=req.args.get('dl').translate(str.maketrans("\"\'\\/<>%`?;",'__________'))#Not_secure_filename!
        return send_file(os.path.join(DataDir,target),as_attachment = True)
    #POST
    if req.method == 'POST':
        if 'pass' in req.form:
            passwd=secure_filename(req.form['pass'])
        if 'upload_file' in req.form and 'upload' in req.files:
            target=req.files['upload'].filename.translate(str.maketrans("\"\'\\/<>%`?;",'__________'))#Not_secure_filename!
            if sql_reg(target,passwd,mode=1)!=0:
                req.files['upload'].save(os.path.join(DataDir,target))
        if 'delete' in req.form:
            target=req.form['delete'].translate(str.maketrans("\"\'\\/<>%`?;",'__________'))#Not_secure_filename!
            if sql_reg(target,passwd,mode=0)!=0:
                os.remove(os.path.join(DataDir,target))
            
    return wsgi_util.render_template_2("fud.html",FILES=htmlwalk(),PASS=passwd)
Example #4
0
def show(req):
    global status_GCS, storage_client, config_dict
    global iii
    iii += 1
    status_table = html_create_recode("access_counter", str(iii))
    clearance = 0  #0:non-login,1:general,2:admin
    if req.method == 'POST':
        #Check Auth
        if "fbtoken" in req.form:
            fbtoken = secure_filename(
                req.form["fbtoken"])  #Firebase_Token_keep
        try:  #User authentication
            if config_dict[
                    "FB_admin_uid"] == firebase_admin.auth.verify_id_token(
                        fbtoken)["uid"]:
                config_json_update(req.form)
                status_table += html_create_recode("Authority", "<b>Admin</b>")
                clearance = 2
            else:
                status_table += html_create_recode("Authority", "general")
                clearance = 1
        except:
            status_table += html_create_recode("Authority", "Non-login")
            clearance = 0
        #/Check Auth
        #Operation
        if "gcs_upload" in req.form and secure_filename(
                req.form["gcs_upload"]) == "True":
            if clearance == 2:
                try:
                    storage_client.get_bucket(parse.urlsplit(config_dict["form_gcs_uri"])[1])\
                    .blob(parse.urlsplit(config_dict["form_gcs_uri"])[2].strip("/")).upload_from_filename(config_dict["dir_db"])
                    status_GCS = "APP→GCS" + datetime.now(
                        pytz.UTC).strftime(" %Y/%m/%d %H:%M:%S (UTC)")
                except:
                    status_GCS = "APP→×GCS" + datetime.now(
                        pytz.UTC).strftime(" %Y/%m/%d %H:%M:%S (UTC)")
            else:
                status_table += html_create_recode(
                    "APP→×GCS",
                    "The operation Don't allowed for your clearance.",
                    color="red")
        if "gcs_download" in req.form and secure_filename(
                req.form["gcs_download"]) == "True":
            if clearance == 2:
                try:
                    storage_client.get_bucket(parse.urlsplit(config_dict["form_gcs_uri"])[1])\
                    .blob(parse.urlsplit(config_dict["form_gcs_uri"])[2].strip("/")).download_to_filename(config_dict["dir_db"])
                    status_GCS = "GCS→APP" + datetime.now(
                        pytz.UTC).strftime(" %Y/%m/%d %H:%M:%S (UTC)")
                except:
                    status_GCS = "GCS→×APP" + datetime.now(
                        pytz.UTC).strftime(" %Y/%m/%d %H:%M:%S (UTC)")
            else:
                status_table += html_create_recode(
                    "GCS→×APP",
                    "The operation Don't allowed for your clearance.",
                    color="red")
        if "gcs_client_reload" in req.form and secure_filename(
                req.form["gcs_client_reload"]) == "True":
            if clearance == 1 or clearance == 2:
                try:  #get_key
                    storage_client = storage.Client.from_service_account_json(
                        "FirebaseAdmin_Key.json")
                    status_GCS = "reload:gcs_client" + datetime.now(
                        pytz.UTC).strftime(" %Y/%m/%d %H:%M:%S (UTC)")
                except:
                    status_GCS = "×gcs_client_reload" + datetime.now(
                        pytz.UTC).strftime(" %Y/%m/%d %H:%M:%S (UTC)")
            else:
                status_table += html_create_recode(
                    "×gcs_client_reload",
                    "The operation Don't allowed for your clearance.",
                    color="red")

        if "fb_fs" in req.form and secure_filename(
                req.form["fb_fs"]) == "True":
            db = firestore.client()
            resp = db.collection('users').document('alovelace').get().to_dict()
            status_table += html_create_recode("Firestore", json.dumps(resp))
        if "Resource_Reload" in req.form and secure_filename(
                req.form["Resource_Reload"]) == "True":
            wsgi_util.Resource_Reload()
    return wsgi_util.render_template_2(
        "config.html",
        STATUS_GCS=status_GCS,
        DIR_DB=config_dict["dir_db"],
        form_gcs_uri=config_dict["form_gcs_uri"],
        STATUS_TABLE=status_table)
Example #5
0
def show(req):
    output=""
    endpoint="https://us-central1-crack-atlas-251509.cloudfunctions.net/janome_banilla"
    random_art="https://api.syosetu.com/novelapi/api?of=t-w-s&lin=10&st=_RANDINT2000_"
    change_prob=0.2
    #FaaS wakeup
    threading.Thread(name='t1', target=FaaS_wakeup, kwargs={'url': endpoint}).start()
    if req.method == 'POST':
        if 'endpoint' in req.form:
            endpoint=req.form['endpoint'].translate(str.maketrans("","","\"\'<>`;"))#Not_secure_filename!
        if 'random_art' in req.form:
            random_art=req.form['random_art'].translate(str.maketrans("","","\"\'<>`;"))#Not_secure_filename!
        if 'change_prob' in req.form:
            change_prob=float(secure_filename(req.form['change_prob']))
        if 'submit' in req.form and secure_filename(req.form['submit'])=="True":
            if 'text' in req.form:
                target=req.form['text'].translate(str.maketrans("","","\"\'\\/<>%`?;"))#Not_secure_filename!
                output+=FaaS_janome(endpoint,fields={"surface":target})+"<br>"
                output+=FaaS_janome(endpoint,fields={"speech":target})+"<br>"
                output+=FaaS_janome(endpoint,fields={"phonetic":target})+"<br>"
                output+=FaaS_janome(endpoint,fields={"speech2":target})

        if 'noun' in req.form and secure_filename(req.form['noun'])=="True":
            tmp=""#_RANDINTxxx_ → randint(1,xxx) on url
            for i,txt in enumerate(random_art.split("_RANDINT")):
                if i==0:tmp=txt;continue
                tmp+=str(random.randint(1,int(txt.split("_")[0])))
                if 1<len(txt.split("_")):tmp+=''.join(txt.split("_")[1:])
            rand_text=web_rand(tmp)
            rand_text_surface=FaaS_janome(endpoint,fields={"surface":rand_text})
            rand_text_speech=FaaS_janome(endpoint,fields={"speech":rand_text})
            rand_noun=set(["佐藤"])
            rand_verb=set(["送る"])
            for i in range(len(rand_text_speech.split(","))):
                if rand_text_speech.split(",")[i]=="名詞":rand_noun.add(rand_text_surface.split(",")[i])
                if rand_text_speech.split(",")[i]=="動詞":rand_verb.add(rand_text_surface.split(",")[i])
            for _ in range(15):output+=random.choice(list(rand_noun))+" "
            output+="<br>"
            for _ in range(15):output+=random.choice(list(rand_verb))+" "
            output+="<br>"
                    
        if 'change' in req.form and secure_filename(req.form['change'])=="True":
            if 'text' in req.form:
                target=req.form['text'].translate(str.maketrans("","","\"\'\\/<>%`?;"))#Not_secure_filename!
                text_surface=FaaS_janome(endpoint,fields={"surface":target})
                text_speech=FaaS_janome(endpoint,fields={"speech":target})

                tmp=""#_RANDINTxxx_ → randint(1,xxx) on url
                for i,txt in enumerate(random_art.split("_RANDINT")):
                    if i==0:tmp=txt;continue
                    tmp+=str(random.randint(1,int(txt.split("_")[0])))
                    if 1<len(txt.split("_")):tmp+=''.join(txt.split("_")[1:])
                
                rand_text=web_rand(tmp)
                rand_text_surface=FaaS_janome(endpoint,fields={"surface":rand_text})
                rand_text_speech=FaaS_janome(endpoint,fields={"speech":rand_text})
                rand_noun=set(["佐藤"])
                rand_verb=set(["送る"])
                for i in range(len(rand_text_speech.split(","))):
                    if rand_text_speech.split(",")[i]=="名詞":rand_noun.add(rand_text_surface.split(",")[i])
                    if rand_text_speech.split(",")[i]=="動詞":rand_verb.add(rand_text_surface.split(",")[i])

                for i in range(len(text_surface.split(","))):
                    if text_speech.split(",")[i]=="名詞" and change_prob>random.random():
                        output+=random.choice(list(rand_noun));continue
                    output+=text_surface.split(",")[i]
        
    return wsgi_util.render_template_2("jm.html",OUTPUT=output,ENDPOINT=endpoint,RANDOM_ART=random_art,CHANGE_PROB=str(change_prob))
Example #6
0
def show(req):
    #declare
    urls="https://api.search.nicovideo.jp/api/v2/video/contents/search"
    query=""
    passwd=""
    fields=""
    fields_c=""#fields_command
    fbtoken=""
    if req.method == 'POST':
        if "fbtoken" in req.form:fbtoken=secure_filename(req.form["fbtoken"])#Firebase_Token_keep
        if 'url' in req.form:
            urls=req.form['url'].translate(str.maketrans("\"\'<>`?;",'_______'))#Not_secure_filename!
        if 'query' in req.form:
            query=req.form['query'].translate(str.maketrans("\"\'<>`?;",'_______'))#Not_secure_filename!
        if 'pass' in req.form:
            passwd=secure_filename(req.form['pass'])
        if 'fields_c' in req.form:
            fields_c=secure_filename(req.form["fields_c"])
        #read_query_forms
        f1=[req.form[j].translate(str.maketrans("\"\'\\/<>%`?;",'__________')) for j in req.form if "field1_" in j]#Not_secure_filename!
        f2=[req.form[j].translate(str.maketrans("\"\'\\/<>%`?;",'__________')) for j in req.form if "field2_" in j]#Not_secure_filename!
        f3=[secure_filename(req.form[j]) for j in req.form if "field3_" in j]
        if "fields_ad" in req.form:
            if secure_filename(req.form['fields_ad'])=="add":
                f1.append("");f2.append("");f3.append("False")
            if secure_filename(req.form['fields_ad'])=="del" and 1<len(f1) and f3[-1]!="True":
                f1.pop(-1);f2.pop(-1);f3.pop(-1)
        for i in range(len(f1)):
            fields+=fields_to_html_text_forms(i,f1[i],f2[i],f3[i])
            query+="&"+f1[i]+"="+f2[i]
        if "launch" in req.form and secure_filename(req.form["launch"])=="True":
            try:
                for x in fields_c.split():
                    if len(x.split("_"))==4:#a_b_c_d → [a for a in range(b,c,d)]
                        if (int(x.split("_")[2])-int(x.split("_")[1]))/int(x.split("_")[3])>5000:
                            print("\nerror:Too many order");continue
                        for Y in [y for y in range(int(x.split("_")[1]),int(x.split("_")[2]),int(x.split("_")[3]))]:
                            Order_Into_SQL(passwd,urls+"?"+query.replace(x.split("_")[0],str(Y)))
                #If there is no command.
                if len(fields_c.split())==0:
                    Order_Into_SQL(passwd,urls+"?"+query)
            except:print("Order_Into_SQL:error")        
        #Reload query for clearing query's params which ware added by html_text_forms
        if 'query' in req.form:
            query=req.form['query'].translate(str.maketrans("\"\'<>`?;",'_______'))#Not_secure_filename!
        if "clear" in req.form and secure_filename(req.form["clear"])=="True":
            Clear_Order_SQL(passwd)
        if "delete" in req.form and secure_filename(req.form["delete"])=="True":
            delete_files(passwd)
        if "download" in req.form and secure_filename(req.form["download"])=="True":
            return download_files(passwd)
        
        #select_API_endpoint is a command which cause to reset forms as like no POST
        if "select_API_endpoint" in req.form:
            urls=req.form["select_API_endpoint"].translate(str.maketrans("\"\'<>`?;",'_______'))#Not_secure_filename!
            fields,fields_c=fill_default_fields(urls)
    else :
        fields,fields_c=fill_default_fields(urls)
    
    orders=Display_Current_SQL(passwd)
    _,size_files=about_files(passwd)
    return wsgi_util.render_template_2("nicoapi.html",ORDERS=orders,URL=urls,QUERY=query,PASS=passwd,\
    SIZE_FILES=size_files,FIELDS=fields,FIELDS_C=fields_c)