#!/usr/bin/perl # Support Center # Provided By CGI Connection # http://www.CGIConnection.com $| = 1; use Socket; srand(); # Directory to store all messages # Eg. /path/to/your/web/server # CHMOD to 777 #$save_dir = "!SAVEDIR!"; $save_dir = "./supportlogs/"; # SMTP server (usually set to localhost or leave blank) #$SMTP_SERVER = "!SMTP!"; $SMTP_SERVER = localhost; # Username to login to administration section #$username = "!USERNAME!"; $username = "mike"; # Password to login to administration section #$password = "!PASSWORD!"; $password = "letmesee"; # Entire URL to your support.cgi script # Eg. http://www.yourserver.com/cgi-bin/support.cgi #$cgi_url = "http://!SCRIPTURL!"; $cgi_url = "http://lusoft.com/support/supporter.cgi"; # Size / Color of text message box for user and admin to type in $background = "CCCCCC"; $cols = 40; $rows = 5; # E-mail notification options # 0 = no e-mail notification / 1 = only send to admin / 2 = only send to user / 3 = send to both $mode = 3; # Subject line to send user and admin: \$subject variable gets replaced with actual subject of message $subject_user = "Confirmation: \$subject"; $subject_admin = "LuSoft Online Support Request: \$subject"; # Admin e-mail address that will receive support requests # Don't forget to escape the @ sign by using a backslash before it. # Eg. your\@address.com #$to_address = "!EMAIL!"; $to_address ="support\@lusoft.com"; # Admin's real name $to_name = "Support"; # Should Admin's e-mail be shown on user's web browser? 0 = NO / 1 = YES $to_show = 0; # Message to send user confirmation receipt of their request $message_user = " This is an automated response to your support request.
Please do not reply to this message.
You can view the status of your request any time at:
$cgi_url?area=status&id=\$id
Normally it take 3 hours to 24 hours to get response on any trouble ticket.
Please be patient. According to new company regulation, we no longer
provide phone assistance to any client. Thank you.
IP Adddress submitted from: \$ip

Thank you

Lusoft support team
www.LuSoft.com "; # Message to send admin when new requests for support are made. $message_admin = " Date: \$date
Time: \$time
ID: \$id
From: \$name
Email: \$from_address
IP Address: \$ip

\$message "; ####################################### # DO NOT EDIT BELOW THIS LINE ####################################### &parse_form; $area = $FORM{'area'}; $name = $FORM{'name'}; $from_address = $FORM{'from'}; $subject = $FORM{'subject'}; $message = $FORM{'message'}; $id = $FORM{'id'}; $status = $FORM{'status'}; $now_date = time(); print "Content-type: text/html\n\n"; if ($area eq "") { &show_screen; exit; } if ($area eq "status") { ($status_current, $subdir, $name, $email, $subject) = &get_ticket("$id"); $status_desc = "Unread" if $status_current eq "N"; $status_desc = "Opened" if $status_current eq "O"; $status_desc = "Closed" if $status_current eq "C"; print "Support Center [$status_current]\n"; if ($status_current eq "") { print "Ticket #$id does not exist.\n"; exit; } print "
Status: $status_desc

\n"; &choose_status("$id", "$name", "$email", "$subject", "replyuser", "$status_current"); &show_message("$subdir", "$id"); print "\n"; exit; } if ($area eq "replyuser") { if ($from_address eq "" or $name eq "" or $subject eq "" or $message eq "") { print ""; exit; } if ($from_address =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $from_address !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) { print ""; exit; } &save_reply("$id", "replyuser"); print "\n"; print "

Support Center

\n"; print "Ticket $id has been updated\n"; exit; } if ($area eq "send") { if (not -e "$save_dir\/new") { $backok = mkdir("$save_dir\/new", 0777); if ($backok == 0) { print ""; exit; } } if ($from_address eq "" or $name eq "" or $subject eq "" or $message eq "") { print ""; exit; } if ($from_address =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $from_address !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) { print ""; exit; } $new_id = &get_id; &update_status("$new_id", "N", "$now_date", "N/A", "N/A", "$from_address", "$name", "$subject"); &lock("$new_id"); open(FILE, ">$save_dir\/new\/$new_id"); print FILE "\n"; print FILE "$now_date\n"; print FILE "$name\n"; print FILE "$from_address\n"; print FILE "$subject\n"; print FILE "$message\n"; print FILE "\n"; close(FILE); &unlock("$new_id"); &send_user; &send_admin; print ""; exit; } if ($area eq "login") { &login_screen; exit; } if ($area eq "main") { &check_login; &main_screen; exit; } if ($area eq "config") { &check_login; &config_screen; exit; } if ($area eq "reply") { &check_login; if ($status eq "D") { ($status, $date_made, $date_opened, $date_changed, $email_old, $name_old, $subject_old) = &get_status("$id"); $subdir_new = "new" if $status eq "N"; $subdir_new = "open" if $status eq "O"; $subdir_new = "closed" if $status eq "C"; unlink("$save_dir\/$subdir_new\/$id"); unlink("$save_dir\/status\/$id"); print "\n"; print "

Support Center

\n"; print "Ticket #$id has been deleted

\n"; print "Menu\n"; exit; } else { if ($from_address eq "" or $name eq "" or $subject eq "" or $message eq "") { print ""; exit; } if ($from_address =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $from_address !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) { print ""; exit; } &save_reply("$id", "reply"); print "\n"; print "

Support Center

\n"; print "Ticket $id has been updated

\n"; print "Menu\n"; print "\n"; exit; } } if ($area eq "open") { &check_login; print "Support Center\n"; print "

Support Center

\n"; print "Menu
\n"; print "Open Tickets


\n"; &show_tickets("open"); exit; } if ($area eq "closed") { &check_login; print "Support Center\n"; print "

Support Center

\n"; print "Menu
\n"; print "Closed Tickets


\n"; &show_tickets("closed"); exit; } if ($area eq "read") { &check_login; print "Support Center\n"; print "

Support Center

\n"; print "Menu

\n"; ($status_current, $subdir, $name, $email, $subject) = &get_ticket("$id"); &choose_status("$id", "$name", "$email", "$subject", "reply", "$status_current"); &show_message("$subdir", "$id"); exit; } if ($area eq "new") { &check_login; print "Support Center\n"; print "

Support Center

\n"; print "Menu
\n"; print "New Unread Tickets


\n"; &show_tickets("new"); exit; } exit; sub send_mail { my ($fromaddr, $replyaddr, $to, $smtp, $subject, $message) = @_; $to =~ s/[ \t]+/, /g; # pack spaces and add comma $fromaddr =~ s/.*<([^\s]*?)>/$1/; # get from email address $replyaddr =~ s/.*<([^\s]*?)>/$1/; # get reply email address $replyaddr =~ s/^([^\s]+).*/$1/; # use first address $message =~ s/^\./\.\./gm; # handle . as first character $message =~ s/\r\n/\n/g; # handle line ending $message =~ s/\n/\r\n/g; $smtp =~ s/^\s+//g; # remove spaces around $smtp $smtp =~ s/\s+$//g; if (!$to) { return(-8); } if ($SMTP_SERVER ne "") { my($proto) = (getprotobyname('tcp'))[2]; my($port) = (getservbyname('smtp', 'tcp'))[2]; my($smtpaddr) = ($smtp =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) ? pack('C4',$1,$2,$3,$4) : (gethostbyname($smtp))[4]; if (!defined($smtpaddr)) { return(-1); } if (!socket(MAIL, AF_INET, SOCK_STREAM, $proto)) { return(-2); } if (!connect(MAIL, pack('Sna4x8', AF_INET, $port, $smtpaddr))) { return(-3); } my($oldfh) = select(MAIL); $| = 1; select($oldfh); $_ = ; if (/^[45]/) { close(MAIL); return(-4); } print MAIL "helo $SMTP_SERVER\r\n"; $_ = ; if (/^[45]/) { close(MAIL); return(-5); } print MAIL "mail from: <$fromaddr>\r\n"; $_ = ; if (/^[45]/) { close(MAIL); return(-5); } foreach (split(/, /, $to)) { print MAIL "rcpt to: <$_>\r\n"; $_ = ; if (/^[45]/) { close(MAIL); return(-6); } } print MAIL "data\r\n"; $_ = ; if (/^[45]/) { close MAIL; return(-5); } } if ($SEND_MAIL ne "") { open (MAIL,"| $SEND_MAIL"); } print MAIL "To: $to\n"; print MAIL "From: $fromaddr\n"; print MAIL "Reply-to: $replyaddr\n" if $replyaddr; print MAIL "X-Mailer: Support Center\n"; print MAIL "Subject: $subject\n"; print MAIL "Content-type: text/html\n\n"; print MAIL "$message"; print MAIL "\n.\n"; if ($SMTP_SERVER ne "") { $_ = ; if (/^[45]/) { close(MAIL); return(-7); } print MAIL "quit\r\n"; $_ = ; } close(MAIL); return(1); } sub show_screen { if ($to_address eq "") { print "document.write('You must supply your return address using the \"to_address\" variable.');"; exit; } { print<
Support Center
Provided by Support Team
Name:
E-mail:
Subject:
Message:
END } } sub parse_form { if ("\U$ENV{'REQUEST_METHOD'}\E" eq 'GET') { # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ("\U$ENV{'REQUEST_METHOD'}\E" eq 'POST') { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); } else { &error('request_method'); } foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # If they try to include server side includes, erase them, so they # arent a security risk if the html gets returned. Another # security hole plugged up. $value =~ s///g; # Remove HTML Tags if ($allow_html == 0) { $value =~ s/<([^>]|\n)*>//g; } # Create two associative arrays here. One is a configuration array # which includes all fields that this form recognizes. The other # is for fields which the form does not recognize and will report # back to the user in the html return page and the e-mail message. # Also determine required fields. if ($FORM{$name} && ($value)) { $FORM{$name} = "$FORM{$name}, $value"; } elsif ($value ne "") { $FORM{$name} = $value; } } } sub error { local($msg) = @_; print "Content-Type: text/html\n\n"; print "

$msg

\n"; exit; } sub get_id { my ($rndval, $passcode); $rndval = int(rand(10000000000000)); return("$passcode$rndval"); } sub update_status { my ($this_id, $status, $date_made, $date_opened, $date_changed, $email, $name, $subject) = @_; if (not -e "$save_dir\/status") { $backok = mkdir("$save_dir\/status", 0777); if ($backok == 0) { print ""; exit; } } &lock("$this_id\.status"); open (FILE, ">$save_dir\/status\/$this_id"); print FILE "$status\n"; print FILE "$date_made\n"; print FILE "$date_opened\n"; print FILE "$date_changed\n"; print FILE "$email\n"; print FILE "$name\n"; print FILE "$subject\n"; close(FILE); &unlock("$this_id\.status"); } sub get_status { my ($this_id) = @_[0]; my ($status, $date_made, $date_opened, $date_changed, $email, $name, $subject); if (not -e "$save_dir\/status") { $backok = mkdir("$save_dir\/status", 0777); if ($backok == 0) { print ""; exit; } } if (not -e "$save_dir\/status\/$this_id") { return(0); } &lock("$this_id\.status"); open (FILE, "<$save_dir\/status\/$this_id"); $status = ; $date_made = ; $date_opened = ; $date_changed = ; $email = ; $name = ; $subject = ; close(FILE); &unlock("$this_id\.status"); chop($status); chop($date_made); chop($date_opened); chop($date_changed); chop($email); chop($name); chop($subject); return("$status", "$date_made", "$date_opened", "$date_changed", "$email", "$name", "$subject"); } sub send_admin { return if $mode == 0; return if $mode == 2; my ($date_now, $time_now) = &date_info($now_date); $message_admin =~ s/\$date/$date_now/ig; $message_admin =~ s/\$time/$time_now/ig; $message_admin =~ s/\$id/$new_id/ig; $message_admin =~ s/\$ip/$ENV{'REMOTE_ADDR'}/ig; $message_admin =~ s/\$name/$name/ig; $message_admin =~ s/\$from_address/$from_address/ig; $message_admin =~ s/\$message/$message/ig; $message_admin =~ s/\$subject/$subject/ig; $subject_admin =~ s/\$subject/$subject/ig; my $result = &send_mail("$from_address", "$from_address", "$to_address", $SMTP_SERVER, "$subject_admin", "$message_admin"); } sub send_user { return if $mode == 0; return if $mode == 1; my ($date_now, $time_now) = &date_info($now_date); $message_user =~ s/\$date/$date_now/ig; $message_user =~ s/\$time/$time_now/ig; $message_user =~ s/\$id/$new_id/ig; $message_user =~ s/\$name/$name/ig; $message_user =~ s/\$from_address/$from_address/ig; $message_user =~ s/\$message/$message/ig; $message_user =~ s/\$subject/$subject/ig; $message_user =~ s/\$ip/$ENV{'REMOTE_ADDR'}/ig; $subject_user =~ s/\$subject/$subject/ig; my $result = &send_mail("$to_address", "$to_address", "$from_address", $SMTP_SERVER, "$subject_user", "$message_user"); } sub date_info { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(@_[0]); if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } $mon++; if ($mon < 10) { $month = "0$mon"; } else { $month = "$mon"; } if ($mday < 10) { $mday = "0$mday"; } $year += 1900; my $date_now = "$month\-$mday\-$year"; my $time_now = "$hour\:$min\:$sec"; return("$date_now", "$time_now"); } sub check_login { if ($username ne $FORM{'username'}) { print "Invalid Username.\n"; exit; } if ($password ne $FORM{'password'}) { print "Invalid Password.\n"; exit; } } sub login_screen { { print< Support Center

Support Center

Username:
Password:
END } } sub main_screen { my $new_files = &calculate_files("new"); my $open_files = &calculate_files("open"); my $closed_files = &calculate_files("closed"); { print< Support Center

Support Center

View New Unread Tickets ($new_files)
View Open Tickets ($open_files)
View Closed Tickets ($closed_files)
END } } sub show_tickets { my $subdir = @_[0]; my @all_files; my ($date_this, $time_this, $datec_this, $timec_this); splice(@all_files, 0); opendir(FILES, "$save_dir\/$subdir"); @all_files = readdir(FILES); closedir(FILES); print "
\n"; print "\n"; for ($j = 2; $j < @all_files; $j++) { ($status, $date_made, $date_opened, $date_changed, $email, $name, $subject) = &get_status("@all_files[$j]"); ($date_this, $time_this) = &date_info($date_opened) if $date_opened ne "N/A"; ($datec_this, $timec_this) = &date_info($date_changed) if $date_changed ne "N/A"; if ( @all_files[$j] !=~ 'html' ) { print "\n"; } } print "
ID Opened Changed Name Subject E-mail
@all_files[$j] $date_this $time_this $datec_this $timec_this $name $subject $email
\n"; } sub get_ticket { my ($this_id) = @_[0]; my ($status, $date_made, $date_opened, $date_changed, $email, $name, $subject, $subdir); ($status, $date_made, $date_opened, $date_changed, $email, $name, $subject) = &get_status("$this_id"); if ($status eq "" or not -e "$save_dir\/status\/$this_id") { print "Support Center[$status] Ticket #$this_id does not exist.\n"; exit; } print "Support Center\n"; $subdir = "new" if $status eq "N"; $subdir = "open" if $status eq "O"; $subdir = "closed" if $status eq "C"; return("$status", "$subdir", "$name", "$email", "$subject"); } sub show_message { my ($subdir, $this_id) = @_; &lock("$this_id"); open(FILE, "<$save_dir\/$subdir\/$this_id"); until(eof(FILE)) { $line = ; if ($line eq "\n") { $now_date = ; $name = ; $from_address = ; $subject = ; chop($now_date); chop($name); chop($from_address); chop($subject); $now_date = localtime($now_date); print "
\n"; print "Date: $now_date
\n"; print "From: $name ($from_address)
\n"; print "Subject: $subject

\n"; $found = 0; until(eof(FILE) or $found == 1) { $line = ; $found = 1 if $line eq "\n"; $line =~ s/\n/
/ig; print "$line\n"; } } } close(FILE); &unlock("$this_id"); } sub choose_status { my ($this_id, $name, $from_address, $subject, $reply_type, $status) = @_; if ($reply_type eq "replyuser") { $username = ""; $password = ""; } if ($reply_type eq "replyuser" and $status eq "C") { } else { print< END } if ($reply_type eq "reply") { print< END } if ($reply_type eq "replyuser" and $status eq "C") { } else { print<
Name:
E-mail:
Subject:
Message:
New / Unread Open Close Delete

END } } sub save_reply { my ($id, $reply_type) = @_; if (not -e "$save_dir\/open") { $backok = mkdir("$save_dir\/open", 0777); if ($backok == 0) { print ""; exit; } } if (not -e "$save_dir\/closed") { $backok = mkdir("$save_dir\/closed", 0777); if ($backok == 0) { print ""; exit; } } ($status_current, $subdir, $name2, $email2, $subject2) = &get_ticket("$id"); my ($status_old, $date_made, $date_opened, $date_changed, $email_old, $name_old, $subject_old) = &get_status("$id"); if (($date_opened eq "N/A" or $date_opened eq "") and $status_old eq "N") { $date_opened = $now_date; } if ($reply_type eq "replyuser") { $status = $status_old; } $subdir_new = "new" if $status eq "N"; $subdir_new = "open" if $status eq "O"; $subdir_new = "closed" if $status eq "C"; &update_status("$id", "$status", "$date_made", "$date_opened", "$now_date", "$from_address", "$name", "$subject"); $from_old = $from_address; if ($reply_type eq "reply") { $name = $to_name; $from_address = ""; } &lock("$id"); open(FILE, ">$save_dir\/$id"); print FILE "\n"; print FILE "$now_date\n"; print FILE "$name\n"; print FILE "$from_address\n"; print FILE "$subject\n"; print FILE "$message\n"; print FILE "\n"; open(FILEI, "<$save_dir\/$subdir\/$id"); until(eof(FILEI)) { $line = ; print FILE "$line"; } close(FILEI); close(FILE); unlink("$save_dir\/$subdir\/$id"); rename("$save_dir\/$id", "$save_dir\/$subdir_new\/$id"); &unlock("$id"); $new_id = $id; $from_address = $from_old; &send_user; &send_admin; } sub calculate_files { my ($subdir) = @_[0]; my @all_files; my $num; splice (@all_files, 0); opendir(FILES, "$save_dir\/$subdir"); @all_files = readdir(FILES); closedir(FILES); #$num = @all_files - 2; modified by MFL for index.html $num = @all_files -3; return($num); } sub lock { my $lock_name = @_[0]; my $locks = "$savedir_dir\/"; my $lock_timer = 0; my $lock_timer_stop = 0; my $lock_passed = 0; while ($lock_timer_stop < 1) { for ($locka = 0; $locka < 10; $locka++) { if (not -e "$locks$lock_name") { $lock_timer_stop = 1; } else { $lock_timer_stop = 0; } } if ($lock_timer_stop == 1) { open (LOCKIT, ">$locks$lock_name"); print LOCKIT "LOCKED\n"; close (LOCKIT); } else { $idle_max = 30; splice(@lock_info, 0); @lock_info=stat("$locks$lock_name"); ($dev,$irn,$perm,$hl,$uid,$gid,$dt,$size2,$la,$lm,$slc,$obs,$blocks) = @lock_info; $id_time = time() - $lm; if ($id_time > $idle_max and $lm > 0) { $lock_passed = 1; unlink ("$locks$lock_name"); } select(undef,undef,undef,0.01); $lock_timer++; } } } sub unlock { my $locks = "$save_dir\/"; my $lock_name = @_[0]; unlink ("$locks$lock_name"); }