\n";
$m.="" . $element . " | \n";
$m.="" . ord($value) . " | \n";
$m.="" . (ord($value) >= 32 ? htmlentities($value) : " ") . " | \n";
$m.="
\n";
}
$m.="\n";
return($m);
}
/* The actual interpreter */
function brainfuck_interpret(&$s, &$_s, &$d, &$_d, &$i, &$_i, &$o) {
do {
switch($s[$_s]) {
/* Execute brainfuck commands. Values are not stored as numbers, but as their
representing characters in the ASCII table. This is perfect, as chr(256) is
automagically converted to chr(0). */
case '+': $d[$_d] = chr(ord($d[$_d]) + 1); break;
case '-': $d[$_d] = chr(ord($d[$_d]) - 1); break;
case '>': $_d++; if(!isset($d[$_d])) $d[$_d] = chr(0); break;
case '<': $_d--; break;
/* Output is stored in a variable. Change this to
echo $d[$_d]; flush();
if you would like to have a "live" output (when running long calculations, for example.
Or if you are just terribly impatient). */
case '.': $o .= $d[$_d]; break;
/* Due to PHP's non-interactive nature I have the whole input passed over in a string.
I successively read characters from this string and pass it over to BF every time a
',' command is executed. */
case ',': $d[$_d] = $_i==strlen($i) ? chr(0) : $i[$_i++]; break;
/* Catch loops */
case '[':
/* Skip loop (also nested ones) */
if((int)ord($d[$_d]) == 0) {
$brackets = 1;
while($brackets && $_s++ < strlen($s)) {
if($s[$_s] == '[')
$brackets++;
else if($s[$_s] == ']')
$brackets--;
}
}
/* Execute loop */
else {
$pos = $_s++-1;
/* The closing ] returns true when the loop has to be executed again. If so, then return
to the $pos(ition) where the opening [ is. */
if(brainfuck_interpret($s, $_s, $d, $_d, $i, $_i, $o))
$_s = $pos;
}
break;
/* Return true when loop has to be executed again. It is redundant to the [ checking, but
it will save some parsing time (otherwise the interpreter would have to return to [ only
to skip all characters again) */
case ']': return ((int)ord($d[$_d]) != 0);
/* Call debug function */
case '#': $o.=brainfuck_debug($s, $_s, $d, $_d, $i, $_i, $o);
}
} while(++$_s < strlen($s));
}
/* Call this one in order to interpret brainfuck code */
function brainfuck($source, $input='') {
/* Define needed variables:
$data Brainfuck's memory
$source Source data
$input Simulate STDIN
$output Save output in here
Each with according index variables
*/
$data = array();
$data[0] = chr(0); /* It is necessary to set every element explicitly, as
PHP treats arrays as hashes */
$data_index = 0;
$source_index = 0;
$input_index = 0;
$output = '';
/* Call the actual interpreter */
brainfuck_interpret($source, $source_index,
$data, $data_index,
$input, $input_index,
$output);
return $output;
}
?>
nanoweb_2.2.9/modules/mod_fb.php 0000644 0000000 0000000 00000014226 11023557654 015361 0 ustar root root
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
define("NW_TMPL_FB_HEADER", "fb_header");
define("NW_TMPL_FB_FOOTER", "fb_footer");
define("NW_TMPL_FB_PARENT", "fb_parent_name");
define("NW_TMPL_FB_ROW_D", "fb_directory_row");
define("NW_TMPL_FB_ROW_F", "fb_file_row");
class mod_fb {
function mod_fb() {
$this->modtype="core_directory_handler";
$this->modname="Files and directories browser";
}
function main() {
global $http_uri, $docroot, $conf, $vhost, $rq_err, $out_contenttype, $real_uri, $out_add_headers, $accessdir, $mime, $query_string;
foreach (access_query("fbiconbytype") as $icndef) {
$ic=explode(" ", $icndef);
$icons[trim($ic[1])]=trim($ic[0]);
}
$icndef=access_query("fbicondefault", 0);
if (!($icndir=access_query("fbicondirectory", 0))) $icndir=$icndef;
if ($http_uri[strlen($http_uri)-1]!="/") $http_uri.="/";
if (access_query("filebrowser", 0)) {
if (@is_readable($docroot.$http_uri)) {
$dfmt=access_query("fbdateformat", 0)
or $dfmt="d-M-Y H:i:s";
$rq_err=200;
$out_contenttype="text/html";
// Generate directory listing
$hnd=opendir(realpath($docroot.$http_uri));
unset($fb_arr);
unset($fsort);
while ($f=readdir($hnd)) {
$fi=stat($docroot.$http_uri.$f);
$fi["isdir"]=is_dir($docroot.$http_uri.$f);
$fi["f"]=$f;
$fb_arr[$f]=$fi;
if (!$fi["isdir"]) {
$fb_ts+=$fi[7];
$fb_tf++;
}
}
if ($fbstmp=access_query("fbsortorder", 0)) {
$fbsort=explode(" ", $fbstmp);
} else {
$fbsort=array("name");
}
parse_str($query_string, $ptmp);
if (count($ptmp)) {
if ($ptmp["sort"]) $fbsort[0]=$ptmp["sort"];
if ($ptmp["order"]) $fbsort[1]=$ptmp["order"];
}
switch ($fbsort[0]) {
case "date": $sortidx=9;
break;
case "size": $sortidx=7;
break;
case "name":
default: $sortidx="f";
}
$dsort = $fsort = array();
foreach ($fb_arr as $fstmp) if (!$fstmp["isdir"]) {
$fsort[$fstmp["f"]] = $fstmp[$sortidx];
} else {
if ($fstmp["f"] != "..") {
$dsort[$fstmp["f"]] = $fstmp[$sortidx];
} else {
$has_parent = $fstmp[$sortidx];
}
}
if ($fbsort[1]=="desc") {
arsort($fsort);
arsort($dsort);
} else {
asort($fsort);
asort($dsort);
}
if ($has_parent) {
$dsort = array_reverse($dsort);
$dsort[".."] = $has_parent;
$dsort = array_reverse($dsort);
}
// Do other processing
if (@is_readable($wfn=$docroot.$http_uri.$conf[$vhost]["fbwelcomefile"][0])) {
$wfc=implode("