Re: [SOGo] Delete users from database

2011-06-08 Thread Paul van der Vlis
Op 07-06-11 23:47, Alan Bover schreef:
 Hi, I missed an utility in SOGo for delete the users from the database (for
 example, if a user-account gets corrupted, or a user leaves a company, etc).
 That's why I created a simple python script that I share with you. For run it,
 MySQLdb module for python needs to be installed.

Nice!  Just what I need ;-)

But it's an interactive shell and I would like to give direct commands.
This works in a bash script:

sogodel EOD
user delete $user
exit
EOD
echo


And because I also use mysql authentication, I needed this too:

mysql EOD
use sogo;
DELETE FROM sogo_users WHERE c_uid=$user;
EOD
---

With regards,
Paul van der Vlis.



-- 
Linux systeembeheer Groningen
http://www.vandervlis.nl

-- 
users@sogo.nu
https://inverse.ca/sogo/lists


[SOGo] Delete users from database

2011-06-07 Thread Alan Bover
Hi, I missed an utility in SOGo for delete the users from the database (for
example, if a user-account gets corrupted, or a user leaves a company, etc).
That's why I created a simple python script that I share with you. For run it,
MySQLdb module for python needs to be installed.

Caution! That script have been tested only with sogo 1.3.7!

#!/usr/bin/python
# By: Alan Bover Argelaga

import MySQLdb

usage = \n Help: \n user list \t \t \t list the users in the database \n user
delete user \t \t Delete user from the database \n exit \t \t \t \t Exit the
script \n 

def user(action):
def user_delete(user):
global db
cursor = db.cursor()
cursor.execute( SELECT c_location, c_quick_location,
c_acl_location FROM sogo_folder_info WHERE c_path2 = %s, (user,))
if cursor.rowcount  0:
result=cursor.fetchall()
for user_tables in result:
user_tables_for_delete =
[user_tables[0].partition('sogo/')[2],user_tables[1].partition('sogo/')[2],user_tables[2].partition('sogo/')[2]]
for user_table_for_delete in
user_tables_for_delete:
cursor.execute(DROP TABLE IF EXISTS 
+ user_table_for_delete)
cursor.execute(DELETE FROM sogo_user_profile WHERE
c_uid = %s, (user,))
cursor.execute(DELETE FROM sogo_folder_info WHERE
c_path2 = %s, (user,))
print User  + user +  has been deleted 

else:   
print User  + user +  cannot be found in database

def user_list():
global db
cursor = db.cursor()
cursor.execute(SELECT c_uid FROM sogo_user_profile;)
result=cursor.fetchall()
for existing_user in result:
print existing_user[0]
def user_help():
global usage
print %s % usage

action_func = { delete:   user_delete,
list: user_list   }

order = action.partition( )
if order[0] == delete:
action_func[order[0]](order[2])
elif order[0] == list:
action_func[order[0]]()
else:
user_help()

def quit():
print quit

exit = False
try: 
databaseuser = raw_input(Database user: )
database = raw_input(Database name: )
password = raw_input(Database password: )
db =
MySQLdb.connect(host='localhost',user=databaseuser,passwd=password,db=database)

except MySQLdb.Error, e:
print Database conection error
print e.args[1]
exit = True

while not exit:
entrada = raw_input( )
order = entrada.partition( )
if order[0] == user:
user(order[2])
else:
if entrada == exit:
exit = True
else :
print %s % usage
-- 
users@sogo.nu
https://inverse.ca/sogo/lists


Re: [SOGo] Delete users from database

2011-06-07 Thread Alan Bover
Sorry, I realized that the code here lose the format.

You can acces it on:

http://pastebin.com/SLKgxJDS
-- 
users@sogo.nu
https://inverse.ca/sogo/lists