-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactivity.py
executable file
·167 lines (132 loc) · 5.46 KB
/
activity.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/python2
import config
import header
import cgi,commands,os,MySQLdb
header.header_content()
if(os.environ['REQUEST_METHOD'] == "GET"):
db = MySQLdb.connect("localhost","root", "Aj1.....", "arcus")
cursor = db.cursor()
user_id = header.cookie_value()
print """
<div class="panel panel-primary">
<div class="panel-heading">NFS Storage History</div>
<div class="panel-body"> """
print """
<table class="table table-striped table-hover">
<thead>
<tr>
<th style="text-align:center;">Number</th>
<th style="text-align:center;">Drive Size</th>
<th style="text-align:center;">Extend</th>
<th style="text-align:center;">Remove</th>
<th style="text-align:center;">Unmount/Mount</th>
<th style="text-align:center;">Snapshot</th>
<tr>
</thead>
<tbody> """
sql = "SELECT * FROM nfs WHERE user_id={0}". format(user_id)
try:
cursor.execute(sql)
results = cursor.fetchall()
except:
print "Error: unable to fecth data"
i=1
for row in results:
print("<tr>")
print('<td style="text-align:center;">' + str(i) + "</td>")
print('<td style="text-align:center;">' + str(row[2]) + "</td>")
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=extend&id={1}&type=nfs" method="POST"><input type="text" name="extendSize" placeholder="current:{0} MB"/> <button type="submit">Extend</button></form> </td>'. format(row[2], row[0]))
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=remove&id={0}&type=nfs" method="POST"> <button type="submit">Remove</button></form></td>"'. format(row[0]))
if(row[6] == 'm'):
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=unmount&id={0}&type=nfs" method="POST"> <button type="submit">Unmount</button></form></td>"'. format(row[0]))
else:
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=mount&id={0}&type=nfs" method="POST"> <button type="submit">Mount</button></form></td>"'. format(row[0]))
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=snapshot&id={0}&type=nfs" method="POST"> <button type="submit">Snap</button></form></td>"'. format(row[0]))
print("</tr>")
n = "SELECT * FROM snapshot WHERE nfs_id={0}". format(row[0])
try:
rs = cursor.execute(n)
if(rs != 0):
a = cursor.fetchall()
j=1
for b in a:
print("<tr>")
print('<td></td>')
print('<td></td>')
print('<td></td>')
print('<td></td>')
print('<td></td>')
print('<td style="text-align:center;"><a href="/recover.py?n={0}&id={3}">snap-{1} {2}</a></td>'. format(b[2], j, b[3], b[1]))
print("</tr>")
j+=1
except:
print "Error: unable to fecth data"
i+=1
print("</tbody>")
print("</table>")
print("</div></div></div>")
# iscsi server
print """
<div class="panel panel-primary">
<div class="panel-heading">iSCSI Storage History</div>
<div class="panel-body"> """
print """
<table class="table table-striped table-hover">
<thead>
<tr>
<th style="text-align:center;">Number</th>
<th style="text-align:center;">Drive Size</th>
<th style="text-align:center;">Extend</th>
<th style="text-align:center;">Login/Logout</th>
<th style="text-align:center;">Snapshot</th>
<tr>
</thead>
<tbody> """
sql = "SELECT * FROM iscsi WHERE user_id={0}". format(user_id)
try:
cursor.execute(sql)
results = cursor.fetchall()
except:
print "Error: unable to fecth data"
i=1
for row in results:
print("<tr>")
print('<td style="text-align:center;">' + str(i) + "</td>")
print('<td style="text-align:center;">' + str(row[2]) + "</td>")
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=extend&id={1}&type=iscsi" method="POST"><input type="text" name="extendSize" placeholder="current:{0} MB"/> <button type="submit">Extend</button></form> </td>'. format(row[2], row[0]))
if(row[4] == 'login'):
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=logout&id={0}&type=iscsi" method="POST"> <button type="submit">Logout</button></form></td>"'. format(row[0]))
else:
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=login&id={0}&type=iscsi" method="POST"> <button type="submit">Login</button></form></td>"'. format(row[0]))
print('<td style="text-align:center;"> <form action="/activity_execute.py?service=snapshot&id={0}&type=iscsi" method="POST"> <button type="submit">Snap</button></form></td>"'. format(row[0]))
print("</tr>")
n = "SELECT * FROM snapshot_iscsi WHERE iscsi_id={0}". format(row[0])
try:
rs = cursor.execute(n)
if(rs != 0):
a = cursor.fetchall()
j=1
for b in a:
print("<tr>")
print('<td></td>')
print('<td></td>')
print('<td></td>')
print('<td></td>')
print('<td style="text-align:center;"><a href="/recover.py?n={0}">snap-{1} {2}</a></td>'. format(b[2], j, b[3]))
print("</tr>")
j+=1
except:
print "Error: unable to fecth data"
i+=1
print("</tbody>")
print("</table>")
print("</div></div></div>")
print """
<script src="/js/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
<script src="/js/script.min.js"></script>
</body>
</html>
"""