forked from public/pyceo
Add CLI version of mysql thing
This commit is contained in:
parent
6f4f0e6621
commit
c0d9e7f3c7
5
bin/ceo
5
bin/ceo
|
@ -8,6 +8,7 @@ from ceo import ldapi, members, library
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
try:
|
try:
|
||||||
|
if len(sys.argv) == 1:
|
||||||
print "Reading config file...",
|
print "Reading config file...",
|
||||||
members.configure()
|
members.configure()
|
||||||
library.configure()
|
library.configure()
|
||||||
|
@ -15,9 +16,11 @@ def start():
|
||||||
print "Connecting to LDAP..."
|
print "Connecting to LDAP..."
|
||||||
members.connect(AuthCallback())
|
members.connect(AuthCallback())
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
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)
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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))
|
||||||
|
|
Loading…
Reference in New Issue