#!/usr/bin/perl # Written By Jon # This script takes CONF_IN and populates # 3 templates which are then put into a final file all # together # Usage: perl conf_add.pl # requires: # input: templates in templates folder # input: list of conference IDs and conference PINs # with ID and PIN on one line in order. # program outputs to file: conference_additions # # TODO: Error handling when there are no entries in CONF_ID # TODO: SCP files to server # TODO: Random Number Generator # TODO: Add insert.pl use strict; use warnings; use File::Copy ("cp"); use POSIX; my $TEMPLATES_DIR = "templates"; my $FINISHED_DIR = "finished_list"; my $OUTPUT_DIR = "additions"; my $date = POSIX::strftime('%d_%b', localtime); open(my $confid_fh, "<", $ARGV[0]) || die("$!\n"); my $i = 0; while (my $line = <$confid_fh>) { $i++; my ($confID, $confPIN) = split(" ", $line); process_template("conf_template1", "conf_list1.tmp", { XXXXXX => $confID }); process_template("conf_template2", "conf_list2.tmp", { XXXXXX => $confID, AAAA => $confPIN }); process_template("conf_template3", "conf_list3.tmp", { XXXXXX => $confID }); } close $confid_fh; open(my $confadd_fh, ">>", $OUTPUT_DIR . "/additions_$ARGV[0]_$date") || die("$!\n"); # adds 1st set of conf config to conf_additions print $confadd_fh "; start conference config 1\n"; append("conf_list1.tmp", $confadd_fh); # adds 2nd set of conf config to conf_additions print $confadd_fh "\n\n; start conference config 2\n"; append("conf_list2.tmp", $confadd_fh); # adds 3rd set of conf config to conf_additions print $confadd_fh "\n\n; meetme_additional_custom.conf\n"; append("conf_list3.tmp", $confadd_fh); close $confadd_fh; # moves list to finished folder cp($ARGV[0], $FINISHED_DIR . "/$ARGV[0].finished"); unlink $ARGV[0]; # deletes temporary files unlink "conf_list1.tmp" || die("$!\n"); unlink "conf_list2.tmp" || die("$!\n"); unlink "conf_list3.tmp" || die("$!\n"); print "Number of Entries processed: $i\n"; exit 0; sub process_template { my ($tmplfile, $outfile, $substitutions_ref) = @_; open(my $out_fh, ">>", $outfile) || die("$!\n"); open(my $template_fh, "<", $TEMPLATES_DIR . "/" . $tmplfile) || die("$!\n"); while (my $line = <$template_fh>) { while (my ($key, $value) = each %{$substitutions_ref}) { $_ =~ s/$key/$value/g; } print $out_fh $_; } close $template_fh; close $out_fh || die("$!\n"); } sub append { my ($infile, $out_fh) = @_; open(my $in_fh, "<", $infile) || die("$!\n"); while (<$in_fh>) { print $out_fh $_; } close $in_fh; }