Example #1
0
#!/usr/bin/env python
import bitheadclient as bhc

bhc.sendRequest('postinstall')
Example #2
0
#!/usr/bin/env python
import bitheadclient as bhc
from os import mkdir
from os.path import exists

res = bhc.sendRequest('pubkey')
key = res['key']
if not exists('/root/.ssh'):
    mkdir('/root/.ssh')
fd = open('/root/.ssh/authorized_keys', 'a')
with fd:
    fd.write(key + "\n")
Example #3
0
                


        entry = {}
        # Win env has USERNAME; Linux  PAM env has PAM_USER
        entry['user'] = environ.get('USERNAME') or environ.get('PAM_USER')
        entry['login_time'] = str(datetime.now())

        entries.append(entry)
        fsave = open(logpath, 'w')
        dump(entries, fsave) 
        fsave.close()
	try:
	    entry['login'] = True
	    #send login notice
	    sendRequest('realog', **entry)
	except:
	    pass
    except IOError as e:
        entry = {}
        entry['now'] = str(datetime.now())
        entry['errormsg'] = socket.gethostname() + ': Could not open logfile when trying to save login time'
        entry['error'] = e
        sendRequest('realog', **entry)
        # Send Error message, Quit program
    finally:
        exit()


#### LOGOUT ####
## Write logout time and send  the log entry to bithead
Example #4
0
homedir = '/home/WIN-NTNU-NO/'

un = environ.get('PAM_USER')
if re.search("[^A-Za-z0-9_-]",un): #check if argument is a valid user name
    exit(1)
s = getpwnam(un) #throws exception if un does not match a user 
userdir = s.pw_dir
uid = s.pw_uid
gid = s.pw_gid
if path.exists(userdir): #path to userdir exists
    if path.isdir(userdir): #userdir is a directory
	st = stat(userdir) 
	if uid == st.st_uid: 
	    try:
		if gid != st.st_gid:
		    chown(userdir, -1, gid)
		mode = oct(st.st_mode)[2:]
		if mode != oct(0700):
		    chmod(userdir,0700)		
		exit(0)
	    except Exception as e:
		pass
    else:
	#homedir exists but is not dir
	exit(2)
try:
    res = bhc.sendRequest('newuser',user=un)
except Exception as e:
    print e.message
    exit(3)
Example #5
0
        except Exception as e:
            print e.message

        entry = {}
        # Win env has USERNAME; Linux  PAM env has PAM_USER
        entry['user'] = environ.get('USERNAME') or environ.get('PAM_USER')
        entry['login_time'] = str(datetime.now())

        entries.append(entry)
        fsave = open(logpath, 'w')
        dump(entries, fsave)
        fsave.close()
        try:
            entry['login'] = True
            #send login notice
            sendRequest('realog', **entry)
        except:
            pass
    except IOError as e:
        entry = {}
        entry['now'] = str(datetime.now())
        entry['errormsg'] = socket.gethostname(
        ) + ': Could not open logfile when trying to save login time'
        entry['error'] = e
        sendRequest('realog', **entry)
        # Send Error message, Quit program
    finally:
        exit()

#### LOGOUT ####
## Write logout time and send  the log entry to bithead
Example #6
0
#!/usr/bin/env python
from bitheadclient import sendRequest

addprinter_cmd = "lpadmin -p %(printer_name)s -E -v %(printer_URI)s -P %(ppdfile)s"
res = sendRequest("printers")
printer_info = res["printer_info"]
Example #7
0
homedir = '/home/WIN-NTNU-NO/'

un = environ.get('PAM_USER')
if re.search("[^A-Za-z0-9_-]", un):  #check if argument is a valid user name
    exit(1)
s = getpwnam(un)  #throws exception if un does not match a user
userdir = s.pw_dir
uid = s.pw_uid
gid = s.pw_gid
if path.exists(userdir):  #path to userdir exists
    if path.isdir(userdir):  #userdir is a directory
        st = stat(userdir)
        if uid == st.st_uid:
            try:
                if gid != st.st_gid:
                    chown(userdir, -1, gid)
                mode = oct(st.st_mode)[2:]
                if mode != oct(0700):
                    chmod(userdir, 0700)
                exit(0)
            except Exception as e:
                pass
    else:
        #homedir exists but is not dir
        exit(2)
try:
    res = bhc.sendRequest('newuser', user=un)
except Exception as e:
    print e.message
    exit(3)
Example #8
0
#!/usr/bin/env python
from bitheadclient import sendRequest
addprinter_cmd = "lpadmin -p %(printer_name)s -E -v %(printer_URI)s -P %(ppdfile)s"
res = sendRequest('printers')
printer_info = res['printer_info']