#!/usr/bin/perl -w use strict; ## Scott Wiersdorf ## Created: Mon May 19 11:55:06 MDT 2003 ## $Id: crontab.cgi,v 1.1 2007/07/18 19:53:31 scott Exp $ ## a simple CGI for crontab editing ## ## most useful under Apache's suEXEC wrapper ;o) ## ## This program is a demonstration of the capabilities of the ## Config::Crontab module. The bulk of this program is CGI logic (tip ## o' the hat to Lincoln Stein), but look for the Config::Crontab::* ## calls and objects named $ct, $block, $newblock, and $obj. These are ## all Config::Crontab::* objects (and the reason for this demo ## program's creation). ## ## ## WARNING * ACHTUNG * AVISO ## ## ## This program may modify your crontab file. This program is provided ## AS IS under the terms of the Perl Artistic License to illustrate ## some possible uses of Config::Crontab. ## ## This program inherently is a security problem because it provides ## no authentication mechanism. You should enable your web server's ## authentication to prevent unauthorized access to this script. ## ## The author assumes no liability for damages of any kind caused by ## (mis)?use of this program. Please see paragraph 10 of the Artistic ## License distributed with Perl. Have a nice day! ## ## to do: ## ## - enable/disable blocks and lines within a block use CGI; use Config::Crontab; ######################### ## user-servicable parts: ######################### my $file = ''; ## set this to a pathname of a file (it needn't ## exist) if you want to practice with a temporary ## crontab file instead of your real one my $DEBUG = 0; ## a little extra information in your error_log ####################################### ## no user-servicable parts below here: ####################################### my $q = new CGI; my $self = $q->url; my $info; ## used for passing messages to main form print $q->header; ACTION: { ############################################################# ############################################################# ## ## ## General Block Operations: these don't require 'blockno' ## ## ## ############################################################# ############################################################# ############################################## ## Cancel Block Operation ## ############################################## if( $q->param('Block Cancel') || $q->param('Cancel') ) { $info = "Action cancelled"; last ACTION; } ############################################## ## Complete Block Operation ## ############################################## elsif( $q->param('Block Done') ) { $info = "Action completed"; last ACTION; } ############################################## ## New Raw Block ## ############################################## elsif( $q->param('Block Raw New') ) { ## display edit page and exit print $q->start_html("New crontab block for " . getpwuid($<)), $q->strong('Add a new crontab entry:'), $q->p, "\n\n"; print "
| !, $q->start_form; print $q->submit("New Line", "Add"), $q->br; print $q->hidden('blockno'); $q->param('Block Edit', 1); print $q->hidden('Block Edit'); print $q->radio_group(-name => 'newobjtype', -values => ['Comment','Environment','Event'], -default => 'Event'); print "\n"; print $q->end_form, qq! |
| Delete | Commit | Undo | First | Up | Down | Last | |||||||||
| !, $q->submit("Delete Line", 'X'), " | \n"; print q!!, $q->submit("Commit Line", 'O'), " | \n"; print q!!, $q->submit("Revert Line", 'U'), " | \n"; print q!!, $q->submit("First Line", '|<'), " | \n"; print q!!, $q->submit("Up Line", '<'), " | \n"; print q!!, $q->submit("Down Line", '>'), " | \n"; print q!!, $q->submit("Last Line", '>|'), " | \n"; $q->param('Block Edit', 1); print $q->hidden('Block Edit'), "\n"; $q->param('objno', $i++); print $q->hidden(-name => 'objno'), "\n"; print $q->hidden('blockno'), "\n"; if( UNIVERSAL::isa($obj, 'Config::Crontab::Comment') ) { print qq!!;
$q->param('comment', $obj->dump);
print "Comment: ", $q->textfield(-name => "comment", -size => 25), "\n"; print $q->hidden('objtype', 'comment'), "\n"; print " | ";
}
elsif( UNIVERSAL::isa($obj, 'Config::Crontab::Env') ) {
print qq!!;
$q->param('envname', $obj->name);
print "Name: ", $q->textfield(-name => "envname", -size => 12), "\n"; print " | = | ";
$q->param('envvalue', $obj->value);
print "Value: ", $q->textfield(-name => "envvalue", -value => $obj->value), "\n"; print $q->hidden('objtype', 'env'), "\n"; print " | ";
}
elsif( UNIVERSAL::isa($obj, 'Config::Crontab::Event') ) {
print qq!!;
$q->param('datetime', $obj->datetime);
print "Scheduled: ", $q->textfield(-name => "datetime", -size => 12), "\n"; print qq! | !;
$q->param('command', $obj->command);
print "Command: ", $q->textfield(-name => "command"), "\n"; print $q->hidden('objtype', 'event'), "\n"; print " | ";
}
print "|||
| Delete | Edit | Raw Edit | First | Up | Down | Last | |
| ", $q->submit("Block Delete", "X"), " | \n"; print "", $q->submit("Block Edit", "E"), " | \n"; print "", $q->submit("Block Raw Edit", "R"), " | \n"; print "", $q->submit("Block First", "|<"), " | \n"; print "", $q->submit("Block Up", "<"), " | \n"; print "", $q->submit("Block Down", ">"), " | \n"; print "", $q->submit("Block Last", ">|"), " | \n"; print "\n";
print $block->dump;
print " | \n";
print "