Add CLI version of mysql thing

This commit is contained in:
Michael Spang 2009-11-02 20:18:55 +00:00
parent 6f4f0e6621
commit c0d9e7f3c7
4 changed files with 52 additions and 8 deletions

17
bin/ceo
View File

@ -8,16 +8,19 @@ from ceo import ldapi, members, library
def start(): def start():
try: try:
print "Reading config file...",
members.configure()
library.configure()
print "Connecting to LDAP..."
members.connect(AuthCallback())
if len(sys.argv) == 1: if len(sys.argv) == 1:
print "Reading config file...",
members.configure()
library.configure()
print "Connecting to LDAP..."
members.connect(AuthCallback())
ceo.urwid.main.start() ceo.urwid.main.start()
else: else:
members.configure()
library.configure()
members.connect(AuthCallback())
ceo.console.main.start() ceo.console.main.start()
except ldap.LOCAL_ERROR, e: except ldap.LOCAL_ERROR, e:
print ldapi.format_ldaperror(e) print ldapi.format_ldaperror(e)

View File

@ -5,15 +5,16 @@ from ceo.console.memberlist import MemberList
from ceo.console.updateprograms import UpdatePrograms from ceo.console.updateprograms import UpdatePrograms
from ceo.console.expiredaccounts import ExpiredAccounts from ceo.console.expiredaccounts import ExpiredAccounts
from ceo.console.inactive import Inactive from ceo.console.inactive import Inactive
from ceo.console.mysql import MySQL
commands = { commands = {
'memberlist' : MemberList(), 'memberlist' : MemberList(),
'updateprograms' : UpdatePrograms(), 'updateprograms' : UpdatePrograms(),
'expiredaccounts' : ExpiredAccounts(), 'expiredaccounts' : ExpiredAccounts(),
'inactive': Inactive(), 'inactive': Inactive(),
'mysql': MySQL(),
} }
help_opts = [ '--help', '-h' ] help_opts = [ '--help', '-h' ]
def start(): def start():
args = sys.argv[1:] args = sys.argv[1:]
if args[0] in help_opts: if args[0] in help_opts:

38
ceo/console/mysql.py Normal file
View File

@ -0,0 +1,38 @@
from ceo import members, terms, mysql
class MySQL:
help = '''
mysql create <username>
Creates a mysql database for a user.
'''
def main(self, args):
if len(args) != 2 or args[0] != 'create':
print self.help
return
username = args[1]
problem = None
try:
password = mysql.create_mysql(username)
try:
mysql.write_mysql_info(username, password)
helpfiletext = "Settings written to ~%s/ceo-mysql-info." % username
except (KeyError, IOError, OSError), e:
helpfiletext = "An error occured writing the settings file: %s" % e
print "MySQL database created"
print ("Connection Information: \n"
"\n"
"Database: %s\n"
"Username: %s\n"
"Hostname: localhost\n"
"Password: %s\n"
"\n"
"%s\n"
% (username, username, password, helpfiletext))
except mysql.MySQLException, e:
print "Failed to create MySQL database"
print
print "We failed to create the database. The error was:\n\n%s" % e

View File

@ -29,6 +29,8 @@ def check_auth(remote_user, mysql_user, response):
if remote_user == mysql_user: if remote_user == mysql_user:
return response_message(response, 0, 'user %s creating database for self' % remote_user) return response_message(response, 0, 'user %s creating database for self' % remote_user)
club = members.get(mysql_user) club = members.get(mysql_user)
if not club:
return response_message(response, errno.EPERM, 'user %s does not exist' % mysql_user)
if 'club' in club.get('objectClass', []): if 'club' in club.get('objectClass', []):
if check_group(remote_user, mysql_user): if check_group(remote_user, mysql_user):
return response_message(response, 0, 'user %s is in club group %s' % (remote_user, mysql_user)) return response_message(response, 0, 'user %s is in club group %s' % (remote_user, mysql_user))