#!/usr/local/bin/perl # chooser.cgi # Outputs HTML for a frame-based path chooser require './smf-lib.pl'; &init_config(); &ReadParse(); if (defined($in{'path'})) { $path = $in{'path'}; # +'s get converted to spaces, convert back $path =~ s/\s/+/g; if ($path =~ /^(\/.*)$/) { # path entered is valid $path=$1; } } else { $path="/"; } $add = int($in{'add'}); $frame = $in{'frame'}; if ($frame eq "" ) { $frame = 0; } if ($in{'frame'} == 0) { # base frame &PrintHeader(); print "$text{'path_chooser_title'}\n"; print "\n"; print "\n"; print "\n"; print "\n"; } elsif ($in{'frame'} == 1) { # List of svcs &header(); print < function pathclick(path, expand) { top.bottomframe.document.forms[0].path.value = path; if (expand == 1) { location ="path_chooser.cgi?frame=1&add=$add&path="+path; } } EOF print "", &text('path_chooser_path', $path),"\n"; print "\n"; # get file/dir list if (opendir(CURRDIR, $path)) { # remove extra trailing "/" if there. $fixed_filepath = $path; $fixed_filepath =~ s/(.*)\/$/$1/; foreach $f (readdir(CURRDIR)) { if ($f eq ".") { # skip } elsif ($f eq "..") { $uplevel = "$fixed_filepath"; if ($uplevel =~ /^((\/[^\/]*)*)\/[^\/]*$/) { $uplevel = $1; } if ($uplevel eq "") { $uplevel = "/"; } $uplevel = &urlize($uplevel); push(@pathlist, ""); } else { $expand = 0; $img = "images/file.gif"; # is this a file or a dir? if (opendir(DISCARD, "$fixed_filepath/$f")) { close(DISCARD); $expand = 1; $img = "images/dir.gif"; } $newpath = &urlize("$fixed_filepath/$f"); push(@pathlist, ""); } } closedir(CURRDIR); } foreach $p (@pathlist) { print "\n"; print "$p"; print "\n"; } print "
..$f
\n"; &footer(); } elsif ($in{'frame'} == 2) { # Current path and OK/cancel buttons &header(); print < function pathchosen() { if ($add == 0) { top.opener.ifield.value = "file://localhost"+document.forms[0].path.value; } else { if (top.opener.ifield.value != "") { top.opener.ifield.value += " "; } top.opener.ifield.value += "file://localhost"+document.forms[0].path.value; } top.close(); } EOF print "
\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; print "
"; print ""; print "
"; print "
\n"; &footer(); }