// DEBUGGING: Debug Kommentare werden in ein Textfeld am Anfang der HTML-Seite eingefügt.
// Achtung: Benutze `\\n´ statt `\n´ in debug-Texten!
$DEBUG=1;
function debug($txt) {
global $DEBUG;
if($DEBUG) {
echo "";
flush();
}
}
if($DEBUG) {
echo '';
echo "";
}
?>
// Global constants, like PATHS
$TIMEOUT=360; // 5 minutes
$STORE="0-999";
$BIN_PATH= "/home/btcd/btcd03/unimolis_root/cgi-bin";
$WWW_PATH= "/home/btcd/btcd03/unimolis_root/docs";
$TMP_PATH= $WWW_PATH."/var";
$BIN_PATH= $WWW_PATH."/bin";
$DOCS_PATH= $WWW_PATH;
?>
// declare variables (with initial value)
$nextpage="";
$backpage="";
$formula ="";
$ringsize ="3-inf";
$reset =0;
$CNT_generate=`ps -ef | grep generate | grep -v grep | wc -l 2>&1`-0;
debug("Running generate processes: $CNT_generate\\n");
$CNT_jmolviewd=`ps -ef | grep jmolviewd2 | grep -v grep | wc -l 2>&1`-0;
debug("Running jmolviewd servers: $CNT_jmolviewd\\n");
// Overwrite variable values with the data given via POST
debug("POST-Variablen: ");
foreach($_POST as $key => $value) {
debug("$key=$value,\t");
if($key=="nextpage") $nextpage=$value;
if($key=="backpage") $backpage=$value;
if($key=="formula") $formula=$value;
if($key=="formula") $formula=$value;
if($key=="reset") $reset=1;
}
if($formula=="") $reset=1;
debug("\\n");
// Reset data, if this was requested
if($reset) {
$formula="C6H6";
}
?>
// Einige PHP-Funktionen, die weiter unten aufgerufen werden...
// Simulate an un-buffered fgets so that istream doesnt
// hang there waiting for some input
function fgets_u($istream) {
$pArr = array($istream);
if (false === ($num_changed_streams = stream_select($pArr, $write = NULL, $except = NULL, 0))) {
print("\$ 001 Socket Error : UNABLE TO WATCH $istream.\n");
return FALSE;
} elseif ($num_changed_streams>0) {
return trim(fgets($istream, 1024));
}
return FALSE;
}
// Überschreibe Anzahl gefundener Moleküle
function set_nocalc($nr,$stat) {
echo <<
document.getElementById("nocalc").firstChild.nodeValue="$nr"
document.getElementById("status").firstChild.nodeValue="$stat"
document.getElementById("jmolview").notifyChange()
END;
}
// For each molgen-run we need a unique processid
// Last used processid is stored in file $TMP_PATH/processid.dat.
// The id is running cyclic through the values 100-999.
// Thus, after 900 calls the output files are automatically overwritten.
// (Hoping, that the file is not used any more!)
function get_processid() {
global $pidfile;
// Lese zuletzt genutzte process_id
$file=fopen($pidfile,"r");
$process_id=fread($file,10);
fclose($file);
// Neue process_id:
if($process_id<100 || $process_id>=999) $process_id=100;
else $process_id=1+$process_id;
// Schreibe neue processid:
$file=fopen($pidfile,"w");
fwrite($file,"$process_id\n");
fclose($file);
return $process_id;
}
function start_molgen() {
global $sdffile;
global $logfile;
global $pid;
global $process;
global $pipes;
global $command;
$REMOTE_ADDR=getenv('REMOTE_ADDR');
$HTTP_USER_AGENT=getenv('HTTP_USER_AGENT');
$fp=fopen("$logfile","a");
fputs($fp,date("[Y/m/d-H:i:s]")." $REMOTE_ADDR: START PROCESS $pid:\n $command \t($HTTP_USER_AGENT)\n");
fclose($fp);
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a file to write to: Number of chars=number of generated molecules
2 => array("pipe", "w") // stderr is a pipe that the child will write to
// 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
// 2 => array("file", "$logfile", "w") // stderr is a file to write to
);
$process = proc_open("$command", $descriptorspec, $pipes);
}
function close_molgen() {
global $logfile;
global $pid;
global $process;
global $pipes;
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
$REMOTE_ADDR=getenv('REMOTE_ADDR');
$HTTP_USER_AGENT=getenv('HTTP_USER_AGENT');
$fp=fopen("$logfile","a");
fputs($fp,date("[Y/m/d-H:i:s]")." $REMOTE_ADDR: PROCESS $pid DONE. (".connection_status()."): $command \t($HTTP_USER_AGENT)\n");
fclose($fp);
}
function start_jmolviewd() {
global $sdffile;
global $logfile;
global $pid;
global $process_jmolviewd;
global $pipes_jmolviewd;
global $command_jmolviewd;
echo "Starting demon...\n";
$REMOTE_ADDR=getenv('REMOTE_ADDR');
$HTTP_USER_AGENT=getenv('HTTP_USER_AGENT');
$fp=fopen("$logfile","a");
fputs($fp,date("[Y/m/d-H:i:s]")." $REMOTE_ADDR: START PROCESS $pid:\n $command_jmolviewd \t($HTTP_USER_AGENT)\n");
fclose($fp);
$command_jmolviewd="$BIN_PATH/jmolviewd2.wwwlauncher $sdffile";
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a file to write to: Number of chars=number of generated molecules
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
$process = proc_open("$command_jmolviewd", $descriptorspec, $pipes_jmolviewd);
}
// **************************************************
// Initialisierungen...
if($reset==0) {
// build up command line:
$logfile="$TMP_PATH/molgen.log";
$pidfile="$TMP_PATH/molgen.pid";
debug("\$logfile: $logfile\\n");
debug("\$pidfile: $pidfile\\n");
$pid=get_processid();
$sdffile="$TMP_PATH/gen${pid}.sdf";
$DUMMY=`touch $sdffile`;
debug("\$sdffile: $sdffile\\n");
// Launch jmolviewd server:
debug("Calling jmolviewd: \\n `$BIN_PATH/jmolviewd2.wwwlauncher $sdffile 2>&1` \\n");
$handle= popen("$BIN_PATH/jmolviewd2.wwwlauncher $sdffile 2>&1","r");
$IOR = fgets($handle);
pclose($handle);
debug("DONE.\\n");
debug("IOR: $IOR\\n"); // Aus irgendeinem Grund erscheint das nicht, vmtl. zu lang?
}
?>
MOLiS: Eingabe in MOLGEN
MOLGEN
Geben Sie eine Molekülformel ein (Indizes werden automatisch gesetzt):
if($reset==1) {
echo <<0 Moleküle mit dieser Summenformel (rechnet).
END;
}
?>
(c) Walter.Wagner ät uni-bayreuth.de, Universität Bayreuth; Impressum