Browse Source

add scripts

pull/10/head
Cian Butler 4 years ago
parent
commit
b671b22dd1
12 changed files with 636 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +148
    -0
      install-manual.txt
  3. +3
    -0
      reuser/README
  4. +4
    -0
      reuser/editme
  5. +15
    -0
      scripts/fixuidNumber.py
  6. +7
    -0
      scripts/generate_noob_list.sh
  7. +15
    -0
      scripts/getnewbemails.pl
  8. +22
    -0
      scripts/getuids.pl
  9. +10
    -0
      scripts/ldif_founder_soc_fix.py
  10. +49
    -0
      scripts/newyear_ldapmodify_ldif.py
  11. +78
    -0
      scripts/vote.py
  12. +283
    -0
      scripts/voting.pl

+ 2
- 0
.gitignore View File

@@ -93,3 +93,5 @@ ENV/

# Rope project settings
.ropeproject

tmp

+ 148
- 0
install-manual.txt View File

@@ -0,0 +1,148 @@

Installation Manual:
RedBrick Registration System

Cillian Sharkey, CASE3, 50716197
1. Introduction
2. Pre-requisites
1. Requirements for all setups
2. Requirements for main setup
3. Requirements for web setup
3. Installation
1. Installing software
2. Setting up database
4. Configuration

Introduction

There are essentially two kinds of setups for RRS:
* Main setup - this is the setup of the machine where the user database and accounts permanently reside. There is at a minimum, full use of useradm for both database and
account administration.
* Web setup - this is the machine used for hosting the clubs & societies day system. Full use of the rrs cgi for database administration and limited use of useradm for
database only administration.

Note that the web setup could also be used on the main setup, so that full use of useradm and the rrs cgi would be available.

The installation requirements and steps below will indicate if they only pertain to one of the given setups ('main' or 'web') above, otherwise it can be assumed that they are
required for both types of setup.

It is also worth noting that much of RRS is very specific to the RedBrick and DCU environment and so as such is not designed for widespread use on generic machines. The web
setup mentioned above however, is not as specific in its requirements and is intended to be reasonably 'portable'.

Pre-requisites

Requirements for all setups

Platform

RRS is designed primarily to run on a Unix platform however, it should be possible to run the web interface part on a non-Unix platform although this has not been tested. Note
that root (superuser) access is required for performing any account or filesystem operations with useradm, everything else can be performed using a user / unprivileged account
(assuming it has access to the user database).

PostgresSQL

PostgresSQL version 7.2 or higher must be installed. Details on doing this vary depending on the operating system and is outside the scope of this document however, full
instructions can be found on the PostgresSQL website.

Python

Python version 2.2 or higher must be installed. Details on doing this vary depending on the operating system and is outside the scope of this document however, full
instructions can be found on the Python website.

The following Python modules are included in the standard Python release, but may need to be installed or configured to work:
* readline - provides command line editing and completion functionality for useradm. Requires GNU readline to be installed.

The following additional 3rd party Python modules must be installed:
* PyGresSQL - Python interface to PostgresSQL database. Note that this is actually included in the PostgresSQL database release, however ensure that version 3.2 or later is
installed.
* Python-LDAP - a Python interface to LDAP. Requires OpenLDAP to be installed. Tested with Python-LDAP version 1.10alpha3 and OpenLDAP 1.2.13. This module is currently only
used by rebuild_userdb_student and the rebuild_userdb_staff scripts.

Requirements for main setup

Account utilities

The account utilities useradd, usermod and userdel need to be installed. Typically, these are provided as part of the native operating system and have been found to have a
consistent interface on Solaris, Linux and NetBSD.

Setquota

The 3rd party utility setquota must be installed for the manipulation of disk quotas. There appear to be a number of implementations of this command each with different command
line syntax for different operating systems. Tested with a setquota utility for Solaris written by David Mitchell of Dept of Computer Science, Sheffield University.

Mailman

RRS automatically subscribes (and unsubscribes) users to a variety of RedBrick mailing lists, specifically the announce-redbrick, redbrick-newsletter, comittee, rb-admins and
admin-discuss lists. For this reason the mailing list software Mailman should be installed with the above mentioned lists created and working. It is not entirely necessary
however as "dummy" scripts can be used in place of the add_members and remove_members mailman commands.

Mail Transfer Agent

Any MTA that provides the generic sendmail command line interface will suffice, e.g. Exim, Postfix, Sendmail, etc.

Requirements for web setup

Apache

A web server is required for the rrs cgi. Web servers other than Apache should work as the CGI standard is web server independant. Tested against Apache 1.3.26.

Installation

Installing software

The installation of RRS simply involves unpacking the RRS distribution tarball in a filesystem location of your choosing. Say you have downloaded the tarball to
/tmp/rrs.tar.gz. Installation to the directory /usr/local/rrs is as follows:
# cd /usr/local
# tar zxf /tmp/rrs.tar.gz

Setting up database

A database userdb needs to be created with the postgres command "createdb userdb" run as the postgres user. For the account setup, the root user will need access to the
database. For the web setup, the user the web server runs as will need access to the database. This is achieved by first creating the users if they don't already exist with the
postgres createuser command and making sure that postgres is setup to grant access to the userdb database for these users by appropriate editing of the pg_hba.conf and possibly
pg_ident.conf files.

Creating database [main setup]

This step sets up a new database from scratch.

Create the tables for the database:
main$ cat userdb_reserved.sql userdb_staff.sql userdb_students.sql \
userdb_usertypes.sql userdb_users.sql | psql userdb

Make sure that access to these tables is granted to all users who need it. The above scripts include full access for root and SELECT (read only) access for users www and
webgroup as this is the default used on the RedBrick system.

Then populate the student, staff and reserved tables by running each of the rebuild scripts, e.g:
main$ ./rebuild_userdb_reserved
userdb/reserved: Purge. Populate. Done [45]
main$ ./rebuild_userdb_students
userdb/students: Search [19523]. Purge. Populate. Done [19436/19523].
main$ ./rebuild_userdb_staff
userdb/staff: Search [1829]. Purge. Populate. Done [397/1829].

Creating database [web setup]

If the web setup is on a seperate machine to the main system machine, the database must be copied across. This can be achieved as follows:
main$ pg_dump -f userdb.dump userdb
[copy file userdb.dump to the web machine]
web$ psql userdb < userdb.dump

You will need to grant full access to the users table to the user the web server runs as. The "GRANT ALL ON users TO username" SQL command achieves this when run as the owner
of the userdb.

An empty rrs.log file needs to be created before any actions can be performed with the web interface. This can be achieved by:
[create rrs.log in directory that rrs is installed]
web$ touch rrs.log
[make sure web server user can write to file]
web$ chown www rrs.log

Configuration

Local configuration can be performed by editing the rbconfig.py file. The majority of this configuration file is for providing local account and filesystem location paths to
the rbaccount module. The defaults provided are of course suited for the RedBrick system.

At this point, all necessary installation and configuration should be complete for use of RRS.
___________________________________________________________________________________________________________________________________________________________________________

$Id: install-manual.html,v 1.1 2003/03/28 16:33:07 cns Exp $

+ 3
- 0
reuser/README View File

@@ -0,0 +1,3 @@
Change the username to users name and run the following

ldapmodify -x -D cn=root,ou=ldap,o=redbrick -y /etc/ldap.secret -f editme

+ 4
- 0
reuser/editme View File

@@ -0,0 +1,4 @@
dn: uid=shivo,ou=accounts,o=redbrick
changetype: modify
replace: loginShell
loginShell: /usr/local/shells/zsh

+ 15
- 0
scripts/fixuidNumber.py View File

@@ -0,0 +1,15 @@
#! /usr/bin/env python

from rbuserdb import *
udb = RBUserDB()
udb.connect()
fd, n = udb.uidNumber_getnext()
for line in sys.stdin:
if line == 'uidNumber: -1\n':
print 'uidNumber:', n
n += 1
else:
print line,

udb.uidNumber_savenext(fd, n)
udb.uidNumber_unlock(fd)

+ 7
- 0
scripts/generate_noob_list.sh View File

@@ -0,0 +1,7 @@
#!/bin/bash

noobs=`/srv/admin/scripts/rrs/useradm list_newbies`

for noob in $noobs; do
echo $noob@redbrick.dcu.ie >> noob_list.txt
done

+ 15
- 0
scripts/getnewbemails.pl View File

@@ -0,0 +1,15 @@
#!/usr/bin/perl
use warnings;
use strict;

open NEWBS,"newbies";
my @newbies = <NEWBS>;
close NEWBS;

foreach(@newbies) {
chomp;
my $altmail_line = `/local/admin/scripts/rrs/useradm show $_ | grep altmail`;
$altmail_line =~ m/altmail:\s(\S*?)\n/igs;
print $1. "\n";
}


+ 22
- 0
scripts/getuids.pl View File

@@ -0,0 +1,22 @@
#!/usr/bin/perl
use warnings;
use strict;

open USERLIST,"userlist";
my @users = <USERLIST>;
close USERLIST;

foreach my $user(@users) {
chomp $user;
my @info = `/local/admin/scripts/rrs/useradm show $user`;

# get uidNumber
my $uidNumber;
foreach my $infoline(@info) {
if($infoline =~ /uidNumber: (\d*)/) {
$uidNumber = $1;
}
}
print $uidNumber . "\n";
}


+ 10
- 0
scripts/ldif_founder_soc_fix.py View File

@@ -0,0 +1,10 @@
#!/usr/bin/python
import sys
for i in sys.stdin:
i = i.rstrip()
if i.startswith("yearsPaid:"):
print "yearsPaid:", int(i.split()[1]) + 9
elif i.startswith("newbie:"):
print "newbie: FALSE"
else:
print i

+ 49
- 0
scripts/newyear_ldapmodify_ldif.py View File

@@ -0,0 +1,49 @@
#!/usr/bin/python
import sys,string

"""
-mak
This simply takes the ldif generated by newyear_ldif.py
and builds it into an ldapmodify formatted ldif.

To be used with the ldap modify query below
ldapmodify -x -D cn=root,ou=ldap,o=redbrick -y /etc/ldap.secret -f [LDIF_FROM_THIS_SCRIPT]
"""

yearsPaid = ''
uid = ''

#print modify ldif template
def modifyTemplate(uid,yearsPaid,newbie,reserved):
if uid != '' and yearsPaid != '' and reserved == False:
modTemp = "dn: uid="+uid.strip()+"\nchangetype: modify\nreplace: yearsPaid\nyearsPaid: "+yearsPaid.strip()+"\n"
if newbie == '1':
modTemp += "-\nreplace: newbie\nnewbie: FALSE\n\n"
else:
modTemp += "\n"
print modTemp

#open ldif
with open(sys.argv[1], 'r') as content:
ldif = content.read()
#split by user
getdn = string.split(ldif, 'dn: uid=')
for i in range(1,len(getdn)):
thisdn = getdn[i].split('\n')
newbie = 'NONE'
reserved = False
#split by users variables
for j in range(0,len(thisdn)):
x = thisdn[j].rstrip()
uid = thisdn[0].rstrip()
if 'reserved' in uid:
reserved = True
try:
if x.startswith("yearsPaid:"):
yearsPaid = str(int(x.split()[1])).strip()
elif x.startswith("newbie:"):
newbie = '1'
else: continue
except IndexError:
break
modifyTemplate(uid,yearsPaid,newbie,reserved)

+ 78
- 0
scripts/vote.py View File

@@ -0,0 +1,78 @@
#!/usr/bin/python

import sys
import readline
import re
import os

from rbuser import *
from rbuserdb import *

voteregister= 'voted.txt'

#-----------------------------------------------------------------------------#
# MAIN #
#-----------------------------------------------------------------------------#

def main():
"""Program entry function."""

voted = {}

if os.path.exists(voteregister):
fd = open(voteregister, 'r')
for line in fd.readlines():
voted[line.rstrip()] = 1
fd.close()

fd = open(voteregister, 'a')

udb = RBUserDB()
udb.connect()

while 1:
usr = RBUser()
tmp = None
while not tmp:
tmp = raw_input("Please enter Username/Student ID/Student Card: ")
res = re.search(r'\D*\d{2}(\d{8})\d{3}\D*', tmp)
if res:
usr.id = int(res.group(1))
print 'CARD', usr.id
else:
res = re.search(r'^(\d{8})$', tmp)
if res:
usr.id = int(tmp)
print 'ID', usr.id
try:
if usr.id:
udb.get_user_byid(usr)
udb.show(usr)
else:
usr.uid = tmp
udb.get_user_byname(usr)
udb.show(usr)
except RBError:

print 'NO SUCH USER YOU FUCKING DICKHEAD'
else:
if voted.has_key(usr.uid):
print '\nGO FUCK YOUSELF YOU TWO-VOTING PRICK\n'
continue

if usr.usertype not in ('member', 'committe', 'staff'):
print '\nTELL THE COCKMUCH TO GET A REAL MEMBER ACCOUNT\n'
elif usr.yearsPaid <= 0:
print '\nTELL THE SCABBY BASTARD TO PISS OFF\n'
else:
fd.write('%s\n' % usr.uid)
fd.flush()
voted[usr.uid] = 1
print '\nBIG VOTE GO NOW!\n'

fd.close()
sys.exit(0)

if __name__ == "__main__":
main()


+ 283
- 0
scripts/voting.pl View File

@@ -0,0 +1,283 @@
#!/usr/bin/perl

# Perl Sucks The Proverbial Donkey Dick.

use POSIX;

$USERDB = "./users";
$AUTOFLUSH = 1;
$CLEAR = `clear`;
$LINE = "===========================================\n";
$LOG = "./voters.log";
$COLORS = 1;

my %stats;

print $CLEAR;
print "Redbrick voting system\n";
print $LINE;
print "Reading userdb...";
open(IN, $USERDB) or error("Could not open userdb");

my %users;
my %registered;

%usertypes = (100 => 'committe', 103 => 'member', 109 => 'staff', 107 => 'associat', 108 => 'guest');
$total = 0;
$user = "";
$usertype = "";
$yearsPaid = "";
$id = "";
$email = "";
$cn = "";

foreach $line (<IN>)
{
if ($line =~ /^dn: uid=(.+),ou=accounts,o=redbrick/) {
$user = $1;
#print "\n$1|";
} elsif ($line =~ /^\s*$/) {
if ($user and $yearsPaid > 0 and ($usertype eq "member" or $usertype eq "staff" or $usertype eq "committe")) {
$total++;
#print "\n|$user|$yearsPaid|$id|$usertype|$cn|$email\n";
my @tmp = ($user, $usertype, $cn, '', $email, $id, '', '', $yearsPaid);
$users{$id} = \@tmp;
}
$user = "";
} elsif ($user) {
if ($line =~ /^gidNumber: (.+)$/) {
#print "$1|";
$usertype = $usertypes{$1} or "non-voter";
} elsif ($line =~ /^yearsPaid: (.+)$/) {
#print "$1|";
$yearsPaid = $1;
} elsif ($line =~ /^cn: (.+)$/) {
#print "$1|";
$cn = $1;
} elsif ($line =~ /^id: (.+)$/) {
#print "$1|";
$id = $1;
} elsif ($line =~ /^altmail: (.+)$/) {
#print "$1|";
$email = $1;
}
}
}

$quorom = ceil(sqrt($total));

close IN;
print "done\n";

if(-e $LOG)
{


while(!($ans =~ /^[yY]/) and !($ans =~ /^[nN]/))
{
print "\nA voting log has been found, do you want to register all the voters\nfrom this log? [Y/N]: ";
$ans = <STDIN>
}

if($ans =~ /^[yY]/)
{
readStatus();
}
else
{
system("rm $LOG") and warning("Could not remove voter log");
}
}

do
{
print "Please enter a student number/card-swipe/username: ";
$input = <STDIN>;
chomp $input;
print $CLEAR;

if($input =~ /^\;\d{13}\?$/)
{
# Read the format the Redbrick Magreader produces
$input = substr($input, 3, 8);
}
elsif(!($input =~ /^\d{8}$/))
{
# Read a username
# Search database for the user
foreach $key (keys %users)
{
if($users{$key}[0] eq "$input")
{
$input = $key;
last;
}
}
}
# At this stage if I don't have the student number something bad
# has happened
if($input =~ /^\d{8}$/)
{
printDetails($input);
checkEligibility($input);
if(!exists($registered{$input}))
{
saveStatus($input);
doStats($input);
}
else
{
warning("Duplicate entry");
}
printStats();
$registered{"$input"} = 1;
}
else
{
warning("Invalid entry or entry not found");
printStats();
}
}
while(1);

#================ SUBROUTINES ==================#

sub trim($)
{
$input = $_[0];
$input =~ s/^\s+//;
$input =~ s/\s+$//;
return $input;
}

sub printStats()
{
print $LINE;
foreach $type ("member", "committe", "staff", "associat", "guest")
{
print ("$type: " . ($stats{"$type"} or 0). "\n");
}
print $LINE;

print ("Paid eligible voters: " . (($stats{"member"} + $stats{"staff"} + $stats{"committe"}) or 0) . "\n");
print ("Quorom: $quorom\n");
}

sub doStats($)
{
$input = $_[0];
if(exists($users{"$input"}))
{
@bits = @{$users{"$input"}};
$usertype = lc($bits[1]);
$stats{"$usertype"}++ if($usertype ne "");
}
}

sub printDetails($)
{
unless(exists $users{$_[0]} and ref($users{$_[0]}) eq "ARRAY")
{
warning("User is not a redbrick member");
return 0;
}
@bits = @{$users{$_[0]}};
print $LINE;
print "Username: $bits[0]\n";
print "Realname: $bits[2]\n";
print "Usertype: $bits[1]\n";
print "Email: $bits[4]\n";
print "Years paid: $bits[8]\n";
print "Number: $bits[5]\n";
print $LINE;
}

sub saveStatus($)
{
$id = "$_[0]";
if(exists($users{$id}))
{
@bits = @{$users{$id}};
open(OUT, ">>$LOG");
print OUT "$bits[5] $bits[0]\n";
close OUT;
}
}

sub readStatus
{
open(IN, "<$LOG") or return 0;
foreach $line (<IN>)
{
chomp $line;
if($line =~ /\s*(\d{8})\s/)
{
if(!exists($registered{$1}))
{
doStats($1);
$registered{$1} = 1;
}
else
{
warning("Duplicate student number found in log file!");
}
}
}
close IN;
printStats();
return 1;
}

sub checkEligibility($)
{
@details = @{$users{$_[0]}};
$failure = "";
if(!(exists($users{$_[0]})))
{
$failure .= "(Not member) "
}
else
{
if($details[8] <= 0)
{
$failure .= "(Not paid up) ";
}

unless((lc($details[1]) eq "member" or lc($details[1]) eq "staff" or lc($details[1]) eq "committe"))
{
$failure .= "(Wrong usertype)";
}
}

if($COLORS) {
print ("Vote: " . ($failure eq "" ? "YES\n" : "NO $failure\n"));
}
else {
print ("Vote: " . ($failure eq "" ? "YES\n" : "NO $failure\n"));
}
}

sub error($)
{
die($_[0]);
}

sub warning($)
{
if($COLORS)
{
print "WARNING: $_[0]\n";
}
else
{
print "WARNING: $_[0]\n";
}
}

Loading…
Cancel
Save