#!/bin/sh
# Add new webmin user from the command shell on Linux
# In BSD there might be minor changes in the script required
# Written by hip0
# Thu Jul  8 14:40:11 EEST 2010
# Licensed under GPL v2
# http://www.gnu.org/licenses/gpl2.txt

webmin_etc_path=/etc/webmin;
webmin_passwd=miniserv.users;
webmin_acl_file=webmin.acl;
passwd_file=/etc/passwd;
webmin_init_script=/etc/init.d/webmin;
change_pass_loc=/usr/share/webmin/changepass.pl;

echo "Add new Webmin user - by hip0";
echo -e "------------------------------------\n\n";
echo -n "Please enter new webmin username:";
read user;
if [ "$user" != "" ]; then
echo -e "Please specify persmission for $user choose and type all the persmissions from the list below:\n\n"
echo -e "acl adsl-client apache at backup-config bacula-backup bandwidth bind8 burner cfengine change-user cluster-copy cluster-cron cluster-passwd cluster-shell cluster-software cluster-useradmin cluster-usermin cluster-webmin cpan cron custom dfsadmin dhcpd dnsadmin dovecot exim exports fdisk fetchmail file filter firewall frox fsdump grub heartbeat htaccess-htpasswd idmapd inetd init inittab ipfilter ipfw ipsec jabber krb5 ldap-client ldap-server ldap-useradmin lilo logrotate lpadmin lvm mailboxes mailcap majordomo man mon mount mysql net nis openslp package-updates pam pap passwd phpini postfix postgresql ppp-client pptp-client pptp-server procmail proc proftpd pserver qmailadmin quota raid samba sarg sendmail sentry servers shell shorewall smart-status smf software spam squid sshd status stunnel syslog syslog-ng system-status tcpwrappers telnet time tunnel updown useradmin usermin vgetty webalizer webminlog webmin wuftpd xinetd\n\n";

echo -n "Please type user $user's permissions:";
read acl;
fi
#read acl;
if [ "$acl" != "" ]; then
echo "$user, $acl";
get_user_id=$(grep -i soccerfame $passwd_file|sed -e "s#:# #g"|awk '{ print $3 }');
if [ "$get_user_id" != "" ]; then
# add user to miniserv.users and webmin.acl files
echo "$user:12ZWQKVLRpihs:$get_user_id" >> $webmin_etc_path/$webmin_passwd
echo "$user: $acl" >> $webmin_etc_path/$webmin_acl_file
# Restart webmin to enable webmin read the new user
$webmin_init_script restart;
else
echo "$user is not existant in $passwd_file or some kind of fatal error occured!";
fi

echo -e "Now set a password for the newly created $user\n\n";
echo -n "Type a password for $user:";
read password;

if [ "$password" != "" ]; then
$change_pass_loc $webmin_etc_path $user $password;
fi

fi

