-
Notifications
You must be signed in to change notification settings - Fork 1
/
samba2.php
148 lines (132 loc) · 3.83 KB
/
samba2.php
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
<?php
include("header.php");
if($_SESSION['flag']=="allowed")
{
$action=$_POST['samba2'];
if($action=="convert")
{
$name=$_POST['name'];
$cmd = `cat /etc/passwd | grep $name`;
if($cmd)
{
$cmd1=`sudo smbpasswd -a $name`;
echo $cmd1;
echo '<label class="alert alert-success">User '.$name.' has been converted!!</label>';
$res = `sudo service smb restart`;
}
else
echo '<label class="alert alert-danger">User '.$name.' does not exist!!</label>';
}
if($action=="create")
{
$name=$_POST['name'];
$dir=$_POST['dir'];
$writable=strtolower($_POST['writable']);
$printable=strtolower($_POST['printable']);
$path=$_POST['path'];
$owner=$_POST['owner'];
$gowner=$_POST['gowner'];
$vusers=$_POST['vusers'];
$iusers=$_POST['iusers'];
$vgroups=$_POST['vgroups'];
$igroups=$_POST['igroups'];
$comment=$_POST['comment'];
$cmd = `sudo cat /etc/samba/smb.conf | grep -w $name`;
$path_check = `sudo find $path/$dname`;
if($cmd)//share name does not exist
{
if($path_check)//valid path
{
if($writable=="yes" && $printable=="yes")
{
$cmd1=`sudo touch samba.sh`;
$cmd2=`sudo chmod 777 samba.sh`;
$cnd3= `echo 'echo "[$dir]
comment = $comment
guest account = $dir
writeable = yes
printable = yes
path = $path/$dir;
force user = $owner,@$gowner
valid users = $vusers,@$vgroups
invalid users = $iusers,@$igroups" >> /etc/samba/smb.conf' > samba.sh`;
$cmd4=`sudo bash samba.sh`;
$cmd5=`sudo rm -rf samba.sh`;
$cmd6=`sudo service smb restart`;
}
if($writable=="no" && $printable=="yes")
{
$cmd1=`sudo touch samba.sh`;
$cmd2=`sudo chmod 777 samba.sh`;
$cnd3= `echo 'echo "[$dir]
comment = $comment
guest account = $dir
writeable = no
printable = yes
path = $path/$dir;
force user = $owner,@$gowner
valid users = $vusers,@$vgroups
invalid users = $iusers,@$igroups" >> /etc/samba/smb.conf' > samba.sh`;
$cmd4=`sudo bash samba.sh`;
$cmd5=`sudo rm -rf samba.sh`;
$res=`sudo service smb restart`;
}
if($writable=="yes" && $printable=="no")
{
$cmd1=`sudo touch samba.sh`;
$cmd2=`sudo chmod 777 samba.sh`;
$cnd3= `echo 'echo "[$dir]
comment = $comment
guest account = $dir
writeable = yes
printable = no
path = $path/$dir;
force user = $owner,@$gowner
valid users = $vusers,@$vgroups
invalid users = $iusers,@$igroups" >> /etc/samba/smb.conf' > samba.sh`;
$cmd4=`sudo bash samba.sh`;
$cmd5=`sudo rm -rf samba.sh`;
$res=`sudo service smb restart`;
}
}
echo '<label class="alert alert-danger">Invalid Path!!</label>';
}
else
{
echo '<label class="alert alert-danger">Share name already exist!!</label>';
}
}
if($action=="undo")
{
$name=$_POST['name'];
$path=$_POST['path'];
if(fopen("$path", "r") == TRUE)
{
$cmd1=`sudo grep -w "$a" -n /etc/samba/smb.conf`;
$cmd2=`sudo grep -w "$b" -n /etc/samba/smb.conf`;
$cmd3=explode(":",$cmd1);
$cmd4=explode(":",$cmd2);
$start=$cmd3[0];
$end=$cmd4[0];
$cmd5=`sudo sed -i '{$start},{$end}d' /etc/samba/smb.conf`;
$cmd6=`sudo /etc/init.d/smb restart`;
$res=`sudo service smb restart`;
}
else
echo '<label class="alert alert-danger">Invalid Directory!!</label>';
}
if($action=="change")
{
$pass=$_POST['pass'];
$name=$_POST['name'];
$cmd=`cat /etc/passwd | grep $name`;
if($cmd)
{
$cmd1=`echo $pass | sudo passwd --stdin $name`;
}
else
echo '<label class="alert alert-danger">User'.$name.' does not exist!!</label>';
}
}
else
header("location:index.php");