Ver a proveniência

Merge branch 'master' into cleanup

pull/6/head
Cian Butler há 4 anos
committed by butlerx
ascendente
cometimento
18ca36ef13
9 ficheiros alterados com 82 adições e 43 eliminações
  1. +9
    -1
      .codeclimate.yml
  2. +1
    -0
      accounts.d/how_many_newbies_logged_in.sh
  3. +3
    -3
      bash/mysql-slave-permissions.sh
  4. +35
    -1
      bash/postgres_add
  5. +19
    -24
      bash/rbsearch
  6. +5
    -4
      ldap/ldapmodify_ldif.py
  7. +7
    -7
      python/groupmail.py
  8. +1
    -1
      python/not_a_user_db.py
  9. +2
    -2
      python/yearspaid_mak_fix.py

+ 9
- 1
.codeclimate.yml Ver ficheiro

@@ -10,8 +10,16 @@ engines:
enabled: true
pep8:
enabled: true
checks:
E501:
enabled: false
E302:
enabled: false
radon:
enabled: false
enabled: true
checks:
Complexity:
enabled: false
shellcheck:
enabled: true
ratings:


+ 1
- 0
accounts.d/how_many_newbies_logged_in.sh Ver ficheiro

@@ -1,3 +1,4 @@
#!/bin/bash
NUMBER=0

for a in $(/srv/admin/scripts/rrs/useradm list_newbies); do


+ 3
- 3
bash/mysql-slave-permissions.sh Ver ficheiro

@@ -5,13 +5,13 @@ success=0
loops=0

while [ $success -eq 0 ]; do
success=$(grep -c success /backup/mysql/$date/summary)
success=$(grep -c success /backup/mysql/"$date"/summary)
if [ "$success" -gt 0 ]; then
files=$(find /backup/mysql/$date/tree/dumps/ -type f -printf "%P \n")
files=$(find /backup/mysql/"$date"/tree/dumps/ -type f -printf "%P \n")
for file in $files; do
username=${file%.sql}
group=$(id -g "$username")
chown "$username":"$group" /backup/mysql/$date/tree/dumps/"$file"
chown "$username":"$group" /backup/mysql/"$date"/tree/dumps/"$file"
done
elif [ $loops -gt 12 ]; then
exit 1


+ 35
- 1
bash/postgres_add Ver ficheiro

@@ -1,2 +1,36 @@
#!/bin/bash
su postgres -c "createuser --no-superuser --no-createdb --no-createrole $1; createdb $1 -O $1"

SCRIPTNAME="postgres_add"
USERNAME="micro"

function usage () {
echo "Usage: $SCRIPTNAME [ -u | --username ] user"
echo "eg. $SCRIPTNAME -u $USERNAME"
echo " $SCRIPTNAME --username $USERNAME"
echo ""
}

if [[ $# -eq 0 ]]; then
echo "Enter the user to create the db for"
read -r USER
fi

while [[ $# -gt 1 ]]; do
key="$1"
case $key in
-u|--username)
USER="$2"
shift
;;
-h|--help)
usage
;;
*)
echo Unrecognised flag
usage
;;
esac
shift
done

su postgres -c "createuser --no-superuser --no-createdb --no-createrole $USER; createdb $USER -O $USER"

+ 19
- 24
bash/rbsearch Ver ficheiro

@@ -21,6 +21,20 @@ function dcusearch () {
ldapsearch -x -h ad.dcu.ie -D "CN=rblookup,OU=Service Accounts,DC=ad,DC=dcu,DC=ie" -w "$(</etc/ldap_dcu.secret)" -b "OU=Students,DC=ad,DC=dcu,DC=ie" -s sub "($SEARCH)" cn gecos mail
}

function usage () {
echo "Usage: $SCRIPTNAME [-altmail] [-uid] [-id] [-name] [-nick] [-fullname] [--dcu [username] [fullname]] query"
echo "eg. $SCRIPTNAME -altmail $EMAIL"
echo " $SCRIPTNAME -uid $USERNAME"
echo " $SCRIPTNAME -fullname $FULLNAME"
echo " $SCRIPTNAME -update $USERNAME"
echo " $SCRIPTNAME -dcu username $USERNAME"
echo " $SCRIPTNAME -dcu fullname $FULLNAME"
echo ""
echo "Only fullname takes 2 arguments."
echo "All results will give just uid(s) apart from [-uid]"
echo "[-uid] prints all ldap info for that uid"
}

case $1 in
-update)
if [ ! -z "$3" ]; then
@@ -32,7 +46,7 @@ case $1 in
-altmail)
$SEARCH "altmail=$2" uid
;;
-uid)
-uid|--user|-u)
$SEARCH "uid=$2"
;;
-id)
@@ -54,7 +68,7 @@ case $1 in
-newbie)
$SEARCH "newbie=TRUE" uid
;;
-dcu)
--dcu)
case $2 in
username)
SEARCH="cn=$3"
@@ -69,29 +83,10 @@ case $1 in
fi
esac
;;
-h)
echo "Usage: $SCRIPTNAME [-altmail] [-uid] [-id] [-name] -[nick] -[fullname] query"
echo "eg. $SCRIPTNAME -altmail $EMAIL"
echo " $SCRIPTNAME -uid $USERNAME"
echo " $SCRIPTNAME -fullname $FULLNAME"
echo " $SCRIPTNAME -update $USERNAME"
echo " $SCRIPTNAME -dcu username $USERNAME"
echo " $SCRIPTNAME -dcu fullname $FULLNAME"
echo ""
echo "Only fullname takes 2 arguments."
echo "All results will give just uid(s) apart from [-uid]"
echo "[-uid] prints all ldap info for that uid"
-h|--help)
usage
;;
*)
echo "Usage: $SCRIPTNAME [-altmail] [-uid] [-id] [-name] [-nick] [-fullname] [-dcu [username] [fullname]] query"
echo "eg. $SCRIPTNAME -altmail $EMAIL"
echo " $SCRIPTNAME -uid $USERNAME"
echo " $SCRIPTNAME -fullname $FULLNAME"
echo " $SCRIPTNAME -update $USERNAME"
echo " $SCRIPTNAME -dcu username $USERNAME"
echo " $SCRIPTNAME -dcu fullname $FULLNAME"
echo ""
echo "Only fullname takes 2 arguments."
echo "All results will give just uid(s) apart from [-uid]"
usage
;;
esac

+ 5
- 4
ldap/ldapmodify_ldif.py Ver ficheiro

@@ -20,16 +20,16 @@ def modify_template(l_uid, l_years_paid, l_newbie, l_reserved):
mod_temp += "\n"
print(mod_temp)

#open ldif
# open ldif
with open(sys.argv[1], 'r') as content:
LDIF = content.read()
#split by user
# split by user
GETDN = LDIF.split('dn: uid=')
for i in range(1, len(GETDN)):
thisdn = GETDN[i].split('\n')
newbie = 'NONE'
reserved = False
#split by users variables
# split by users variables
for j in range(0, len(thisdn)):
x = thisdn[j].rstrip()
uid = thisdn[0].rstrip()
@@ -40,7 +40,8 @@ for i in range(1, len(GETDN)):
years_paid = str(int(x.split()[1])).strip()
elif x.startswith("newbie:"):
newbie = '1'
else: continue
else:
continue
except IndexError:
break
modify_template(uid, years_paid, newbie, reserved)

+ 7
- 7
python/groupmail.py Ver ficheiro

@@ -54,7 +54,7 @@ def mailgroup(ldif, frm, subject, body, prnt):
if prnt:
print(uid + ' - ' + ldap_cn + ' : ' + altmail)
else:
#Send mail to each
# Send mail to each
print('Send mail to ' + ldap_cn + ' using ' + altmail + ' (y|n)?')
send = input('default(y): ')
if(send == 'n') or (send == 'N'):
@@ -65,8 +65,8 @@ def mailgroup(ldif, frm, subject, body, prnt):

def check_args(args):
"""check args for sending"""
if(args.GROUPS is None and args.FROM != None and args.TO != None and args.SUBJECT != None and
args.MSG != None):
if(args.GROUPS is None and args.FROM is not None and args.TO is not None and
args.SUBJECT is not None and args.MSG is not None):
return not args.PRINT
return False

@@ -86,7 +86,7 @@ def main():
parser.add_argument('-s', dest='SUBJECT', type=str, help='Subject of mail.')
args = parser.parse_args()

if args.GROUPS != None:
if args.GROUPS is not None:
if ',' in args.GROUPS:
search_params = args.GROUPS.split(',')
else:
@@ -97,17 +97,17 @@ def main():
else:
ldapsearch += '"(|'
for i in search_params:
ldapsearch += '(objectClass='+ i +')'
ldapsearch += '(objectClass=' + i + ')'
ldapsearch += ')" uid cn altmail'

ldif = os.popen(ldapsearch).read()
if args.FROM != None and args.SUBJECT != None and args.MSG != None:
if args.FROM is not None and args.SUBJECT is not None and args.MSG is not None:
mailgroup(ldif, args.FROM, args.SUBJECT, args.MSG, args.PRINT)
else:
mailgroup(ldif, '', '', '', args.PRINT)
exit()

if args.MSG != None:
if args.MSG is not None:
with open(args.MSG, 'r') as content:
args.MSG = content.read()



+ 1
- 1
python/not_a_user_db.py Ver ficheiro

@@ -17,7 +17,7 @@ def get_courses(db_name):
return False
return True

#start processing input
# start processing input
if sys.argv[1]:
try:
FILENAME = sys.argv[1]


+ 2
- 2
python/yearspaid_mak_fix.py Ver ficheiro

@@ -14,10 +14,10 @@ def modify_template(user_id):
ldap_dn += "\nchangetype: modify\ndelete: yearsPaid\n\n"
print(ldap_dn)

#open ldif
# open ldif
with open(sys.argv[1], 'r') as content:
LDIF = content.read()
#split by user
# split by user
GETDN = LDIF.split('dn: uid=')
for i in GETDN:
try:


Carregando…
Cancelar
Guardar