#!/usr/bin/perl use strict; use warnings; use Apache::DBI; use DBI; use CGI; use HTML::Template; use vars qw($q $template); sub myMain { $q = CGI->new(); # Instance the template object $template = new HTML::Template(filename => 'templates/usermanagement.tpl', die_on_bad_params => 0, stack_debug => 0, cache => 0, debug => 0); print $q->header(); if(defined($q->param("submit"))) { send_user_info(); } # print out base template print_menu(); } sub print_menu() { $template->param("MAIN_MENU" => 1); print $template->output(); } sub send_user_info() { my $enteredUsername = $q->param("username") || ""; my $enteredEmail = $q->param("email") || ""; if($enteredUsername eq "" && $enteredEmail eq "") { return print_status_message("#FF0000", "You must fill in at least one search parameter."); } if($enteredUsername eq "") { $enteredUsername = "%"; } if($enteredEmail eq "") { $enteredEmail = "%"; } # Instance the database connection my $dbh = DBI->connect("DBI:mysql:database=omnovia_conf;host=db.omnovia.com;", "secconf", "s3cc0nf", {'RaiseError' => 1}); # my $shorturl = substr $ENV{'HTTP_HOST'}, 0,index($ENV{'HTTP_HOST'},'.'); # my $sql = "SELECT companyID from company WHERE shorturl = '$shorturl'"; # my ($companyID) = $dbh->selectrow_array($sql); #$sql = "SELECT username, password, email FROM users" # . " WHERE companyID = $companyID AND LOWER(username) LIKE LOWER('$enteredUsername') AND LOWER(email) LIKE LOWER('$enteredEmail')"; my $sql = "SELECT username, password, email FROM users" . " WHERE LOWER(username) LIKE LOWER('$enteredUsername') AND LOWER(email) LIKE LOWER('$enteredEmail')"; my ($username, $password, $email) = $dbh->selectrow_array($sql); if(defined($password)) { send_info($username, $password, $email); return print_status_message("#00c300", "Your login information has been sent to the email address on file."); } else { return print_status_message("#FF0000", "No username was found matching entered criteria."); } } sub send_info() { my ($username, $password, $to) = @_; my $from = "omNovia Support "; my $subject = "omNovia Web Conference Username and Password"; my $body = "This is an automated email response. Please do not reply.\n\nomNovia Web Conference Login Information\n\nUsername: $username\nPassword: $password"; open(MAIL, "|/usr/lib/sendmail -t") || die "Can't open /usr/lib/sendmail!\n"; print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n"; print MAIL $body; close(MAIL); } sub print_status_message() { my ($color, $statusMsg) = @_; $template->param("SHOW_STATUS" => 1, "STATUS_MSG" => $statusMsg, "STATUS_COLOR" => $color); return 1; } &myMain();