2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
7 # <sales@bestpractical.com>
9 # (Except where explicitly superseded by other copyright notices)
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # 02110-1301 or visit their web page on the internet at
28 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
31 # CONTRIBUTION SUBMISSION POLICY:
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
48 # END BPS TAGGED BLOCK }}}
49 # Designed and implemented for Best Practical Solutions, LLC by
50 # Abhijit Menon-Sen <ams@wiw.org>
55 if ( $ARGV[0] && $ARGV[0] =~ /^(?:--help|-h)$/ ) {
57 print Pod::Usage::pod2usage( { verbose => 2 } );
61 # This program is intentionally written to have as few non-core module
62 # dependencies as possible. It should stay that way.
67 use HTTP::Request::Common;
70 use Time::Local; # used in prettyshow
73 # strong (GSSAPI based) authentication is supported if the server does provide
74 # it and the perl modules GSSAPI and LWP::Authen::Negotiate are installed
75 # it can be suppressed by setting externalauth=0 (default is undef)
76 eval { require GSSAPI };
77 my $no_strong_auth = 'missing perl module GSSAPI';
79 eval {require LWP::Authen::Negotiate};
80 $no_strong_auth = $@ ? 'missing perl module LWP::Authen::Negotiate' : 0;
83 # We derive configuration information from hardwired defaults, dotfiles,
84 # and the RT* environment variables (in increasing order of precedence).
85 # Session information is stored in ~/.rt_sessions.
88 my $HOME = eval{(getpwuid($<))[7]}
89 || $ENV{HOME} || $ENV{LOGDIR} || $ENV{HOMEPATH}
94 user => eval{(getpwuid($<))[0]} || $ENV{USER} || $ENV{USERNAME},
96 server => 'http://localhost/',
97 query => "Status!='resolved' and Status!='rejected'",
100 # to protect against unlimited searches a better choice would be
101 # queue => 'Unknown_Queue',
102 # setting externalauth => undef will try GSSAPI auth if the corresponding perl
103 # modules are installed, externalauth => 0 is the backward compatible choice
106 config_from_file($ENV{RTCONFIG} || ".rtrc"),
109 my $session = Session->new("$HOME/.rt_sessions");
110 my $REST = "$config{server}/REST/1.0";
111 $no_strong_auth = 'switched off by externalauth=0'
112 if defined $config{externalauth};
118 sub DEBUG { warn @_ if $config{debug} >= shift }
120 # These regexes are used by command handlers to parse arguments.
121 # (XXX: Ask Autrijus how i18n changes these definitions.)
123 my $name = '[\w.-]+';
124 my $CF_name = '[^,]+?';
125 my $field = '(?i:[a-z][a-z0-9_-]*|C(?:ustom)?F(?:ield)?-'.$CF_name.'|CF\.\{'.$CF_name.'\})';
126 my $label = '[^,\\/]+';
127 my $labels = "(?:$label,)*$label";
128 my $idlist = '(?:(?:\d+-)?\d+,)*(?:\d+-)?\d+';
130 # Our command line looks like this:
132 # rt <action> [options] [arguments]
134 # We'll parse just enough of it to decide upon an action to perform, and
135 # leave the rest to per-action handlers to interpret appropriately.
138 # handler => [ ...aliases... ],
139 version => ["version", "ver"],
141 logout => ["logout"],
142 help => ["help", "man"],
143 show => ["show", "cat"],
144 edit => ["create", "edit", "new", "ed"],
145 list => ["search", "list", "ls"],
146 comment => ["comment", "correspond"],
147 link => ["link", "ln"],
149 grant => ["grant", "revoke"],
150 take => ["take", "steal", "untake"],
151 quit => ["quit", "exit"],
152 setcommand => ["del", "delete", "give", "res", "resolve",
157 foreach my $fn (keys %handlers) {
158 foreach my $alias (@{ $handlers{$fn} }) {
159 $actions{$alias} = \&{"$fn"};
163 # Once we find and call an appropriate handler, we're done.
168 push @ARGV, 'shell' if (!@ARGV); # default to shell mode
169 shift @ARGV if ($ARGV[0] eq 'rt'); # ignore a leading 'rt'
170 if (@ARGV && exists $actions{$ARGV[0]}) {
171 $action = shift @ARGV;
172 return $actions{$action}->($action);
175 print STDERR "rt: Unknown command '@ARGV'.\n";
176 print STDERR "rt: For help, run 'rt help'.\n";
186 # The following subs are handlers for each entry in %actions.
190 my $term = Term::ReadLine->new('RT CLI');
191 while ( defined ($_ = $term->readline($prompt)) ) {
192 next if /^#/ || /^\s*$/;
194 @ARGV = shellwords($_);
200 print "rt $VERSION\n";
205 submit("$REST/logout") if defined $session->cookie;
216 my ($action, $type, $rv) = @_;
217 $rv = defined $rv ? $rv : 0;
220 # What help topics do we know about?
223 foreach my $item (@{ Form::parse(<DATA>) }) {
224 my $title = $item->[2]{Title};
225 my @titles = ref $title eq 'ARRAY' ? @$title : $title;
227 foreach $title (grep $_, @titles) {
228 $help{$title} = $item->[2]{Text};
233 # What does the user want help with?
234 undef $action if ($action && $actions{$action} eq \&help);
235 unless ($action || $type) {
236 # If we don't know, we'll look for clues in @ARGV.
238 if (exists $help{$_}) { $key = $_; last; }
241 # Tolerate possibly plural words.
243 if ($_ =~ s/s$// && exists $help{$_}) { $key = $_; last; }
248 if ($type && $action) {
249 $key = "$type.$action";
251 $key ||= $type || $action || "introduction";
253 # Find a suitable topic to display.
254 while (!exists $help{$key}) {
255 if ($type && $action) {
256 if ($key eq "$type.$action") { $key = $action; }
257 elsif ($key eq $action) { $key = $type; }
258 else { $key = "introduction"; }
261 $key = "introduction";
265 print STDERR $help{$key}, "\n\n";
269 # Displays a list of objects that match some specified condition.
272 my ($q, $type, %data);
273 my $orderby = $config{orderby};
275 if ($config{orderby}) {
276 $data{orderby} = $config{orderby};
280 my $reverse_sort = 0;
281 my $queue = $config{queue};
287 $bad = 1, last unless defined($type = get_type_argument());
290 $bad = 1, last unless get_var_argument(\%data);
293 $data{'orderby'} = shift @ARGV;
295 elsif (/^-([isl])$/) {
300 $queue = shift @ARGV;
306 if ($ARGV[0] !~ /^(?:(?:$field,)*$field)$/) {
307 whine "No valid field list in '-f $ARGV[0]'.";
310 $data{fields} = shift @ARGV;
311 $data{format} = 's' if ! $data{format};
314 elsif (!defined $q && !/^-/) {
318 my $datum = /^-/ ? "option" : "argument";
319 whine "Unrecognised $datum '$_'.";
323 if ( ! $rawprint and ! exists $data{format} ) {
326 if ( $reverse_sort and $data{orderby} =~ /^-/ ) {
327 $data{orderby} =~ s/^-/+/;
328 } elsif ($reverse_sort) {
329 $data{orderby} =~ s/^\+?(.*)/-$1/;
336 $q =~ s/^#//; # get rid of leading hash
338 # only digits, must be an id, formulate a correct query
339 $q = "id=$q" if $q =~ /^\d+$/;
341 # a string only, take it as an owner or requestor (quoting done later)
342 $q = "(Owner=$q or Requestor like $q) and $config{query}"
343 if $q =~ /^[\w\-]+$/;
344 # always add a query for a specific queue or (comma separated) queues
345 $queue =~ s/,/ or Queue=/g if $queue;
346 $q .= " and (Queue=$queue)" if $queue and $q and $q !~ /Queue\s*=/i
349 # correctly quote strings in a query
350 $q =~ s/(=|like\s)\s*([^'\d\s]\S*)\b/$1\'$2\'/g;
353 unless ($type && defined $q) {
354 my $item = $type ? "query string" : "object type";
355 whine "No $item specified.";
358 #return help("list", $type) if $bad;
359 return suggest_help("list", $type, $bad) if $bad;
361 print "Query:$q\n" if ! $rawprint;
362 my $r = submit("$REST/search/$type", { query => $q, %data });
366 my $forms = Form::parse($r->content);
372 # Displays selected information about a single object.
375 my ($type, @objects, %data);
383 s/^#// if /^#\d+/; # get rid of leading hash
385 $bad = 1, last unless defined($type = get_type_argument());
388 $bad = 1, last unless get_var_argument(\%data);
390 elsif (/^-([isl])$/) {
394 elsif (/^-$/ && !$slurped) {
395 chomp(my @lines = <STDIN>);
397 unless (is_object_spec($_, $type)) {
398 whine "Invalid object on STDIN: '$_'.";
406 if ($ARGV[0] !~ /^(?:(?:$field,)*$field)$/) {
407 whine "No valid field list in '-f $ARGV[0]'.";
410 $data{fields} = shift @ARGV;
411 # option f requires short raw listing format
415 elsif (/^\d+$/ and my $spc2 = is_object_spec("ticket/$_", $type)) {
416 push @objects, $spc2;
417 $histspec = is_object_spec("ticket/$_/history", $type);
419 elsif (/^\d+\// and my $spc3 = is_object_spec("ticket/$_", $type)) {
420 push @objects, $spc3;
421 $rawprint = 1 if $_ =~ /\/content$/;
423 elsif (my $spec = is_object_spec($_, $type)) {
424 push @objects, $spec;
425 $rawprint = 1 if $_ =~ /\/content$/ or $_ =~ /\/links/ or $_ !~ /^ticket/;
428 my $datum = /^-/ ? "option" : "argument";
429 whine "Unrecognised $datum '$_'.";
434 push @objects, $histspec if $histspec;
435 $data{format} = 'l' if ! exists $data{format};
439 whine "No objects specified.";
442 #return help("show", $type) if $bad;
443 return suggest_help("show", $type, $bad) if $bad;
445 my $r = submit("$REST/show", { id => \@objects, %data });
447 # if this isn't a text reply, remove the trailing newline so we
448 # don't corrupt things like tarballs when people do
449 # show ticket/id/attachments/id/content > foo.tar.gz
450 if ($r->content_type !~ /^text\//) {
457 # I do not know how to get more than one form correctly returned
458 $c =~ s!^RT/[\d\.]+ 200 Ok$!--!mg;
459 my $forms = Form::parse($c);
465 # To create a new object, we ask the server for a form with the defaults
466 # filled in, allow the user to edit it, and send the form back.
468 # To edit an object, we must ask the server for a form representing that
469 # object, make changes requested by the user (either on the command line
470 # or interactively via $EDITOR), and send the form back.
474 my (%data, $type, @objects);
475 my ($cl, $text, $edit, $input, $output, $content_type);
477 use vars qw(%set %add %del);
478 %set = %add = %del = ();
484 s/^#// if /^#\d+/; # get rid of leading hash
486 if (/^-e$/) { $edit = 1 }
487 elsif (/^-i$/) { $input = 1 }
488 elsif (/^-o$/) { $output = 1 }
489 elsif (/^-ct$/) { $content_type = shift @ARGV }
491 $bad = 1, last unless defined($type = get_type_argument());
494 $bad = 1, last unless get_var_argument(\%data);
496 elsif (/^-$/ && !($slurped || $input)) {
497 chomp(my @lines = <STDIN>);
499 unless (is_object_spec($_, $type)) {
500 whine "Invalid object on STDIN: '$_'.";
510 while (@ARGV && $ARGV[0] =~ /^($field)([+-]?=)(.*)$/s) {
511 my ($key, $op, $val) = ($1, $2, $3);
512 my $hash = ($op eq '=') ? \%set : ($op =~ /^\+/) ? \%add : \%del;
514 vpush($hash, lc $key, $val);
519 whine "No variables to set.";
524 elsif (/^(?:add|del)$/i) {
526 my $hash = ($_ eq "add") ? \%add : \%del;
528 while (@ARGV && $ARGV[0] =~ /^($field)=(.*)$/s) {
529 my ($key, $val) = ($1, $2);
531 vpush($hash, lc $key, $val);
536 whine "No variables to set.";
541 elsif (/^\d+$/ and my $spc2 = is_object_spec("ticket/$_", $type)) {
542 push @objects, $spc2;
544 elsif (my $spec = is_object_spec($_, $type)) {
545 push @objects, $spec;
548 my $datum = /^-/ ? "option" : "argument";
549 whine "Unrecognised $datum '$_'.";
554 if ($action =~ /^ed(?:it)?$/) {
556 whine "No objects specified.";
562 whine "You shouldn't specify objects as arguments to $action.";
566 whine "What type of object do you want to create?";
569 @objects = ("$type/new") if defined($type);
571 #return help($action, $type) if $bad;
572 return suggest_help($action, $type, $bad) if $bad;
574 # We need a form to make changes to. We usually ask the server for
575 # one, but we can avoid that if we are fed one on STDIN, or if the
576 # user doesn't want to edit the form by hand, and the command line
577 # specifies only simple variable assignments. We *should* get a
578 # form if we're creating a new ticket, so that the default values
579 # get filled in properly.
581 my @new_objects = grep /\/new$/, @objects;
587 elsif ($edit || %add || %del || !$cl || @new_objects) {
588 my $r = submit("$REST/show", { id => \@objects, format => 'l' });
592 # If any changes were specified on the command line, apply them.
595 # We're updating forms from the server.
596 my $forms = Form::parse($text);
598 foreach my $form (@$forms) {
599 my ($c, $o, $k, $e) = @$form;
602 next if ($e || !@$o);
608 # Make changes to existing fields.
610 if (exists $add{lc $key}) {
611 $val = delete $add{lc $key};
612 vpush($k, $key, $val);
613 $k->{$key} = vsplit($k->{$key}) if $val =~ /[,\n]/;
615 if (exists $del{lc $key}) {
616 $val = delete $del{lc $key};
617 my %val = map {$_=>1} @{ vsplit($val) };
618 $k->{$key} = vsplit($k->{$key});
619 @{$k->{$key}} = grep {!exists $val{$_}} @{$k->{$key}};
621 if (exists $set{lc $key}) {
622 $k->{$key} = delete $set{lc $key};
626 # Then update the others.
627 foreach $key (keys %set) { vpush($k, $key, $set{$key}) }
628 foreach $key (keys %add) {
629 vpush($k, $key, $add{$key});
630 $k->{$key} = vsplit($k->{$key});
632 push @$o, (keys %add, keys %set);
635 $text = Form::compose($forms);
638 # We're rolling our own set of forms.
641 my ($type, $ids, $args) =
642 m{^($name)/($idlist|$labels)(?:(/.*))?$}o;
645 foreach my $obj (expand_list($ids)) {
646 my %set = (%set, id => "$type/$obj$args");
647 push @forms, ["", [keys %set], \%set];
650 $text = Form::compose(\@forms);
660 @files = @{ vsplit($set{'attachment'}) } if exists $set{'attachment'};
665 # We'll let the user edit the form before sending it to the server,
666 # unless we have enough information to submit it non-interactively.
667 if ( $type && $type eq 'ticket' && $text !~ /^Content-Type:/m ) {
668 $text .= "Content-Type: $content_type\n"
669 if $content_type and $content_type ne "text/plain";
672 if ($edit || (!$input && !$cl)) {
673 my ($newtext) = vi_form_while(
676 my ($text, $form) = @_;
677 return 1 unless exists $form->[2]{'Attachment'};
679 foreach my $f ( @{ vsplit($form->[2]{'Attachment'}) } ) {
680 return (0, "File '$f' doesn't exist") unless -f $f;
682 @files = @{ vsplit($form->[2]{'Attachment'}) };
686 return $newtext unless $newtext;
687 # We won't resubmit a bad form unless it was changed.
688 $text = ($synerr && $newtext eq $text) ? undef : $newtext;
691 delete @data{ grep /^attachment_\d+$/, keys %data };
693 foreach my $file (@files) {
694 $data{"attachment_$i"} = bless([ $file ], "Attachment");
699 my $r = submit("$REST/edit", {content => $text, %data});
700 if ($r->code == 409) {
701 # If we submitted a bad form, we'll give the user a chance
702 # to correct it and resubmit.
703 if ($edit || (!$input && !$cl)) {
704 my $content = $r->content . "\n";
705 $content =~ s/^(?!#)/# /mg;
706 $text = $content . $text;
720 # handler for special edit commands. A valid edit command is constructed and
721 # further work is delegated to the edit handler
725 my ($id, $bad, $what);
728 $id = $1 if (m|^(?:ticket/)?($idlist)$|);
732 whine "No ticket number specified.";
735 if ($action eq 'subject') {
736 my $subject = '"'.join (" ", @ARGV).'"';
738 $what = "subject=$subject";
739 } elsif ($action eq 'give') {
740 my $owner = shift @ARGV;
741 $what = "owner=$owner";
744 if ( $action eq 'delete' or $action eq 'del' ) {
745 $what = "status=deleted";
746 } elsif ($action eq 'resolve' or $action eq 'res' ) {
747 $what = "status=resolved";
748 } elsif ($action eq 'take' ) {
749 $what = "owner=$config{user}";
750 } elsif ($action eq 'untake') {
751 $what = "owner=Nobody";
756 whine "Extraneous arguments for action $action: @ARGV.";
760 whine "unrecognized action $action.";
762 return help("edit", undef, $bad) if $bad;
763 @ARGV = ( $id, "set", $what );
764 print "Executing: rt edit @ARGV\n";
768 # We roll "comment" and "correspond" into the same handler.
772 my (%data, $id, @files, @bcc, @cc, $msg, $content_type, $wtime, $edit);
781 elsif (/^-(?:[abcmw]|ct)$/) {
783 whine "No argument specified with $_.";
788 unless (-f $ARGV[0] && -r $ARGV[0]) {
789 whine "Cannot read attachment: '$ARGV[0]'.";
792 push @files, shift @ARGV;
795 $content_type = shift @ARGV;
798 my $a = $_ eq "-b" ? \@bcc : \@cc;
799 @$a = split /\s*,\s*/, shift @ARGV;
803 if ( $msg =~ /^-$/ ) {
805 while (<STDIN>) { $msg .= $_ }
808 elsif (/-w/) { $wtime = shift @ARGV }
810 elsif (!$id && m|^(?:ticket/)?($idlist)$|) {
814 my $datum = /^-/ ? "option" : "argument";
815 whine "Unrecognised $datum '$_'.";
821 whine "No object specified.";
824 #return help($action, "ticket") if $bad;
825 return suggest_help($action, "ticket") if $bad;
829 [ "Ticket", "Action", "Cc", "Bcc", "Attachment", "TimeWorked", "Content-Type", "Text" ],
835 Attachment => [ @files ],
836 TimeWorked => $wtime || '',
837 'Content-Type' => $content_type || 'text/plain',
843 my $text = Form::compose([ $form ]);
845 if ($edit || !$msg) {
846 my ($tmp) = vi_form_while(
849 my ($text, $form) = @_;
850 foreach my $f ( @{ vsplit($form->[2]{'Attachment'}) } ) {
851 return (0, "File '$f' doesn't exist") unless -f $f;
853 @files = @{ vsplit($form->[2]{'Attachment'}) };
857 return $tmp unless $tmp;
862 foreach my $file (@files) {
863 $data{"attachment_$i"} = bless([ $file ], "Attachment");
866 $data{content} = $text;
868 my $r = submit("$REST/ticket/$id/comment", \%data);
873 # Merge one ticket into another.
881 s/^#// if /^#\d+/; # get rid of leading hash
887 whine "Unrecognised argument: '$_'.";
893 my $evil = @id > 2 ? "many" : "few";
894 whine "Too $evil arguments specified.";
897 #return help("merge", "ticket") if $bad;
898 return suggest_help("merge", "ticket", $bad) if $bad;
900 my $r = submit("$REST/ticket/$id[0]/merge/$id[1]");
905 # Link one ticket to another.
908 my ($bad, $del, %data) = (0, 0, ());
911 my %ltypes = map { lc $_ => $_ } qw(DependsOn DependedOnBy RefersTo
912 ReferredToBy HasMember MemberOf);
914 while (@ARGV && $ARGV[0] =~ /^-/) {
921 $bad = 1, last unless defined($type = get_type_argument());
924 whine "Unrecognised option: '$_'.";
929 $type = "ticket" unless $type; # default type to tickets
932 my ($from, $rel, $to) = @ARGV;
933 if (($type eq "ticket") && ( ! exists $ltypes{lc $rel})) {
934 whine "Invalid link '$rel' for type $type specified.";
937 %data = (id => $from, rel => $rel, to => $to, del => $del);
940 my $bad = @ARGV < 3 ? "few" : "many";
941 whine "Too $bad arguments specified.";
944 return suggest_help("link", $type, $bad) if $bad;
946 my $r = submit("$REST/$type/link", \%data);
951 # Take/steal a ticket
954 my ($bad, %data) = (0, ());
961 unless ($id =~ /^\d+$/) {
962 whine "Invalid ticket ID $id specified.";
967 [ "Ticket", "Action" ],
975 my $text = Form::compose([ $form ]);
976 $data{content} = $text;
979 $bad = @ARGV < 1 ? "few" : "many";
980 whine "Too $bad arguments specified.";
983 return suggest_help("take", "ticket", $bad) if $bad;
985 my $r = submit("$REST/ticket/$id/take", \%data);
990 # Grant/revoke a user's rights.
995 whine "$cmd is unimplemented.";
999 # Client <-> Server communication.
1000 # --------------------------------
1002 # This function composes and sends an HTTP request to the RT server, and
1003 # interprets the response. It takes a request URI, and optional request
1004 # data (a string, or a reference to a set of key-value pairs).
1007 my ($uri, $content) = @_;
1009 my $ua = LWP::UserAgent->new(agent => "RT/3.0b", env_proxy => 1);
1010 my $h = HTTP::Headers->new;
1012 # Did the caller specify any data to send with the request?
1014 if (defined $content) {
1015 unless (ref $content) {
1016 # If it's just a string, make sure LWP handles it properly.
1017 # (By pretending that it's a file!)
1018 $content = [ content => [undef, "", Content => $content] ];
1020 elsif (ref $content eq 'HASH') {
1022 foreach my $k (keys %$content) {
1023 if (ref $content->{$k} eq 'ARRAY') {
1024 foreach my $v (@{ $content->{$k} }) {
1028 else { push @data, $k, $content->{$k} }
1035 # Should we send authentication information to start a new session?
1036 my $how = $config{server} =~ /^https/ ? 'over SSL' : 'unencrypted';
1037 (my $server = $config{server}) =~ s/^.*\/\/([^\/]+)\/?/$1/;
1038 if ($config{externalauth}) {
1039 $h->authorization_basic($config{user}, $config{passwd} || read_passwd() );
1040 print " Password will be sent to $server $how\n",
1041 " Press CTRL-C now if you do not want to continue\n"
1042 if ! $config{passwd};
1043 } elsif ( $no_strong_auth ) {
1044 if (!defined $session->cookie) {
1045 print " Strong encryption not available, $no_strong_auth\n",
1046 " Password will be sent to $server $how\n",
1047 " Press CTRL-C now if you do not want to continue\n"
1048 if ! $config{passwd};
1049 push @$data, ( user => $config{user} );
1050 push @$data, ( pass => $config{passwd} || read_passwd() );
1054 # Now, we construct the request.
1056 $req = POST($uri, $data, Content_Type => 'form-data');
1061 $session->add_cookie_header($req);
1062 if ($config{externalauth}) {
1066 # Then we send the request and parse the response.
1067 DEBUG(3, $req->as_string);
1068 my $res = $ua->request($req);
1069 DEBUG(3, $res->as_string);
1071 if ($res->is_success) {
1072 # The content of the response we get from the RT server consists
1073 # of an HTTP-like status line followed by optional header lines,
1074 # a blank line, and arbitrary text.
1076 my ($head, $text) = split /\n\n/, $res->content, 2;
1077 my ($status, @headers) = split /\n/, $head;
1078 $text =~ s/\n*$/\n/ if ($text);
1080 # "RT/3.0.1 401 Credentials required"
1081 if ($status !~ m#^RT/\d+(?:\S+) (\d+) ([\w\s]+)$#) {
1082 warn "rt: Malformed RT response from $config{server}.\n";
1083 warn "(Rerun with RTDEBUG=3 for details.)\n" if $config{debug} < 3;
1087 # Our caller can pretend that the server returned a custom HTTP
1088 # response code and message. (Doing that directly is apparently
1089 # not sufficiently portable and uncomplicated.)
1092 $res->content($text);
1093 $session->update($res) if ($res->is_success || $res->code != 401);
1095 if (!$res->is_success) {
1096 # We can deal with authentication failures ourselves. Either
1097 # we sent invalid credentials, or our session has expired.
1098 if ($res->code == 401) {
1100 if (exists $d{user}) {
1101 warn "rt: Incorrect username or password.\n";
1104 elsif ($req->header("Cookie")) {
1105 # We'll retry the request with credentials, unless
1106 # we only wanted to logout in the first place.
1108 return submit(@_) unless $uri eq "$REST/logout";
1111 # Conflicts should be dealt with by the handler and user.
1112 # For anything else, we just die.
1113 elsif ($res->code != 409) {
1114 warn "rt: ", $res->content;
1120 warn "rt: Server error: ", $res->message, " (", $res->code, ")\n";
1127 # Session management.
1128 # -------------------
1130 # Maintains a list of active sessions in the ~/.rt_sessions file.
1135 # Initialises the session cache.
1137 my ($class, $file) = @_;
1139 file => $file || "$HOME/.rt_sessions",
1143 # The current session is identified by the currently configured
1145 ($s, $u) = @config{"server", "user"};
1147 bless $self, $class;
1153 # Returns the current session cookie.
1156 my $cookie = $self->{sids}{$s}{$u};
1157 return defined $cookie ? "RT_SID_$cookie" : undef;
1160 # Deletes the current session cookie.
1163 delete $self->{sids}{$s}{$u};
1166 # Adds a Cookie header to an outgoing HTTP request.
1167 sub add_cookie_header {
1168 my ($self, $request) = @_;
1169 my $cookie = $self->cookie();
1171 $request->header(Cookie => $cookie) if defined $cookie;
1174 # Extracts the Set-Cookie header from an HTTP response, and updates
1175 # session information accordingly.
1177 my ($self, $response) = @_;
1178 my $cookie = $response->header("Set-Cookie");
1180 if (defined $cookie && $cookie =~ /^RT_SID_(.[^;,\s]+=[0-9A-Fa-f]+);/) {
1181 $self->{sids}{$s}{$u} = $1;
1185 # Loads the session cache from the specified file.
1187 my ($self, $file) = @_;
1188 $file ||= $self->{file};
1190 open( my $handle, '<', $file ) or return 0;
1192 $self->{file} = $file;
1193 my $sids = $self->{sids} = {};
1196 next if /^$/ || /^#/;
1197 next unless m#^https?://[^ ]+ \w+ [^;,\s]+=[0-9A-Fa-f]+$#;
1198 my ($server, $user, $cookie) = split / /, $_;
1199 $sids->{$server}{$user} = $cookie;
1204 # Writes the current session cache to the specified file.
1206 my ($self, $file) = shift;
1207 $file ||= $self->{file};
1209 open( my $handle, '>', "$file" ) or return 0;
1211 my $sids = $self->{sids};
1212 foreach my $server (keys %$sids) {
1213 foreach my $user (keys %{ $sids->{$server} }) {
1214 my $sid = $sids->{$server}{$user};
1216 print $handle "$server $user $sid\n";
1234 # Forms are RFC822-style sets of (field, value) specifications with some
1235 # initial comments and interspersed blank lines allowed for convenience.
1236 # Sets of forms are separated by --\n (in a cheap parody of MIME).
1238 # Each form is parsed into an array with four elements: commented text
1239 # at the start of the form, an array with the order of keys, a hash with
1240 # key/value pairs, and optional error text if the form syntax was wrong.
1242 # Returns a reference to an array of parsed forms.
1246 my @lines = split /\n/, $_[0] if $_[0];
1247 my ($c, $o, $k, $e) = ("", [], {}, "");
1251 my $line = shift @lines;
1253 next LINE if $line eq '';
1255 if ($line eq '--') {
1256 # We reached the end of one form. We'll ignore it if it was
1257 # empty, and store it otherwise, errors and all.
1258 if ($e || $c || @$o) {
1259 push @forms, [ $c, $o, $k, $e ];
1260 $c = ""; $o = []; $k = {}; $e = "";
1264 elsif ($state != -1) {
1265 if ($state == 0 && $line =~ /^#/) {
1266 # Read an optional block of comments (only) at the start
1270 while (@lines && $lines[0] =~ /^#/) {
1271 $c .= "\n".shift @lines;
1275 elsif ($state <= 1 && $line =~ /^($field):(?:\s+(.*))?$/) {
1276 # Read a field: value specification.
1280 # Read continuation lines, if any.
1281 while (@lines && ($lines[0] eq '' || $lines[0] =~ /^\s+/)) {
1282 push @v, shift @lines;
1284 pop @v while (@v && $v[-1] eq '');
1286 # Strip longest common leading indent from text.
1288 foreach my $ls (map {/^(\s+)/} @v[1..$#v]) {
1289 $ws = $ls if (!$ws || length($ls) < length($ws));
1291 s/^$ws// foreach @v;
1293 push(@$o, $f) unless exists $k->{$f};
1294 vpush($k, $f, join("\n", @v));
1298 elsif ($line !~ /^#/) {
1299 # We've found a syntax error, so we'll reconstruct the
1300 # form parsed thus far, and add an error marker. (>>)
1302 $e = Form::compose([[ "", $o, $k, "" ]]);
1303 $e.= $line =~ /^>>/ ? "$line\n" : ">> $line\n";
1307 # We saw a syntax error earlier, so we'll accumulate the
1308 # contents of this form until the end.
1312 push(@forms, [ $c, $o, $k, $e ]) if ($e || $c || @$o);
1314 foreach my $l (keys %$k) {
1315 $k->{$l} = vsplit($k->{$l}) if (ref $k->{$l} eq 'ARRAY');
1321 # Returns text representing a set of forms.
1326 foreach my $form (@$forms) {
1327 my ($c, $o, $k, $e) = @$form;
1340 foreach my $key (@$o) {
1343 my @values = ref $v eq 'ARRAY' ? @$v : $v;
1345 $sp = " "x(length("$key: "));
1346 $sp = " "x4 if length($sp) > 16;
1348 foreach $v (@values) {
1354 push @lines, "$line\n\n";
1357 elsif (@lines && $lines[-1] !~ /\n\n$/) {
1360 push @lines, "$key: $v\n\n";
1363 length($line)+length($v)-rindex($line, "\n") >= 70)
1365 $line .= ",\n$sp$v";
1368 $line = $line ? "$line,$v" : "$key: $v";
1372 $line = "$key:" unless @values;
1374 if ($line =~ /\n/) {
1375 if (@lines && $lines[-1] !~ /\n\n$/) {
1380 push @lines, "$line\n";
1384 $text .= join "", @lines;
1392 return join "\n--\n\n", @text;
1398 # Returns configuration information from the environment.
1399 sub config_from_env {
1402 foreach my $k (qw(EXTERNALAUTH DEBUG USER PASSWD SERVER QUERY ORDERBY)) {
1404 if (exists $ENV{"RT$k"}) {
1405 $env{lc $k} = $ENV{"RT$k"};
1412 # Finds a suitable configuration file and returns information from it.
1413 sub config_from_file {
1417 # We'll use an absolute path if we were given one.
1418 return parse_config_file($rc);
1421 # Otherwise we'll use the first file we can find in the current
1422 # directory, or in one of its (increasingly distant) ancestors.
1424 my @dirs = split /\//, cwd;
1426 my $file = join('/', @dirs, $rc);
1428 return parse_config_file($file);
1431 # Remove the last directory component each time.
1435 # Still nothing? We'll fall back to some likely defaults.
1436 for ("$HOME/$rc", "/opt/rt3/local/etc/rt.conf", "/etc/rt.conf") {
1437 return parse_config_file($_) if (-r $_);
1444 # Makes a hash of the specified configuration file.
1445 sub parse_config_file {
1448 local $_; # $_ may be aliased to a constant, from line 1163
1450 open( my $handle, '<', $file ) or return;
1454 next if (/^#/ || /^\s*$/);
1456 if (/^(externalauth|user|passwd|server|query|orderby|queue)\s+(.*)\s?$/) {
1460 die "rt: $file:$.: unknown configuration directive.\n";
1471 my $sub = (caller(1))[3];
1472 $sub =~ s/^main:://;
1473 warn "rt: $sub: @_\n";
1478 eval 'require Term::ReadKey';
1480 die "No password specified (and Term::ReadKey not installed).\n";
1484 Term::ReadKey::ReadMode('noecho');
1485 chomp(my $passwd = Term::ReadKey::ReadLine(0));
1486 Term::ReadKey::ReadMode('restore');
1497 my ($c, $o, $k, $e);
1499 my $ntext = vi($text);
1500 return undef if ($error && $ntext eq $text);
1504 my $form = Form::parse($text);
1506 ($c, $o, $k, $e) = @{ $form->[0] };
1509 $c = "# Syntax error.";
1516 my ($status, $msg) = $cb->( $text, [$c, $o, $k, $e] );
1517 unless ( $status ) {
1523 $text = Form::compose([[$c, $o, $k, $e]]);
1531 my $editor = $ENV{EDITOR} || $ENV{VISUAL} || "vi";
1535 my $handle = File::Temp->new;
1536 print $handle $text;
1539 system($editor, $handle->filename) && die "Couldn't run $editor.\n";
1541 open( $handle, '<', $handle->filename ) or die "$handle: $!\n";
1548 # Add a value to a (possibly multi-valued) hash key.
1550 my ($hash, $key, $val) = @_;
1551 my @val = ref $val eq 'ARRAY' ? @$val : $val;
1553 if (exists $hash->{$key}) {
1554 unless (ref $hash->{$key} eq 'ARRAY') {
1555 my @v = $hash->{$key} ne '' ? $hash->{$key} : ();
1556 $hash->{$key} = \@v;
1558 push @{ $hash->{$key} }, @val;
1561 $hash->{$key} = $val;
1565 # "Normalise" a hash key that's known to be multi-valued.
1569 my @values = ref $val eq 'ARRAY' ? @$val : $val;
1571 foreach my $line (map {split /\n/} @values) {
1572 # XXX: This should become a real parser, Ã la Text::ParseWords.
1575 my ( $a, $b ) = split /\s*,\s*/, $line, 2;
1578 no warnings 'uninitialized';
1581 while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/
1582 && $a =~ /(\\)+'$/ )) {
1583 ( $a, $b ) = split /\s*,\s*/, $b, 2;
1588 elsif ( $a =~ /^q\{/ ) {
1590 while ( $a !~ /\}$/ ) {
1592 split /\s*,\s*/, $b, 2;
1602 ( $a, $b ) = split /\s*,\s*/, $b, 2;
1611 # WARN: this code is duplicated in lib/RT/Interface/REST.pm
1612 # change both functions at once
1617 foreach (split /\s*,\s*/, $list) {
1618 push @elts, /^(\d+)-(\d+)$/? ($1..$2): $_;
1621 return map $_->[0], # schwartzian transform
1623 defined $a->[1] && defined $b->[1]?
1626 :!defined $a->[1] && !defined $b->[1]?
1629 # mix, number must be first
1630 :defined $a->[1]? -1: 1
1632 map [ $_, (defined( /^(\d+)$/ )? $1: undef), lc($_) ],
1636 sub get_type_argument {
1640 $type = shift @ARGV;
1641 unless ($type =~ /^[A-Za-z0-9_.-]+$/) {
1642 # We want whine to mention our caller, not us.
1643 @_ = ("Invalid type '$type' specified.");
1648 @_ = ("No type argument specified with -t.");
1652 $type =~ s/s$//; # "Plural". Ugh.
1656 sub get_var_argument {
1660 my $kv = shift @ARGV;
1661 if (my ($k, $v) = $kv =~ /^($field)=(.*)$/) {
1662 push @{ $data->{$k} }, $v;
1665 @_ = ("Invalid variable specification: '$kv'.");
1670 @_ = ("No variable argument specified with -S.");
1675 sub is_object_spec {
1676 my ($spec, $type) = @_;
1678 $spec =~ s|^(?:$type/)?|$type/| if defined $type;
1679 return $spec if ($spec =~ m{^$name/(?:$idlist|$labels)(?:/.*)?$}o);
1684 my ($action, $type, $rv) = @_;
1686 print STDERR "rt: For help, run 'rt help $action'.\n" if defined $action;
1687 print STDERR "rt: For help, run 'rt help $type'.\n" if defined $type;
1692 # simplified procedure for parsing date, avoid loading Date::Parse
1693 my %month = (Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5,
1694 Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11);
1696 my ($mon, $day, $hr, $min, $sec, $yr, $monstr);
1697 if ( /(\w{3})\s+(\d\d?)\s+(\d\d):(\d\d):(\d\d)\s+(\d{4})/ ) {
1698 ($monstr, $day, $hr, $min, $sec, $yr) = ($1, $2, $3, $4, $5, $6);
1699 $mon = $month{$monstr} if exists $month{$monstr};
1700 } elsif ( /(\d{4})-(\d\d)-(\d\d)\s+(\d\d):(\d\d):(\d\d)/ ) {
1701 ($yr, $mon, $day, $hr, $min, $sec) = ($1, $2-1, $3, $4, $5, $6);
1703 if ( $yr and defined $mon and $day and defined $hr and defined $sec ) {
1704 return timelocal($sec,$min,$hr,$day,$mon,$yr);
1706 print "Unknown date format in parsedate: $_\n";
1712 my ($old, $new) = @_;
1713 $new = time() if ! $new;
1714 $old = str2time($old) if $old !~ /^\d+$/;
1715 $new = str2time($new) if $new !~ /^\d+$/;
1716 return "???" if ! $old or ! $new;
1718 my %seconds = (min => 60,
1723 yr => 60*60*24*365);
1725 my $diff = $new - $old;
1727 my $howmuch = $diff;
1728 for ( sort {$seconds{$a} <=> $seconds{$b}} keys %seconds) {
1729 last if $diff < $seconds{$_};
1731 $howmuch = int($diff/$seconds{$_});
1733 return "$howmuch $what";
1738 my ($form) = grep { exists $_->[2]->{Queue} } @$forms;
1740 # dates are in local time zone
1742 print "Date: $k->{Created}\n";
1743 print "From: $k->{Requestors}\n";
1744 print "Cc: $k->{Cc}\n" if $k->{Cc};
1745 print "X-AdminCc: $k->{AdminCc}\n" if $k->{AdminCc};
1746 print "X-Queue: $k->{Queue}\n";
1747 print "Subject: [rt #$k->{id}] $k->{Subject}\n\n";
1749 # dates in these attributes are in GMT and will be converted
1750 foreach my $form (@$forms) {
1751 my ($c, $o, $k, $e) = @$form;
1752 next if ! $k->{id} or exists $k->{Queue};
1753 if ( exists $k->{Created} ) {
1754 my ($y,$m,$d,$hh,$mm,$ss) = ($k->{Created} =~ /(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/);
1756 my $created = localtime(timegm($ss,$mm,$hh,$d,$m,$y));
1757 if ( exists $k->{Description} ) {
1758 print "===> $k->{Description} on $created\n";
1761 print "$k->{Content}\n" if exists $k->{Content} and
1762 $k->{Content} !~ /to have no content$/ and
1763 ($k->{Type}||'') ne 'EmailRecord';
1764 print "$k->{Attachments}\n" if exists $k->{Attachments} and
1771 my $heading = "Ticket Owner Queue Age Told Status Requestor Subject\n";
1772 $heading .= '-' x 80 . "\n";
1774 foreach my $form (@$forms) {
1775 my ($c, $o, $k, $e) = @$form;
1777 print $heading if $heading;
1780 $id =~ s!^ticket/!!;
1781 my $owner = $k->{Owner} eq 'Nobody' ? '' : $k->{Owner};
1782 $owner = substr($owner, 0, 5);
1783 my $queue = substr($k->{Queue}, 0, 5);
1784 my $subject = substr($k->{Subject}, 0, 30);
1785 my $age = date_diff($k->{Created});
1786 my $told = $k->{Told} eq 'Not set' ? '' : date_diff($k->{Told});
1787 my $status = substr($k->{Status}, 0, 6);
1788 my $requestor = substr($k->{Requestors}, 0, 9);
1789 my $line = sprintf "%6s %5s %5s %6s %6s %-6s %-9s %-30s\n",
1790 $id, $owner, $queue, $age, $told, $status, $requestor, $subject;
1791 if ( $k->{Owner} eq 'Nobody' ) {
1793 } elsif ($k->{Owner} eq $config{user} ) {
1799 print "No matches found\n" if $heading;
1800 printf "========== my %2d open tickets ==========\n", scalar @me if @me;
1802 printf "========== %2d unowned tickets ==========\n", scalar @open if @open;
1803 print @open if @open;
1812 This is a command-line interface to RT 3.0 or newer.
1814 It allows you to interact with an RT server over HTTP, and offers an
1815 interface to RT's functionality that is better-suited to automation
1816 and integration with other tools.
1818 In general, each invocation of this program should specify an action
1819 to perform on one or more objects, and any other arguments required
1820 to complete the desired action.
1822 For more information:
1824 - rt help usage (syntax information)
1825 - rt help objects (how to specify objects)
1826 - rt help actions (a list of possible actions)
1827 - rt help types (a list of object types)
1829 - rt help config (configuration details)
1830 - rt help examples (a few useful examples)
1831 - rt help topics (a list of help topics)
1841 rt <action> [options] [arguments]
1845 Each invocation of this program must specify an action (e.g. "edit",
1846 "create"), options to modify behaviour, and other arguments required
1847 by the specified action. (For example, most actions expect a list of
1848 numeric object IDs to act upon.)
1850 The details of the syntax and arguments for each action are given by
1851 "rt help <action>". Some actions may be referred to by more than one
1852 name ("create" is the same as "new", for example).
1854 You may also call "rt shell", which will give you an 'rt>' prompt at
1855 which you can issue commands of the form "<action> [options]
1856 [arguments]". See "rt help shell" for details.
1858 Objects are identified by a type and an ID (which can be a name or a
1859 number, depending on the type). For some actions, the object type is
1860 implied (you can only comment on tickets); for others, the user must
1861 specify it explicitly. See "rt help objects" for details.
1863 In syntax descriptions, mandatory arguments that must be replaced by
1864 appropriate value are enclosed in <>, and optional arguments are
1865 indicated by [] (for example, <action> and [options] above).
1867 For more information:
1869 - rt help objects (how to specify objects)
1870 - rt help actions (a list of actions)
1871 - rt help types (a list of object types)
1872 - rt help shell (how to use the shell)
1878 Title: configuration
1881 This program has two major sources of configuration information: its
1882 configuration files, and the environment.
1884 The program looks for configuration directives in a file named .rtrc
1885 (or $RTCONFIG; see below) in the current directory, and then in more
1886 distant ancestors, until it reaches /. If no suitable configuration
1887 files are found, it will also check for ~/.rtrc, /opt/rt3/local/etc/rt.conf
1890 Configuration directives:
1892 The following directives may occur, one per line:
1894 - server <URL> URL to RT server.
1895 - user <username> RT username.
1896 - passwd <passwd> RT user's password.
1897 - query <RT Query> Default RT Query for list action
1898 - orderby <order> Default RT order for list action
1899 - queue <queuename> Default RT Queue for list action
1900 - externalauth <0|1> Use HTTP Basic authentication
1901 explicitely setting externalauth to 0 inhibits also GSSAPI based
1902 authentication, if LWP::Authen::Negotiate (and GSSAPI) is installed
1904 Blank and #-commented lines are ignored.
1906 Sample configuration file contents:
1908 server https://rt.somewhere.com/
1909 # more than one queue can be given (by adding a query expression)
1910 queue helpdesk or queue=support
1911 query Status != resolved and Owner=myaccount
1914 Environment variables:
1916 The following environment variables override any corresponding
1917 values defined in configuration files:
1923 - RTDEBUG Numeric debug level. (Set to 3 for full logs.)
1924 - RTCONFIG Specifies a name other than ".rtrc" for the
1926 - RTQUERY Default RT Query for rt list
1927 - RTORDERBY Default order for rt list
1936 <type>/<id>[/<attributes>]
1938 Every object in RT has a type (e.g. "ticket", "queue") and a numeric
1939 ID. Some types of objects can also be identified by name (like users
1940 and queues). Furthermore, objects may have named attributes (such as
1941 "ticket/1/history").
1943 An object specification is like a path in a virtual filesystem, with
1944 object types as top-level directories, object IDs as subdirectories,
1945 and named attributes as further subdirectories.
1947 A comma-separated list of names, numeric IDs, or numeric ranges can
1948 be used to specify more than one object of the same type. Note that
1949 the list must be a single argument (i.e., no spaces). For example,
1950 "user/root,1-3,5,7-10,ams" is a list of ten users; the same list
1951 can also be written as "user/ams,root,1,2,3,5,7,8-10".
1953 If just a number is given as object specification it will be
1954 interpreted as ticket/<number>
1958 1 # the same as ticket/1
1960 ticket/1/attachments
1961 ticket/1/attachments/3
1962 ticket/1/attachments/3/content
1964 ticket/1-3,5-7/history
1968 For more information:
1970 - rt help <action> (action-specific details)
1971 - rt help <type> (type-specific details)
1979 You can currently perform the following actions on all objects:
1981 - list (list objects matching some condition)
1982 - show (display object details)
1983 - edit (edit object details)
1984 - create (create a new object)
1986 Each type may define actions specific to itself; these are listed in
1987 the help item about that type.
1989 For more information:
1991 - rt help <action> (action-specific details)
1992 - rt help types (a list of possible types)
1994 The following actions on tickets are also possible:
1996 - comment Add comments to a ticket
1997 - correspond Add comments to a ticket
1998 - merge Merge one ticket into another
1999 - link Link one ticket to another
2000 - take Take a ticket (steal and untake are possible as well)
2002 For several edit set subcommands that are frequently used abbreviations
2003 have been introduced. These abbreviations are:
2005 - delete or del delete a ticket (edit set status=deleted)
2006 - resolve or res resolve a ticket (edit set status=resolved)
2007 - subject change subject of ticket (edit set subject=string)
2008 - give give a ticket to somebody (edit set owner=user)
2015 You can currently operate on the following types of objects:
2022 For more information:
2024 - rt help <type> (type-specific details)
2025 - rt help objects (how to specify objects)
2026 - rt help actions (a list of possible actions)
2033 Tickets are identified by a numeric ID.
2035 The following generic operations may be performed upon tickets:
2042 In addition, the following ticket-specific actions exist:
2058 The following attributes can be used with "rt show" or "rt edit"
2059 to retrieve or edit other information associated with tickets:
2061 links A ticket's relationships with others.
2062 history All of a ticket's transactions.
2063 history/type/<type> Only a particular type of transaction.
2064 history/id/<id> Only the transaction of the specified id.
2065 attachments A list of attachments.
2066 attachments/<id> The metadata for an individual attachment.
2067 attachments/<id>/content The content of an individual attachment.
2075 Users and groups are identified by name or numeric ID.
2077 The following generic operations may be performed upon them:
2089 Queues are identified by name or numeric ID.
2091 Currently, they can be subjected to the following actions:
2104 rt subject <id> <new subject text>
2106 Change the subject of a ticket whose ticket id is given.
2115 rt give <id> <accountname>
2117 Give a ticket whose ticket id is given to another user.
2126 Steal a ticket whose ticket id is given, i.e. set the owner to myself.
2137 Take a ticket whose ticket id is given, i.e. set the owner to myself.
2148 Untake a ticket whose ticket id is given, i.e. set the owner to Nobody.
2160 Resolves a ticket whose ticket id is given.
2172 Deletes a ticket whose ticket id is given.
2183 Terminates the currently established login session. You will need to
2184 provide authentication credentials before you can continue using the
2185 server. (See "rt help config" for details about authentication.)
2196 rt <ls|list|search> [options] "query string"
2198 Displays a list of objects matching the specified conditions.
2199 ("ls", "list", and "search" are synonyms.)
2201 Conditions are expressed in the SQL-like syntax used internally by
2202 RT. (For more information, see "rt help query".) The query string
2203 must be supplied as one argument.
2205 (Right now, the server doesn't support listing anything but tickets.
2206 Other types will be supported in future; this client will be able to
2207 take advantage of that support without any changes.)
2211 The following options control how much information is displayed
2212 about each matching object:
2214 -i Numeric IDs only. (Useful for |rt edit -; see examples.)
2215 -s Short description.
2216 -l Longer description.
2217 -f <field[s] Display only the fields listed and the ticket id
2221 -o +/-<field> Orders the returned list by the specified field.
2222 -r reversed order (useful if a default was given)
2223 -q queue[s] restricts the query to the queue[s] given
2224 multiple queues are separated by comma
2225 -S var=val Submits the specified variable with the request.
2226 -t type Specifies the type of object to look for. (The
2227 default is "ticket".)
2231 rt ls "Priority > 5 and Status=new"
2232 rt ls -o +Subject "Priority > 5 and Status=new"
2233 rt ls -o -Created "Priority > 5 and Status=new"
2234 rt ls -i "Priority > 5"|rt edit - set status=resolved
2235 rt ls -t ticket "Subject like '[PATCH]%'"
2237 rt ls -f owner,subject
2246 rt show [options] <object-ids>
2248 Displays details of the specified objects.
2250 For some types, object information is further classified into named
2251 attributes (for example, "1-3/links" is a valid ticket specification
2252 that refers to the links for tickets 1-3). Consult "rt help <type>"
2253 and "rt help objects" for further details.
2255 If only a number is given it will be interpreted as the objects
2256 ticket/number and ticket/number/history
2258 This command writes a set of forms representing the requested object
2263 The following options control how much information is displayed
2264 about each matching object:
2266 Without any formatting options prettyprinted output is generated.
2267 Giving any of the two options below reverts to raw output.
2268 -s Short description (history and attachments only).
2269 -l Longer description (history and attachments only).
2272 - Read IDs from STDIN instead of the command-line.
2273 -t type Specifies object type.
2274 -f a,b,c Restrict the display to the specified fields.
2275 -S var=val Submits the specified variable with the request.
2279 rt show -t ticket -f id,subject,status 1-3
2280 rt show ticket/3/attachments/29
2281 rt show ticket/3/attachments/29/content
2282 rt show ticket/1-3/links
2283 rt show ticket/3/history
2284 rt show -l ticket/3/history
2297 rt edit [options] <object-ids> set field=value [field=value] ...
2298 add field=value [field=value] ...
2299 del field=value [field=value] ...
2301 Edits information corresponding to the specified objects.
2303 A purely numeric object id nnn is translated into ticket/nnn
2305 If, instead of "edit", an action of "new" or "create" is specified,
2306 then a new object is created. In this case, no numeric object IDs
2307 may be specified, but the syntax and behaviour remain otherwise
2310 This command typically starts an editor to allow you to edit object
2311 data in a form for submission. If you specified enough information
2312 on the command-line, however, it will make the submission directly.
2314 The command line may specify field-values in three different ways.
2315 "set" sets the named field to the given value, "add" adds a value
2316 to a multi-valued field, and "del" deletes the corresponding value.
2317 Each "field=value" specification must be given as a single argument.
2319 For some types, object information is further classified into named
2320 attributes (for example, "1-3/links" is a valid ticket specification
2321 that refers to the links for tickets 1-3). These attributes may also
2322 be edited. Consult "rt help <type>" and "rt help object" for further
2327 - Read numeric IDs from STDIN instead of the command-line.
2328 (Useful with rt ls ... | rt edit -; see examples below.)
2329 -i Read a completed form from STDIN before submitting.
2330 -o Dump the completed form to STDOUT instead of submitting.
2331 -e Allows you to edit the form even if the command-line has
2332 enough information to make a submission directly.
2334 Submits the specified variable with the request.
2335 -t type Specifies object type.
2336 -ct content-type Specifies content type of message(tickets only).
2340 # Interactive (starts $EDITOR with a form).
2343 rt create -t ticket -ct text/html
2346 rt edit ticket/1-3 add cc=foo@example.com set priority=3 due=tomorrow
2347 rt ls -t tickets -i 'Priority > 5' | rt edit - set status=resolved
2348 rt edit ticket/4 set priority=3 owner=bar@example.com \
2349 add cc=foo@example.com bcc=quux@example.net
2350 rt create -t ticket set subject='new ticket' priority=10 \
2351 add cc=foo@example.com
2361 rt <comment|correspond> [options] <ticket-id>
2363 Adds a comment (or correspondence) to the specified ticket (the only
2364 difference being that comments aren't sent to the requestors.)
2366 This command will typically start an editor and allow you to type a
2367 comment into a form. If, however, you specified all the necessary
2368 information on the command line, it submits the comment directly.
2370 (See "rt help forms" for more information about forms.)
2374 -m <text> Specify comment text.
2375 -ct <content-type> Specify content-type of comment text.
2376 -a <file> Attach a file to the comment. (May be used more
2377 than once to attach multiple files.)
2378 -c <addrs> A comma-separated list of Cc addresses.
2379 -b <addrs> A comma-separated list of Bcc addresses.
2380 -w <time> Specify the time spent working on this ticket.
2381 -e Starts an editor before the submission, even if
2382 arguments from the command line were sufficient.
2386 rt comment -m 'Not worth fixing.' -a stddisclaimer.h 23
2395 rt merge <from-id> <to-id>
2397 Merges the first ticket specified into the second ticket specified.
2406 rt link [-d] <id-A> <link> <id-B>
2408 Creates (or, with -d, deletes) a link between the specified tickets.
2409 The link can (irrespective of case) be any of:
2411 DependsOn/DependedOnBy: A depends upon B (or vice versa).
2412 RefersTo/ReferredToBy: A refers to B (or vice versa).
2413 MemberOf/HasMember: A is a member of B (or vice versa).
2415 To view a ticket's links, use "rt show ticket/3/links". (See
2416 "rt help ticket" and "rt help show".)
2420 -d Deletes the specified link.
2424 rt link 2 dependson 3
2425 rt link -d 4 referredtoby 6 # 6 no longer refers to 4
2432 RT uses an SQL-like syntax to specify object selection constraints.
2433 See the <RT:...> documentation for details.
2435 (XXX: I'm going to have to write it, aren't I?)
2437 Until it exists here a short description of important constructs:
2439 The two simple forms of query expressions are the constructs
2440 Attribute like Value and
2441 Attribute = Value or Attribute != Value
2443 Whether attributes can be matched using like or using = is built into RT.
2444 The attributes id, Queue, Owner Priority and Status require the = or !=
2447 If Value is a string it must be quoted and may contain the wildcard
2448 character %. If the string does not contain white space, the quoting
2449 may however be omitted, it will be added automatically when parsing
2452 Simple query expressions can be combined using and, or and parentheses
2453 can be used to group expressions.
2455 As a special case a standalone string (which would not form a correct
2456 query) is transformed into (Owner='string' or Requestor like 'string%')
2457 and added to the default query, i.e. the query is narrowed down.
2459 If no Queue=name clause is contained in the query, a default clause
2460 Queue=$config{queue} is added.
2463 Status!='resolved' and Status!='rejected'
2464 (Owner='myaccount' or Requestor like 'myaccount%') and Status!='resolved'
2472 This program uses RFC822 header-style forms to represent object data
2473 in a form that's suitable for processing both by humans and scripts.
2475 A form is a set of (field, value) specifications, with some initial
2476 commented text and interspersed blank lines allowed for convenience.
2477 Field names may appear more than once in a form; a comma-separated
2478 list of multiple field values may also be specified directly.
2480 Field values can be wrapped as in RFC822, with leading whitespace.
2481 The longest sequence of leading whitespace common to all the lines
2482 is removed (preserving further indentation). There is no limit on
2483 the length of a value.
2485 Multiple forms are separated by a line containing only "--\n".
2487 (XXX: A more detailed specification will be provided soon. For now,
2488 the server-side syntax checking will suffice.)
2499 Get help on any of the following subjects:
2501 - tickets, users, groups, queues.
2502 - show, edit, ls/list/search, new/create.
2504 - query (search query syntax)
2505 - forms (form specification)
2507 - objects (how to specify objects)
2508 - types (a list of object types)
2509 - actions/commands (a list of actions)
2510 - usage/syntax (syntax details)
2511 - conf/config/configuration (configuration details)
2512 - examples (a few useful examples)
2520 some useful examples
2522 All the following list requests will be restricted to the default queue.
2523 That can be changed by adding the option -q queuename
2525 List all tickets that are not rejected/resolved
2527 List all tickets that are new and do not have an owner
2528 rt ls "status=new and owner=nobody"
2529 List all tickets which I have sent or of which I am the owner
2531 List all attributes for the ticket 6977 (ls -l instead of ls)
2533 Show the content of ticket 6977
2535 Show all attributes in the ticket and in the history of the ticket
2537 Comment a ticket (mail is sent to all queue watchers, i.e. AdminCc's)
2539 This will open an editor and lets you add text (attribute Text:)
2540 Other attributes may be changed as well, but usually don't do that.
2541 Correspond a ticket (like comment, but mail is also sent to requestors)
2543 Edit a ticket (generic change, interactive using the editor)
2545 Change the owner of a ticket non interactively
2546 rt edit 6977 set owner=myaccount
2548 rt give 6977 account
2551 Change the status of a ticket
2552 rt edit 6977 set status=resolved
2555 Change the status of all tickets I own to resolved !!!
2556 rt ls -i owner=myaccount | rt edit - set status=resolved
2567 Opens an interactive shell, at which you can issue commands of
2568 the form "<action> [options] [arguments]".
2570 To exit the shell, type "quit" or "exit".
2572 Commands can be given at the shell in the same form as they would
2573 be given at the command line without the leading 'rt' invocation.
2577 rt> create -t ticket set subject='new' add cc=foo@example.com
2591 rt <take|untake|steal> <ticket-id>
2593 Sets the owner of the specified ticket to the current user,
2594 assuming said user has the bits to do so, or releases the
2597 'Take' is used on tickets which are not currently owned
2598 (Owner: Nobody), 'steal' is used on tickets which *are*
2599 currently owned, and 'untake' is used to "release" a ticket
2600 (reset its Owner to Nobody). 'Take' cannot be used on
2601 tickets which are currently owned.
2604 alice$ rt create -t ticket set subject="New ticket"
2607 # Owner changed from Nobody to alice
2610 # Owner changed from alice to bob
2612 # Owner changed from bob to Nobody
2620 Use "quit" or "exit" to leave the shell. Only valid within shell
2632 rt - command-line interface to RT 3.0 or newer
2640 This script allows you to interact with an RT server over HTTP, and offers an
2641 interface to RT's functionality that is better-suited to automation and
2642 integration with other tools.
2644 In general, each invocation of this program should specify an action to
2645 perform on one or more objects, and any other arguments required to complete