Browse files

Initial commit.

  • Loading branch information...
1 parent 42f10d6 commit 38229e6bb51b9e2a6a71e9fc63c275b0b382df18 @japharl committed Jul 22, 2012
View
20 root/clean.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use DBI;
+use Config::Tiny;
+
+my $cfg = new Config::Tiny->read('config.ini');
+
+if ($< == 0){
+ print "Great, we are root, continuing...\n";
+} else {
+ print "Please run this script as root!\n";
+ exit(0);
+}
+
+my $dbh = DBI->connect("DBI:mysql:database=present;host=localhost;port=" . $cfg->{mysql}->{port},$cfg->{mysql}->{username},$cfg->{mysql}->{password}) or die "Unable to connect...\n";
+$dbh->do("delete from events");
+$dbh->do("delete from active_recording");
+$dbh->do("delete from vnc_clients");
+
+print "OK.\n";
View
33 root/config.ini
@@ -0,0 +1,33 @@
+[main]
+main_dir=/root/
+[mysql]
+username=root
+password=password
+port=3306
+[record]
+record_string=/usr/bin/arecord -f S16_LE -c1 -r44100 -D hw:1,0 -t wav
+topic_default= Default topic.
+www_root=/var/www/podcast/
+data_path=/var/www/data/
+
+[produce]
+# #EPISODENUMBER# - Episode number
+# #MONTH# - Month of recording
+# #YEAR# - Year of recording
+# #TOPIC# - Topic of recording
+start_string=You are listening to the podcast. This is episode number #EPISODENUMBER#. The topic for this podcast is #TOPIC#. This was a meeting during the month of #MONTH# in the year #YEAR#. Check us out at a relevant url. Now, on with the podcast...
+temp_directory=/root/tempdirectory/
+flite_path =/usr/bin/flite
+sox_path=/usr/local/bin/sox
+lame_path=/usr/bin/lame
+public_path=/var/www/public/
+mp32info2_path=/usr/local/bin/mp3info2
+perl_produce_path=/usr/bin/perl /root/produce.pl
+# Use _ for spaces for the following
+author=Your_Name
+# Able to use #EPISODENUMBER# , #MONTH# , #YEAR# and #TOPIC# are available here.
+title=Podcast_Episode_#EPISODENUMBER#
+[update_website]
+website_url=http://yourhost.org/
+rsync=/usr/bin/rsync --delete -avz /var/www/public/ -e ssh -i identify_file.txt ubuntu@yourhost.org:/var/www/
+template_dir=/root/templates/
View
14 root/create_podcasts.sql
@@ -0,0 +1,14 @@
+drop database if exists podcasts;
+create database podcasts;
+use podcasts;
+create table data(
+ podcast_id int not null primary key auto_increment,
+ epoch_time int null,
+ topic varchar(4000)
+);
+
+create table links(
+ link_id int not null primary key auto_increment,
+ podcast_id int,
+ link varchar(4000)
+);
View
32 root/create_present.sql
@@ -0,0 +1,32 @@
+drop database present;
+create database present;
+use present;
+create table vnc_clients(
+ client_id int,
+ password varchar(255),
+ barcode_ok int,
+ host_alias varchar(255),
+ ip varchar(255)
+);
+
+create table barcode_ok_code(
+ code int,
+ descript varchar(255)
+);
+
+insert into barcode_ok_code(code,descript) values (1,'Unable to connect.');
+insert into barcode_ok_code(code,descript) values (2,'Barcode unreadable.');
+insert into barcode_ok_code(code,descript) values (3,'Fail Reconnect Test.');
+insert into barcode_ok_code(code,descript) values (4,'Success.');
+
+create table active_recording(
+ epoch_start int
+);
+
+create table events(
+ event_epoch int,
+ event_type varchar(20),
+ event_extra varchar(4000)
+);
+
+create index x on events(event_epoch);
View
67 root/links.pl
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+use DBI;
+use Config::Tiny;
+
+my $cfg = new Config::Tiny->read('config.ini');
+
+if ($< == 0){
+ print "Great, we are root, continuing...\n";
+} else {
+ print "Please run this script as root!\n";
+ exit(0);
+}
+
+my $dbh = DBI->connect("DBI:mysql:database=podcasts;host=localhost;port=" . $cfg->{mysql}->{port},$cfg->{mysql}->{username},$cfg->{mysql}->{password}) or die "Unable to connect...\n";
+
+print "Menu:\n";
+print "1. Add link.\n";
+print "2. Remove Link.\n";
+print "Q. (Or anything other than 1 or 2): Quit\n";
+print "Selection: ";
+my $in = <STDIN>;
+$in =~ chomp ($in);
+if ($in eq '1'){
+ print "\n\nFor what podcast number? Selection:";
+ my $podin = <STDIN>;
+ $podin =~ chomp($podin);
+
+ print "\nLink: ";
+ my $linkin = <STDIN>;
+ $linkin =~ chomp($linkin);
+
+ my $sql2=qq{INSERT INTO links (podcast_id,link) values (?,?)};
+ my $sth2 = $dbh->prepare($sql2);
+ $sth2->execute($podin,$linkin);
+ print "Done!\n";
+ exit(0);
+}
+if ($in eq '2'){
+ my $sql3=qq{Select podcast_id,link,link_id from links order by link_id};
+ my $sth3 = $dbh->prepare($sql3);
+ $sth3->execute();
+ my $pod_id;
+ my $link;
+ my $link_id;
+ $sth3->bind_columns(undef,\$pod_id,\$link,\$link_id);
+ my $i=0;
+ while ($sth3->fetch()){
+ print "Link ID: $link_id \tLink: $link \tPodcast id: $pod_id\n";
+ $i = $i + 1;
+ }
+ if ($i > 1){
+ print "Link ID From Above: ";
+ my $x = <STDIN>;
+ $x =~ chomp($x);
+ my $sql4=qq{DELETE FROM links where link_id = ?};
+ my $sth4 = $dbh->prepare($sql4);
+ $sth4->execute($x);
+ print "OK.\n";
+ exit(0);
+ } else {
+ print "Nothing to delete...\n";
+ exit(0);
+ }
+}
+print "Exiting...\n";
+exit(0);
View
158 root/produce.pl
@@ -0,0 +1,158 @@
+#!/usr/bin/perl
+
+use File::Path ;
+use Proc::Background;
+use DBI;
+use File::Copy;
+use MP3::ID3v1Tag;
+use Config::Tiny;
+use strict;
+
+if ($< == 0){
+ print "Great, we are root, continuing...\n";
+} else {
+ print "Please run this script as root!\n";
+ exit(0);
+}
+
+
+my $cfg = new Config::Tiny->read('config.ini');
+
+mkpath $cfg->{produce}->{temp_directory} ;
+
+my $data_path = $cfg->{record}->{data_path};
+
+my $dbh = DBI->connect("DBI:mysql:database=present;host=localhost;port=" . $cfg->{mysql}->{port},$cfg->{mysql}->{username},$cfg->{mysql}->{password}) or die "Unable to connect to main db...\n";
+my $dbh2 = DBI->connect("DBI:mysql:database=podcasts;host=localhost;port=" . $cfg->{mysql}->{port},$cfg->{mysql}->{username},$cfg->{mysql}->{password}) or die "Unable to connect to podcast db...\n";
+
+my $sql = qq{SELECT epoch_start FROM active_recording};
+my $sth = $dbh->prepare($sql);
+$sth->execute();
+my @ary = $sth->fetchrow_array();
+my $epoch = $ary[0];
+print "START \n";
+if (!( -e $data_path . $epoch . "/audio.wav")){
+ print "Audio does not exist.\n";
+}
+my $x = Proc::Background->new("/bin/cp " . $data_path . $epoch . "/audio.wav " . $data_path . $epoch . "/convert.wav ");
+$x->wait(); # Make audio.wav a convert.wav # need to do the directory thing here!
+
+print "Inserting into podcast table...\n";
+
+my $sql = qq{SELECT event_extra FROM events where event_epoch = ?};
+my $sth = $dbh->prepare($sql);
+$sth->execute($epoch);
+
+my ($topic) = $sth->fetchrow_array();
+
+my $sqlp = qq{INSERT INTO data(epoch_time,topic) values (?,?)};
+my $sthp = $dbh2->prepare($sqlp);
+$sthp->execute($epoch,$topic);
+
+my $last_id = $dbh2->{'mysql_insertid'};
+&writePodcastIntro($last_id,$epoch,$topic);
+
+my $x = Proc::Background->new($cfg->{produce}->{flite_path} . " " . $cfg->{produce}->{temp_directory} . "tmp.txt -o " . $cfg->{produce}->{temp_directory} . "tmp.wav");
+$x->wait();
+
+print "Done!\n";
+print "Converting...\n";
+my $cv = Proc::Background->new($cfg->{produce}->{sox_path} . " " . $cfg->{produce}->{temp_directory} . "tmp.wav " . $cfg->{produce}->{temp_directory} . "tmpconv.wav rate 44.1k");
+$cv->wait();
+
+print "Making paths...\n";
+mkpath ($cfg->{produce}->{public_path} . "pngs/$last_id/");
+mkpath ($cfg->{produce}->{public_path} . "attachments/$last_id/");
+mkpath ($cfg->{produce}->{public_path} . "mp3s/$last_id/");
+print "Done!\nIdentifying events to edit...";
+
+my $sqlpub = qq {SELECT event_epoch,event_type from events where event_epoch >= ? order by event_epoch};
+
+my $sthpub = $dbh->prepare($sqlpub);
+$sthpub->execute($epoch);
+my $ee;
+my $et;
+my $filestart ;
+my $start = 0;
+my $stop;
+my $part = 0;
+my $quited = 0;
+$sthpub->bind_columns(undef,\$ee,\$et);
+while ($sthpub->fetch()){
+ next if ($quited == 1);
+ print "event type: $et\n";
+ if ($et eq 'START'){
+ $filestart = $ee;
+ $start = $ee;
+ }
+ if ($et eq 'QUIT') {
+ $quited=1;
+ $part = $part + 1;
+ $stop = $ee;
+ my $x = $cfg->{'produce'}->{'sox_path'} . " " . $cfg->{'record'}->{'data_path'} . $epoch . "/convert.wav " . $cfg->{'record'}->{'data_path'} . $epoch . "/part" . $part . ".wav trim " . ($start - $filestart) . " " . ($stop-$start) ;
+ print "$x\n";
+ my $z = Proc::Background->new($x);
+ $z->wait();
+ }
+ if (($et eq 'Screen Capture')){
+ copy ($cfg->{'record'}->{'data_path'} . $epoch . "/$ee.png",$cfg->{'produce'}->{'public_path'} . "/pngs/" . $last_id . "/");
+ }
+}
+
+print "Generating new wav file...\n";
+my $zstr = $cfg->{'produce'}->{'sox_path'} . " " . $cfg->{produce}->{temp_directory} . "tmpconv.wav " . $cfg->{'record'}->{'data_path'} . $epoch . "/convert.wav " . $cfg->{'record'}->{'data_path'} . $epoch . "/tmp.wav";
+my $z = Proc::Background->new($zstr);
+$z->wait();
+
+my $i = 1;
+while ($i < $part){
+ $i = $i + 1;
+ print "Processing Part $i\n";
+ my $str = $cfg->{'produce'}->{'sox_path'} . " " . $cfg->{'record'}->{'data_path'} . $epoch ."/tmp.wav " . $cfg->{'record'}->{'data_path'} . $epoch . "/part$i.wav " . $cfg->{'record'}->{'data_path'} . $epoch . "/tmp2.wav";
+ $z = Proc::Background->new($str);
+ $z->wait();
+ move($cfg->{'record'}->{'data_path'} . $epoch . "/tmp2.wav",$cfg->{'record'}->{'data_path'} . $epoch . "/tmp.wav");
+}
+mkpath ($cfg->{'produce'}->{'public_path'} . "/mp3s/$last_id/");
+print "running lame...\n";
+my $x = Proc::Background->new($cfg->{'produce'}->{'lame_path'} . " -h " . $cfg->{'record'}->{'data_path'} . $epoch . "/tmp.wav " . $cfg->{'produce'}->{'public_path'} . "mp3s/$last_id/$epoch.mp3");
+$x->wait();
+
+my $author = $cfg->{produce}->{author};
+my $title = $cfg->{produce}->{title};
+$title =~s/\#EPISODENUMBER\#/$last_id/g;
+$title =~s/\#TOPIC\#/$topic/g;
+my @local = localtime($epoch);
+my @abbr = qw( January Febuary March Aprl May June July August September October November December );
+my $year = $local[5] + 1900;
+$title =~s/\#YEAR\#/$year/g;
+my $month = $abbr[$local[4]];
+$title =~s/\#MONTH\#/$month/g;
+
+
+my $z = Proc::Background->new($cfg->{'produce'}->{'mp32info2_path'} . " -t " . $title . " -a " . $author . " -n $last_id " . $cfg->{'produce'}->{'public_path'} . "mp3s/$last_id/$epoch.mp3");
+$z->wait();
+print "Done!\n";
+
+sub writePodcastIntro{
+ my $last_id = shift;
+ my $epoch = shift;
+ my $topic = shift;
+
+ my @local = localtime($epoch);
+ my @abbr = qw( January Febuary March Aprl May June July August September October November December );
+
+ my $start = $cfg->{produce}->{start_string};
+ $start =~s/\#EPISODENUMBER\#/$last_id/g;
+ $start =~s/\#TOPIC\#/$topic/g;
+ my $year = $local[5] + 1900;
+ $start =~s/\#YEAR\#/$year/g;
+ my $month = $abbr[$local[4]];
+ $start =~s/\#MONTH\#/$month/g;
+
+
+ open (OUT,">",$cfg->{produce}->{temp_directory} . "tmp.txt");
+ print OUT $start;
+ close OUT;
+
+}
View
126 root/record.pl
@@ -0,0 +1,126 @@
+#!/usr/bin/perl
+
+use File::Path ;
+use Proc::Background;
+use DBI;
+use Net::VNC;
+use Config::Tiny;
+
+my $cfg = new Config::Tiny->read('config.ini');
+
+if ($< == 0){
+ print "Great, we are root, continuing...\n";
+} else {
+ print "Please run this script as root!\n";
+ exit(0);
+}
+
+my $dbh = DBI->connect("DBI:mysql:database=present;host=localhost;port=" . $cfg->{mysql}->{port},$cfg->{mysql}->{username},$cfg->{mysql}->{password}) or die "Unable to connect...\n";
+$dbh->do("delete from events");
+$dbh->do("delete from active_recording");
+print "Default topic: " . $cfg->{record}->{topic_default} . "\n";
+print "Default topic will be used for the topic unless you change the value below.\n";
+print "Enter topic for the inital podcast: ";
+my $topic = <STDIN>;
+$topic =~ chomp ($topic);
+
+if (length($topic)==0){
+ print "Using default topic...\n";
+ $topic = $cfg->{record}->{topic_default};
+}
+
+my $epoch = time;
+
+my $data_dir = $cfg->{record}->{data_path} . $epoch;
+mkpath $data_dir;
+my $sql = qq{INSERT into active_recording(epoch_start) value (?)};
+my $sth = $dbh->prepare($sql);
+$sth->execute($epoch);
+&insertEvent($epoch,"START",$topic);
+my $recorder = Proc::Background->new($cfg->{record}->{record_string} . " " . $data_dir ."/audio.wav");
+sleep (1);
+if ($recorder->alive()){
+ print "OK\n";
+} else {
+ print "There was something wrong with the record string. Check the value and try again.\n";
+ exit (0);
+}
+system("clear");
+
+while (1==1){
+ print "Menu:\n";
+ my $sql2=qq{SELECT host_alias,password,ip from vnc_clients where barcode_ok=4 order by client_id};
+ my $sth2 = $dbh->prepare($sql2);
+ $sth2->execute();
+ my $ha;
+ my $pw;
+ my $ip;
+ $sth2->bind_columns(undef,\$ha,\$pw,\$ip);
+ my $i = 0;
+ my %hash;
+ while ($sth2->fetch()){
+ $i = $i + 1;
+ print "$i : $ha : $ip \n";
+ $hash{$i} = $ha . ":" . $ip . ":" . $pw;
+ }
+ print "S or +: Delay 5 seconds before doing x...\n";
+ print "Q: Quit\n";
+
+ print "Selection:";
+ my $sel = <STDIN>;
+ $sel =~ chomp ($sel);
+ if (($sel =~/\+/) || ($sel =~ /S/i)){
+ print "Sleeping 5 seconds...\n";
+ sleep(5);
+ $sel =~ s/\+//g;
+ $sel =~ s/S//g;
+ $sel =~ s/s//g;
+ $sel =~ s/\ //g; # Remove space between commands if any
+ }
+ if ($sel =~/q/i){
+ print "Quiting...\n";
+ $recorder->die();
+ my $z = time;
+ &insertEvent($z,"QUIT");
+ exit(0);
+ }
+
+ if ($sel =~/[0-9]+/){
+ my $vnc;
+ if (exists $hash{$sel}){
+ print "Capturing screen...\n";
+ eval{
+ my @parts = split /\:/,$hash{$sel};
+ print "Conecting to : $parts[1] ... \n";
+ $vnc = Net::VNC->new({hostname=>$parts[1],password=>$parts[2]});
+ $vnc->login();
+ print "conected ok...\n";
+ my $z = time;
+ &insertEvent($z,"Screen Capture");
+ my $img = $vnc->capture();
+ $img->save($data_dir . "/" . $z . ".png");
+ print "Done!\n";
+ };
+ if ($@){
+ print "error occured capturing screen shot...\n";
+ }
+ }
+ }
+}
+
+sub insertEvent{
+ my $epoch = shift;
+ my $event_type = shift;
+ my $optional = shift;
+
+ if (length($optional)==0){
+ my $esql = qq{INSERT INTO events(event_epoch,event_type) values (?,?)};
+ my $esth = $dbh->prepare($esql);
+ $esth->execute($epoch,$event_type);
+ } else {
+ my $esql = qq{INSERT INTO events(event_epoch,event_type,event_extra) values (?,?,?)};
+ my $esth = $dbh->prepare($esql);
+ $esth->execute($epoch,$event_type,$optional);
+
+ }
+}
View
25 root/templates/index_head.html
@@ -0,0 +1,25 @@
+<HTML><BODY>
+<!--
+
+Zachary Zebrowski ; zaz@mitre.org
+
+The author’s affiliation with the MITRE Corporation is provided for identification purposes only and is not intended to convey or imply MITRE’s concurrence with, or support for, the positions opinions or viewpoints expressed by the author.
+
+Date of release: (TBD)
+Case-Number (TBD)
+
+Not Yet Approved for Public Release ; Distribution Limited
+
+© 2012 The MITRE Corporation. All Rights Reserved
+
+
+
+This software is licensed under the perl artisitic license. The description of the license appears below, and is available via :
+
+http://perldoc.perl.org/perlartistic.html
+-->
+
+<IMG SRC="header.jpg"><BR><BR>
+Our main web page: <A HREF="http://oursite.org">http://oursite.org</A><BR>
+Our podcast feed: <A HREF="rss_feed.rss">rss_feed.rss</A>.<BR>
+Our itunes URL link: <A HREF="http://itunes.apple.com/...">Link</A>.<BR><BR>
View
7 root/templates/rss_head.txt
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<rss version="2.0">
+<channel>
+<title>Podcast</title>
+<link>http://yourhost.org</link>
+<copyright>CC-Attribution-NonCommercial-ShareAlike 3.0 United States License</copyright>
+<description>Podcast</description>
View
141 root/update_website.pl
@@ -0,0 +1,141 @@
+#!/usr/bin/perl
+
+use DBI;
+use Proc::Background;
+use File::Find;
+use Config::Tiny;
+use URI::Escape;
+use File::Path qw(make_path);
+my $cfg = Config::Tiny->read('config.ini');
+
+if ($< == 0){
+ print "Great, we are root, continuing...\n";
+} else {
+ print "Please run this script as root!\n";
+ exit(0);
+}
+
+
+my $dbh2 = DBI->connect("DBI:mysql:database=podcasts;host=localhost;port=3306",$cfg->{'mysql'}->{'username'},$cfg->{'mysql'}->{'password'}) or die "Unable to connect to podcast db...\n";
+
+# Generate HTML Index & RSS Feed
+my $sql = qq{SELECT podcast_id,topic from data order by podcast_id desc};
+my $sth = $dbh2->prepare($sql);
+$sth->execute();
+
+my $pid;
+my $topic;
+$sth->bind_columns(undef,\$pid,\$topic);
+open (INDEXHTML,">",$cfg->{'produce'}->{'public_path'} . "index.html");
+open (INDEXHEAD,"<",$cfg->{'update_website'}->{'template_dir'} . "index_head.html") or die "No html head";
+while (<INDEXHEAD>){
+ print INDEXHTML $_;
+}
+close INDEXHEAD;
+open (NEWRSSINDEX,">",$cfg->{'produce'}->{'public_path'} . "rss_feed.rss");
+open (RSSHEADER,"<",$cfg->{'update_website'}->{'template_dir'} . "rss_head.txt");
+while (<RSSHEADER>){
+ print NEWRSSINDEX $_;
+}
+close RSSHEADER;
+my $size;
+my $count;
+my $attachmentcount;
+
+while ($sth->fetch()){
+ $count = 0;
+ $attachmentcount=0;
+ print INDEXHTML "Episode # " . $pid . " : $topic : <A HREF=\"./mp3s/$pid/" ;
+ find(\&printHTMLName,$cfg->{'produce'}->{'public_path'} . "./mp3s/$pid/");
+ print INDEXHTML "\">mp3</A> ";
+ find(\&checkForPics,$cfg->{'produce'}->{'public_path'} . "pngs/$pid/");
+ if ($count == 1){
+ print INDEXHTML " : <A HREF=\"./pngs/$pid/\">Screen Shots</A>";
+ }
+ find(\&attachments,$cfg->{'produce'}->{'public_path'} . "attachments/$pid/");
+ if ($attachmentcount == 1){
+ print INDEXHTML " : <A HREF=\"./attachments/$pid/\">Attachments</A>";
+ }
+ my $sql1=qq{SELECT COUNT(*) FROM links where podcast_id = ?};
+ my $sth1 = $dbh2->prepare($sql1);
+ $sth1->execute($pid);
+ my @ary = $sth1->fetchrow_array();
+ if ($ary[0] > 0){
+ print INDEXHTML " : <A HREF=\"./links/$pid/links.html\">Links</A>";
+ }
+ print INDEXHTML "<BR>";
+ print NEWRSSINDEX "<item>\n";
+ print NEWRSSINDEX " <title>Episode #" . $pid . "</title>\n";
+ my $new_topic = $topic;
+ $new_topic = uri_escape($topic);
+ $new_topic =~ s/%20/ /g;
+ print NEWRSSINDEX " <description>Episode #" . $pid . " : " . $new_topic . "</description>\n";
+ print NEWRSSINDEX " <enclosure url=\"" . $cfg->{'update_website'}->{'website_url'} . "mp3s/" . $pid . "/";
+ find(\&printName,$cfg->{'produce'}->{'public_path'} . "mp3s/$pid/");
+ print NEWRSSINDEX "\" length=\"$size\" type=\"audio/mpeg\" />\n";
+ print NEWRSSINDEX "</item>\n";
+}
+print NEWRSSINDEX "</channel>\n";
+print NEWRSSINDEX "</rss>";
+close NEWRSSINDEX;
+print INDEXHTML "<BR></BODY></HTML>";
+close INDEXHTML ;
+
+my $linksql = qq{select distinct(podcast_id) from links};
+my $linksth = $dbh2->prepare($linksql);
+$linksth->execute();
+
+my $p;
+$linksth->bind_columns(undef,\$p);
+while ($linksth->fetch()){
+ make_path $cfg->{'produce'}->{'public_path'} . "/links/$p/";
+ my $sql2=qq{select link from links where podcast_id = ?};
+ my $sth2 = $dbh2->prepare($sql2);
+ $sth2->execute($p);
+ my $link;
+ $sth2->bind_columns(undef,\$link);
+ open(OUT,">",$cfg->{'produce'}->{'public_path'} . "/links/$p/links.html");
+ print OUT "<HTML><BODY>";
+ print OUT "Links:<BR><BR>";
+ while ($sth2->fetch()){
+ print OUT "<A HREF=\"$link\">$link</A><BR><BR>";
+ }
+ print OUT "</BODY></HTML>";
+ close OUT;
+}
+
+sub checkForPics{
+ my $x = $_;
+ next if (-d $x);
+ next if ($x =~/index.html/);
+ $count = 1;
+}
+sub attachments{
+ my $x = $_;
+ next if (-d $x);
+ $attachmentcount = 1;
+}
+
+
+sub printName{
+ my $fn = $_;
+ next if (-d $fn);
+ print NEWRSSINDEX $fn ;
+ $size = -s $fn;
+}
+sub printHTMLName{
+ my $fn = $_;
+ next if (-d $fn);
+ print INDEXHTML $fn ;
+}
+
+# Set permissions on files...
+my $x = Proc::Background->new("/bin/chmod 755 -R " . $cfg->{'produce'}->{'public_path'} );
+$x->wait();
+
+# Sync /public directory to site.
+
+my $z = Proc::Background->new($cfg->{'update_website'}->{'rsync'});
+$z->wait();
+
+print "Done!\n";
View
28 www/Barcode/barcode.css
@@ -0,0 +1,28 @@
+/*==============================================================
+ CODE 128 styles
+===============================================================*/
+
+/* ------------------- Horizontal Barcode -------------------- */
+.barcode128h {
+ clear: both;
+ padding: 0 10px /*quiet zone*/;
+ overflow: auto;
+ height: 900px /*size*/;
+}
+
+.barcode128h div {
+ /*float: left;*/
+ height: 880px /*size*/;
+ display: inline-block;
+}
+
+
+.barcode128h .bar1 { border-left: 10px solid black }
+.barcode128h .bar2 { border-left: 20px solid black }
+.barcode128h .bar3 { border-left: 30px solid black }
+.barcode128h .bar4 { border-left: 40px solid black }
+.barcode128h .space0 { margin-right: 0px }
+.barcode128h .space1 { margin-right: 10px }
+.barcode128h .space2 { margin-right: 20px }
+.barcode128h .space3 { margin-right: 30px }
+.barcode128h .space4 { margin-right: 40px }
View
74 www/Barcode/barcode.js
@@ -0,0 +1,74 @@
+BARS = [212222,222122,222221,121223,121322,131222,122213,122312,132212,221213,221312,231212,112232,122132,122231,113222,123122,123221,223211,221132,221231,213212,223112,312131,311222,321122,321221,312212,322112,322211,212123,212321,232121,111323,131123,131321,112313,132113,132311,211313,231113,231311,112133,112331,132131,113123,113321,133121,313121,211331,231131,213113,213311,213131,311123,311321,331121,312113,312311,332111,314111,221411,431111,111224,111422,121124,121421,141122,141221,112214,112412,122114,122411,142112,142211,241211,221114,413111,241112,134111,111242,121142,121241,114212,124112,124211,411212,421112,421211,212141,214121,412121,111143,111341,131141,114113,114311,411113,411311,113141,114131,311141,411131,211412,211214,211232,23311120];
+START_BASE = 38
+STOP = 106 //BARS[STOP]==23311120 (manually added a zero at the end)
+
+var fromType128 = {
+ A: function(charCode) {
+ if (charCode>=0 && charCode<32)
+ return charCode+64;
+ if (charCode>=32 && charCode<96)
+ return charCode-32;
+ return charCode;
+ },
+ B: function(charCode) {
+ if (charCode>=32 && charCode<128)
+ return charCode-32;
+ return charCode;
+ },
+ C: function(charCode) {
+ return charCode;
+ }
+};
+
+function code128(code, barcodeType) {
+ if (arguments.length<2)
+ barcodeType = code128Detect(code);
+ if (barcodeType=='C' && code.length%2==1)
+ code = '0'+code;
+ var a = parseBarcode128(code, barcodeType);
+ return bar2html128(a.join('')) ;//+ '<label>' + code + '</label>';
+}
+
+function code128Detect(code) {
+ if (/^[0-9]+$/.test(code)) return 'C';
+ if (/[a-z]/.test(code)) return 'B';
+ return 'A';
+}
+
+function parseBarcode128(barcode, barcodeType) {
+ var bars = [];
+ bars.add = function(nr) {
+ var nrCode = BARS[nr];
+ this.check = this.length==0 ? nr : this.check + nr*this.length;
+ this.push( nrCode || format("UNDEFINED: %1->%2", nr, nrCode) );
+ };
+
+ bars.add(START_BASE + barcodeType.charCodeAt(0));
+ for(var i=0; i<barcode.length; i++)
+ {
+ var code = barcodeType=='C' ? +barcode.substr(i++, 2) : barcode.charCodeAt(i);
+ converted = fromType128[barcodeType](code);
+ if (isNaN(converted) || converted<0 || converted>106)
+ throw new Error(format("Unrecognized character (%1) at position %2 in code '%3'.", code, i, barcode));
+ bars.add( converted );
+ }
+ bars.push(BARS[bars.check % 103], BARS[STOP]);
+
+ return bars;
+}
+
+function format(c){
+ var d=arguments;
+ var e= new RegExp("%([1-"+(arguments.length-1)+"])","g");
+ return(c+"").replace(e,function(a,b){return d[b]})
+}
+
+function bar2html128(s) {
+ for(var pos=0, sb=[]; pos<s.length; pos+=2)
+ {
+ sb.push('<div class="bar' + s.charAt(pos) + ' space' + s.charAt(pos+1) + '"></div>');
+ }
+ return sb.join('');
+}
+
+
View
6 www/cgi-bin/config.ini
@@ -0,0 +1,6 @@
+[main]
+main_dir=/root/
+[mysql]
+username=root
+password=password
+port=3306
View
21 www/cgi-bin/index.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use CGI qw/:standard/;
+use Net::Address::IP::Local;
+
+print header;
+
+print "<HTML><BODY>";
+print "DC.PM Podcaster Software<BR><BR>";
+print "My IP address is: " . Net::Address::IP::Local->public_ipv4 . "<BR><BR>";
+
+# Check to see if presentation is ready
+# If so
+
+print "To add yourself as a presentor, click <A HREF=\"present.pl\">here</A>.<BR>";
+
+print "</BODY></HTML>";
+
+
+
+
View
23 www/cgi-bin/present.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+
+use CGI qw/:standard/;
+use Net::Address::IP::Local;
+
+print header;
+
+print "<HTML><BODY>";
+print "Thank you for being a presenter.<BR>";
+print "Pleae make sure VNC is installed as a service on your computer.<BR>";
+print "<B><FONT COLOR=\"RED\">PLEASE NOTE</FONT>:";
+print "Your screen will be captured through the course of your presentation. This may be shared over the podcast. Please refrain from sharing personal information you do not wish to have publically available during this time.<BR>";
+print "You acknowledge by proceeding that you have read this disclaimer.<BR></B>";
+print "<BR><BR>";
+print "Once you hit submit, you will see a barcode on your screen while we test to ensure that VNC has been set up correctly on your computer.<BR>";
+print "Do <b>not</b> minimize the window while the barcode is displayed.<BR>";
+print "You will see an OK message once your machine has been verified, with a PC number that we will use to access your screen. Please be sure that Zak knows this number... :)<BR>";
+print "<FORM METHOD=\"post\" action=\"presentor_start.pl\">";
+print "Optional - VNC Password: <INPUT TYPE=\"PASSWORD\" NAME=\"PASSWORD\"><BR>";
+print "Your name / Machine name (eg. Brock's PC or Brock's Phone): <INPUT TYPE=\"TEXT\" NAME=\"HOST_ALIAS\"><BR><BR>";
+print "<INPUT TYPE=\"submit\" NAME=\"Submit\" VALUE=\"Submit\"><BR>";
+print "</BODY></HTML>";
+
View
37 www/cgi-bin/presentor_start.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use DBI;
+use Net::Address::IP::Local;
+use URL::Encode qw/url_encode/;
+
+
+use CGI qw/:standard/;
+
+print header;
+
+my $number = int(rand 1000) + 100;
+
+my $password = param("PASSWORD");
+my $host_alias = param("HOST_ALIAS");
+
+print "<HTML><head>";
+print "<meta http-equiv=\"refresh\" content=\"30; url=http://" . Net::Address::IP::Local->public_ipv4 . "/cgi-bin/vnc_results.pl?SOURCE=$number\">";
+print "<link rel=\"stylesheet\" href=\"/Barcode/barcode.css\" type=\"text/css\">";
+print "<script src=\"/Barcode/barcode.js\" type=\"text/javascript\"></script>";
+
+print "</head><BODY onload=\"go();\">";
+print "Please wait... <BR>";
+print "Number : $number <BR>";
+print "<div class=\"barcode128h\" id=\"barcode\"></div>";
+print "<BR>";
+print "<script type=\"text/javascript\">";
+print " var strBarcodeHTML = code128('Z' + $number);"; # Darn u javascript
+print " document.getElementById(\"barcode\").innerHTML = strBarcodeHTML;";
+print "function go(){";
+print "var image = new Image();";
+print "image.onload = function() {";
+print "window.location=\"http://" . Net::Address::IP::Local->public_ipv4 . "/cgi-bin/vnc_results.pl?SOURCE=$number\";";
+print "};";
+print " image.src='/cgi-bin/wait_for_vnc.pl?SOURCE=$number&P=" . url_encode($password) . "&HA=" . url_encode($host_alias) . "';";
+
+print "}\n";
+print "</script></body></html>";
View
59 www/cgi-bin/vnc_results.pl
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+use HTML::Barcode::Code128;
+use Image::Dot;
+use DBI;
+use Net::VNC;
+use URL::Encode qw/url_encode/;
+use Proc::Background;
+use Config::Tiny;
+
+my $cfg = Config::Tiny->read('config.ini');
+
+
+use CGI qw/:standard/;
+
+my $source = param("SOURCE"); # Source ID
+
+my $dbh = DBI->connect("DBI:mysql:database=present;host=localhost;port=3306",$cfg->{'mysql'}->{'username'},$cfg->{'mysql'}->{'password'});
+
+my $sql = qq{select barcode_ok from vnc_clients where client_id = ?};
+my $sth = $dbh->prepare($sql);
+$sth->execute($source);
+
+my @result = $sth->fetchrow_array();
+
+print header;
+print "<HTML><BODY>";
+print "Results:<BR>";
+if ($result[0] ==1){
+ print "<B>Not OK</B><BR>";
+ print "We were unable to connect to your system. <BR>";
+ print "<UL><LI>Is VNC Running?</LI><LI>Did you enter your password correctly?</LI><LI>Do you have a firewall blocking the connection?</LI><LI>Do you need to accept incoming vnc requests? (Please disable this. :))</LI></UL>";
+ print "When you wish to start again, click <A HREF=\"/cgi-bin/present.pl\">here</A><BR>";
+ print "</BODY></HTML>";
+ exit(0);
+}
+
+if ($result[0] == 2){
+ print "<B>Not OK</B><BR>";
+ print "We were able to connect to your system, but we were unable to scan the barcode which indicates that your system is running succesfully...<BR>";
+ print "<UL><LI>Is your VNC software up to date? (This error is generally fixed with newer versions)</LI><LI>Did you minimize the window before you got a success message?</LI></UL>";
+ print "When you wish to start again, click <A HREF=\"/cgi-bin/present.pl\">here</A><BR>";
+ print "</BODY></HTML>";
+ exit(0);
+}
+if ($result[0] == 3){
+ print "<B>Not OK</B><BR>";
+ print "We were able to connect to your system initially, but we were unable to connect to your system a second time. (Each time we capture the screen, we make a new vnc connection to your system.) Please fix this.<BR>";
+ print "When you wish to start again, click <A HREF=\"/cgi-bin/present.pl\">here</A><BR>";
+ print "</BODY></HTML>";
+ exit(0);
+}
+if ($result[0] == 4){
+ print "<B>OK!</B><BR>";
+ print "You have been added as a presentor. You may close this window or navigate to another page...<BR>";
+ print "Or click <A HREF=\"/\">here</A> to go back to the main menu of this app.<BR>";
+ print "</BODY></HTML>";
+ exit(0);
+}
+
View
71 www/cgi-bin/wait_for_vnc.pl
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+use HTML::Barcode::Code128;
+use Image::Dot;
+use DBI;
+use Net::VNC;
+use URL::Encode qw/url_encode/;
+use Proc::Background;
+use Config::Tiny;
+use CGI qw/:standard/;
+
+my $cfg = Config::Tiny->read('config.ini');
+
+my $source = param("SOURCE"); # Source ID
+my $host_alias = param("HA");
+my $password = param("P");
+my $remote_ip = $ENV{REMOTE_ADDR};
+
+my $dbh = DBI->connect("DBI:mysql:database=present;host=localhost;port=3306",$cfg->{'mysql'}->{'username'},$cfg->{'mysql'}->{'password'});
+
+my $vnc ;
+eval{
+ $vnc = Net::VNC->new({hostname=>$remote_ip,password=>$password});
+ $vnc->login();
+ my $img = $vnc->capture;
+ $img->save("/tmp/img_$source.png");
+ undef $vnc;
+};
+if ($@){
+ # Error caught
+ &doInsert(1);
+}
+
+my $proc = Proc::Background->new("/usr/bin/zbarimg --raw /tmp/img_" . $source . ".png > /tmp/img_" . $source . "_result.txt");
+$proc->wait();
+
+open (IN,"<","/tmp/img_" . $source . "_result.txt");
+my $line;
+while (<IN>){
+ $line = $_;
+ $line =~ chomp ($line);
+}
+close IN;
+my $test = 'Z' . $source;
+if ($line eq $test){
+ eval{
+ $vnc = Net::VNC->new({hostname=>$remote_ip,password=>$password});
+ $vnc->login();
+ my $img = $vnc->capture;
+ $img->save("/tmp/img_$source.png");
+ };
+ my $a = $@;
+ if ($a){
+ &doInsert(3);
+ } else {
+ &doInsert(4);
+ }
+} else {
+ &doInsert(2);
+}
+
+sub doInsert{
+ my $ok = shift;
+ my $sql = qq{INSERT INTO vnc_clients(client_id,password,barcode_ok,host_alias,ip) values (?,?,?,?,?)};
+ my $sth = $dbh->prepare($sql);
+ $sth->execute($source,$password,$ok,$host_alias,$remote_ip);
+ print header(type=>'image/png');
+ my $reddot = dot_PNG_RGB(255, 0, 0);
+ print $reddot;
+ exit(0);
+}
+
View
8 www/index.html
@@ -0,0 +1,8 @@
+<html><body><A HREF="/cgi-bin/index.pl">Click here...</A><BR>
+<script type="text/javascript">
+<!--
+window.location = "../cgi-bin/index.pl";
+//-->
+</script>
+
+</body></html>
View
BIN www/static/wait.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 38229e6

Please sign in to comment.