[rt-users] Re: RT ticket from web page? (Mike Dent)
Thomas M. Payerle
payerle at physics.umd.edu
Mon Apr 3 13:36:51 EDT 2006
> Hi,
> I'd like to include some code to input a ticket to my RT box on one of
> my web pages.
> I need the ability to put data in to some custom fields too.
> I'd like to include some anti-spam capability on the web page too,
> such as one of those distorted
> images containing characters which you need to input correctly.
>
> The RT box and apache web server are located on different boxes, on
> different networks.
>
> Is this possible and could some kind soul point me in the right
> direction please?
>
This can be done fairly easily. I've not done it with different boxes
for RT and web server, but I do not think that is a big problem.
I have a set up wherein via an anonymous web connection an user connects
to a static html form I created, and when submit it gets processed by
standard CGI to submit the request in a designated queue. The meat of the
CGI code is
------
use RT::Interface::CLI qw(CleanEnv);
CleanEnv();
use RT;
RT::LoadConfig();
RT::Init();
use RT::Ticket;
use RT::CustomField;
my $system = $RT::SystemUser;
my $customfield = new RT::CustomField($system);
sub submit_request($)
{ my $hash = shift;
my $ticket = new RT::Ticket($system);
my $ticket_body = MIME::Entity->build(Data => $hash->{Content},
Type => 'text/plain');
my %ticket_vals = (
Queue => $queue,
Subject => $hash->{Subject},
Requestor => $hash->{RequestorEmail},
);
my @custom_fields = qw(
RequestorName RequestorEmail RequestorBuilding RequestorRoom
RequestorPhone RequestorAltPhone RequestorAltEmail
RequestorBestTime );
my ($fld, $val);
foreach $fld (@custom_fields)
{ next unless exists $hash->{$fld};
$val = $hash->{$fld};
next unless defined $val && $val;
set_custom_field(\%ticket_vals, $fld, $val);
}
set_custom_field(\%ticket_vals,'RequestorUsername','');
my ($id, $transaction_object, $err) = $ticket->Create(%ticket_vals);
fatal_error($err) unless $err=~/created/;
return $id;
}
sub set_custom_field($$$)
{ my $phash = shift;
my $field = shift;
my $val = shift;
my $res = $customfield->LoadByName(Name=>$field);
my $id = $customfield->Id;
$phash->{"CustomField-$id"} = $val;
}
-----
The hash coming into submit_request() contains keys for each legit field
in the form, with values being the values. (It is assumed to have been
previously sanitized, checked for missing required values, etc.)
I believe that in order for this to work, the CGI script needs ability to
access to RT database. It seemed to just happen when the two are the same
machine, but will likely need some tweaking if on different systems.
An alternative route if that does not work too well is to cheat and use
the rt-mailgate package, guts as follows:
------
sub submit_request($)
{ my $hash = shift;
my $subj_line="Subject: " . $hash->{Subject};
my $queue = $hash->{Queue} || "General";
my $from_line = "From: " . $hash->{Username};
my $uidline = "Uid: " . $hash->{Username};
my $url = "https://physhelp.physics.umd.edu/rt";
my $description = $hash->{Description};
my $rtmailgate = "/dept/phys/software/rt/bin/rt-mailgate";
open(PIPE,"| $rtmailgate --queue $queue --url $url") or
fatal_error("Unable to open pipe");
print PIPE <<EOF;
$subj_line
$uidline
$from_line
$description
EOF
close(PIPE) or fatal_error("Error closing pipe");
}
---
The above does not handle custom fields, but I believe it could be tweaked
to add them (probably need to give an extra field either in header or in
body of the "mail" message).
I have also had good success on using modified versions of the standard RT
Ticket create page for priv'ed and unpriv'ed users (actually some minor
hacks to the prived Ticket/Create.html so will work in self-service area).
Tom Payerle
Dept of Physics payerle at physics.umd.edu
University of Maryland (301) 405-6973
College Park, MD 20742-4111 Fax: (301) 314-952et_custom_field(\%ticket_vals,'RequestorUsername','');
More information about the rt-users
mailing list