From d7665e244f4206d695da707e7a391b0b198f3edc Mon Sep 17 00:00:00 2001 From: b Date: Wed, 23 Dec 2015 08:59:15 +0000 Subject: [PATCH] Added url- and entity encoding git-svn-id: svn://botcastle1b/yplom/proxy@15 05ce6ebb-7522-4a6e-a768-0026ae12be9f --- makefile.1.mak | 2 +- proxy.1.pl | 10 +++++----- proxy_lib.1.pm | 25 ++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/makefile.1.mak b/makefile.1.mak index ca6fe27..1db823e 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -53,7 +53,7 @@ access.pl: access.1.pl configure.pl settings access.c: access.1.c configure.pl settings $(PL) configure.pl settings access.c - + access: access.c $(CC) $(CF) -o access access.c diff --git a/proxy.1.pl b/proxy.1.pl index 05244b5..a035766 100755 --- a/proxy.1.pl +++ b/proxy.1.pl @@ -36,7 +36,7 @@ use strict; #use warnings; ###LIB; -use proxy_lib qw(urldecode divideurl urldiv2path getcgi formatheader access); +use proxy_lib qw(urldecode divideurl entityencode urldiv2path getcgi formatheader access); use POSIX qw(strftime); ###UNLOCK_LOG; @@ -652,7 +652,7 @@ sub unlockpage { print ''; print '

Unlock the proxy

'; if($message ne ''){ - print $message; + print '

'.entityencode($message).'

'; } print '
'; print 'Username:
'; @@ -682,15 +682,15 @@ sub fail { print ''; print ''; if($title ne ''){ - print "$title"; + print ''.entityencode($title).''; } print ''; print ''; if($title ne ''){ - print "

$title

"; + print '

'.entityencode($title).'

'; } if($message ne ''){ - print $message; + print '

'.entityencode($message).'

'; } print "\n"; } diff --git a/proxy_lib.1.pm b/proxy_lib.1.pm index a7dcfc4..2671a30 100644 --- a/proxy_lib.1.pm +++ b/proxy_lib.1.pm @@ -274,7 +274,7 @@ use constant entitycode => { $VERSION = 0.000004; @ISA = qw(Exporter); @EXPORT = (); -@EXPORT_OK = qw(access divideurl entitydecode formatheader getcgi joinurl path2url url2path path2urldiv readconfigfile readheaderfile urldecode urldiv2path); +@EXPORT_OK = qw(access divideurl entitydecode entityencode formatheader getcgi joinurl path2url url2path path2urldiv readconfigfile readheaderfile urlencode urldecode urldiv2path); %EXPORT_TAGS = (); # This function checks if the user has unlocked the proxy. Nonzero means yes. @@ -454,6 +454,29 @@ sub entitydecode { return $t; } +# function to encode entities, decimal, +sub entityencode { + (my $t, my $all) = @_; + if ($all) { + $t =~ s/(.)/sprintf('\&#%02hu;',ord($1))/eg; + } + else { + $t =~ s/([\"=><\&])/sprintf('&#%02hu;',ord($1))/eg; + } + return $t; +} + +sub urlencode { + (my $t, my $all) = @_; + if ($all) { + $t =~ s/(.)/sprintf('%%%02hX',ord($1))/eg; + } + else { + $t =~ s/([^0-9A-Za-z.~\-_])/sprintf('%%%02hX',ord($1))/eg; + } + return $t; +} + # Function for decoding one html entity, called from entitydecode(). sub entitydecode1ch { my $t = $_[0]; -- 2.30.2