#!/usr/local/bin/perl # # sickday.pl 0.0.1 # by miff (miff@9mm.com) # written November 1999 # # purpose: # To give you a random day off once in a while. # # -interactive # -asks for: # frequency of sickness (scale of 1 to 10) # boss's email & name # your email & name # # future: # -illness list/description cache # -whatever else you want # # peace to all my homiez. # # best musical artist: Mike Patton. # print "\n\n\n\n\n\n\n\n\n"; print "Welcome to sickday.pl by miff \n\n"; #First find out if sickday is initialized - we want settings # in $HOME/sickday/sickday.conf #We'll also put the default emails there. #ultimately we'll have all the sicknesses in there too heh. my $home = $ENV{HOME}; my $mode; unless (-e "$home/sickday") { print "setting up $home/sickday \n"; mkdir "$home/sickday",0700; $mode = "NEW"; } unless (-e "$home/sickday/sickday.conf") { #need a conf file $mode = "NEW"; print "missing sickday.conf - creating default file \n"; print "YOU DEFINITELY NEED TO CONFIGURE THIS BEFORE RUNNING IT.\n"; open CFILE, ">$home/sickday/sickday.conf"; print CFILE "mymail=you\@youhost.com \n"; print CFILE "bossmail=boss\@bossmail.com \n"; print CFILE "freq=1 \n"; #frequency scale 1-10 print CFILE "bossname=daman \n"; print CFILE "myname=joeworker \n"; close CFILE; } unless (-e "$home/sickday/email.dayoff") { #need a email to self print "missing email.dayoff (email to you) - creating default message \n"; open EMAIL, ">$home/sickday/email.dayoff"; print EMAIL "YOURE SICK TODAY, HOMIE! \n Kick back and take the day off.\n"; print EMAIL "You deserve it. \n Maybe catch a flick or go see the monster "; print EMAIL "truck rally downtown... \n\n"; close EMAIL; } unless (-e "$home/sickday/email.boss") { #need a email to boss print "missing email.boss (email to boss) - creating default message \n"; open EMAIL, ">$home/sickday/email.boss"; print EMAIL "Im really not feeling well this morning - I'm afraid I can't "; print EMAIL "make it in to work today. \n\n"; close EMAIL; } unless (-e "$home/sickday/daily.run") { # we need the actual daily program!! print "you dont have daily.run - writing now... \n\n"; &createprog; } #check if we have something in cron my $cronline; open CRONCHECK, "crontab -l 2>&1 |"; while ($line = ) { chomp $line; if ($line =~ "sickday") { #we're cronned print "found sickday in cron: \n"; print "$line \n\n"; $cronline = $line; } } close CRONCHECK; #WELP, I guess thats it except for the main menu and all the routines... my $input; #MAIN MENU while (1) { print "\n\n\n"; print "\n\t\t SICKDAY MAIN MENU \n\n"; print "1.) Instructions \t\t 5.) Remove Sickday \n"; print "2.) Edit Configuration \t\t 6.) Kick a Shoutout \n"; print "3.) Manually Run NOW \t\t 7.) About \n"; print "4.) FIRE AND FORGET \t\t 8.) Out with Gout '88 \n"; print "\n"; $input = <>; chomp $input; if ($input == 1) { &instructions; } elsif ($input == 2) { &editconfig; } elsif ($input == 3) { &manualrun; } elsif ($input == 4) { &firenforget; } elsif ($input == 5) { &remove; } elsif ($input == 6) { &kickshout; } elsif ($input == 7) { &about; } elsif ($input == 8) { exit(0); } else { print "\n PBCAK \n"; print "\n \n You'll note that there is a menu presented for your \n"; print "choosing pleasure. Please confine yourself to the numbers \n"; print "listed above and everything will be just fine. \n"; print "If you would like to exit, choose number 8. \n"; print "\n PBCAK \n"; } } sub instructions { print "\n\n sickday.pl INSTRUCTIONS \n\n"; print " This utility will occaisionally give you a day off from work. \n"; print " You set the probability (its a random event) and other things \n"; print " Like your name, boss's name, email addresses, and we handle the \n"; print " rest. sickday.pl creates a default email to you and your boss \n"; print " in your $home/sickday directory - feel free to edit them! \n"; print " Maybe in the future we'll have a random sickness pop up as well. \n"; print " \n IMPORTANT: you MUST check your email each morning before going \n"; print " to work!!! Also make sure your system clock is reasonably correct. \n"; print " \n\n (continue) \n"; my $input = <>; print "\n\n"; print "--> use the Edit Configuration menu item to configure \n"; print "--> use the Manual Run menu item to test / run immediately \n"; print "--> use the Fire n Forget menu item to set it to autorun each day \n"; print "--> use the Remove menu item to stop it from autorunning each day \n"; print "(note: this only runs on weekdays and doesnt respect holidays) \n\n"; print " \n\n (continue) \n"; my $input = <>; } sub editconfig { #edit the user's config file: my $cdata; my %config; open CFILE, "$home/sickday/sickday.conf"; while ($cdata = ) { #read in each config line chomp $cdata; if ($cdata =~ "=") { my ($anchor, $value) = split /=/, $cdata; $config{$anchor} = $value; } else { print "config line without and = sign! \n"; print $cdata; print "\n"; } } close CFILE; #our hash is full; show it and go into edit mode: my $edit = 1; while ($edit == 1) { print "\n\n\n\n\n\t\t CONFIGURE SICKDAY \n\n"; print "current values: \n"; # print hash my $anchor; my $odd; foreach $anchor (keys (%config)) { print "$anchor=$config{$anchor}"; if ($odd) { print "\n"; $odd = 0; } else { print "\t\t"; $odd = 1; } } print "\n\n\t TO CHANGE any value enter SETTING=VALUE \n"; print "Enter 0 to return to main menu with no save \n"; print "Type 'save' to save your new configuration and return. \n"; print " you can also manually edit the file btw... \n"; print "\nNOTE: freq is the frequency you want to be absent on a 1-10\n"; print "scale. 1 is about once a year and 10 is about once a week. \n\n"; my $input = <>; chomp $input; if ($input eq "0") { return; } elsif ($input eq "save") { $edit = 0; } elsif ($input =~ "=") { if ($input =~ "freq") { #pretest frequency... my ($anchor,$value) = split /=/,$input; if ($anchor eq "freq") { if ($value < 1) { print "\n\n\n\nfrequency value too low; try again silly."; next; } elsif ($value > 11) { print "\n\n\n\nfrequency value too high; try again silly."; next; } elsif ($value == 11) { print "\n\n\nWow! This guy goes to Eleven!"; } } } my ($anchor,$value) = split /=/,$input; $config{$anchor} = $value; } else { print "\n\n\n\nPBCAK \n"; print "problems interpreting your entry. \n"; print "try again. \n\n"; } } #outside main loop: if we are here that means save and return. open CFILE, ">$home/sickday/sickday.conf"; foreach $value (keys (%config)) { print CFILE "$value=$config{$value}\n"; } close CFILE; } sub manualrun { # manually kickoff daily.run: print "\nmanually kicking off a daily.run process...\n\n"; my $mrun = "$home/sickday/daily.run"; system("$mrun"); print "continue... \n\n"; my $input = <>; } sub firenforget { #write sickday to cron print "\nwriting sickday to cron... \n\n"; my $cronline; my $newcron; open CRONCHECK, "crontab -l |"; while ($line = ) { chomp $line; if ($line =~ "sickday") { #we're cronned print "replacing exiting sickday in cron: \n"; $cronline = $line; } else { $newcron .= "$line \n"; } } close CRONCHECK; #now add the new line: $newcron .= "\n0 5 * * mon-fri $home/sickday/daily.run\n"; # now make the new cron... open NEWCRON, "|crontab -"; print NEWCRON $newcron; close NEWCRON; } sub remove { #remove sickday from cron print "\nremoving sickday from cron... \n\n"; my $cronline; my $newcron; open CRONCHECK, "crontab -l 2>&1 |"; while ($line = ) { chomp $line; if ($line =~ "sickday") { #we're cronned print "removing sickday from cron: \n"; print "$line <-- REMOVED\n\n"; $cronline = $line; } elsif ($line =~ "no crontab") { #nothing print "$line \n\n"; return; } else { $newcron .= "$line \n"; } } close CRONCHECK; # now make the new cron... open NEWCRON, "|crontab -"; print NEWCRON $newcron; close NEWCRON; } sub kickshout { my @shouts = ('xyg','incr','b_','lumpy','DjM','X','prym','dk','tiki','shinex','suph','kubiak'); srand(time ^ $$); my $randum = int(rand(11)); print "\n\n YO YO YO YO I'D LIKE TO KICK A SHOUT OUT TO MAH HOMIE $shouts[$randum] \n\n"; print "What you rollin in, boo? \n"; my $input = <>; } sub about { # a little somethin print "\n\n\n\nsickday.pl by miff\@9mm.com \n"; print "\nWritten to give you a little surprise break once in a while\n"; print "kinda like a snow day up north.\n"; print "continue.."; my $input = <>; } #put this last cuz the formatting sux: sub createprog { open PROGRAM, ">$home/sickday/daily.run"; print PROGRAM <) { #read in each config line chomp \$cdata; if (\$cdata =~ "=") { my (\$anchor, \$value) = split /=/, \$cdata; \$config{\$anchor} = \$value; } } close CFILE; #now check for freq value unless (\$config{freq} > 0 && \$config{freq} < 12) { #no frequency, we bomb... my \$msg = "sickday is misconfigured - please add a freq= entry for frequency\n"; system ("echo '\$msg' | mail \$config{mymail} "); } my \$freq = \$config{freq}; # got freq; assume we have the other stuff... # man I used to have all sorts of math in here to calc frequencies based # on sliding scale of 1-10 being 1/260 - 1/5 and like it didnt correspond # to what people would think sooooo Im just gonna wing it: # note the weird scale... heh. my \$likelihood; my \$magicnumber = 3; # 3 is the magic number. if (\$freq == 1) { \$likelihood = 260; } elsif (\$freq == 2) { \$likelihood = 190; } elsif (\$freq == 3) { \$likelihood = 130; } elsif (\$freq == 4) { \$likelihood = 100; } elsif (\$freq == 5) { \$likelihood = 78; } elsif (\$freq == 6) { \$likelihood = 46; } elsif (\$freq == 7) { \$likelihood = 23; } elsif (\$freq == 8) { \$likelihood = 15; } elsif (\$freq == 9) { \$likelihood = 10; } elsif (\$freq == 10) { \$likelihood = 5; } elsif (\$freq == 11) { # wow this guy goes to 11 # thats every other day! \$likelihood = 2; \$magicnumber = 1; } else { #unsupported frequency!! exit; } my \$home = \$ENV{HOME}; srand(time ^ \$\$); my \$randum = int(rand(\$likelihood)); \$randum++; if (\$randum == \$magicnumber) { # WOO HOOO!! ITS A SICKDAY!! #send email to self: \$mymail = "$home/sickday/email.dayoff"; \$bossmail = "$home/sickday/email.boss"; \$daysoff = "$home/sickday/daysoff.had"; system ("cat \$mymail | mail \$config{mymail}"); #system ("cat \$bossmail | mail \$config{bossmail}"); # boss's mail is harder bc its got to and from and maybe subj. my \$bmail = "\$config{bossname}, \n"; open BMAIL, "\$bossmail"; \$bmail .= ; \$bmail .= "\n\n -\$config{myname}\n"; system ("echo '\$bmail' | mail \$config{bossmail}"); system ("date >> \$daysoff"); } EOP close PROGRAM; #now chmod it! chmod 0755, "$home/sickday/daily.run" }