Beruflich Dokumente
Kultur Dokumente
/usr/bin/perl
&program_start;
sub program_start {
print "If adding someone, press enter twice.\n\n";
print "u/ "; chomp($registered_user_username = <>);
print "p/ "; chomp($registered_user_password = <>);
sub ask_registration {
system("clear");
print "Answer the following with \"yes\" or \"no\".\n";
print "\n";
print "Add User?> "; chomp($register_question = <>);
if($register_question eq "yes") {
&client_register_yes;
}
elsif($register_question eq "no") {
&client_register_no;
}else{
print "Input \"$register_question\" does
not exist.\n";
&ask_registration;
}
}
sub client_register_yes{
sub client_register_no {
if($you_sure eq "yes") {
¬_registered;
}
elsif($you_sure eq "no") {
&ask_registration;
}else{
print "Unknown command...\n";
&ask_registration;
}
}
sub client_register_confirmation {
if($you_sure eq "yes") {
&log_file;
}
elsif($you_sure eq "no") {
system("clear");
&client_register_yes;
}else{
print "Input \"$you_sure\" does not
exist.";
system("clear");
&client_register_confirmation;
}
}
sub thank_you {
system("clear");
print "$new_name has been added.\n";
&program_start;
}
sub client_approved {
system("clear");
print "Logged in as $registered_user_username.\n";
print color 'bold blue';
print "For a list of commands, type: /?\n";
print color 'reset';
&choose_operations;
}
sub choose_operations {
use Term::ANSIColor;
if($operation_selection eq "/showusers") {
&show_clients;
}
elsif($operation_selection eq "/showusers?") {
print color 'bold blue';
print "/showuser tells you, in a list, which users
were added.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/clear") {
system("clear");
&choose_operations;
}
elsif($operation_selection eq "/clear?") {
print color 'bold blue';
print "/clear clears up the terminal screen. Gets
rid of older text.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/exit") {
system("clear");
system("exit");
}
elsif($operation_selection eq "/exit?") {
print color 'bold blue';
print "/exit logs the user out of the program. Exits
the program.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/editusers") {
print color 'bold blue';
system("nano clients.txt");
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/editusers?") {
print color 'bold blue';
print "/editusers loads a GNU/Nano screen to edit
currently added users.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/?") {
print color 'bold blue';
print "\nNote: For more command info, put a \"?\"
after it (no spaces).\n\n";
print "/showusers /editusers /clear /exit
/proginfo\n";
print "/time /db.backup /db.revert /logoff\n";
print "/db.del.main /db.del.bkp /db.nuke\n";
print "/db.main.check /db.bkp.check /ls\n\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/??") {
print color 'bold blue';
print "/? shows the list of commands currently
available.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/proginfo") {
print color 'bold blue';
print "Programmed in Perl 5. Programmed by
Francois.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/proginfo?") {
print color 'bold blue';
print "Shows program information.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/time") {
system("date");
&choose_operations;
}
elsif($operation_selection eq "/time?") {
print color 'bold blue';
print "/time will tell you your system time.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/db.backup") {
system("cp clients.txt clients.txt.backup");
&choose_operations;
}
elsif($operation_selection eq "/db.backup?") {
print color 'bold blue';
print "/db.backup will create a backup of
clients.txt\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/db.revert") {
system("cp clients.txt.backup clients.txt");
&choose_operations;
}
elsif($operation_selection eq "/db.revert?") {
print color 'bold blue';
print "/db.revert will put the database backup as
the new database (used if mistake in main database).\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/logoff") {
system("clear");
print "Logged off as $registered_user_username.\n";
&program_start;
}
elsif($operation_selection eq "/logoff?") {
print color 'bold blue';
print "/logoff will log you off as admin and bring
you back to the login screen.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/db.del.main") {
&delete_database_main;
}
elsif($operation_selection eq "/db.del.main?") {
print color 'bold blue';
print "/db.del will delete clients.txt (main
database). Password required.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/db.del.bkp") {
&delete_database_backup;
}
elsif($operation_selection eq "/db.del.bkp?") {
print color 'bold blue';
print "/db.del.bkp will delete the backup databases.
Password required.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/db.nuke") {
&db_nuke;
}
elsif($operation_selection eq "/db.main.check") {
&db_main_check;
}
elsif($operation_selection eq "/db.main.check?") {
print color 'bold blue';
print "/db.main.check will tell you if the contact list file
exists in the directory.\n";
print color 'reset';
&db_main_check;
}
elsif($operation_selection eq "/db.bkp.check") {
&db_backup_check;
}
elsif($operation_selection eq "/db.bkp.check?") {
print color 'bold blue';
print "/db.bkp.check will tell you if the backup file
exists.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/ls") {
&list_directory;
}
elsif($operation_selection eq "/ls?") {
print color 'bold blue';
print "/ls will show files in directory.\n";
print color 'reset';
&choose_operations;
}
elsif($operation_selection eq "/db.nuke?") {
print color 'bold blue';
print "/db.nuke will delete all the databases.\n";
print color 'reset';
&choose_operations;
}else{
print "Your input of
\"$operation_selection\" does not exist. For help: /?\n\n";
&choose_operations;
}
}
sub list_directory {
system("ls");
&choose_operations;
}
sub db_backup_check {
$checkbackup = "clients.txt.backup";
if(-e $checkbackup) {
print "Backup exists\n";
&choose_operations;
}else{
print "Backup does not exist.\n";
&choose_operations;
}
}
sub db_main_check {
$checkmain = "clients.txt";
if(-e $checkmain) {
print "Main Database file exists.\n";
&choose_operations;
}else{
print "Main Database does not
exist.\n";
&choose_operations;
}
}
sub db_nuke {
if($db_nuke eq "deletenow"){
system("rm clients.txt; rm clients.txt~; rm clients.txt.backup; rm
clients.txt.backup~");
&choose_operations;
}else{
print "Wrong password.\n";
&choose_operations;
}
}
sub delete_database_backup {
print "Password> "; chomp($db_bkp_del = <>);
if($db_bkp_del eq "deletenow"){
system("rm clients.txt.backup; rm clients.txt.backup~");
&choose_operations;
}else{
print "Wrong password.\n";
&choose_operations;
}
}
sub delete_database_main {
if($db_main_del eq "deletenow") {
system("rm clients.txt; rm clients.txt~");
&choose_operations;
}else{
print "Wrong password.\n";
&choose_operations;
}
}
sub not_registered {
print "User exited.\n\n";
exit;
}
sub log_file {
sub show_clients {
sub wrong_password {
system("clear");
print "Wrong password\n\n";
&program_start;
}