-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
76 lines (55 loc) · 1.63 KB
/
server.py
File metadata and controls
76 lines (55 loc) · 1.63 KB
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
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3.7
# coding: utf-8
from flask import Flask, render_template, redirect, url_for, request
import subprocess
import sh
#initialize global variables
port = 5000
host = 'http://127.0.0.1:'+str(port)
# init app
app = Flask(__name__)
def get_href(prefix, addr, refstr):
return prefix + "<a href=\"" + addr + "\">" + refstr + "</a>"
@app.route('/')
def home():
# msg = sh.pwd()
msg = 'Home page'
return str(msg)
@app.route('/install')
def install_ansible():
msg = subprocess.check_output('pip install ansible', shell=True)
return msg
@app.route('/start', methods=['GET', 'POST'])
def start():
msg = None
if request.method == 'POST':
#redirect(url_for('install_ansible'))
msg = subprocess.check_output('pip install ansible', shell=True)
return render_template('install_ansible.html', msg=msg)
@app.route('/ls')
def get_list():
msg = subprocess.check_output ('ls -al', shell=True)
return msg + get_href('<br/><br/>', host+'/pwd', 'pwd')
# '''
# <br/><br/><a href="http://localhost:5000/pwd">pwd</a>
# '''
@app.route('/pwd')
def get_pwd():
return str(sh.pwd())
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != 'a' or request.form['password'] != 'a':
error = 'Try Again'
else:
return redirect(url_for('get_pass'))
return render_template('index.html', error=error)
@app.route('/pass')
def get_pass():
return 'Secret'
# start server
if __name__ == "__main__":
app.run(port=port, debug=True)
else:
print("server init fail")