diff options
author | James Meyer <james.meyer@operamail.com> | 2013-02-19 21:10:18 (GMT) |
---|---|---|
committer | James Meyer <james.meyer@operamail.com> | 2013-02-19 21:10:18 (GMT) |
commit | 2648e999d277eac5c3d331a3609bcc73fafbea71 (patch) | |
tree | 40951fb8e7fdbe28a0baa324ae615055203f1e2e /abs/core/LinHES-config/myth_user_call | |
parent | c759b5e0c4aa6fc37412b4dee2cf9ad993fd376d (diff) | |
parent | 7e6f7ca174e1af67178dc5293a312a4a733eb095 (diff) | |
download | linhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.zip linhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.tar.gz linhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.tar.bz2 |
Merge branch 'testing'
# By James Meyer (1091) and others
# Via James Meyer (5) and others
* testing: (1148 commits)
LinHES-config: during install don't kill off lirc. This keeps the remote active all the way to the finish
Change version numbers to 8.0 to match the release number. LinHES-conifg LinHES-system mythdb-initial runit-scripts supplemental-web
LinHES-conifig: mv_install.py for the last partition don't go all the way to the end. Gotta leave room for gpt tables.
xf86-video-ati: xorg ati driver.
LinHES-config: timezip.py add syncing up of parental lvl passwords and starting level with MBE.
LinHES-system: correct the logic for breaking out of the wmctrl loop. As written it would break out of the inner loop..but not the 60 iteration loop.
e16_theme_settings: remove slide-in prop for new windows. For whatever reason this was preventing mplayer from being positioned correctly for appletrailers.
LinHES-config, mythinstall: change case of hd_pvr and serial to all lower refs #902
zilog-firmware: firmware for TX support of the hdpvr and pvr-150 In general I can't recommend anybody using these transmitters but including the firmware just in case someone really wants to
linhes-udev-rules: added hdprv_lirc rule. All of these lirc rules are limited to exactly one device. If more then one device is present then only the last device in init will get the symlink
runit-scripts: fix logging for igdeamon, add support to remote init script so that the blaster is always the first device in the chain. added support specificly for hd_pvr
LinHES-system: add lh_system_restore and lh_system_backup. These scripts are called from the mythmenu. refs #900
iguanair: rebuild with python 2.7
LinHES-system: msg_daemon.py fix init and nasty bug related to timeout. In a nutshell timeout wouldn't work unless a msg without a timeout was called first.
linhes-udev-rules: add rules for mce,streamzap,serial lirc devices.
mythinstall: recompile for matching libs
mythtv: latest .25-fixes and change mythbackup/restore call lh_system_$op to replace mythbackup/mythrestore. mythbackup no longer works correctly with the new windowmanager
linhes-scripts: myth2mp3, myth2x264, myth2xvid: use mythutil to get cutlist
LinHES-config, supplimental-web: Fix proxy numbering for Ceton infiniTV
linhes-system: add additional stuff to the system backup and also introduced an exclude file. The exclude/include files are locate in /home/mythtv/backup_config/
...
Diffstat (limited to 'abs/core/LinHES-config/myth_user_call')
-rw-r--r-- | abs/core/LinHES-config/myth_user_call | 319 |
1 files changed, 152 insertions, 167 deletions
diff --git a/abs/core/LinHES-config/myth_user_call b/abs/core/LinHES-config/myth_user_call index 0914b03..1b8d315 100644 --- a/abs/core/LinHES-config/myth_user_call +++ b/abs/core/LinHES-config/myth_user_call @@ -1,174 +1,159 @@ -#!/bin/bash +#!/usr/bin/python2 +# -*- coding: utf-8 -*- #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 - usermod -a -G mythtv $USERNAME - - 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 - +import pexpect, sys, time +import os, re, getopt +import mv_common + + + + +def chroot_check(): + if not INIT_CHECK : + return False + cmd = '''ps -p 1 -o comm=''' + init = mv_common.runcmd_output(cmd).strip() + if init == "runit": + return False + else: + return True + + +def store_commands(full_call): + file_name = "/root/myth_user_call.out" + try: + f = open(file_name,'a') + except: + print "%s could not be opened" % file_name + sys.exit(1) + f.write(full_call) + f.write("\n") + f.close() + try: + os.chmod(600,file_name) + except: + pass + + +def add_user(username,full_call): + if chroot_check() : + print "calling myth_call_user in chroot to add user" + store_commands(full_call) + else: + print "Adding user %s" %username + cmd = '''useradd -m -s /bin/bash %s -G audio,video,optical,storage,users''' %username + mv_common.runcmd(cmd) + cmd = ''' usermod -a -G mythtv %s ''' %username + + +def del_user(username,full_call): + if chroot_check() : + print "calling myth_call_user in chroot to del user" + store_commands(full_call) + else: + print "Removing user %s" %username + cmd = '''userdel %s ''' %username + mv_common.runcmd(cmd) + + +def pass_change(username,password,full_call) : + if chroot_check() : + print "calling myth_call_user in chroot to change password" + store_commands(full_call) + else: + print "changing password for %s" %username + passwd = pexpect.spawn("/usr/bin/passwd %s" % username) + + for repeat in (1, 2): + passwd.expect("password: ") + passwd.sendline(password) + time.sleep(0.1) + +def web_security(username,password) : + file_name = "/etc/lighttpd/lighttpd.user" + file_contents = '' + if os.path.exists(file_name): + try: + f = open(file_name,'r') + file_contents = f.readlines() + except: + print " couldn't read %s" % file_name + try: + f = open(file_name,'w') + except: + print "%s could not be opened for writing" % file_name + return + + for line in file_contents: + if not re.search(username, line): + f.write(line) + line = "%s:%s" %(username, password) + f.write(line) + f.write("\n") + f.close() + + +def usage (): + print "Valid options are:" + print " -c (add|delete|pass|web)" + print " -u USERNAME" + print " -p password" + sys.exit(0) + +def main(argv): + global INIT_CHECK + full_call = "" + INIT_CHECK = True + try: + opts, args = getopt.getopt(argv, 'c:u:p:ih' ) + except getopt.GetoptError, why: + print why + usage() + print "exception happened" + sys.exit(2) + + for opt, arg in opts: + if opt in ("-h", "--help"): + usage() + sys.exit(0) + elif opt in ("-c") : + module = arg + full_call += ''' -c %s ''' %re.escape(arg) + elif opt in ("-u") : + username = arg + full_call += ''' -u %s ''' %re.escape(arg) + elif opt in ("-p") : + password = arg + full_call += ''' -p %s ''' %re.escape(arg) + elif opt in ("-i") : + INIT_CHECK = False + full_call += ''' -i ''' + try: + username + except: + usage() + + if module == "add": + add_user(username,full_call) + elif module == "delete": + del_user(username,full_call) + elif module == "pass": + try: + password + except: + print "needs a password" + usage() + pass_change(username,password,full_call) + elif module == "web": + web_security(username,password) + else: + usage() + +if __name__ == "__main__": + main(sys.argv[1:]) |