[rt-users] web interface

Erik Wolf erikw at soltec.com
Wed May 3 10:42:17 EDT 2000


On Wed, 3 May 2000, Paul Reilly wrote:

> Has anyone got any pointers to settings up a web submission interface to
> RT? You know, so that users can fill in a problem request through a form?
> I could get it to email the form contents to RT, but perhaps I can submit
> the form contents to RT some other way through cgi?

Attached is something i hacked together to do this.  Its ugly, but you
should be able to get it to work without much modification.  It uses a
form to collect the info, then directly calls the
(add_request|add_transaction) procedures in rt/database/database.pm.

--
e
-------------- next part --------------

#!/usr/local/bin/perl
#
# Simple RT submitter
$ENV{'PATH'} = '/bin:/usr/bin';
package rt;
$rt_dir = "/usr/local/packages/rt/devl";
push (@INC, "$rt_dir/lib");
push (@INC, "$rt_dir/etc");
require "$rt_dir/etc/config.pm";
require rt::database::manipulate;
my $driver = "mysql";
my $host="localhost";
my $user="<rt-user here>";
my $password="<rt-user password here>";
my $dbname="<queue name>";
my $dsn = "DBI:$driver:database=$dbname;host=$hostname";
my $dbh = DBI->connect($dsn, $user, $password);



sub grab {
  local($inp, $tinp, $name, $part, $tpart, $ind);
  $inp = "&" . $_[0] . "&";
  $name = $_[1];
  $tinp = $inp;
  $part = "";

  for (;;) {
    ($tpart) = ($tinp =~ /&$name=([^&]*)&/);
    $ind = index($tinp, "$name=$tpart") + length("$name=$tpart");
    $tpart =~ tr/+/ /;
    $tpart =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $tpart =~ s/\r//eg;
    if ($tpart eq "") {
      last;
    }

    if ($part ne "") {
      $part = "$part, $tpart";
    } else {
      $part = $tpart;
    }

    $tinp = substr($tinp, $ind);
    if ($tinp eq "") {
      last;
    }
  }

  $part;
}


sub compute_due_date {
   
   use Time::Local;
   my %monthhash = ( "Jan"        => 0,
                     "Feb"    => 1,
	             "Mar"    => 2,
	             "Apr"    => 3,
	             "May"    => 4,
		     "Jun"    => 5,
		     "Jul"    => 6,
		     "Aug"    => 7,
		     "Sep"    => 8,
		     "Oct"    => 9,
		     "Nov"    => 10,
		     "Dec"    => 11);

   my $due_month = shift @_;
   my $due_day = shift @_;
   my $current_time = time;
   my $current_year = (localtime($current_time))[5];
   my $due_date = timelocal(0,0,0,$due_day, $monthhash{$due_month}, $current_year);
   if ($due_date < $current_time) {
      $current_year++;
      $due_date = timelocal(0,0,0,$due_day, $monthhash{$due_month}, $current_year);
    }
    return $due_date;
}


sub print_submit_form {
print "Content-type: text/html\n\n";
print <<EOF;

<html>
<head>
<title>Help Desk</title>
</head>


<body bgcolor="#FFFFFF">
<h3> Help Desk Request Form</h3>
<HR>
<form action="submit.cgi" method=post>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<tr><td bgcolor="e0e0ff"><b>From:</b></td><td bgcolor="#eaeaea" colspan=3><input type=text name=from size=30><----<i>Required Field</i>
</td></tr>
<tr><td bgcolor="e0e0ff"><b>Synopsis:</b></td><td bgcolor="#eaeaea" colspan=3><input type=text name=subject size=40><-----<i>Required Field</i>
</td></tr>
<tr><td bgcolor="e0e0ff"><b>Priority:</b></td><td bgcolor="#eaeaea" colspan=3>
<select name="priority1">
<option selected>0<option>1<option>2
<option>3<option>4<option>5<option>6
<option>7<option>8<option>9<option>10
</select>
</td></tr>
<tr><td bgcolor="e0e0ff"><b>Due Date:</b></td><td bgcolor="#eaeaea" colspan=3>
<input type="radio" name="due_or_not" value="no" checked>None set
<input type="radio" name="due_or_not" value="yes"> 
<select name="month">
<option>Jan<option>Feb<option>Mar
<option>Apr<option>May<option>Jun
<option>Jul<option>Aug<option>Sep
<option>Oct<option>Nov<option>Dec
</select>
<select name="day">
<option>1<option>2<option>3
<option>4<option>5<option>6
<option>7<option>8<option>9
<option>10<option>11<option>12
<option>13<option>14<option>15
<option>16<option>17<option>18
<option>19<option>20<option>21
<option>22<option>23<option>24
<option>25<option>26<option>27
<option>28<option>29<option>30
<option>31</select>
</td>
EOF

print <<EOF;
</select>
</td></tr>
<tr><td bgcolor="e0e0ff"><b>Message</b></td><td colspan=3 bgcolor="#eaeaea">
<textarea rows=15 cols=78 name=message wrap=hard>
</textarea>
</td></tr>
</table>

<p>

Click <input type=submit value=here> to the submit the request.
</form>
</body>
</html>
EOF
}

# Main driver loop
$content_length = $ENV{"CONTENT_LENGTH"};
read(STDIN, $input, $content_length);

use CGI;
$query = new CGI;


if ($content_length == 0) {
  print_submit_form;
  exit 0;
} 


$message = &grab($input, "message");
$subject = &grab($input, "subject");
$from = &grab($input, "from");
$priority1 = &grab($input, "priority1");
$month = &grab($input, "month");
$day = &grab($input, "day");
$due_or_not = &grab($input, "due_or_not");
#$keywords = &grab($input, "keywords");
$keywords = "";
$difficulty = 0;

print "Content-type: text/html\n";
print <<EOF;

<HTML>
<HEAD>
<TITLE>Request Submitter Results</TITLE>
</HEAD>
<BODY  bgcolor="#FFFFFF">

EOF


if ($message eq "" || $subject eq "" || $from eq "") {
   &error_out($message, $subject, $from);
}

$queue_id = "devl";
$alias = "";
$status = "submitted";
$date_told = "";
$current_user = "root";
$priority = $priority1;
$message = "Symptoms: $message

Desired result:

Current workaround:

Related Applications:

Experience Level:

Time estimate:

Response time needed:

";

$final_priority = $priority;
if ($due_or_not eq "yes") {
   $date_due = &compute_due_date($month, $day);
} else {
   $date_due = "";
}
$date_created = time;
$owner = "";
$category = "";


$serial_num=&add_request($queue_id, $category, $from, $alias, $owner, $subject, $final_priority, $priority, $status, $date_created, $date_told, $date_due, $current_user);
$transaction_num=&add_transaction($serial_num, $from, 'create','', $message, time, 1, $current_user);


print <<EOF;

<B>Your request has been sent and assigned a serial number of $serial_num.</B><p>
<A HREF="/rt/list.cgi">Click here</a> to view the request queue.
</BODY>
</HTML>

EOF

exit 0;

sub error_out {

   my $message = shift @_;
   my $subject = shift @_;
   my $from = shift @_;
   my $error;
   if ($from eq "") {
      $error = "from";
   } elsif ($subject eq "") {
      $error = "subject";
   } else {
      $error = "message";
   }
   print "<H3> The $error field has been left blank</H3>  Please go back and make sure this field is filled out<p>";   
   print "</BODY></HTML>";
   exit 0;

}




More information about the rt-users mailing list