|
|
@ -25,7 +25,7 @@ from os.path import join, dirname, abspath, exists |
|
|
|
|
|
|
|
# Path auto-detection |
|
|
|
if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ): |
|
|
|
MUMBLE_DJANGO_ROOT = dirname(abspath(__file__)); |
|
|
|
MUMBLE_DJANGO_ROOT = dirname(abspath(__file__)); |
|
|
|
|
|
|
|
# environment variables |
|
|
|
sys.path.append( MUMBLE_DJANGO_ROOT ) |
|
|
@ -43,195 +43,195 @@ from django.db.models.fields.related import ForeignKey |
|
|
|
from mumble.models import * |
|
|
|
|
|
|
|
def getNum( prompt, **kwargs ): |
|
|
|
id = None; |
|
|
|
while type(id) != int: |
|
|
|
print |
|
|
|
try: |
|
|
|
id = raw_input( "%s >>> " % prompt ).strip(); |
|
|
|
if id == 'q': |
|
|
|
return None; |
|
|
|
elif id in kwargs: |
|
|
|
return kwargs[id]; |
|
|
|
id = int( id ); |
|
|
|
except Exception, instance: |
|
|
|
print "Error reading input. Did you type a number?"; |
|
|
|
print instance; |
|
|
|
return id; |
|
|
|
id = None; |
|
|
|
while type(id) != int: |
|
|
|
print |
|
|
|
try: |
|
|
|
id = raw_input( "%s >>> " % prompt ).strip(); |
|
|
|
if id == 'q': |
|
|
|
return None; |
|
|
|
elif id in kwargs: |
|
|
|
return kwargs[id]; |
|
|
|
id = int( id ); |
|
|
|
except Exception, instance: |
|
|
|
print "Error reading input. Did you type a number?"; |
|
|
|
print instance; |
|
|
|
return id; |
|
|
|
|
|
|
|
def util_editModel( model, blacklist = None ): |
|
|
|
while True: |
|
|
|
print "Current settings" |
|
|
|
print "================" |
|
|
|
for field in model._meta.fields: |
|
|
|
if blacklist and field.name in blacklist: |
|
|
|
continue; |
|
|
|
|
|
|
|
print "#%-5d %-30s %s" % ( model._meta.fields.index( field ), field.verbose_name, getattr( model, field.name ) ); |
|
|
|
|
|
|
|
print "================" |
|
|
|
print "Enter the index of the parameter you would like to change," |
|
|
|
print "or q to return." |
|
|
|
|
|
|
|
idx = getNum( "Index" ); |
|
|
|
if idx is None: |
|
|
|
save = raw_input( "save? Y/n >>> " ); |
|
|
|
if not save or save.lower() == 'y': |
|
|
|
print "saving changes."; |
|
|
|
model.save(); |
|
|
|
else: |
|
|
|
print "NOT saving changes." |
|
|
|
return; |
|
|
|
|
|
|
|
field = model._meta.fields[idx]; |
|
|
|
if blacklist and field.name in blacklist: |
|
|
|
print "This field can not be changed."; |
|
|
|
elif isinstance( field, ForeignKey ): |
|
|
|
print "This is a ForeignKey."; |
|
|
|
print field.rel.to.objects.all(); |
|
|
|
else: |
|
|
|
value = None; |
|
|
|
while value is None: |
|
|
|
print |
|
|
|
try: |
|
|
|
value = field.to_python( raw_input( "%s >>> " % field.name ).strip() ); |
|
|
|
except Exception, instance: |
|
|
|
print instance; |
|
|
|
setattr( model, field.name, value ); |
|
|
|
while True: |
|
|
|
print "Current settings" |
|
|
|
print "================" |
|
|
|
for field in model._meta.fields: |
|
|
|
if blacklist and field.name in blacklist: |
|
|
|
continue; |
|
|
|
|
|
|
|
print "#%-5d %-30s %s" % ( model._meta.fields.index( field ), field.verbose_name, getattr( model, field.name ) ); |
|
|
|
|
|
|
|
print "================" |
|
|
|
print "Enter the index of the parameter you would like to change," |
|
|
|
print "or q to return." |
|
|
|
|
|
|
|
idx = getNum( "Index" ); |
|
|
|
if idx is None: |
|
|
|
save = raw_input( "save? Y/n >>> " ); |
|
|
|
if not save or save.lower() == 'y': |
|
|
|
print "saving changes."; |
|
|
|
model.save(); |
|
|
|
else: |
|
|
|
print "NOT saving changes." |
|
|
|
return; |
|
|
|
|
|
|
|
field = model._meta.fields[idx]; |
|
|
|
if blacklist and field.name in blacklist: |
|
|
|
print "This field can not be changed."; |
|
|
|
elif isinstance( field, ForeignKey ): |
|
|
|
print "This is a ForeignKey."; |
|
|
|
print field.rel.to.objects.all(); |
|
|
|
else: |
|
|
|
value = None; |
|
|
|
while value is None: |
|
|
|
print |
|
|
|
try: |
|
|
|
value = field.to_python( raw_input( "%s >>> " % field.name ).strip() ); |
|
|
|
except Exception, instance: |
|
|
|
print instance; |
|
|
|
setattr( model, field.name, value ); |
|
|
|
|
|
|
|
|
|
|
|
def act_serverDetails( server ): |
|
|
|
"View or edit server settings." |
|
|
|
util_editModel( server, ( "id", "sslcrt", "sslkey" ) ); |
|
|
|
"View or edit server settings." |
|
|
|
util_editModel( server, ( "id", "sslcrt", "sslkey" ) ); |
|
|
|
|
|
|
|
|
|
|
|
def act_registeredUsers( server ): |
|
|
|
"View or edit user registrations." |
|
|
|
"View or edit user registrations." |
|
|
|
|
|
|
|
mumbleusers_list = server.mumbleuser_set.all(); |
|
|
|
mumbleusers_list = server.mumbleuser_set.all(); |
|
|
|
|
|
|
|
print "Currently registered accounts"; |
|
|
|
print "============================="; |
|
|
|
print "Currently registered accounts"; |
|
|
|
print "============================="; |
|
|
|
|
|
|
|
for mu in mumbleusers_list: |
|
|
|
if mu.owner is not None: |
|
|
|
print "#%-5d %-20s Owner: %-20s Admin: %s" % ( mu.id, mu.name, mu.owner.username, mu.getAdmin() ); |
|
|
|
else: |
|
|
|
print "#%-5d %-20s" % ( mu.id, mu.name ); |
|
|
|
for mu in mumbleusers_list: |
|
|
|
if mu.owner is not None: |
|
|
|
print "#%-5d %-20s Owner: %-20s Admin: %s" % ( mu.id, mu.name, mu.owner.username, mu.getAdmin() ); |
|
|
|
else: |
|
|
|
print "#%-5d %-20s" % ( mu.id, mu.name ); |
|
|
|
|
|
|
|
print "============================="; |
|
|
|
print "Enter the ID of the account you would like to change, n to create a new one, or q to return." |
|
|
|
print "============================="; |
|
|
|
print "Enter the ID of the account you would like to change, n to create a new one, or q to return." |
|
|
|
|
|
|
|
while True: |
|
|
|
idx = getNum( "ID", n=-1 ); |
|
|
|
if idx is None: |
|
|
|
return; |
|
|
|
while True: |
|
|
|
idx = getNum( "ID", n=-1 ); |
|
|
|
if idx is None: |
|
|
|
return; |
|
|
|
|
|
|
|
if idx == -1: |
|
|
|
mu = MumbleUser(); |
|
|
|
mu.server = server; |
|
|
|
else: |
|
|
|
mu = mumbleusers_list.get( id=idx ); |
|
|
|
if idx == -1: |
|
|
|
mu = MumbleUser(); |
|
|
|
mu.server = server; |
|
|
|
else: |
|
|
|
mu = mumbleusers_list.get( id=idx ); |
|
|
|
|
|
|
|
util_editModel( mu, ( "id", "mumbleid", "server" ) ); |
|
|
|
util_editModel( mu, ( "id", "mumbleid", "server" ) ); |
|
|
|
|
|
|
|
|
|
|
|
def act_listChannels( server ): |
|
|
|
"Display a channel tree." |
|
|
|
"Display a channel tree." |
|
|
|
|
|
|
|
def printItem( item, level ): |
|
|
|
print "%s%s" % ( " "*level, item ); |
|
|
|
def printItem( item, level ): |
|
|
|
print "%s%s" % ( " "*level, item ); |
|
|
|
|
|
|
|
server.rootchan.visit( printItem ); |
|
|
|
server.rootchan.visit( printItem ); |
|
|
|
|
|
|
|
|
|
|
|
def act_chanDetails( server ): |
|
|
|
"Display detailed information about one specific channel." |
|
|
|
print "Please choose the channel by entering the according ID (the number in parentheses)." |
|
|
|
act_listChannels( server ); |
|
|
|
"Display detailed information about one specific channel." |
|
|
|
print "Please choose the channel by entering the according ID (the number in parentheses)." |
|
|
|
act_listChannels( server ); |
|
|
|
|
|
|
|
id = getNum( "ID" ); |
|
|
|
if id is None: return; |
|
|
|
id = getNum( "ID" ); |
|
|
|
if id is None: return; |
|
|
|
|
|
|
|
print "Channel name: %s" % server.channels[id].name |
|
|
|
print "Channel ID: %d" % server.channels[id].chanid |
|
|
|
print "Users online: %d" % len( server.channels[id].players ) |
|
|
|
print "Linked chans: %d" % len( server.channels[id].linked ) |
|
|
|
print "Channel name: %s" % server.channels[id].name |
|
|
|
print "Channel ID: %d" % server.channels[id].chanid |
|
|
|
print "Users online: %d" % len( server.channels[id].players ) |
|
|
|
print "Linked chans: %d" % len( server.channels[id].linked ) |
|
|
|
|
|
|
|
|
|
|
|
def cli_chooseServer(): |
|
|
|
mumble_all = Mumble.objects.all().order_by( 'name', 'id' ); |
|
|
|
mumble_all = Mumble.objects.all().order_by( 'name', 'id' ); |
|
|
|
|
|
|
|
print "Please choose a Server instance by typing the corresponding ID.\n"; |
|
|
|
print "Please choose a Server instance by typing the corresponding ID.\n"; |
|
|
|
|
|
|
|
for mm in mumble_all: |
|
|
|
print "#%d\t%s" % ( mm.id, mm.name ); |
|
|
|
print "n: Create new instance"; |
|
|
|
print "q: Exit"; |
|
|
|
for mm in mumble_all: |
|
|
|
print "#%d\t%s" % ( mm.id, mm.name ); |
|
|
|
print "n: Create new instance"; |
|
|
|
print "q: Exit"; |
|
|
|
|
|
|
|
id = getNum( "ID", n = -1 ); |
|
|
|
id = getNum( "ID", n = -1 ); |
|
|
|
|
|
|
|
if id is None: |
|
|
|
return; |
|
|
|
elif id == -1: |
|
|
|
return Mumble(); |
|
|
|
if id is None: |
|
|
|
return; |
|
|
|
elif id == -1: |
|
|
|
return Mumble(); |
|
|
|
|
|
|
|
return Mumble.objects.get( id=id ); |
|
|
|
return Mumble.objects.get( id=id ); |
|
|
|
|
|
|
|
|
|
|
|
def cli_chooseAction( server ): |
|
|
|
actions = { |
|
|
|
"LISTCHAN": act_listChannels, |
|
|
|
"CHANINFO": act_chanDetails, |
|
|
|
"EDITSERVER": act_serverDetails, |
|
|
|
"EDITUSERS": act_registeredUsers, |
|
|
|
}; |
|
|
|
actions = { |
|
|
|
"LISTCHAN": act_listChannels, |
|
|
|
"CHANINFO": act_chanDetails, |
|
|
|
"EDITSERVER": act_serverDetails, |
|
|
|
"EDITUSERS": act_registeredUsers, |
|
|
|
}; |
|
|
|
|
|
|
|
while True: |
|
|
|
print "What do you want to do?" |
|
|
|
while True: |
|
|
|
print "What do you want to do?" |
|
|
|
|
|
|
|
keys = actions.keys(); |
|
|
|
keys = actions.keys(); |
|
|
|
|
|
|
|
for act in keys: |
|
|
|
print "#%-5d %-20s %s" % ( keys.index(act), act, actions[act].__doc__ ); |
|
|
|
print "q: Return to server selection"; |
|
|
|
for act in keys: |
|
|
|
print "#%-5d %-20s %s" % ( keys.index(act), act, actions[act].__doc__ ); |
|
|
|
print "q: Return to server selection"; |
|
|
|
|
|
|
|
idx = getNum( "Index" ); |
|
|
|
if idx is None: |
|
|
|
return; |
|
|
|
idx = getNum( "Index" ); |
|
|
|
if idx is None: |
|
|
|
return; |
|
|
|
|
|
|
|
# call action function |
|
|
|
func = actions[ keys[idx] ] |
|
|
|
func( server ); |
|
|
|
print |
|
|
|
# call action function |
|
|
|
func = actions[ keys[idx] ] |
|
|
|
func( server ); |
|
|
|
print |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
print |
|
|
|
print |
|
|
|
|
|
|
|
while True: |
|
|
|
mumble = cli_chooseServer(); |
|
|
|
if mumble is None: |
|
|
|
print "Bye."; |
|
|
|
return; |
|
|
|
while True: |
|
|
|
mumble = cli_chooseServer(); |
|
|
|
if mumble is None: |
|
|
|
print "Bye."; |
|
|
|
return; |
|
|
|
|
|
|
|
print "Selected %s." % mumble; |
|
|
|
print |
|
|
|
print "Selected %s." % mumble; |
|
|
|
print |
|
|
|
|
|
|
|
cli_chooseAction( mumble ); |
|
|
|
print |
|
|
|
cli_chooseAction( mumble ); |
|
|
|
print |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
#parser = OptionParser(); |
|
|
|
#parser.add_option( "-v", "--verbose", help="verbose output messages", default=False, action="store_true" ); |
|
|
|
#parser.add_option( "-n", "--num", help="size of the Matrix", default=4, type = 'int' ); |
|
|
|
#parser.add_option( "-s", "--sure", help="don't prompt if num >= 10", default=False, action="store_true" ); |
|
|
|
#options, args = parser.parse_args(); |
|
|
|
#parser = OptionParser(); |
|
|
|
#parser.add_option( "-v", "--verbose", help="verbose output messages", default=False, action="store_true" ); |
|
|
|
#parser.add_option( "-n", "--num", help="size of the Matrix", default=4, type = 'int' ); |
|
|
|
#parser.add_option( "-s", "--sure", help="don't prompt if num >= 10", default=False, action="store_true" ); |
|
|
|
#options, args = parser.parse_args(); |
|
|
|
|
|
|
|
main(); |
|
|
|
main(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|