00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 require_once("./config.php");
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 function set_header()
00028 {
00029 global $app_name, $app_dir;
00030
00031 echo "<html>";
00032
00033 echo "<head>";
00034 echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">";
00035 echo "<meta name=\"DESCRIPTION\" content=\"a web interface to run TINKER molecular modelling on the EGEE grid\">";
00036 echo "<meta name=\"AUTHOR\" content=\"EMBnet/CNB\">";
00037 echo "<meta name=\"COPYRIGHT\" content=\"(c) 2004-5 by CSIC - Open Source Software\">";
00038 echo "<meta name=\"GENERATOR\" content=\"$app_name\">";
00039 echo "<link rel=\"StyleSheet\" href=\"$app_dir/style/style.css\" type=\"text/css\"/>";
00040 echo "<link rel=\"shortcut icon\" href=\"$app_dir/images/favicon.ico\"/>";
00041 echo "<title=\"$app_name\">";
00042 echo "</head>";
00043
00044 echo "<body bgcolor=\"white\" background=\"$app_dir/images/6h2o-w-small.gif\" link=\"ffc600\" VLINK=\"#cc9900\" ALINK=\"#4682b4\">";
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054 function set_footer()
00055 {
00056 global $maintainer, $app_dir;
00057
00058 echo "</body><hr>";
00059
00060 echo "<center><table border=\"0\" width=\"90%\"><tr>";
00061
00062 echo "<td><A HREF=\"$app_dir/c/copyright.html\">©</a>EMBnet/CNB</td>";
00063
00064 echo "<td align=\"RIGHT\"><A HREF=\"emailto:$maintainer\">$maintainer</a></td>";
00065 echo "</tr></table></center>";
00066
00067 echo "</html>";
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 function warning($msg)
00082 {
00083 echo "<script language=\"JavaScript\">";
00084 echo "alert(\"WARNING:\n $msg\");";
00085 echo "</script>";
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 function error($where, $what)
00105 {
00106
00107 echo "<p></p><center><table border=\"2\">\n";
00108 echo "<tr><td><center><font color=\"red\"><strong>\n";
00109
00110
00111 echo "ERROR - HORROR\n";
00112
00113
00114 echo "</strong></font></center></td></tr>\n";
00115 echo "<tr><td><center><b>$where</b></center></td></tr>\n";
00116 echo "<tr><td><center>$what</center></td></tr>\n";
00117 echo "</table></center><p></p>\n";
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 function letal($what, $where)
00139 {
00140 error($what, $where);
00141 set_footer();
00142 exit();
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 function ssh_passthru($remote, $password, $command, $status)
00179 {
00180 umask(0077);
00181 $tmpfname = tempnam("/tmp", "egTinker");
00182 chmod($tmpfname, 0700);
00183 $fp = fopen($tmpfname, "w");
00184 fputs($fp, "#!/bin/sh\necho $password\n");
00185 fputs($fp, "rm -f $tmpfname\n");
00186 fclose($fp);
00187 putenv("DISPLAY=none:0.");
00188 putenv("SSH_ASKPASS=$tmpfname");
00189 return passthru("ssh -x -t -t $remote $command", $status);
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 function ssh_copy($origin, $destination, $password)
00207 {
00208 umask(0077);
00209 $tmpfname = tempnam("/tmp", "egTinker");
00210 chmod($tmpfname, 0700);
00211 $fp = fopen($tmpfname, "w");
00212 fputs($fp, "#!/bin/sh\necho $password\n");
00213 fputs($fp, "rm $tmpfname\n");
00214 fclose($fp);
00215 putenv("DISPLAY=none:0.");
00216 putenv("SSH_ASKPASS=$tmpfname");
00217 system("scp -pqrC $origin $destination", $status);
00218 if ($status == 0)
00219 return TRUE;
00220 else
00221 return FALSE;
00222 }
00223
00224 function ssh_open($remote, $password)
00225 {
00226 global $php_version;
00227 global $debug;
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 if ($php_version < 5) {
00243
00244 $descriptorspec = array(
00245 0 => array("pipe", "r"),
00246 1 => array("pipe", "w"),
00247 2 => array("pipe", "w")
00248 );
00249
00250 putenv("DISPLAY=none:0.");
00251 putenv("SSH_ASKPASS=$tmpfname");
00252 umask(0077);
00253 $tmpfname = tempnam("/tmp", "egTinker");
00254 chmod($tmpfname, 0700);
00255 $fp = fopen($tmpfname, "w");
00256 fputs($fp, "#!/bin/sh\necho $password\n");
00257 fputs($fp, "rm $tmpfname\n");
00258 fclose($fp);
00259
00260 $process = proc_open("ssh -x -t -t $remote",
00261 $descriptorspec,
00262 $pipes);
00263 if ($debug) echo "ssh -x -t -t $remote<br />\n";
00264
00265 if (!is_resource($process))
00266 {
00267 letal("SSH::connect", "cannot connect to the remote host");
00268 return;
00269 }
00270 if ($debug) echo "proc_open<br />\n";
00271
00272 }
00273 else {
00274
00275 $descriptorspec = array(
00276 0 => array("pty"),
00277 1 => array("pty"),
00278 2 => array("pty")
00279 );
00280
00281 putenv("DISPLAY=none:0.");
00282 putenv("SSH_ASKPASS=$tmpfname");
00283 umask(0077);
00284 $tmpfname = tempnam("/tmp", "egTinker");
00285 chmod($tmpfname, 0700);
00286 $fp = fopen($tmpfname, "w");
00287 fputs($fp, "#!/bin/sh\necho $password\n");
00288 fputs($fp, "rm $tmpfname\n");
00289 fclose($fp);
00290
00291 $process = proc_open("ssh -x -t -t $remote",
00292 $descriptorspec,
00293 $pipes);
00294
00295
00296 if (!is_resource($process))
00297 {
00298 letal("SSH::connect", "cannot connect to the remote host");
00299 return;
00300 }
00301
00302 $status = proc_get_status($process);
00303 if ($status->running == FALSE) {
00304 fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]);
00305 proc_close($process);
00306 letal("SSH::connect", "connection exited ".$status->exitcode);
00307 return;
00308 }
00309 if ($status->signaled) {
00310 fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]);
00311 proc_close($process);
00312 letal("SSH::connect", "connection terminated by ".$status->termsig);
00313 return;
00314 }
00315 if ($status->stopped) {
00316
00317 warning("SSH::connect stopped by ".$status->stopsig.
00318 " it may still have a chance though");
00319 }
00320
00321 }
00322
00323
00324
00325
00326
00327
00328
00329 return array('stdin' => $pipes[0],
00330 'stdout' => $pipes[1],
00331 'stderr' => $pipes[2] );
00332 }
00333
00334 ?>