File Coverage

blib/lib/HTTP/DAV/Xythos.pm
Criterion Covered Total %
statement 10 52 19.2
branch 0 28 0.0
condition 0 6 0.0
subroutine 4 6 66.6
pod 0 1 0.0
total 14 93 15.0


line stmt bran cond sub pod time code
1             package HTTP::DAV::Xythos;
2             BEGIN {
3 2     2   27387 $HTTP::DAV::Xythos::VERSION = '1.101180';
4             }
5              
6 2     2   21 use strict;
  2         4  
  2         78  
7 2     2   12 use warnings;
  2         4  
  2         80  
8              
9 2     2   10 use base qw(HTTP::DAV);
  2         4  
  2         3111  
10              
11             my @xythos_args = qw(ticket);
12              
13             sub new
14             {
15 0     0 0   my ($class, %args) = @_;
16              
17             # save the original args
18 0           my %orig_args = %args;
19              
20 0           for ( @xythos_args ) {
21             # make sure that we have the Xythos args
22 0 0         die "arg '$_' is required\n" unless defined $orig_args{$_};
23              
24             # remove the Xythos args from the call to the HTTP::DAV constructor
25 0           delete $args{$_};
26             }
27              
28             # create the HTTP::DAV object
29 0           my $self = $class->SUPER::new( %args );
30              
31             # login to the Xythos ticket
32 0 0         if ( $orig_args{ticket} ) {
33 0 0         unless ( $self->_login_ticket(%orig_args) ) {
34 0           die "failed to login\n";;
35             }
36             }
37            
38 0           return $self;
39             }
40              
41             sub _login_ticket {
42 0     0     my ($self, %args) = @_;
43              
44 0           my ($xythos_uri, $webui_uri) = $args{ticket} =~ m#^(https?://.*?)(/.*)/#;
45 0 0 0       return $self->err( '', "unable to parse ticket\n" ) unless ( $xythos_uri and $webui_uri );
46              
47             # add the cookie jar to the user agent
48 0           $self->get_user_agent()->cookie_jar({});
49              
50             # access the ticket
51 0           my $req = HTTP::Request->new(GET => $args{ticket});
52 0           my $res = $self->get_user_agent()->request($req);
53              
54             # authenticate to ticket
55 0 0 0       if ( defined $args{pass} and length $args{pass} ) {
56              
57 0 0         return $self->err( '', "Unable to connect to ticket URL: ".$res->status_line."\n" ) unless ($res->is_success);
58              
59 0           my ($server2) = $res->content =~ m#($webui_uri/.*?)'#;
60 0 0         return $self->err( '', "Problem logging in to ticket (invalid ticket url, or invalid password?)\n") unless ( $server2 );
61              
62 0           $server2 = "$xythos_uri$server2";
63              
64 0           $req = HTTP::Request->new(POST => $server2);
65 0           $req->content_type('application/x-www-form-urlencoded');
66 0           $req->content("password=$args{pass}&action=invitationalGroup&subaction=joinGroup");
67 0           $res = $self->get_user_agent()->request($req);
68              
69 0 0         return $self->err( '', "Unable to login to ticket (wrong password?)\n") unless ( $res->code eq "302" );
70              
71             # page redirects
72 0           $req = HTTP::Request->new(GET => $res->headers->{location});
73 0           $res = $self->get_user_agent()->request($req);
74 0 0         return $self->err( '', "Unable to login to ticket (wrong password?)\n") unless ( $res->code eq "302" );
75             }
76             else {
77 0 0         return $self->err( '', "Unable to access ticket (is the ticket URL valid?)\n") unless ( $res->code eq "302" );
78              
79             # page redirects
80 0           $req = HTTP::Request->new(GET => $res->headers->{location});
81 0           $res = $self->get_user_agent()->request($req);
82 0 0         return $self->err( '', "Unable to login to ticket (wrong password?)\n") unless ( $res->code eq "302" );
83             }
84              
85             # process the final redirect
86 0           $req = HTTP::Request->new(GET => $res->headers->{location});
87 0           $res = $self->get_user_agent()->request($req);
88 0 0         return $self->err( '', "Unable to redirect: ".$res->status_line."\n") unless ($res->is_success);
89              
90             # gather information needed for upload
91 0           my ($posturi) = $res->content =~ m#id="filesForm" action="(.*?)"#;
92 0 0         return $self->err( '', "unable to upload (is the ticket to a file instead of a directory?)\n") unless ( $posturi );
93 0           ($self->{webdav_url}) = $posturi =~ m#$webui_uri(.*)#;
94 0 0         return $self->err( '', "failed to parse information needed for upload\n") unless ( $self->{webdav_url} );
95              
96             # set the webdav_url variable
97 0           $self->{webdav_url} = $xythos_uri.$self->{webdav_url};
98              
99 0           return 1;
100             }
101             1;
102             __END__