summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config-svn/myth_user_call
diff options
context:
space:
mode:
authorCecil Hugh Watson <knoppmyth@gmail.com>2009-09-26 01:57:08 (GMT)
committerCecil Hugh Watson <knoppmyth@gmail.com>2009-09-26 01:57:08 (GMT)
commit7b29169fff9e7c624890c5edffe85def8a293136 (patch)
tree47753889faa3a2063b66d1c7e7681e703eb1b39a /abs/core/LinHES-config-svn/myth_user_call
parentc491dea779dac29afff3578bf8245943817c2339 (diff)
downloadlinhes_pkgbuild-7b29169fff9e7c624890c5edffe85def8a293136.zip
linhes_pkgbuild-7b29169fff9e7c624890c5edffe85def8a293136.tar.gz
linhes_pkgbuild-7b29169fff9e7c624890c5edffe85def8a293136.tar.bz2
LinHES 6.01.00
Diffstat (limited to 'abs/core/LinHES-config-svn/myth_user_call')
-rw-r--r--abs/core/LinHES-config-svn/myth_user_call172
1 files changed, 172 insertions, 0 deletions
diff --git a/abs/core/LinHES-config-svn/myth_user_call b/abs/core/LinHES-config-svn/myth_user_call
new file mode 100644
index 0000000..0479895
--- /dev/null
+++ b/abs/core/LinHES-config-svn/myth_user_call
@@ -0,0 +1,172 @@
+#!/bin/bash
+#Wrapper script to manage USERNAME accounts + web security
+# myth_USERNAME_all -c add -u USERNAME
+# myth_USERNAME_all -c delete -u USERNAME
+# myth_USERNAME_all -c pass -u USERNAME -p pass
+# myth_USERNAME_all -c web -u USERNAME -p pass
+
+INIT_CHECK=TRUE
+FULL_CALL="$@"
+function CHROOT_CHECK {
+ INIT=`ps -p 1 -o comm=`
+ if [ x$INIT = xrunit ]
+ then
+ CHROOT_NEEDED=FALSE
+ else
+ CHROOT_NEEDED=TRUE
+ fi
+}
+
+function store_commands () {
+ echo "$FULL_CALL" >> /root/myth_user_call.out
+ chmod 600 /root/myth_user_call.out
+}
+
+
+function add_user() {
+ if [ $CHROOT_NEEDED = TRUE ]
+ then
+ echo "calling myth_call_user in chroot to add user"
+ store_commands
+ else
+ echo "adding user $USERNAME"
+ useradd -m -s /bin/bash $USERNAME -G audio,video,optical,storage,users
+ fi
+
+}
+
+
+function del_user() {
+ if [ $CHROOT_NEEDED = TRUE ]
+ then
+ echo "calling myth_call_user in chroot to delete user"
+ store_commands
+ else
+ echo "removing user $USERNAME"
+ userdel $USERNAME
+ fi
+
+}
+
+
+function pass_change() {
+ if [ $CHROOT_NEEDED = TRUE ]
+ then
+ echo "calling myth_call_user in chroot to change password"
+ store_commands
+ else
+ echo "changing password for $USERNAME"
+ echo $USERNAME:$PASSWORD | chpasswd
+ fi
+
+}
+
+
+function web_security {
+
+ grep -q ${USERNAME}: /etc/lighttpd/lighttpd.user
+ if [ $? = 0 ]
+ then
+ #delete user
+ sed -i "/${USERNAME}\:/d" /etc/lighttpd/lighttpd.user
+ fi
+ echo "${USERNAME}:${PASSWORD}" >> /etc/lighttpd/lighttpd.user
+
+}
+
+function ARG_ERR() {
+ if [ x$OPTARG = "x" ]
+ then
+ echo "$SWITCH NEEDS AND ARG"
+ exit 11
+ fi
+}
+
+
+function print_help {
+
+ echo "Valid options are:"
+ echo " -c (add|delete|pass|web)"
+ echo " -u USERNAMEname"
+ echo " -p password"
+ exit 1
+}
+
+if [ $# -eq 0 ]
+then
+ print_help
+fi
+
+declare -r OPTSTRING="c:u:p:i"
+while getopts "$OPTSTRING" SWITCH
+do
+ case $SWITCH in
+
+ c) ARG_ERR
+ OPERATION=$OPTARG
+ ;;
+ u) ARG_ERR
+ USERNAME=$OPTARG
+ ;;
+ p) ARG_ERR
+ PASSWORD=$OPTARG
+ ;;
+ i) INIT_CHECK=FALSE
+
+ esac
+done
+
+if [ $INIT_CHECK = TRUE ]
+then
+ CHROOT_CHECK
+else
+ CHROOT_NEEDED=FALSE
+fi
+
+case $OPERATION in
+ add)
+ if [ x$USERNAME = x ]
+ then
+ print_help
+ fi
+ add_user
+ ;;
+ delete)
+ if [ x$USERNAME = x ]
+ then
+ print_help
+ fi
+ del_user
+ ;;
+ pass)
+ if [ x$USERNAME = x ]
+ then
+ print_help
+ fi
+
+ if [ x$PASSWORD = x ]
+ then
+ print_help
+ fi
+ pass_change
+ ;;
+
+ web)
+ if [ x$USERNAME = x ]
+ then
+ print_help
+ fi
+
+
+ if [ x$PASSWORD = x ]
+ then
+ print_help
+ fi
+ echo "adding webUSERNAME $USERNAME with pass $PASSWORD"
+ web_security
+ ;;
+ *) print_help
+ ;;
+esac
+
+