-
Notifications
You must be signed in to change notification settings - Fork 0
/
m_server.py
19 lines (19 loc) · 7.78 KB
/
m_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
H='file'
F=True
from pathlib import Path
from flask import Flask,render_template,request as C,render_template_string as D,send_file as E
import os as A
B=Flask(__name__)
@B.route('/')
def G():B=A.listdir();return D('\n <!DOCTYPE html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>{{FILENAME|length}} Results</title>\n <script src="https://kit.fontawesome.com/61ddec8850.js" crossorigin="anonymous"></script>\n <style>\n body {\n background: #0f0c29; /* fallback for old browsers */\nbackground: -webkit-linear-gradient(to right, #24243e, #302b63, #0f0c29); /* Chrome 10-25, Safari 5.1-6 */\nbackground: linear-gradient(to right, #24243e, #302b63, #0f0c29); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */\n\n color: white;\n font-family: monospace;\n font-size: 35px;\n }\n /* i {\n color: coral;\n } */\n a {\n text-decoration: none;\n }\n /* Works on Firefox */\n * {\n scrollbar-width: thin;\n scrollbar-color: grey black;\n }\n\n /* Works on Chrome, Edge, and Safari */\n *::-webkit-scrollbar {\n width: 7px;\n }\n\n *::-webkit-scrollbar-track {\n background: black;\n }\n\n *::-webkit-scrollbar-thumb {\n background-color: grey;\n border-radius: 20px;\n border: 1px solid black;\n }\n </style>\n </head>\n <body>\n {% for file in FILENAME %}\n {% if os.path.isdir(file) %}\n <a href="/view?file={{file}}">\n <span style="color: coral;"><i class="fas fa-folder-plus fa-small"></i></span>\n </i>\n <span style="color: aquamarine;">{{file}}</span></a>\n <br />\n {% else %}\n <a href="/view?file={{file}}">\n <span style="color:bisque;"><i class="fas fa-file-alt fa-0.5x"></i></span>\n <span style="color: greenyellow;">{{file}}</span></a></a>\n <a href="/download?file={{file}}">\n <i style="color: white;" class="fas fa-download fa-small"></i>\n </a>\n <br />\n {% endif %}\n {% endfor %}\n </body>\n</html>\n \n ',FILENAME=B,request=C,os=A)
@B.route('/download')
def I():A=C.args.get(H);return E(f"./{A}",as_attachment=F)
@B.route('/view')
def J():
B=C.args.get(H)
if A.path.isfile(B):
try:
with open(B)as I:G=I.read();J=len(G.split('\n'));return D('\n <!DOCTYPE html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>{{file}}</title>\n <script\n src="https://kit.fontawesome.com/61ddec8850.js"\n crossorigin="anonymous"\n ></script>\n <script\n src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.1.0/highlight.min.js"\n integrity="sha512-z+/WWfyD5tccCukM4VvONpEtLmbAm5LDu7eKiyMQJ9m7OfPEDL7gENyDRL3Yfe8XAuGsS2fS4xSMnl6d30kqGQ=="\n crossorigin="anonymous"\n referrerpolicy="no-referrer"\n ></script>\n <link\n rel="stylesheet"\n href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/github-dark.min.css"\n integrity="sha512-rO+olRTkcf304DQBxSWxln8JXCzTHlKnIdnMUwYvQa9/Jd4cQaNkItIUj6Z4nvW1dqK0SKXLbn9h4KwZTNtAyw=="\n crossorigin="anonymous"\n referrerpolicy="no-referrer"\n />\n <script>\n hljs.highlightAll();\n </script>\n <style>\n body {\n background-color: #0d1117;\n color: white;\n font-family: monospace;\n margin: 0;\n }\n .wrapper {\n display: flex;\n padding: 1rem 0.5rem;\n font-size: 1rem;\n }\n #code-display {\n padding-top: 0;\n padding-bottom: 0;\n }\n\n .line-numbers {\n color: #7d7d7d;\n font-family: monospace;\n text-align: end;\n }\n [data-text]::after {\n content: attr(data-text);\n }\n .line-numbers {\n font-family: monospace;\n }\n pre {\n margin: 0;\n }\n a {\n font-size: 45px;\n color: greenyellow;\n text-decoration: none;\n }\n .code {\n display: flex;\n padding: 1rem 0.5rem;\n font-size: 1rem;\n }\n /* Works on Firefox */\n * {\n scrollbar-width: thin;\n scrollbar-color: grey black;\n }\n\n /* Works on Chrome, Edge, and Safari */\n *::-webkit-scrollbar {\n width: 7px;\n }\n\n *::-webkit-scrollbar-track {\n background: black;\n }\n\n *::-webkit-scrollbar-thumb {\n background-color: grey;\n border-radius: 20px;\n border: 1px solid black;\n }\n </style>\n </head>\n <body>\n <div class="wrapper">\n <div class="line-numbers">\n {% for i in range(No_of_lines) %}\n <div><span data-text="{{i}}"></span></div>\n {% endfor%}\n </div>\n <pre><code id="code-display">{{in_text}}</code></pre>\n </div>\n </body>\n</html>\n \n ',in_text=G,os=A,No_of_lines=J)
except:return E(f"./{B}",as_attachment=F)
elif A.path.isdir(B):K=A.listdir(B);return D('\n <!DOCTYPE html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>{{FILENAME|length}} Results</title>\n <script src="https://kit.fontawesome.com/61ddec8850.js" crossorigin="anonymous"></script>\n <style>\n body {\n background: #0f0c29; /* fallback for old browsers */\n background: -webkit-linear-gradient(to right, #24243e, #302b63, #0f0c29); /* Chrome 10-25, Safari 5.1-6 */\n background: linear-gradient(to right, #24243e, #302b63, #0f0c29); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */\n\n color: white;\n font-family: monospace;\n font-size: 35px;\n }\n a {\n color: white;\n text-decoration: none;\n }\n /* Works on Firefox */\n * {\n scrollbar-width: thin;\n scrollbar-color: grey black;\n }\n\n /* Works on Chrome, Edge, and Safari */\n *::-webkit-scrollbar {\n width: 7px;\n }\n\n *::-webkit-scrollbar-track {\n background: black;\n }\n\n *::-webkit-scrollbar-thumb {\n background-color: grey;\n border-radius: 20px;\n border: 1px solid black;\n }\n </style>\n </head>\n <body>\n {% for file in FILENAME %} \n {% if "." in file %}\n <a href="/view?file={{request.args.get(\'file\')}}/{{file}}"><span style="color:bisque;"><i class="fas fa-file-alt fa-0.5x"></i></span> \n <span style="color: greenyellow;">{{file}}</span>\n </a>\n <a href="/download?file={{request.args.get(\'file\')}}/{{file}}">\n <i style="color:whitesmoke;" class="fas fa-download fa-small"></i>\n </a>\n <br />\n {% else %}\n <a href="/view?file={{request.args.get(\'file\')}}/{{file}}"><span style="color: coral;"><i class="fas fa-folder-plus fa-small"></i></span>\n </i> <span style="color: aquamarine;">{{file}}</span></a>\n <br />\n {% endif %}\n {% endfor %}\n {% if not FILENAME %}\n <h1>{{FILENAME|length}} Empty Directory</h1>\n {% endif %}\n </body>\n</html>\n\n ',FILENAME=K,request=C,os=A)
B.run(port=5000,host='0.0.0.0',debug=F)