#!/usr/bin/python
# -*- coding: utf-8 -*-
#For debugging purposes only
#import cgitb
#cgitb.enable()
import MySQLdb, sys
#Needs to send these headers
print "Content-Type: text/html; charset=UTF-8"
#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
print """
Available rights
Available user rights
This tool lists all the available user rights per project except the default, global ones
Wiki
Available rights
"""
defaultrights=['bot', 'sysop', 'bureaucrat', 'checkuser', 'steward', 'boardvote', 'import', 'transwiki', 'developer', 'oversight', 'ipblock-exempt', 'confirmed', '']
#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 = cursor.fetchall()
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])
cursor.execute("SELECT DISTINCT ug_group FROM user_groups")
rights=cursor.fetchall()
extra=list(set([r[0] for r in rights])-set(defaultrights))
if extra!=[]:
print """