-
Notifications
You must be signed in to change notification settings - Fork 1
/
sshfs.py
executable file
·186 lines (140 loc) · 5.27 KB
/
sshfs.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/python2
""" storage server IP need to be changed according to requirements in line number 94 """
import config
import header
import cgi,commands,os,MySQLdb
header.header_content()
if(os.environ['REQUEST_METHOD'] == "POST"):
vgname = 'vg1'
userName = cgi.FormContent()['userName'][0]
driveSize = cgi.FormContent()['driveSize'][0]
clientIP = cgi.FormContent()['clientIP'][0]
password = cgi.FormContent()['userPass'][0]
#step2: create lv
ansibleLVCreate = """
- hosts : web
tasks:
- name: make a user
command: sudo useradd {0}
- name: set password
command: echo "redhat" | passwd {0} --stdin
#- name: make a user
# user:
# name: {0}
# password: {3}
- name: make directory
file:
state: directory
path: /sshfs/{0}-lv1
# change owner of shared folder
- name: changing owner to {0}
command: sudo chown -R {0} /sshfs/{0}-lv1/
- name: give all permissions to user {0}
command: sudo chmod 700 /sshfs/{0}-lv1
- name: creating lv from vg
lvol:
lv: {0}-lv1
vg: {2}
size: {1}
# formating the created lv
- name: Format LV
filesystem:
fstype: ext4
dev: /dev/{2}/{0}-lv1
# mount the lv permanently
- name: permanent mount lv
mount:
path: /sshfs/{0}-lv1
src: /dev/{2}/{0}-lv1
fstype: ext4
state: mounted
# restart ssh
- service:
name: "sshd"
state: restarted """. format(userName, driveSize, vgname, password)
sshfsProg = open("/Arcus/public/tmp/sshfs/sshfs.yaml", "w")
sshfsProg.write(ansibleLVCreate)
sshfsProg.close()
ansF= commands.getstatusoutput("sudo ansible-playbook /Arcus/public/tmp/sshfs/sshfs.yaml")
print("<pre>"+ ansF[1]+ "</pre>")
# set up client
commands.getstatusoutput("sudo sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} mkdir /storage/emulated/{2}/".format(password,clientIP,userName))
'''sshpassF = commands.getstatusoutput("sudo sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} yum install sshpass -y".format(password,clientIP))
if(sshpassF[0]==0):
print("sshpass installed")
else:
print(sshpassF[1])'''
'''sshfsF = commands.getstatusoutput("sudo sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} yum install fuse-sshfs -y".format(password,clientIP))
if sshfsF[0]==0:
print("sshfs installed")
else:
print(sshfsF[1])'''
mountF = commands.getstatusoutput("sudo sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} sshfs -o stricthostkeychecking=no {2}@192.168.43.171:/sshfs/{2}-lv1 /storage/emulated/{2}/".format(password,clientIP,userName))
if(mountF[0] == 0):
print("successfully mounted")
else:
print(mountF[1])
elif(os.environ['REQUEST_METHOD'] == "GET"):
print """
<form action="/sshfs.py" method="POST">
user name: <input type="text" name="userName" /> <br/>
drive size: <input type="text" name="driveSize" /> <br/>
IP Address: <input type="text" name="clientIP" /> <br/>
Password: <input type="password" name="userPass" /> <br/>
<button type="submit">Get</button>
</form>
"""
"""
<div class="register-photo">
<div class="form-container">
<div class="image-holder" style="background-image:url("assets/img/svg_cloud_nfs.jpg");margin:10px;padding:20px;"></div>
<form method="post">
<h2 class="text-center">SSHFS SHARE</h2>
<div class="form-group">
<input class="form-control" type="text" name="userName" placeholder="username">
</div>
<div class="table-responsive">
<table class="table"><tr>
<td>
<input type="range" style=" height:40px;
width:130px;
" min="8" step="1" max="2048" for="osDRIVEsize" name="osDRIVE" />
</td>
<td>
<input style=" width:110px;
" type="number" placeholder="Drive Size" class="form-control" min="8" step="1" max="2048" for="osDRIVE" name="osDRIVEsize" />
</td>
<td> <span class="input-group-addon" style=" height:40px;
">GB</span></td>
</tr>
</table>
</div>
<div class="form-group"></div>
<input class="form-control" type="text" name="clientIP" placeholder="Client IP">
<div class="form-group"></div>
<input class="form-control" type="text" name="clientIP" placeholder="Password">
<div class="form-group"></div>
<div class="form-group"></div>
<div class="form-group"></div>
<div class="form-group has-success">
<div class="checkbox">
<label class="control-label" style="margin:auto;">
<input type="checkbox"> Confirm?</label>
</div>
</div>
<div class="form-group">
<button class="btn btn-primary btn-block" type="submit">SUBMIT </button>
</div>
</form>
</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>
"""