Switch layouts home | FAQ | | P1 | P2 | P3 | P4 | P5 |  | A1 | A2 | A3  | | B1

Working with the file system

1. Create a copy or a link to PB. It may be either a hard link or a symbolic link depending on your preferences and settings of the web server. The name of the link can be anything as long as the web server is going to run it as a cgi script. For example, a2.cgi
ln ../cgi-bin/pb.pl ./a2.cgi    or
ln -sf ../cgi-bin/pb.pl ./a2.cgi

2. Create a project configuration file. The name should be cgi-script's name + ".pm". For a2.cgi this file should be ./a2.cgi.pm
use vars qw($dbh $sth);



sub a2_show_file
   my $file=shift | $Parameter{file};
   $file=~s/\.\.//g; $file=~s/\/\///g;$file=~s/\|//g;
   if($file!~/^$top_dir/) {$file="";}
   if( $file ne "" && -e $file )
     print "<pre>";
     while( defined($l=<RD>)){ $l=~ s/&/$HTMLam/g; $l =~ s/</$HTMLlt/g; $l =~ s/>/$HTMLgt/g; $l =~ s/\"/$HTMLqt/g; print $l;}
     close RD;
     print "</pre>";

sub a2_download
  my $file = shift || $Parameter{file};
  my ($fname) = $file =~ /\/([^\/]*)/;
  my $s;
  $s = "";
  my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)= stat($file);
   $file=~s/\.\.//g; $file=~s/\/\///g; $file=~s/\|//g;
  if($file!~/^$top_dir/) {$file="";}
  if( $file ne "" && -e $file )
    read(IN, $s, $size);
    print "Content-type: application/octet-stream\n"
    ."Content-Disposition: Attachment; filename=\"$fname\"\n"
    ."Content-length: "."$size"."\n\n"

3. Create an html-template file, a2-home.html
<!%if $Parameter{file}%><!%set &a2_show_file($Parameter{file})%><!%endif%>
<!%if $Parameter{save}%>"Save" is not allowed<br><!%endif%>
An attempt to save PB tags will cause a security alert
<FORM action="/PB/a2.cgi" method='POST'>
<input type=hidden name="save" value='save'>
<input type='submit' value='Save (not allowed)'> 
<a href="/PB/a2.cgi<!%show $Parameter{cur_dir}?'?cur_dir='."$Parameter{cur_dir}":""%>">ls</a> 
<a href="/PB/a2.cgi?edit=<!%show $Parameter{edit}%>">reload</a>
<br><input type=hidden name=edit value='<!%show $Parameter{edit}%>' size=132 maxsize=255 >
<!%show $Parameter{edit}%>
if($file!~/^$top_dir/ || $file=~/\.\.\// || $file=~/\|/) 
{$file="";$alert="<br><font color=red>Oops!Interesting filename ...<br>Hey, if you want to explore more, contact us !</font>";}
{ $str=&CI_include($file);$str=~s/\</\<\;/g;$str=~s/\>/\>\;/g; }
%><!%show $alert%>
<br><textarea name=my_edit cols=72 rows=30 width='70' wrap=off value=''>
<!%show $str%></textarea>
Listing of "<!%show $cur_dir%>" directory:
if($cur_dir!~/^$top_dir/ || $cur_dir=~/\.\.\// || $cur_dir=~/\|/) 
{$alert="<font color=red>Oops!Interesting cur_dir ... <br>Hey, if you want to explore more, contact us !</font>";$cur_dir=$top_dir;}
{ $str=&CI_include($file);$str=~s/\</\<\;/g;$str=~s/\>/\>\;/g; }
@ls=split("\n",`ls -F $cur_dir`)
%><!%show $alert%>
<TABLE border=1 cellspacing=0>
<!%if $ls[$i]=~m/\/$/%>
<TD colspan=3></TD>
<TD><a href="/PB/a2.cgi?cur_dir=<!%show $cur_dir.$ls[$i]%>"><!%show $ls[$i]%></a></TD>
<TD><a href="/PB/a2.cgi?file=<!%show $cur_dir.$ls[$i]%>">show</a></TD>
<TD><a href="/PB/a2.cgi?Page=download&file=<!%show $cur_dir.$ls[$i]%>">download</a></TD>
<TD><a href="/PB/a2.cgi?edit=<!%show $cur_dir.$ls[$i]%>&cur_dir=<!%show $cur_dir%>">edit</a></TD>
<TD><a href="<!%show $cur_dir.$ls[$i]%>"><!%show $ls[$i]%></a>

4. Create a download template file, a2-download
Content-type: application/octet-stream
<!%set &a2_download($Parameter{file})%>

5. This web project is complete. Check it out: