[ UP ] update cgi. add display percentege bar icons.
[archserver.git] / cgi / shares_manager_user.cgi
blob42cb67857e0cc8baf3c8f62eef627496ee87b42b
1 #!/bin/sh
2 echo -e "Content-type: text/html\n\n";
4 this_page="shares.manager_user"
5 source lib.sh
6 source ./proccgi.sh
8 admin_user=0
9 sambadir=$rootdir/samba
11 ####
12 # Funcions
13 ####
14 function create_user() {
15 [ "$F_passwd" != "$F_passwd_cf" ] && echo "<h1>Password and confirmed password not matched !</h1>" && return
16 # add samba user
17 if echo $F_user_name | egrep '\<admin\>|\<administrator\>'; then
18 useradd_arg="-o -u 0"
19 admin_user=1
21 sudo useradd -m $useradd_arg $F_user_name
22 ret=$?
23 [ $ret != 0 ] && grep "useradd_err_$ret" $sambadir/samba/useradd.err|sed 's/.*=//' && return
25 (echo $F_passwd; echo $F_passwd) |sudo smbpasswd -L -s -a $F_user_name
26 [ $admin_user = 1 ] && return
27 sudo $sambadir/modify_samba_config.pl /etc/samba/smb.conf $F_user_name /home/$F_user_name $F_user_name yes
28 echo "<h1>Add user \"$F_user_name\" OK!</h1>"
31 function update_user() {
32 [ "$F_passwd" != "$F_passwd_cf" ] && echo "<h1>Password and confirmed password not matched !</h1>" && return
33 if sudo cat /etc/samba/private/smbpasswd | cut -f1 -d: | egrep "\<$F_user_name\>"; then
34 (echo $F_passwd; echo $F_passwd) |sudo passwd -s -a $F_user_name
35 echo 'Changed password Succesfully! "'
36 return
38 echo "User $F_user_name not exist, Please create it."
41 # del samba user
42 function delete_user() {
43 sudo smbpasswd -x $F_delname >/dev/null
44 sudo $sambadir/modify_samba_config.pl /etc/samba/smb.conf $F_delname
46 sudo userdel -r $F_delname 2>/dev/null
47 ret=$?
48 [ $ret != 0 ] && grep "userdel_err_$ret" $sambadir/samba/userdel.err|sed 's/.*=//' && return
49 echo "<h1>Delete user \"$F_delname\" OK!</h1>"
50 return
53 ####
54 # Html Start
55 ####
56 h_header
58 #[ "$F_todo" = "" ] &&( $rootdir/shares/manager_user.lua; exit)
60 $rootdir/shares/manager_user.lua
61 h_footer
62 exit
63 # Some checks
64 [ $F_todo != "delete" -a "$F_user_name" = "" ] && h_err_quit "<font color=red>Please enter username</font>"
65 [ $F_todo != "delete" -a "$F_passwd" = "" ] && h_err_quit "<font color=red>Please enter password</font>"
66 [ $F_todo != "delete" -a "$F_passwd_cf" = "" ] && h_err_quit "<font color=red>Please enter confirm password</font>"
67 [ $F_todo = "delete" -a "$F_delname" = "" ] && h_err_quit "<font color=red>Please enter username</font>"
69 # Create user
70 [ "$F_todo" = "create" ] && create_user
72 # Update User
73 [ "$F_todo" = "update" ] && update_user
75 # Delete user
76 [ "$F_todo" = "delete" ] && delete_user
78 h_footer