def write_pw_from_old_group_to_new_group_and_send_email_to_student(matrnr, old_group_name, new_group_name): ssh_password = Config.get_ovid_ssh_password() git_dir_path = Config.get_ovid_git_dir_path() old_group_dir = 'g' + old_group_name new_group_dir = 'g' + new_group_name old_group_pw_file = old_group_dir + '/.passwd' new_group_pw_file = new_group_dir + '/.passwd' student = 's' + str(matrnr) command_list = [ 'cd ' + git_dir_path, 'echo ' + ssh_password + ' | sudo -S chmod 666 ' + old_group_pw_file, 'sudo chmod 666 ' + new_group_pw_file, 'sudo grep ' + student + ' ' + old_group_pw_file + ' >> ' + new_group_pw_file, 'sudo chmod 755 ' + old_group_pw_file, 'sudo chmod 755 ' + new_group_pw_file, 'sudo chmod 666 ' + old_group_pw_file, "sudo sed -i '/" + student + "/d' " + old_group_pw_file, 'sudo chmod 755 ' + old_group_pw_file, ] result = send_commands_to_ovid(command_list) if str(result['exit_status']) == '0': email_subject = 'GDI: Zugangsdaten für Ihr Repository in Eclipse' student_email_address = str(matrnr) + Config.get_email_default_email_domain_students() email_text = \ 'Die URI Ihres Repositorys: http://' + Config.get_ovid_ssh_host_name() + '/git/' + new_group_dir + '/' + new_group_dir + '.git\n' \ + 'Ihr Account-Name: ' + student + '\n' \ + 'Ihr Passwort: Ist gleich geblieben!\n' Emails.sendMailWithTextBody(student_email_address, email_subject, email_text) if Config.get_behavior_send_ovid_information_email(): Emails.sendMailWithTextBody(Config.get_ovid_administrator_email_address(), 'REMINDER: ' + email_subject, 'Student ' + str( matrnr) + ' wechselt von Gruppe ' + old_group_name + ' (' + git_dir_path + old_group_pw_file + ') zur Gruppe ' + new_group_name + ' (' + git_dir_path + new_group_pw_file + ').\n\n' + email_text) else: command_list_repair = [ 'cd ' + git_dir_path, 'echo ' + ssh_password + ' | sudo -S chmod 755 ' + old_group_pw_file, 'sudo chmod 755 ' + new_group_pw_file ] repair_result = send_commands_to_ovid(command_list_repair) if Config.get_behavior_send_ovid_error_email(): send_email_with_error_messages_to_ovid_admin(result, repair_result, 'Student ' + str( matrnr) + ' wechselt von Gruppe ' + old_group_name + ' (' + git_dir_path + old_group_pw_file + ') zur Gruppe ' + new_group_name + ' (' + git_dir_path + new_group_pw_file + ').')
def write_new_pw_to_group_and_send_email_to_student(matrnr, new_group_name): new_password = random.choice('abcdefghij') + str(random.randrange(0, 1000001)) new_group_dir = 'g' + new_group_name new_group_pw_file = new_group_dir + '/.passwd' student = 's' + str(matrnr) ssh_password = Config.get_ovid_ssh_password() git_dir_path = Config.get_ovid_git_dir_path() command_list = [ 'cd ' + git_dir_path, 'echo ' + ssh_password + ' | sudo -S chmod 666 ' + new_group_pw_file, 'sudo htpasswd -b ' + new_group_pw_file + ' ' + student + ' ' + new_password, 'sudo chmod 755 ' + new_group_pw_file ] result = send_commands_to_ovid(command_list) if str(result['exit_status']) == '0': email_subject = 'GDI: Zugangsdaten für Ihr Repository in Eclipse' student_email_address = str(matrnr) + Config.get_email_default_email_domain_students() email_text = \ 'Die URI Ihres Repositorys: http://' + Config.get_ovid_ssh_host_name() + '/git/' + new_group_dir + '/' + new_group_dir + '.git\n' \ + 'Ihr Account-Name: ' + student + '\n' \ + 'Ihr Passwort: ' + new_password + '\n' Emails.sendMailWithTextBody(student_email_address, email_subject, email_text) if Config.get_behavior_send_ovid_information_email(): Emails.sendMailWithTextBody(Config.get_ovid_administrator_email_address(), 'REMINDER: ' + email_subject, 'Student ' + str( matrnr) + ' wurde in Gruppe ' + new_group_name + ' (' + git_dir_path + new_group_pw_file + ') eingetragen.\n\n' + email_text) else: command_list_repair = [ 'cd ' + git_dir_path, 'echo ' + ssh_password + ' | sudo -S chmod 755 ' + new_group_pw_file ] repair_result = send_commands_to_ovid(command_list_repair) if Config.get_behavior_send_ovid_error_email(): send_email_with_error_messages_to_ovid_admin(result, repair_result, 'Student ' + str( matrnr) + ' wurde in Gruppe ' + new_group_name + ' (' + git_dir_path + new_group_pw_file + ') eingetragen.')