Skip to content

Commit 32ec4bd

Browse files
Add files via upload
0 parents  commit 32ec4bd

6 files changed

Lines changed: 674 additions & 0 deletions

File tree

for exe server.py

Lines changed: 390 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,390 @@
1+
from pathlib import Path
2+
from flask import Flask, render_template, request, render_template_string
3+
import os
4+
app = Flask(__name__)
5+
6+
7+
@app.route('/')
8+
def Home():
9+
FILENAME = os.listdir()
10+
return render_template_string('''
11+
<!DOCTYPE html>
12+
<html lang="en">
13+
<head>
14+
<meta charset="UTF-8" />
15+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
16+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
17+
<title>{{FILENAME|length}} Results</title>
18+
<script src="https://kit.fontawesome.com/61ddec8850.js" crossorigin="anonymous"></script>
19+
<style>
20+
body {
21+
background: #0f0c29; /* fallback for old browsers */
22+
background: -webkit-linear-gradient(to right, #24243e, #302b63, #0f0c29); /* Chrome 10-25, Safari 5.1-6 */
23+
background: linear-gradient(to right, #24243e, #302b63, #0f0c29); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
24+
25+
color: white;
26+
font-family: monospace;
27+
font-size: 35px;
28+
}
29+
/* i {
30+
color: coral;
31+
} */
32+
a {
33+
text-decoration: none;
34+
}
35+
/* Works on Firefox */
36+
* {
37+
scrollbar-width: thin;
38+
scrollbar-color: grey black;
39+
}
40+
41+
/* Works on Chrome, Edge, and Safari */
42+
*::-webkit-scrollbar {
43+
width: 7px;
44+
}
45+
46+
*::-webkit-scrollbar-track {
47+
background: black;
48+
}
49+
50+
*::-webkit-scrollbar-thumb {
51+
background-color: grey;
52+
border-radius: 20px;
53+
border: 1px solid black;
54+
}
55+
</style>
56+
</head>
57+
<body>
58+
{% for file in FILENAME %}
59+
{% if os.path.isdir(file) %}
60+
<a href="/view?file={{file}}">
61+
<span style="color: coral;"><i class="fas fa-folder-plus fa-small"></i></span>
62+
</i>
63+
<span style="color: aquamarine;">{{file}}</span></a>
64+
<br />
65+
{% else %}
66+
<a href="/view?file={{file}}">
67+
<span style="color:bisque;"><i class="fas fa-file-alt fa-0.5x"></i></span>
68+
<span style="color: greenyellow;">{{file}}</span></a></a>
69+
<br />
70+
{% endif %}
71+
{% endfor %}
72+
</body>
73+
</html>
74+
75+
''', FILENAME=FILENAME, request=request, os=os)
76+
77+
78+
@app.route('/view')
79+
def view():
80+
filename = request.args.get('file')
81+
if os.path.isfile(filename):
82+
try:
83+
with open(filename) as f:
84+
in_text = f.read()
85+
No_of_lines = len(in_text.split("\n"))
86+
return render_template_string('''
87+
<!DOCTYPE html>
88+
<html lang="en">
89+
<head>
90+
<meta charset="UTF-8" />
91+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
92+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
93+
<title>{{file}}</title>
94+
<script
95+
src="https://kit.fontawesome.com/61ddec8850.js"
96+
crossorigin="anonymous"
97+
></script>
98+
<script
99+
src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.1.0/highlight.min.js"
100+
integrity="sha512-z+/WWfyD5tccCukM4VvONpEtLmbAm5LDu7eKiyMQJ9m7OfPEDL7gENyDRL3Yfe8XAuGsS2fS4xSMnl6d30kqGQ=="
101+
crossorigin="anonymous"
102+
referrerpolicy="no-referrer"
103+
></script>
104+
<link
105+
rel="stylesheet"
106+
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/github-dark.min.css"
107+
integrity="sha512-rO+olRTkcf304DQBxSWxln8JXCzTHlKnIdnMUwYvQa9/Jd4cQaNkItIUj6Z4nvW1dqK0SKXLbn9h4KwZTNtAyw=="
108+
crossorigin="anonymous"
109+
referrerpolicy="no-referrer"
110+
/>
111+
<script>
112+
hljs.highlightAll();
113+
</script>
114+
<style>
115+
body {
116+
background-color: #0d1117;
117+
color: white;
118+
font-family: monospace;
119+
margin: 0;
120+
}
121+
.wrapper {
122+
display: flex;
123+
padding: 1rem 0.5rem;
124+
font-size: 1rem;
125+
}
126+
#code-display {
127+
padding-top: 0;
128+
padding-bottom: 0;
129+
}
130+
131+
.line-numbers {
132+
color: #7d7d7d;
133+
font-family: monospace;
134+
text-align: end;
135+
}
136+
[data-text]::after {
137+
content: attr(data-text);
138+
}
139+
.line-numbers {
140+
font-family: monospace;
141+
}
142+
pre {
143+
margin: 0;
144+
}
145+
a {
146+
font-size: 45px;
147+
color: greenyellow;
148+
text-decoration: none;
149+
}
150+
.code {
151+
display: flex;
152+
padding: 1rem 0.5rem;
153+
font-size: 1rem;
154+
}
155+
/* Works on Firefox */
156+
* {
157+
scrollbar-width: thin;
158+
scrollbar-color: grey black;
159+
}
160+
161+
/* Works on Chrome, Edge, and Safari */
162+
*::-webkit-scrollbar {
163+
width: 7px;
164+
}
165+
166+
*::-webkit-scrollbar-track {
167+
background: black;
168+
}
169+
170+
*::-webkit-scrollbar-thumb {
171+
background-color: grey;
172+
border-radius: 20px;
173+
border: 1px solid black;
174+
}
175+
</style>
176+
</head>
177+
<body>
178+
{% if not in_text %}
179+
<center>
180+
<h1>Such Files Can't Be Previwed , You can Download instead.</h1>
181+
<a
182+
href="./{{request.args.get('file')}}"
183+
download="{{request.args.get('file')}}"
184+
>
185+
<i class="fas fa-file-download"></i>
186+
{{request.args.get('file')}}</a
187+
>
188+
</center>
189+
{% else %}
190+
<div class="wrapper">
191+
<div class="line-numbers">
192+
{% for i in range(No_of_lines) %}
193+
<div><span data-text="{{i}}"></span></div>
194+
{% endfor%}
195+
</div>
196+
<pre><code id="code-display">{{in_text}}</code></pre>
197+
</div>
198+
{% endif %}
199+
</body>
200+
</html>
201+
202+
''', in_text=in_text, os=os, No_of_lines=No_of_lines)
203+
except:
204+
return render_template_string('''
205+
<!DOCTYPE html>
206+
<html lang="en">
207+
<head>
208+
<meta charset="UTF-8" />
209+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
210+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
211+
<title>{{file}}</title>
212+
<script
213+
src="https://kit.fontawesome.com/61ddec8850.js"
214+
crossorigin="anonymous"
215+
></script>
216+
<script
217+
src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.1.0/highlight.min.js"
218+
integrity="sha512-z+/WWfyD5tccCukM4VvONpEtLmbAm5LDu7eKiyMQJ9m7OfPEDL7gENyDRL3Yfe8XAuGsS2fS4xSMnl6d30kqGQ=="
219+
crossorigin="anonymous"
220+
referrerpolicy="no-referrer"
221+
></script>
222+
<link
223+
rel="stylesheet"
224+
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/github-dark.min.css"
225+
integrity="sha512-rO+olRTkcf304DQBxSWxln8JXCzTHlKnIdnMUwYvQa9/Jd4cQaNkItIUj6Z4nvW1dqK0SKXLbn9h4KwZTNtAyw=="
226+
crossorigin="anonymous"
227+
referrerpolicy="no-referrer"
228+
/>
229+
<script>
230+
hljs.highlightAll();
231+
</script>
232+
<style>
233+
body {
234+
background-color: #0d1117;
235+
color: white;
236+
font-family: monospace;
237+
margin: 0;
238+
}
239+
.wrapper {
240+
display: flex;
241+
padding: 1rem 0.5rem;
242+
font-size: 1rem;
243+
}
244+
#code-display {
245+
padding-top: 0;
246+
padding-bottom: 0;
247+
}
248+
249+
.line-numbers {
250+
color: #7d7d7d;
251+
font-family: monospace;
252+
text-align: end;
253+
}
254+
[data-text]::after {
255+
content: attr(data-text);
256+
}
257+
.line-numbers {
258+
font-family: monospace;
259+
}
260+
pre {
261+
margin: 0;
262+
}
263+
a {
264+
font-size: 45px;
265+
color: greenyellow;
266+
text-decoration: none;
267+
}
268+
.code {
269+
display: flex;
270+
padding: 1rem 0.5rem;
271+
font-size: 1rem;
272+
}
273+
/* Works on Firefox */
274+
* {
275+
scrollbar-width: thin;
276+
scrollbar-color: grey black;
277+
}
278+
279+
/* Works on Chrome, Edge, and Safari */
280+
*::-webkit-scrollbar {
281+
width: 7px;
282+
}
283+
284+
*::-webkit-scrollbar-track {
285+
background: black;
286+
}
287+
288+
*::-webkit-scrollbar-thumb {
289+
background-color: grey;
290+
border-radius: 20px;
291+
border: 1px solid black;
292+
}
293+
</style>
294+
</head>
295+
<body>
296+
{% if not in_text %}
297+
<center>
298+
<h1>Such Files Can't Be Previwed , You can Download instead.</h1>
299+
<a
300+
href="./{{request.args.get('file')}}"
301+
download="{{request.args.get('file')}}"
302+
>
303+
<i class="fas fa-file-download"></i>
304+
{{request.args.get('file')}}</a
305+
>
306+
</center>
307+
{% else %}
308+
<div class="wrapper">
309+
<div class="line-numbers">
310+
{% for i in range(No_of_lines) %}
311+
<div><span data-text="{{i}}"></span></div>
312+
{% endfor%}
313+
</div>
314+
<pre><code id="code-display">{{in_text}}</code></pre>
315+
</div>
316+
{% endif %}
317+
</body>
318+
</html>
319+
320+
''', in_text=None, request=request, os=os)
321+
elif os.path.isdir(filename):
322+
FILENAME = os.listdir(filename)
323+
return render_template_string('''
324+
<!DOCTYPE html>
325+
<html lang="en">
326+
<head>
327+
<meta charset="UTF-8" />
328+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
329+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
330+
<title>{{FILENAME|length}} Results</title>
331+
<script src="https://kit.fontawesome.com/61ddec8850.js" crossorigin="anonymous"></script>
332+
<style>
333+
body {
334+
background: #0f0c29; /* fallback for old browsers */
335+
background: -webkit-linear-gradient(to right, #24243e, #302b63, #0f0c29); /* Chrome 10-25, Safari 5.1-6 */
336+
background: linear-gradient(to right, #24243e, #302b63, #0f0c29); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
337+
338+
color: white;
339+
font-family: monospace;
340+
font-size: 35px;
341+
}
342+
a {
343+
color: white;
344+
text-decoration: none;
345+
}
346+
/* Works on Firefox */
347+
* {
348+
scrollbar-width: thin;
349+
scrollbar-color: grey black;
350+
}
351+
352+
/* Works on Chrome, Edge, and Safari */
353+
*::-webkit-scrollbar {
354+
width: 7px;
355+
}
356+
357+
*::-webkit-scrollbar-track {
358+
background: black;
359+
}
360+
361+
*::-webkit-scrollbar-thumb {
362+
background-color: grey;
363+
border-radius: 20px;
364+
border: 1px solid black;
365+
}
366+
</style>
367+
</head>
368+
<body>
369+
{% for file in FILENAME %}
370+
{% if "." in file %}
371+
<a href="/view?file={{request.args.get('file')}}/{{file}}"><span style="color:bisque;"><i class="fas fa-file-alt fa-0.5x"></i></span>
372+
<span style="color: greenyellow;">{{file}}</span>
373+
</a>
374+
<br />
375+
{% else %}
376+
<a href="/view?file={{request.args.get('file')}}/{{file}}"><span style="color: coral;"><i class="fas fa-folder-plus fa-small"></i></span>
377+
</i> <span style="color: aquamarine;">{{file}}</span></a>
378+
<br />
379+
{% endif %}
380+
{% endfor %}
381+
{% if not FILENAME %}
382+
<h1>{{FILENAME|length}} Empty Directory</h1>
383+
{% endif %}
384+
</body>
385+
</html>
386+
387+
''', FILENAME=FILENAME, request=request, os=os)
388+
389+
390+
app.run(port=5000)

0 commit comments

Comments
 (0)