#!/usr/bin/perl

########################################################################
# Choice 3.3 Color Version                                             #
# By Sean Clarke                                                       #
# 3/14/97                                                              #
########################################################################
#                                                                      #
# Setup                                                                #

$version = 'Choice 3.3';
# End of Setup
#
# Terminal stuff
$shell = $ENV{'TERM'};
$user = $ENV{'LOGNAME'};
$hoost = '/etc/.choicehost';
if ($shell ne "linux")  {
system "stty erase ^H";
}
else 
{
}
open (FILE, "$hoost");
while (<FILE>)  {
        $host = $_;
}
close (FILE);
if ($host eq '')  {
$host = `hostname`;
chop $host;
}
# Main menu
MAIN:
system "clear";
print "[1;36;42m-=-=-=-=-=-=-=-=-=-=-=-=- [1;33mWelcome to $host [1;36m=-=-=-=-=-=-=-=-=-=-=-=-[0;0;0m\n\n";
print "[1;33m                               -=- [1;32mMain Menu[33m -=-\n\n[0;36m";
print "1. Check who is on the System\n";
print "2. Talk to someone on the system\n";
print "3. Check or send mail\n";
print "4. Finger someone's account\n";
print "5. Telnet to a diffrent host\n";
print "6. Edit Web Page\n";
print "7. Edit a file\n";
print "8. Change Password\n";
print "9. Browse the Web\n";
print "10. Play a Game\n";
print "11. Preferences\n";
print "12. IRC\n";
print "13. FTP to a host\n";
print "14. Help Desk\n";
print "15. Exit the system\n\n";
print "[31;44mChoice [32;44m==>[0m[36m ";
$main = <STDIN>;
chop $main;
if ($main == 1)
{
system "clear";
print "[1;33m                        -=- [32mCheck Who's On The System[33m -=-[0;36m\n\n";
if (-C "/usr/bin/w")  {   
system "w";
}
elsif (-C "/usr/bin/who")  {
system "who";
}
elsif (-C "/usr/bin/finger")  {
system "finger";
}
else
{
print "No users found";
}
print "\n\n";
print "[31;44mPress enter to return to main menu[0m[31m";
$enter = <STDIN>;
chop $enter;
goto MAIN;
}
if ($main == 2)
{
TALK:
system "clear";
print "[1;33m                           -=- [32mTalk To A User[33m -=-\n[0m[36m\n\n"; 
system "finger";
print "\n\n";
print "[31;44mWhich user would $user like to talk to?[0m[36m ";
$talk = <STDIN>;
chop $talk;
$who = `who|grep $talk 2>/dev/null`;
chop $who;
if (($talk eq '')||($talk =~ ";")||($talk eq "$user"))  {
print "[31;44mYou did not enter somebody to talk to, press enter to continue...[0m[36m";
$ytalkw = <STDIN>;
chop $ytalkw;  
goto MAIN;
}
elsif ($who ne '')
{
system "ytalk $talk";
print "[31;44mWould $user like to talk to someone eles? (y/n)[0m[36m ";
$talk = <STDIN>;
chop $talk;
if ($talk eq "y")
{
goto TALK;
}
if ($talk eq "n")
{
goto MAIN;
}
}
else
{
print "[31;44mThere was some kind of error, user not found?, press enter[0m[36m";
$wait = <STDIN>; 
chop $wait;
goto MAIN;
}
}
if ($main == 3)
{
system "pine";
goto MAIN;
}
if ($main == 4)
{
FINGER:
system "clear";
print "[1;33m                         -=- [32mFinger Someones Account [33m-=-[0;36m\n\n";
print "[31;44mWho would $user like to finger and at what host?[0m[36m ";
$finger = <STDIN>;
chop $finger;
if (($finger eq '')||($finger =~ ";"))  {
print "^[[31;44mYou entered something wrong^[[0m^[[36m";
$waiting = <STDIN>;
chop $waiting;
goto FINGER;   
}
else   
{
if (-C "/usr/bin/finger")  {
system "finger $finger|more";
}
else
{
print "No finger command found!";
}
print "\n";
print "[31;44mPress enter to return to Main menu[0m[36m";
$enter = <STDIN>;
chop $enter;
goto MAIN;
}
}
if ($main == 5)
{
TELNET:
system "clear";
print "[1;33m                            -=- [32mTelnet To A Host [33m-=-[0;36m\n\n";
print "[31;44mTelnet to which host:[0m[36m ";
$telnet = <STDIN>;
chop $telnet;
if (($telnet =~ ";")||($telnet eq ''))  {
print "[31;44mYou have entered an invalid character. Press enter[0m[36m";
$waiting = <STDIN>;
chop $waiting; 
goto TELNET;
}
else
{
system "clear";
if (-C "/usr/bin/telnet")  {
system "telnet $telnet";
}
else
{
print "[31;44mNo telnet command found, press enter[0m[36m";
$wait = <STDIN>;
chop $wait; 
}
goto MAIN;
}
}
if ($main == 6)
{
system "clear";
print "[1;33m                          -=- [32mEdit Your HTML Files -=-[33m\n\n[0;36m";
print "[31;44mEnter the name of the html file:[0m[36m ";
$page = <STDIN>;
chop $page;
if (($page eq '')||($page =~ "../"))  {
print "[31;44m$user entered an something wrong. Press enter[0m[36m";
$waittt = <STDIN>;
chop $waittt;
goto MAIN;
}
else
{
if (-C "/usr/bin/pico")  {
system "pico -o ~/ ~/www/$page";
}
else
{
print "[31;44No text editor found!  Press enter[0m[36m";
$wait = <STDIN>;
chop $wait;
}
goto MAIN;
}
}
if ($main == 7)
{
system "clear";
print "[1;33m                               -=- [32mEdit Files [33m-=-[0;36m\n\n";
print "[31;44mEnter the file you would like to edit:[0m[36m ";
$file = <STDIN>;
chop $file;
if (($file eq '')||($file =~ "../"))  {
print "[31;44mYou entered an something wrong. Press enter[0m[36m";
$waitt = <STDIN>;
chop $waitt;
goto MAIN;
}
else
{
if (-C "/usr/bin/pico")
{
system "pico -o ~/ ~/$file";
}
else
{
print "[31;44mNo text editor found!  Press enter[0m[36m";
$wait = <STDIN>;
chop $wait;
}
goto MAIN;
}
}
if ($main == 8)
{
system "clear";
print "[1;33m                          -=- [32mChange Your Password[33m -=-[0;36m\n\n";
system "passwd";
system "sleep 2";
goto MAIN;
}
if ($main == 9)
{
system "lynx";
goto MAIN;
}
if ($main eq "10")
{
GAME:
system "clear";
print "[1;33m                               -=- [32mPlay A Game [33m-=-[0;36m\n\n";
system "ls /usr/games";
print "\n";
print "[31;44mWhich game would you like to play?[0m[36m ";
$game = <STDIN>;
chop $game;
if (($game =~ "../")||($game =~ "/")||($game =~ ";")) {
print "[31;44mYou Entered a invalid character!  Press enter[0m[36m ";    
$wa = <STDIN>;
chop $wa;
goto MAIN;
}
else 
{
system "clear";
system "/usr/games/$game";
print "\n\n";
print "[31;44mWould you like to play another game? (y/n)[0m[36m ";
$ano = <STDIN>;
chop $ano;
if (($ano eq "n")||($ano eq "N")||($ano eq "no"))
{
goto MAIN;
}
if (($ano eq "y")||($ano eq "Y")||($ano eq "yes"))
{
goto GAME;
}
goto MAIN;
}
}
if ($main == 11)
{
PRE:
system "clear";
print "[1;33m                               -=- [32mPreferences [33m-=-[0;36m\n\n";
print "1. Mesg on or off\n";
print "2. To edit plan\n";
print "3. Change Finger info\n";
print "4. Change permission settings (chmod) in a directory or file.\n";
print "5. Back to main menu\n\n";
print "[31;44mChoice [32m==>[0m[36m ";
$pref = <STDIN>;
chop $pref;
if ($pref == 1)
{
system "clear";
print "[31;44mWould you like mesg on or off? (on/off)[0m[36m ";
$mesg = <STDIN>;
chop $mesg;
if (($mesg eq "on")||($mesg eq "ON")||($mesg eq "On"))
{
print "Turning messages on...\n\n";
system "mesg y";
}
if (($mesg eq "off")||($mesg eq "OFF")||($mesg eq "Off"))
{
print "Turning messages off..\n\n";
system "mesg n";
}
system "sleep 2";
goto PRE;
}
if ($pref == 2)
{
system "pico -o ~/ ~/.plan";
goto PRE;
}
if ($pref == 3)
{
system "clear";
print "[1;33m                       -=- [32mChanging Finger Information [33m-=-[0;36m\n\n";
system "chfn";
goto PRE;
}
if ($pref == 4)
{
MOD:
system "clear";
print "[31;44mEnter file name or directory name (if home dir type .) :[0m[36m ";
$file = <STDIN>;
chop $file;
if (($file eq '')||($file =~ "../"))  {
print "[31;44mYou entered and invalid character. Press enter.[0m[36m";
$waiter = <STDIN>;
chop $waiter;
goto PRE;
}
CHMODER:
print "\n";
print "[31;44mEnter mode (if don't know press enter) :[0m[36m ";
$mod = <STDIN>;
chop $mod;
if ($mod eq '')  {
print "So you don't know what mode to choose OR what it is.  Here are a
few basic one's:
644 = all html files should be this chmod
700 = no user can view or execute it
711 = most dir mode, users can get to your dir, but can't view what files are in it
775 = all users can read it but can't edit it
777 = all users have total access and can change the file and everything
Those are just a FEW basic ones, there are 7777 modes to choose from!\n";
print "[31;44mPress t to try again, and r to return to menu? (t/r)[0m[36m ";
$tr = <STDIN>;
chop $tr;
if (($tr eq 't')||($tr eq 'T'))  {
goto CHMODER;  
}
elsif (($tr eq 'r')||($tr eq 'R'))  {
goto PRE;
}
#elsif (($tr ne 'r')||($tr ne 'R')||($tr ne 't')||($tr ne 'T'))  {
#goto PRE;
#}
}
else 
{
print "\n";
#print "[31;44mIs file/dir in your www dir? (y/n)[0m[36m ";
#$www = <STDIN>;
#chop $www;
#print "\n\n";
#if (($www eq "y")||($www eq "Y")||($www eq "yes"))
#{
#print "Changing mode in progress...\n\n";
#system "chmod $mod ~/www/$file";
#}
#if (($www eq "n")||($www eq "N")||($www eq "no"))
#{
print "Chaning mode in progress...done\n\n";
system "chmod $mod ~/$file";
#}
BACK:
print "[31;44mp to return to preferences and c to change mod of other file?[0m[36m ";
$back = <STDIN>;
chop $back;
if (($back eq "p")||($back eq "P"))
{
goto PRE;
}
if (($back eq "c")||($back eq "C"))
{
goto MOD;
}
else
{
print "[31mYou did not enter p or c try again![36m \n\n";
goto BACK;
}
}
}
if ($pref == 5)
{
goto MAIN;
}
else
{
goto PRE;
}
}
if ($main == 12)
{
system "clear";
print "[33m                                  -=- [32mIRC[33m -=-[0;36m\n\n";
print "[31;44mWhat nickname :[0m[36m ";
$nick = <STDIN>;
chop $nick;
if ($nick =~ ";")  {
print "[31;44mYou entered an invalid character!  Press enter[0m[36m";
$wait = <STDIN>;
chop $wait;
goto MAIN;
}
print "\n";
print "[31;44mWhat server (just press enter if you don't know) :[0;0m[36m ";
$server = <STDIN>;
chop $server;
if ($server =~ ";")  {
print "[31;44mYou have enetered an invalid character!  Press enter[0m[36m";
$wait = <STDIN>;
chop $wait;
goto MAIN;
}
system "irc $nick $server";
goto MAIN;
}
if ($main == 13)
{
system "clear";
print "[1;33m                                 -=-[32m FTP [33m-=-[0;36m\n\n";
print "[31;44mEnter FTP server name :[0m[36m ";
$name = <STDIN>;
chop $name;
if ($name =~ ";")  {
print "[31;44mYou have entered an invalid character!  Press enter[0m[36m";
$wait = <STDIN>;
chop $wait;
goto MAIN;
}
system "clear";
system "ftp $name";
goto MAIN;
}
if ($main == 14)
{
system "clear";
print "[1;33m                                 -=- [32mHELP [33m-=-[0;36m\n\n";
print "[31;44mIf you have a problem with choice our just want to report a bug press enter or m to go back to main menu:[0;0m[36m ";
$bug = <STDIN>;
chop $bug;
if (($bug eq "m")||($bug eq "M"))
{
goto MAIN;
}
else
{
system "clear";
$mail = '/usr/lib/sendmail';
$to = 'root@smoke.minot.com';
print "Enter E-mail address to respond too: ";
$respond = <STDIN>;
chop $respond;
if ($respond eq '')  {
goto MAIN;
}
system "clear";
open (MAIL, "|$mail $to") || die "Can't open $mail";
print "Enter the bug or problem you are having below:\n";
$mesg = <STDIN>;
chop $mesg;
print MAIL "From: $respond\n";
print MAIL "Subject: Choice Bug\n";
print MAIL "The problem or bug is: $mesg\n";
print MAIL "And that is it";
close (MAIL);
goto MAIN;
}
}
if ($main == 15)
{
system "echo";
print "[31;44mAre you sure you want to exit? (y/n)[0m[36m ";  
$exit = <STDIN>;
chop $exit;
if (($exit eq "y")||($exit eq "Y")||($exit eq "yes")||($exit eq "Yes"))   
{   
system "clear";
print "[36mThanx for using $version!\n";
print "[31mCopyright 1997 Sean Clarke. All rights reserved.\n\n";
print "[36mGoodbye\n\n\n[0;0m";
system "sleep 2";
system "clear";
system "exit";
}
else
{
goto MAIN;
}
}
else
{
system "clear";
print "[31mYou entered a invalid number!\n\n";
print "[44mPress enter to go back to main menu[0m";
$enter = <STDIN>;
chop $enter;
goto MAIN;
}
