"; } else { $configs[$item]["value"]=$value; } } } }/*}}}*/ function parse_menucolor($line){/*{{{*/ global $menucolor; global $menucolor_values; $items=split("=", $line); $mod=split("&", $items[1]); $x=0; while ($x < sizeof($mod)){ $mod[$x]=preg_replace("/\n/", "", $mod[$x]); $x++; } $item=array(); $item["text"]=$items[0]; $item["color"]=$mod[0]; $found=0; foreach ($menucolor_values as $color){ if ($item["color"] == $color) $found=1; } if ($found == 0){ $item["color"] = "gray"; } else { $x = 0; while ($x < sizeof($mod) - 1){ $mod[$x] = $mod[$x+1]; $x++; } $mod[sizeof($mod)-1] = ""; } $item["modifier"]=$mod; $menucolor[]=$item; }/*}}}*/ function parse_line($line, $authoritative){/*{{{*/ if (preg_match("/^OPTIONS=/", $line)){ parse_options(preg_replace("/^OPTIONS=/i", "", $line), $authoritative); } elseif (preg_match("/^BOULDER=(.*)/i", $line, $matches)){ parse_options("boulder:".$matches[1],0); } elseif (preg_match("/^MENUCOLOR=/i", $line)){ parse_menucolor(preg_replace("/^MENUCOLOR=/i", "", $line)); } else { echo "EEP! Don't know how to handle: '$line'
"; } }/*}}}*/ function read_file($filename, $authoritative){/*{{{*/ if (!($rc = @fopen($filename, "r"))){ die ("Can't open $filename"); } while (!feof($rc)) { $line = fgets($rc, 4096); $line = preg_replace("/#.*$/", "", $line); if (!preg_match("/^\s*$/", $line)) parse_line($line, $authoritative); } fclose($rc); }/*}}}*/ function read_values($filename){/*{{{*/ global $values; if (!($rc = @fopen($filename, "r"))){ die ("Can't open $filename"); } while (!feof($rc)) { $line = fgets($rc, 4096); $line = preg_replace("/#.*$/", "", $line); $line = preg_replace("/\n/", "", $line); if (!preg_match("/^\s*$/", $line)){ $items=split(":", $line); $item=strtolower($items[0]); $items=split(";", $items[1]); if ($items[1]){ $x=0; $list=array(); while ($x < sizeof($items)){ $list[]=split(",", $items[$x]); $x++; } $values[$item]=$list; } else { $items=split(",", $items[0]); $values[$item]=$items; } } } fclose($rc); }/*}}}*/ function read_helptxt($filename) {/*{{{*/ global $helptxt; if (!($rc = @fopen($filename, "r"))){ die ("Can't open $filename"); } while (!feof($rc)) { $line = fgets($rc, 4096); $items = split("\|", $line); $helptxt[$items[0]] = $items[1]; } }/*}}}*/ function output_field($config){/*{{{*/ global $values; global $helptxt; if ($values[$config["name"]]){ echo ""; echo "".$config["name"].""; if ($values[$config["name"]][0][1][1]){ // evil check echo ""; $x=0; foreach ($values[$config["name"]] as $conf){ echo ""; $x++; } echo ""; echo "".$helptxt[$config["name"]].""; } else { echo ""; echo ""; echo ""; echo "".$helptxt[$config["name"]].""; } echo ""; } else { if ($config["type"]=="bool"){ echo ""; echo "".$config["name"].""; echo " yes"; echo " no"; echo "".$helptxt[$config["name"]].""; echo ""; } else { echo ""; echo "".$config["name"].""; echo ""; echo "".$helptxt[$config["name"]].""; echo ""; } } }/*}}}*/ function output_menucolor($line,$coloritem){/*{{{*/ global $menucolor_values; global $menucolor_mods; $line["text"] = preg_replace("/^\"/", "", $line["text"]); $line["text"] = preg_replace("/\"$/", "", $line["text"]); echo ""; echo ""; echo ""; foreach ($menucolor_mods as $mod){ echo ""; echo " $mod"; echo ""; } echo ""; }/*}}}*/ /* {{{ auth */ if (!isset($_SERVER['PHP_AUTH_USER']) or !isset($_SERVER['PHP_AUTH_PW'])){ header('WWW-Authenticate: Basic realm="Nethack Web Config"'); header('HTTP/1.0 401 Unauthorized'); die("Invalid Username/Password combination"); } if (!($fd=fopen($dgllogin, "r"))){ die ("Can't open $dgllogin"); } $line=""; $auth=0; while (!feof($fd)) { $line = fgets($fd, 4096); $dgl=split(":", $line); if ($dgl[0] != $_SERVER['PHP_AUTH_USER']){ $line=""; continue; } if ($dgl[2] != crypt($_SERVER['PHP_AUTH_PW'], $_SERVER['PHP_AUTH_PW']) and ($dgl[2] != $_SERVER['PHP_AUTH_PW'])){ header('WWW-Authenticate: Basic realm="Nethack Web Config"'); header('HTTP/1.0 401 Unauthorized'); die("Invalid Username/Password combination"); } else { $auth=1; break; } } fclose($fd); if ($auth == 0) exit; ?>

Nethack WebConfig for

"; echo ""; echo "

Editing the rc-file for user ".$_SERVER['PHP_AUTH_USER']."

"; echo "WARNING: Pressing the SAVE-button will remove all comments in the rc-file.

"; echo "TODO Your current rc-file

"; echo ""; echo ""; foreach ($configs as $config){ output_field($config); } echo "

Common Options

"; $x=0; echo ""; echo ""; foreach ($menucolor as $color){ $x++; output_menucolor($color,$x); } output_menucolor(array(text=>"", color=>"gray", modifier=>array()), ++$x); output_menucolor(array(text=>"", color=>"gray", modifier=>array()), ++$x); output_menucolor(array(text=>"", color=>"gray", modifier=>array()), ++$x); output_menucolor(array(text=>"", color=>"gray", modifier=>array()), ++$x); output_menucolor(array(text=>"", color=>"gray", modifier=>array()), ++$x); echo "

Menucolors

"; echo ""; echo ""; } else {/*}}}*/ /*{{{ output */ read_values("values"); read_file("defaults",1); if (!($fd=fopen($nhrcpath.$_SERVER["PHP_AUTH_USER"].".nethackrc", "w"))){ die ("Can't open ".$nhrcpath.$_SERVER["PHP_AUTH_USER"].".nethackrc"); } fwrite($fd, "# Generated by http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\n"); foreach ($configs as $conf){ if ($values[$conf["name"]][0][1][1]){ // still evil check fwrite($fd, "OPTIONS=".$conf["name"].":"); $x=0; foreach ($values[$conf["name"]] as $tmp){ fwrite($fd, $_POST[$conf["name"]."_$x"]." "); $x++; } fwrite($fd, "\n"); } else { if ($_POST[$conf["name"]] != ""){ if ($conf["type"] == "bool") fwrite($fd, "OPTIONS=".($_POST[$conf["name"]] == "no" ? "no" : "").$conf["name"]."\n"); else fwrite($fd, "OPTIONS=".$conf["name"].":".stripslashes($_POST[$conf["name"]])."\n"); } } } $x=1; while ($_POST["menucolor_$x"]){ if (!$_POST["menucolortext_$x"]){ $x++; continue; } fwrite($fd, "MENUCOLOR=\"".stripslashes($_POST["menucolortext_$x"])."\"=".$_POST["menucolor_$x"]); foreach ($menucolor_mods as $mod){ if ($_POST["menucolor_".$x."_".$mod] == "on") fwrite($fd, "&$mod"); } fwrite($fd, "\n"); $x++; } fclose($fd); echo "Configuration saved!
"; echo "

"; }/*}}}*/ ?>