SF.net SVN: morphix: [2577] trunk/morphixlivekiosk/scripts/index.pl
[email protected] Tue, 30 Oct 2007 15:19:36 -0700
| Newsgroups | gmane.linux.morphix.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 2577
http://morphix.svn.sourceforge.net/morphix/?rev=2577&view=rev
Author: bmsleight
Date: 2007-10-30 15:19:33 -0700 (Tue, 30 Oct 2007)
Log Message:
-----------
A example front end to prove concept.
Added Paths:
-----------
trunk/morphixlivekiosk/scripts/index.pl
Added: trunk/morphixlivekiosk/scripts/index.pl
===================================================================
--- trunk/morphixlivekiosk/scripts/index.pl (rev 0)
+++ trunk/morphixlivekiosk/scripts/index.pl 2007-10-30 22:19:33 UTC (rev 2577)
@@ -0,0 +1,201 @@
+#!/usr/bin/perl -w
+
+use CGI qw(:standard); # Include standard HTML and CGI functions
+use CGI::Carp qw(fatalsToBrowser); # Send error messages to browser
+
+$dir = "/var/local/www/templates/";
+$imagestore ="/var/www/morphix/livekiosk/webservice/images/";
+$templatestore ="/var/www/morphix/livekiosk/webservice/templates/";
+$templatequeue ="/var/local/www/templates/queue.txt";
+$queuecomplete ="/var/local/www/templates/completed.txt";
+$lockfile ="/var/local/www/templates/lock_the_file.loc";
+$domain = "http://www.barwap.com/morphix/livekiosk/webservice/images/";
+$templatestoredomain = "http://www.barwap.com/morphix/livekiosk/webservice/templates/";
+
+
+sub WriteStringToFile {
+ my ($file, $string) = @_;
+ open (OUT, ">$file") or die('cant write %s', $file) ;
+ print OUT $string;
+ close(OUT);
+}
+
+
+if (param("queue")) {
+ print "Content-type: text/html\n\n";
+
+ open(DAT, $templatequeue) || die("Could not open file!");
+ @raw_data=<DAT>;
+ close(DAT);
+
+ foreach $queue (@raw_data)
+ {
+ chop($queue);
+ ($urls,$emails)=split(/\|/,$queue);
+ print "$urls\n";
+ }
+}
+elsif (param("built")) {
+ print header, start_html("Custom Built Kiosk LiveCD"), h1("Custom Built Kiosk LiveCD");
+ $built = param("built");
+ $video = param("v");
+ $iso = param("i");
+ print p("$built/$video \n");
+ print p("$built/$iso \n");
+ $message = "Your custom built Kiosk LiveCD is ready. \n"
+ . "Please download and view the AutoTesting video first. \n "
+ . "The video will show how successful the build was and can save "
+ . "vital bandwidth if the build did not go well. \n\n"
+ . "Video - http://$built/$video \n"
+ . "ISO - http://$built/$iso \n"
+ . "\n"
+ . "Enjoy Your Kiosk - kiosk.liveCD.org";
+ open(DAT, $templatequeue) || die("Could not open file!");
+ $topqueue = <DAT>;
+ close(DAT);
+ ($urls,$emails)=split(/\|/,$topqueue);
+ print h2("$emails");
+ print h2("$urls");
+ print p("$message");
+ print end_html;
+ # There might be a nice perl way - but some times bash is nice
+ print p("Removed $urls from queue");
+
+ system "echo \"$message\" | mail -s 'Custom Built Kiosk LiveCD' $emails -- -r [email protected] -";
+ system "cat $templatequeue | tail -n+2 >$templatequeue ";
+}
+else {
+#
+# Start by printing the content-type, the title of the web page and a heading.
+#
+#
+ print header, start_html("Custom Built Kiosk LiveCD"), h1("Custom Built Kiosk LiveCD");
+ if (param("email")) { # If true, the form has already been filled out.
+ $email = param("email");
+ $url = param("url");
+
+ $flag = "false";
+ open(DAT, $templatequeue) || die("Could not open file!");
+ @raw_data=<DAT>;
+ close(DAT);
+
+ foreach $queue (@raw_data)
+ {
+ chop($queue);
+ ($urls,$emails)=split(/\|/,$queue);
+ if ( $urls eq $url) {
+ $flag = "true";
+ }
+ }
+
+ if ( $flag eq "false" ) {
+ # This checks for the existence of the lock file.
+ # If it exists, we use the sleep command to wait two seconds and try again.
+ while (-e $lockfile) {
+ sleep 2;
+ }
+ # If we get past the while loop, we can now create a lock file to
+ # keep others out until we have written to the file.
+ open (LOCK,">$lockfile") || die ("Cannot open lock file!\n");
+ close (LOCK);
+
+ print p("Email: $email");
+ print p("Template: $url");
+
+ # Open and write to the data file
+ open(DAT,">>$templatequeue") || die("Cannot Open File");
+ print DAT "$url\|$email\n";
+ close(DAT);
+ print p("Template added to queue");
+
+ # Now that writing is done, delete the lock file
+ # to allow others to access the data file
+ unlink($lockfile);
+ }
+ else {
+ print p("Template already in queue");
+ }
+ }
+ elsif (param('graphic')) {
+ $brand = param("brand"); # Extract the value passed from the form.
+ $homepage = param("homepage"); # Extract the value passed from the form.
+ $navbar = param("navbar"); # Extract the value passed from the form.
+ $network = param("network");
+
+ print p("Brand: $brand"); # Print the name.
+ print p("Homepage: $homepage"); # Print the name.
+ print p("Navigation: $navbar"); # Print the name.
+
+ $file = param('graphic');
+ @minis = param('minis');
+ $file=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename
+ open(LOCAL, ">$dir/$file") or die $!;
+ while(<$file>) {
+ print LOCAL $_;
+ }
+ print "$file has been successfully uploaded... thank you.\n";
+
+ #Use convert o amke sure that Imgae upload is an real image not a naughty script
+ system "convert $dir/$file /var/www/morphix/livekiosk/webservice/images/$file";
+
+ $xml = "<comps>"
+ . " <group>"
+ . " <kiosk>";
+ $xml1 = " <version>0.0.1</version>"
+ . " <brand>" . $brand . "</brand>"
+ . " <graphic>" . $domain . $file . "</graphic>"
+ . " <navbar>" . $navbar . "</navbar>";
+
+ $xmlmini = " <extralist>";
+ foreach $mini (@minis) {
+ $xmlmini = $xmlmini . "<MiniModule>" . $mini . "</MiniModule>";
+ }
+ $xmlmini = $xmlmini . " </extralist>";
+
+ $xmlnet = " <network>"
+ . " <dhcp>$network</dhcp>"
+ . " </network>";
+
+ $xmlend = " </kiosk>"
+ . " </group>"
+ . "</comps>";
+
+ $xmllfinished = $xml . $xml1 . $xmlmini . $xmlnet . $xmlend;
+# $templatestore
+ my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
+ $xmlname= "$brand" . "_date_" . "$mon" . "-" . "$mday" . "_" . "IP_" . $ENV{'REMOTE_ADDR'} . ".xml" ;
+ $templateurl=$templatestoredomain . $xmlname;
+ WriteStringToFile( $templatestore . $xmlname , $xmllfinished );
+ print p("Templates successfully created : <a href='$templateurl" . ">" . "$brand" . "</a>");
+ print start_form();
+ print p("Template will be added to the queue to be built.");
+ print p("Once built, we will email the links contain the AutoTest Video and the iso to download");
+ print p("Email Address: ", textfield(-name=>"email", -size=>30), hidden(-name=>'url', -default=> $templateurl ) );
+ print p(submit("Build!"));
+ print end_form();
+ }
+ else { # Else, first time through so present form.
+ print start_form();
+ print p("What is the Brand Name (e.g. MorphixLiveKiosk) ? ", textfield("brand"));
+ print p("Graphics file used from logo and backgrounds ? ", filefield(-name=>'graphic',
+ -size=>30,
+ -maxlength=>80));
+ print p("What is the Homepage URL (e.g. www.morphix.org) ? ", textfield("homepage"));
+ print p("Should the Navigation Bar be visable ? ", radio_group(-name=>'navbar',
+ -values=>['true','false'],
+ -default=>'true'));
+ print p("Should the network use DHCP or static ? ", radio_group(-name=>'network',
+ -values=>['dhcp'],
+ -default=>'dhcp'));
+
+ print p("Extras to inlcude ? ", checkbox_group(-name=>'minis',
+ -values=>['MorphixMini-NonFree-FlashPlugin.xml','MorphixMini-NonFree-Java.xml'],
+ -defaults=>[''],
+ -multiple=>'true'));
+ print p(submit("Submit"));
+ print end_form();
+ }
+ print end_html;
+}
+
+
Property changes on: trunk/morphixlivekiosk/scripts/index.pl
___________________________________________________________________
Name: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/