User Tools

Site Tools


Writing /var/lib/dokuwiki/data/meta/teaching/ie0117/proyectos/2012/i/metodos_de_configuracion_del_sistema.meta failed
teaching:ie0117:proyectos:2012:i:metodos_de_configuracion_del_sistema

Métodos de configuración del sistema

def mail_list_menu():

while True:
	os.system('clear')
	show_basic_mail_list()
	mode=utilities.getInt('\nADMIN MAIL LIST\n\nSelect your choice:\n1.Add mail\n2.Remove mail\n3.Show details\n\n0.Back\n\nChoice:',0,3)
	if mode==1:
		add_mail(str(raw_input('New mail address:')),str(raw_input('LastName:')), str(raw_input('FirstName:')))
	elif mode==2:
		del_mail(str(raw_input('New mail address:')))
	elif mode==3:
		show_full_mail_list()
	elif mode==0:
		break
	os.system('clear')

def add_mail(address, fname, lname):

connection_name = MySQLdb.connect(host='localhost', user='root', passwd='K0p!r1nn4', db='DSS')
cursor = connection_name.cursor()
result = cursor.execute("INSERT INTO MAIL_LIST (Mail, LastName, FirstName) VALUES ('%s' , '%s', '%s');" % (address,lname,fname))
connection_name.commit()
return result

def del_mail(address):

connection_name = MySQLdb.connect(host='localhost', user='root', passwd='K0p!r1nn4', db='DSS')
cursor = connection_name.cursor()
result = cursor.execute(" DELETE FROM MAIL_LIST WHERE Mail='%s';" % (address))
connection_name.commit()
return result

def show_basic_mail_list():

connection_name = MySQLdb.connect(host='localhost', user='root', passwd='K0p!r1nn4', db='DSS')
cursor = connection_name.cursor()
cursor.execute("SELECT * FROM MAIL_LIST;")
data= cursor.fetchall()
mail_list= []
for i in xrange(len(data)):
		mail_list.append(data[i][0])
print 'Current mail list\n' 
for i in xrange(len(mail_list)):
	print str(mail_list[i])

def show_full_mail_list():

connection_name = MySQLdb.connect(host='localhost', user='root', passwd='K0p!r1nn4', db='DSS')
cursor = connection_name.cursor()
cursor.execute("SELECT * FROM MAIL_LIST;")
data= cursor.fetchall()
mail_list= [[] for k in xrange(len(data))]
for j in xrange(len(data)):
	for i in xrange(len(data[0])):
			mail_list[j].append(data[j][i])
			
os.system('clear')
print 'Current List Details:\n'
print '{}				{}		{}'.format('Mail', 'LastName','FirstName')
for j in xrange(len(data)):
	print '{}			{}			{}'.format(mail_list[j][0],mail_list[j][1] ,mail_list[j][2])
print '\n'
	
print '\n'
raw_input("\nPress Enter to continue...")
	
	

# Users list functions

def user_accounts_menu():

while True:
	os.system('clear')
	show_basic_users_list()
	mode=utilities.getInt('\nADMINISTRATE USER LIST\n\nSelect your choice:\n1.Add user\n2.Remove user\n3.Change password\n\n0.Back\n\nChoice:',0,3)
	if mode==1:
		add_user(raw_input('ID:'),str(raw_input('LastName:')), str(raw_input('FirstName:')) , str(raw_input('Job:')) ,str(raw_input('Pivilege Level (0 or 1):')), str(raw_input('Password:')))
	elif mode==2:
		del_user(str(raw_input('User ID:')))
	elif mode==3:
		change_pass(str(raw_input('User ID:')), getpass.getpass('New password:'))
	elif mode==0:
		break
	os.system('clear')	

def add_user(ID, fname, lname, job, privilege,password):

connection_name = MySQLdb.connect(host='localhost', user='root', passwd='K0p!r1nn4', db='DSS')
cursor = connection_name.cursor()
key_file=open("system_key", "r")
passphrase=key_file.readline(44)
result = cursor.execute("INSERT INTO USERS (ID, FirstName, Last Name, Job, Privilege, Password) VALUES (%s,'%s','%s','%s',%s, AES_ENCRYPT('%s','%s'));" % (ID, lname, fname, job, privilege, password , passphrase))
connection_name.commit()
return result

def del_user(ID):

connection_name = MySQLdb.connect(host='localhost', user='root', passwd='K0p!r1nn4', db='DSS')
cursor = connection_name.cursor()
result = cursor.execute(" DELETE FROM USERS WHERE ID=%s;" % (ID))
connection_name.commit()
return result

def change_pass(ID, new_pass):

connection_name = MySQLdb.connect(host='localhost', user='root', passwd='K0p!r1nn4', db='DSS')
cursor = connection_name.cursor()
key_file=open("system_key", "r")
passphrase=key_file.readline(44)
result = cursor.execute("UPDATE USERS SET password = AES_ENCRYPT('%s','%s') WHERE ID=%s;" % (new_pass, passphrase, ID))
connection_name.commit()
return result

def show_basic_users_list():

connection_name = MySQLdb.connect(host='localhost', user='root', passwd='K0p!r1nn4', db='DSS')
cursor = connection_name.cursor()
cursor.execute("SELECT * FROM USERS;")
data= cursor.fetchall()
users= [[] for k in xrange(len(data))]
for j in xrange(len(data)):
	for i in xrange(len(data[0])):
			users[j].append(data[j][i])
os.system('clear')
print 'Current Users Details:' 
print '{}		{}		{}		{}'.format('ID', 'LastName','FirstName','Job')
for j in xrange(len(data)):
	print '{}		{}			{}			{}'.format(users[j][0],users[j][1] ,users[j][2] ,users[j][3])
print '\n'

def product_list_menu():

while True:
	os.system('clear')
	mode=utilities.getInt('PRODUCT LIST MENU\n\nSelect your choice:\n1.Add product from list\n2.Remove product from list\n3.Refresh product popularity\n\n0.Back\n\nChoice:',0,4)
	if mode==1:
		add_product_to_list(raw_input('Family:'),str(raw_input('Product name:')), str(raw_input('Price:')))
	elif mode==2:
		del_product_from_list(str(raw_input('Product name:')))
	elif mode==3:
		change_price(str(raw_input('Product name:')))
	elif mode==4:
		refresh_popularity()
	elif mode==0:
		break
	os.system('clear')

def add_product_to_list(family, name, price):

print 'Under Construction!'
time.sleep(3)

def del_product_from_list(name):

print 'Under Construction!'
time.sleep(3)

def change_price():

print 'Under Construction!'
time.sleep(3)

def refresh_popularity():

print 'Under Construction!'
time.sleep(3)

def check_existence():

con = MySQLdb.connect('localhost', 'root', 'K0p!r1nn4', 'PRODUCTS');
cursor.execute("SELECT COUNT(*) FROM productos;")
data= cursor.fetchall()

print data
cur = con.cursor()
#for i in xrange (data)
cur.execute("UPDATE productos SET ExistenciaUnidad1 = InventarioUnidad1 - UnidadesVendidas") 	
teaching/ie0117/proyectos/2012/i/metodos_de_configuracion_del_sistema.txt · Last modified: 2022/09/20 00:08 (external edit)