<package name="test" surlstyle="get"><domain lang="en">
<import pm="PApp::UserObs"/>
<import pm="PApp::UserObs"/>
<import src="macro/editform"/>
<import src="macro/xpcse"/>

<callback name="up"><perl><![CDATA[
	   my ($upload, $fh, $name, $ct, $cta, $cd) = @_;
           my $fn = "unknown.bin";
           $fn = $cd->{filename} if defined $cd->{filename};
	   $fn =~ s@/@@g;
           $upload->{filename} = $fn;
return $upload->{tmpfn} = "$upload->{path}/$upload->{filename}";
]]></perl></callback>

<perl><![CDATA[
use File::Glob ":glob";
use File::Basename;
use Fcntl ':mode';
use Cwd 'abs_path';

our %ucache;
sub cuname($) {
   $ucache{$_[0]} ||= getpwuid $_[0];
}

our %gcache;
sub cgname($) {
   $gcache{$_[0]} ||= getgrgid $_[0];
}

sub lstime($) {
   my @t = (localtime $_[0])[5,4,3,2,1];
   $t[0]+=1900;
   $t[1]++;
   sprintf "%.4d-%.2d-%.2d %.2d:%.2d", @t;
}

sub modestring($) {
   my $mode = shift;
   my $r;
   $r = "b" if S_ISBLK $mode;
   $r = "c" if S_ISCHR $mode;
   $r = "d" if S_ISDIR $mode;
   $r = "-" if S_ISREG $mode;
   $r = "p" if S_ISFIFO $mode;
   $r = "l" if S_ISLNK $mode;
   $r = "s" if S_ISSOCK $mode;
   $r ||= "?";
   
   $r .= ($mode & S_IRUSR) ? "r" : "-";
   $r .= ($mode & S_IWUSR) ? "w" : "-";
   $r .= ($mode & S_IXUSR) ? "x" : "-";
   $r .= ($mode & S_IRGRP) ? "r" : "-";
   $r .= ($mode & S_IWGRP) ? "w" : "-";
   $r .= ($mode & S_IXGRP) ? "x" : "-";
   $r .= ($mode & S_IROTH) ? "r" : "-";
   $r .= ($mode & S_IWOTH) ? "w" : "-";
   $r .= ($mode & S_IXOTH) ? "x" : "-";

   substr $r, 3, 1, (substr($r,3,1) eq 'x') ? 's' : 'S' if $mode & S_ISUID;
   substr $r, 6, 1, (substr($r,6,1) eq 'x') ? 's' : 'S' if $mode & S_ISGID;
   substr $r, 9, 1, (substr($r,9,1) eq 'x') ? 't' : 'T' if $mode & S_ISVTX;
   $r
}

sub filespec($) {
    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
        $atime,$mtime,$ctime,$blksize,$blocks) = lstat shift;
    my $r = sprintf("%.10s %3d %-8.8s %-8.8s %9d %s",
          modestring $mode,
          $nlink,
          cuname $uid,
          cgname $gid,
          $size,
          lstime $atime);
    $r =~ s/ /&#160;/g;
    $r
}

sub ReadMimetypes() {
   my %mimetypes;
   for my $file ("/usr/local/etc/mime.types", "/usr/share/etc/mime.types", "/etc/mime.types") {
      open my $fh, "<$file" or next;
      while(<$fh>) {
         chomp; lc;
         next if /^#/;
         next if /^$/;
         my($type,@exts) = split;
         for(@exts) {
            $mimetypes{$_} = $type unless exists $mimetypes{$_};
         }
      }
   }
   \%mimetypes;
}
]]></perl>

<module name="">
<perl><![CDATA[
 abort_to "browser", baseurl => abs_path "/tmp";
]]></perl>
</module>

<module name="browser" nosession="">
<state keys="mime path" local="yes"/>
<phtml><![CDATA[

#if !$S{baseurl}
  <:die "no baseurl":>
#endif

  <:my $p = abs_path($S{path} || $S{baseurl}):>
  <:$p = abs_path $S{baseurl} unless $p =~ /^$S{baseurl}/:>

<:$S{mime} ||= ReadMimetypes:>

#if !reload_p
# if $S{unlink}
  <:rmdir $S{unlink}:>
  <:unlink delete $S{unlink}:>
# endif

# if my $d = delete $S{mkdir}
  <:mkdir "$p/$d" unless $d =~ /\//:>
# endif

# if -f $p
  <:basename($p) =~ m/\.([^\.]+)$/; my ($ext,$mime) = ($1||"txt", $S{mime}{$1}|| __"text/plain"):>
  <:internal_redirect client_edit_surl $p, 'image/jpeg', on_exit_only => 1, quiet => 1,
    auth_proxy_username => test, auth_proxy_password => 'kvt3wsp_':> 
# endif
  
#endif
<h1>__"Aktueller Pfad:"&#160;"<?escape_html $p:>"</h1>
<hr/>
<table>
<:for my $e ("$p/.","$p/..",bsd_glob "$p/*") { fileparse_set_fstype("MSWin32");:>
   <tr><td><tt>&#160;<?filespec $e:></tt>&#160;<tt><?slink(escape_html basename($e), path => $e):></tt></td>
   <:$e =~ m/([^\.]+)$/; my $mime = $S{mime}{$1}|| __"text/plain":>
   <td><? -d $e ? "[DIR]" : escape_html "[$mime]":></td>
   <td><?slink __"[Löschen]", unlink => $e:></td>
   </tr>
<:}:>
</table>
<hr/>
<br/>
        <:my $temp = { path => $p }:>
        <?ef_mbegin -upload => $temp:>
        __"Datei hochladen:" &#160;
	<?ef_file $ppkg->refer('up', $temp), "/tmp":>
        <?ef_submit __"Abschicken":>
        <?ef_end:>
        <?ef_sbegin:>__"Verzeichnis erstellen:"&#160;<?ef_string \$S{mkdir}:><?ef_end:>
        <br/>
        __"Ein aktuelles Setup von xpcse (win32) gibt es <a href=\"/setup.exe\">hier</a>"
</body>
</html>
]]></phtml></module>
</domain></package>
