#!/usr/bin/python # -*- coding: utf-8 -*- #For debugging purposes only #import cgitb #cgitb.enable() import cgi, MySQLdb, sys, urllib #Needs to send these headers print "Content-Type: text/html; charset=UTF-8" #Default data stew = False Quser = "" #Handle args f = cgi.FieldStorage() if f.has_key('user'): Quser = f['user'].value if f.has_key('steward'): if f['steward'].value.lower()=="true": stew=True if Quser!="": Quser = Quser[0].upper() + Quser[1:] #DBdata file=open('/data/project/rightstool/replica.my.cnf', 'r') lista=[l.strip("\n") for l in file.readlines()[1:]] file.close() SQLuser=lista[0].split("=")[1].strip("'") SQLpasswd=lista[1].split("=")[1].strip("'") #Generate some html if stew: checked=" checked " else: checked=" " print """ User rights
Username:
""" % (sys.argv[0].replace("/data/project/rightstool/public_html//cgi-bin/", "").replace(".py", ""), Quser, checked) #Do only if the user has been specified if Quser!="": #Getting the wiki list db = MySQLdb.connect(db='meta_p', host="metawiki.labsdb", user=SQLuser, passwd=SQLpasswd) cursor = db.cursor() cursor.execute("SELECT dbname, slice, url FROM wiki WHERE url IS NOT NULL ORDER BY dbname") #wikis=[[i[0], i[1], i[2]] for i in cursor.fetchall()] wikis = cursor.fetchall() #Some more HTML print """

User rights for %s

""" % Quser dbhost = ""; #Getting the data from MySQL for wiki in wikis: try: if wiki[1] != dbhost: db.close() dbhost = wiki[1] db = MySQLdb.connect(host=dbhost, user=SQLuser, passwd=SQLpasswd) cursor = db.cursor() cursor.execute("USE %s_p;" % wiki[0]) sql = "SELECT ug_group FROM user, user_groups WHERE user_name='%s' AND user_id=ug_user;" % Quser.replace("'", "\\'") cursor.execute(sql) result = cursor.fetchall() rights=[result[i][0] for i in range(0, len(result))] if stew: tabrig=u'%s' % (urllib.quote(Quser), wiki[0], u', '.join(rights)) else: tabrig=u", ".join(rights) if rights!=[]: print """""" % (wiki[2].replace("http://", "https://"), wiki[0], tabrig) except Exception as e: print e; db.close() print """
WikiRights
%s %s
""" print """"""