-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockstorage.cgi
130 lines (116 loc) · 6.59 KB
/
blockstorage.cgi
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
#!/usr/bin/python
#common gateway interface
import cgi
import cgitb
import mysql.connector as mariadb
import commands
cgitb.enable()
print"content-type:text/html"
print ""
form=cgi.FieldStorage()#form is a variable
#username="manav" store value whose name is rahul
commands.getstatusoutput("systemctl restart mariadb")
mariadb_connection = mariadb.connect(user='root', password='redhat', database='cloud')
cursor = mariadb_connection.cursor()
hello=form.getvalue('slsize')
he=form.getvalue('proto')
cc=form.getvalue('cook')
username=cc[8:len(cc)]
print he
print hello
print username
passkey='select * from clients where username="'+username+'"'
cursor.execute(passkey)
r=cursor.fetchall()
print r
for i in r:
password=str(i[2])
usernamen=str(i[0])
print password
print usernamen
print usernamen
commands.getstatusoutput("sudo -i mkdir /var/www/html/"+usernamen)
commands.getstatusoutput("sudo -i mkdir /clientpy/" + usernamen)
commands.getstatusoutput("sudo -i chmod 755 /clientpy/" + usernamen)
if he=="nfs":
commands.getstatusoutput("sudo -i lvcreate --size " + str(hello) + "G --name " + usernamen + " thunder")
commands.getstatusoutput("sudo -i mkfs.ext4 /dev/thunder/" + usernamen)
commands.getstatusoutput("sudo -i mkdir /storage/" + usernamen)
commands.getstatusoutput("sudo -i chmod 755 /storage/" +usernamen)
commands.getstatusoutput("sudo -i mount /dev/thunder/" + usernamen + " /storage/"+usernamen)
commands.getstatusoutput("sudo -i chmod 777 /etc/exports")
a="/storage/" + usernamen + " *(rw,no_root_squash)" + "\n"
fh=open("/etc/exports", mode="w")
fh.write(a)
fh.close()
commands.getstatusoutput("sudo -i systemctl restart nfs-server")
commands.getstatusoutput("sudo touch /clientpy/"+usernamen+"/nfsclient.py")
commands.getstatusoutput("sudo -i chmod 777 /clientpy/"+usernamen+"/nfsclient.py")
b='#!/usr/bin/python2\nimport commands\ncommands.getstatusoutput("mkdir /media/'+usernamen+'")\ncommands.getstatusoutput("mount 192.168.0.7:/storage/' + usernamen + ' /media/'+usernamen+'")\n'
commands.getstatusoutput("sudo -i chmod 777 /clientpy/"+usernamen+"/nfsclient.py")
fs=open('/clientpy/'+usernamen+'/nfsclient.py',mode="w")
fs.write(b)
fs.close()
commands.getstatusoutput("sudo -i systemctl restart nfs-server")
commands.getstatusoutput("sudo -i chmod +x /clientpy/"+usernamen+"/nfsclient.py")
#commands.getstatusoutput("mkdir /root/var/www/"+username)
commands.getstatusoutput("sudo -i tar -cvf /var/www/html/"+usernamen+"/nfsclient.tar /clientpy/"+usernamen+"/nfsclient.py")
print "<META HTTP-EQUIV=REFRESH CONTENT=\"0;URL=http://localhost/"+usernamen+"/nfsclient.tar\">\n";
elif he=="smb":
#commands.getstatusoutput("mkdir"+ username)
commands.getstatusoutput("sudo -i useradd -s /sbin/nologin "+usernamen)
commands.getstatusoutput("sudo echo -e '"+password+"\\n"+password+"'|sudo smbpasswd -a "+ usernamen)
commands.getstatusoutput("sudo -i mkdir /samba")
commands.getstatusoutput("sudo -i mkdir /samba/"+usernamen)
commands.getstatusoutput("sudo -i chmod o+w /samba/"+usernamen)
commands.getstatusoutput("sudo -i lvcreate --size " + str(hello) + "G --name "+usernamen+"1 thunder")
commands.getstatusoutput("sudo -i mkfs.ext4 /dev/thunder/" + usernamen+"1")
#commands.getstatusoutput("sudo -i mkdir /storage/" + usernamen)
commands.getstatusoutput("sudo -i mount /dev/thunder/"+usernamen+"1 /samba/"+usernamen)
a="[docs"+usernamen+"]\npath=/samba/"+usernamen+"\nwritable=yes\nvalid users="+usernamen+"\nbrowseable=yes\n"
commands.getstatusoutput("sudo -i chmod o+w /etc/samba/smb.conf")
fh=open("/etc/samba/smb.conf", mode="w")
fh.write(a)
fh.close()
commands.getstatusoutput("sudo -i systemctl restart smb")
commands.getstatusoutput("sudo -i mkdir /"+usernamen)
commands.getstatusoutput("sudo -i chmod o+w /"+usernamen)
commands.getstatusoutput("sudo -i touch /"+usernamen+"/sambaclient.py")
commands.getstatusoutput("sudo -i chmod o+w /"+usernamen+"/sambaclient.py")
b='#!/usr/bin/python2\nimport commands\ncommands.getstatusoutput("mkdir /media/samba")\ncommands.getstatusoutput("mkdir /media/samba/'+usernamen+'")\ncommands.getstatusoutput("mount -o username='+usernamen+' //192.168.0.7/docs'+usernamen+' /media/samba/'+usernamen+'")'
#commands.getstatusoutput("chmod o+w /media/samba/"+usernamen+"/sambaclient.py")
fh=open("/"+usernamen+"/sambaclient.py",mode="w")
fh.write(b)
fh.close()
commands.getstatusoutput("sudo -i chmod +x /"+usernamen+"/sambaclient.py")
#commands.getstatusoutput("mkdir /root/var/www/"+username)
commands.getstatusoutput("sudo -i tar -cvf /var/www/html/"+usernamen+"/sambaclient.tar /"+usernamen+"/sambaclient.py")
commands.getstatusoutput("sudo -i systemctl restart smb")
mariadb_connection.close()
print "<META HTTP-EQUIV=REFRESH CONTENT=\"0;URL=http://localhost/"+usernamen+"/sambaclient.tar\">\n";
#print "<META HTTP-EQUIV=REFRESH CONTENT=\"0;URL=localhost/"+usernamen+"sambaclient.tar\">\n";
"""
elif he=="gluster":
commands.getstatusoutput("sudo -i mkdir /gluster")
commnads.getstatusoutput("sudo -i chmod o+w /gluster")
commands.getstatusoutput("sudo -i mkdir /gluster"+usernamen)
commands.getstatusoutput("sudo -i chmod o+w /gluster/"+usernamen)
commands.getstatusoutput("sudo -i lvcreate --size " + str(hello) + "G --name "+usernamen+"gfs thunder")
commands.getstatusoutput("sudo -i mkfs.ext4 /dev/thunder/" + usernamen+"gfs")
commands.getstatusoutput("sudo -i lvcreate --size " + str(hello) + "G --name "+usernamen+"gfs1 thunder")
commands.getstatusoutput("sudo -i mkfs.ext4 /dev/thunder/" + usernamen+"gfs1")
commands.getstatusoutput("sudo -i mount /dev/thunder/"+usernamen+"gfs /gluster/"+usernamen)
commands.getstatusoutput("sudo -i mount /dev/thunder/"+usernamen+"gfs1 /gluster/"+usernamen)
commands.getstatusoutput("sudo -i systemctl restart glusterd")
commands.getstatusoutput("sudo -i gluster volume create glusterstorage"+usernamen" 192.168.0.7:/thunder/"+usernamen+"gfs 192.168.0.7:/thunder/"+usernamen+"gfs1 force")
commands.getstatusoutput("sudo -i gluster volume start glusterstorage"+usernamen)
commands.getstatusoutput("sudo -i mkdir /"+usernamen+"gfs")
commands.getstatusoutput("sudo -i chmod o+w /"+usernamen+"gfs")
commands.getstatusoutput("sudo -i touch /"+usernamen+"gfs/gfsclient.py")
commands.getstatusoutput("sudo -i chmod o+w /"+usernamen+"/gfsclient.py")
a='#!/usr/bin/python2\nimport commands\ncommands.getstatusoutput("sudo -i mkdir /media/'+usernamen+'gfs")\ncommands.getstatusoutput("sudo -i mount -t glusterfs 192.168.0.7:/glusterstorage'+usernamen+' /media/'+usernamen+'gfs")'
fh=open("/"+usernamen+"gfs/gfsclient.py",mode="at")
fh.write(a)
fh.close(a)
commands.getstatusoutput("sudo -i chmod +x /"+usernamen+"gfs/gfsclient.py")
"""