--- /tmp/lib/TWiki.pm 2006-02-07 16:08:46.000000000 +0100 +++ lib/TWiki.pm 2006-03-20 11:18:35.000000000 +0100 @@ -1520,6 +1520,7 @@ my $path = ''; my $user = ''; my $pass = ''; + my $protocol = 'http'; # For speed, read file directly if URL matches an attachment directory if( $theUrl =~ /^$this->{urlHost}$TWiki::cfg{PubUrlPath}\/([^\/\.]+)\/([^\/\.]+)\/([^\/]+)$/ ) { @@ -1552,21 +1553,31 @@ # fall through; try to include file over http based on MIME setting } - if( $theUrl =~ /http\:\/\/(.+)\:(.+)\@([^\:]+)\:([0-9]+)(\/.*)/ ) { - ( $user, $pass, $host, $port, $path ) = ( $1, $2, $3, $4, $5 ); - } elsif( $theUrl =~ /http\:\/\/(.+)\:(.+)\@([^\/]+)(\/.*)/ ) { - ( $user, $pass, $host, $path ) = ( $1, $2, $3, $4 ); - } elsif( $theUrl =~ /http\:\/\/([^\:]+)\:([0-9]+)(\/.*)/ ) { - ( $host, $port, $path ) = ( $1, $2, $3 ); - } elsif( $theUrl =~ /http\:\/\/([^\/]+)(\/.*)/ ) { - ( $host, $path ) = ( $1, $2 ); + if( $theUrl =~ /https:\/\/.*/ ) { + # provide better default port value, as we have standard port 443 for https protocol + $protocol = 'https'; + $port = 443; + } + + if( $theUrl =~ /(https?)\:\/\/(.+)\:(.+)\@([^\:]+)\:([0-9]+)(\/.*)/ ) { + ( $protocol, $user, $pass, $host, $port, $path ) = ( $1, $2, $3, $4, $5, $6 ); + } elsif( $theUrl =~ /(https?)\:\/\/(.+)\:(.+)\@([^\/]+)(\/.*)/ ) { + ( $protocol, $user, $pass, $host, $path ) = ( $1, $2, $3, $4, $5 ); + } elsif( $theUrl =~ /(https?)\:\/\/([^\:]+)\:([0-9]+)(\/.*)/ ) { + ( $protocol, $host, $port, $path ) = ( $1, $2, $3, $4 ); + } elsif( $theUrl =~ /(https?)\:\/\/([^\/]+)(\/.*)/ ) { + ( $protocol, $host, $path ) = ( $1, $2, $3 ); } else { $text = $this->inlineAlert( 'alerts', 'bad_protocol', $theUrl ); return $text; } try { - $text = $this->{net}->getUrl( $host, $port, $path, $user, $pass ); + if( $protocol =~ /https/ ) { + $text = $this->{net}->getSecureUrl( $host, $port, $path, $user, $pass ); + } else { + $text = $this->{net}->getUrl( $host, $port, $path, $user, $pass ); + } $text =~ s/\r\n/\n/gs; $text =~ s/\r/\n/gs; $text =~ s/^(.*?\n)\n(.*)/$2/s; @@ -1577,8 +1588,13 @@ } if( $contentType =~ /^text\/html/ ) { $path =~ s/[#?].*$//; - $host = 'http://'.$host; - if( $port != 80 ) { + $host = $protocol.'://'.$host; + if( $protocol =~ /https/ ) { + if( $port != 443 ) { + $host .= ":$port"; + } + } + elsif( $port != 80 ) { $host .= ":$port"; } $text = _cleanupIncludedHTML( $text, $host, $path ); --- /tmp/lib/TWiki/Net.pm 2006-02-07 16:08:44.000000000 +0100 +++ lib/TWiki/Net.pm 2006-03-20 11:42:50.000000000 +0100 @@ -114,6 +114,39 @@ return $result; } +=pod + +---++ ObjectMethod getSecureUrl ( $host, $port, $url, $user, $pass, $header ) -> $text + +Get the text at the other end of a secure URL (https://) + +This method currently does not support user authentication. +A given user and password will be silently ignored. + +=cut + +sub getSecureUrl { + my ( $this, $host, $port, $url, $user, $pass, $header ) = @_; + ASSERT($this->isa( 'TWiki::Net')) if DEBUG; + ASSERT($host) if DEBUG; + + if( $user =~ /..*/ ) { + $this->{session}->writeWarning( "TWiki::Net::getSecureUrl user (and password) authentication are currently not supported. The user will be ignored for now." ); + } + + if( $port < 1 ) { + $port = 443; + } + + use LWP; + require HTTP::Request; + #$this->{session}->writeWarning( "TWiki::Net::getSecureUrl request: https://$host:$port$url" ); + my $request = HTTP::Request->new(GET => "https://$host:$port$url"); + my $ua = LWP::UserAgent->new; + my $response = $ua->request($request); + return $response->as_string; +} + # pick a default mail handler sub _installMailHandler { my $this = shift;