#!/usr/bin/php
<?php
if (!extension_loaded('java')) {
  if ((version_compare("5.0.0", phpversion(), "<=")) && (version_compare("5.0.4", phpversion(), ">"))) {
    echo "This PHP version does not support dl().\n";
    echo "Please add an extension=java.so or extension=php_java.dll entry to your php.ini file.\n";
    exit(1);
  }

  echo "Please permanently activate the extension. Loading java extension now...\n";
  if (!@dl('java.so')&&!@dl('php_java.dll')) {
    echo "Error: Either the java extension is not installed \n";
    echo "or it was compiled against an older or newer php version.\n";
    echo "See the HTTP (IIS or Apache) server log for details.\n";
    !dl('java.so')&&!dl('php_java.dll');
    exit(2);
  }
 }
if(@java_get_server_name() != null) {

  try {
    phpinfo();
    print "\n\n";
    
    $v = new JavaClass("java.lang.System");
    $arr=java_values($v->getProperties());
    foreach ($arr as $key => $value) {
      print $key . " -> " .  $value . "<br>\n";
    }
  } catch (JavaException $ex) {
    $trace = new Java("java.io.ByteArrayOutputStream");
    $ex->printStackTrace(new java("java.io.PrintStream", $trace));
    echo "Exception $ex occured:<br>\n" . $trace . "<br>\n";
  }
  echo "<br>\n";
  $Util = new JavaClass("php.java.bridge.Util");
  echo "JavaBridge back-end version: {$Util->VERSION}<br>\n";
  echo "<br>\n";

 } else {

  phpinfo();
  print "\n\n";

  /* java_get_server_name() == null means that the back-end is not
   running */

  $ext_name="java.so";
  if(PHP_SHLIB_SUFFIX != "so") $ext_name="php_java.dll";

  if(isset($_SERVER['HTTPS'])) {
    echo "Error: Could not connect to " . ini_get("java.hosts") ."<br>\n";
    echo "Please add the following entry marked with a + to your<br>\n";
    echo "conf/server.xml (example for Tomcat):<br>\n";
    echo "  &lt;Service name=\"Catalina\"&gt;<br>\n";
    echo "  [...]<br>\n";
    echo "+  &lt;Connector port=\"9157\" address=\"127.0.0.1\"  /&gt;<br>\n";
    echo "  [...]<br>\n";
    echo " &lt;/Service&gt;<br>\n";
  } else {
    echo "Error: The PHP/Java Bridge back-end is not running.<br>\n";
    echo "<br>\n";
    echo "Please start it and/or check if the directory<br>\n";
    echo "<br>\n\t".ini_get("extension_dir")."<br>\n<br>\n";
    echo "contains \"$ext_name\" and \"JavaBridge.jar\".<br>\n";
    echo "<br>\n";
    echo "Check if the following values are correct:<br>\n<br>\n";
    echo "\tjava.java_home = ".ini_get("java.java_home")."<br>\n";
    echo "\tjava.java = ".ini_get("java.java")."<br>\n<br>\n";
    echo "If you want to start the back-end automatically, disable:<br>\n<br>\n";
    echo "\tjava.socketname = ".ini_get("java.socketname")."<br>\n";
    echo "\tjava.hosts = ".ini_get("java.hosts")."<br>\n";
    echo "\tjava.servlet = ".ini_get("java.servlet")."<br>\n";
    echo "<br>\n";
    echo "If that still doesn't work, please check the \"java command\" above and<br>\n";
    echo "report this problem to:<br>\n<br>\n";
    echo "\tphp-java-bridge-users@lists.sourceforge.net.<br>\n";
  }
 }
?>
