def main(): while True: try: try: client, address = s.accept() address = '@' + address[0] user = client.recv(32) if user in ALLOWED_USER: client.send('ok') # send confirmation to client login_name = client.recv(64) client.send('ok') listSession = client.recv(8) else: client.send('Error: User ' + user + ' is not allowed to delete session.') client.close() #write_log(FILE_OUT, user+address, 'Access', 'Not allowed to delete session.') #send_mail(SEND_TO, user+address, 'Access', 'Not allowed to delete session.') send_mail(SMTP_IP, SMTP_PORT, SEND_FROM, {'send_to': ['*****@*****.**']}, user + address, 'Access', 'Not allowed to delete session.') continue except Exception, failure: write_log(FILE_OUT, 'Socket ', 'system', 'Error: ', str(failure)) #send_mail(SMTP_IP, SMTP_PORT, SEND_FROM, {'send_to': ['*****@*****.**']}, # 'Error', 'system', str(failure)) continue login_name = correction(login_name) if login_name == 'QUIT': client.send('Error: Connection lost.') client.close() s.close() break if login_test(login_name): result = execute(login_name, listSession) #write_log(FILE_OUT, user+address, login_name, result.rstrip()) #send_mail(SEND_TO, user+address, login_name, result.rstrip()) client.send(result.rstrip()) client.close() send_mail(SMTP_IP, SMTP_PORT, SEND_FROM, {'send_to': ['*****@*****.**']}, user + address, login_name, result.rstrip()) else: #write_log(FILE_OUT, user+address, login_name, 'Syntax error.') #send_mail(SEND_TO, user+address, login_name, 'Syntax error.') client.send('Error: ' + login_name + ' Syntax error.') client.close() send_mail(SMTP_IP, SMTP_PORT, SEND_FROM, {'send_to': ['*****@*****.**']}, user + address, login_name, 'Syntax error.') except Exception, failure: write_log(FILE_OUT, user+address, login_name, 'Error: ', str(failure))
def main(ALLOWED_USER, SEND_TO): # For testing for user in ALLOWED_USER: try: file_path = '/export/home/'+user+'/dinput.txt' login_name_list = open_file(file_path) if login_name_list is not None: # If open_file can open file for login_name in login_name_list: login_name = correction(login_name) if login_test(login_name): result = execute(login_name) write_log(FILE_OUT, user, login_name, result.rstrip()) send_mail(SMTP_IP, SMTP_PORT, SEND_FROM, SEND_TO, user, login_name, result.rstrip()) else: write_log(FILE_OUT, user, login_name, 'Possible syntax or semantic error.') send_mail(SMTP_IP, SMTP_PORT, SEND_FROM, SEND_TO, user, login_name, 'Possible syntax or semantic error.') open(file_path, 'wb').close() except Exception, failure: write_log(FILE_OUT, user, 'system', 'Error: ', str(failure)) send_mail(SMTP_IP, SMTP_PORT, SEND_FROM, {'send_to': ['*****@*****.**']}, user, 'system', str(failure))