-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.py
71 lines (45 loc) 路 1.47 KB
/
validation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import subprocess
from functools import wraps
from middleWare import allowCors
from flask import request, jsonify
import pathlib
def addressCorrect(func):
@wraps(func)
def decorator(*args, **kwargs):
data = request.json
if data == None or data.get('address') == None:
return allowCors(jsonify({"msg":"bad request"}), 400)
else:
address = data.get('address')
output, err = subprocess.Popen(['hostname', '-i'], stdout=subprocess.PIPE).communicate()
ip = output.decode().strip()
return func(*args, **kwargs) if ip in address else allowCors(jsonify({"msg":"bad request"}), 400)
return decorator
#print(addressCorrect('127.0.1.1:5000'))
def testOne(func):
@wraps(func)
def decorator(*args, **kwargs):
if 1 == 2:
return func(*args, **kwargs)
else:
return "fuk"
return decorator
def testtwo(func):
@wraps(func)
def decorator(*args, **kwargs):
if 1 == 1:
return func(*args, **kwargs)
else:
return "hello"
return decorator
@testtwo
def f():
return 'world'
def isValidPath(req, host_path:str, onlyDir = True):
path:str = req.get("path")
if path.find(host_path) != 0:
return False
is_technically_valid = pathlib.Path(req.get('path')).exists() and (onlyDir or pathlib.Path(req.get('path')).is_file())
if not is_technically_valid :
return False
return True