greening install

測試安裝是否成功

執行結果:test.html

# 建立test.php
vim /var/www/html/auth.xxxx.org/test.php

將下列語法貼上。用瀏覽器執行該網頁,若每個項目都有值,表示安裝成功。

<?php
$CONFIG = [
"AUTH_SITE_ROOT" => "/var/www/html/xxx/auth.xxx.com.tw/" ,
"HTTPD_CONF"=>"/etc/httpd/conf/httpd.conf",
"PG_INIT"=>"/etc/init.d/postgresql-9.4",
"MAIL_TARGET"=>"[email protected]",
];

require($CONFIG["AUTH_SITE_ROOT"]."inc/class.DB.php");
require($CONFIG["AUTH_SITE_ROOT"]."inc/class.Constant.php");
class output {
  static function table_start(){
    echo "<table>";
  }
  static function table_end(){
    echo "</table>";
  }
  static function cmd($opt){
    //          0   1       2
    //$opt = [title,$cmd="",$msg=""]
    if ( !is_array($opt) )
      $opt = [$opt];
    if ( empty($opt[1]) )
      $cmd = $opt[0];
    exec($cmd,$output,$return_var);
    echo "<tr><td>".$opt[0]."</td>
              <td>".$return_var."</td>
              <td><pre>".(empty($output) ? "" : print_r($output,1))."</pre></td>
              <td>".$opt[2]."</td>
          </tr>";
  }
  static function tr($opt){
    //0     1         2
    //$item,$item2="",$item3=""
    if ( is_array($opt[1]) )
      $opt[1] = print_r($opt[1],1);
    if ( !is_array($opt) )
      $opt = [$opt];
    switch (max(array_keys($opt))) {
      case 0:
          echo "<tr><td style='background-color: lightgray;' colspan='4'>".$opt[0]."</td></tr>";
          break;
      case 1:
          echo "<tr><td>".$opt[0]."</td><td colspan='2'>".$opt[1]."</td></tr>";
          break;
      //case 2 :
      default:
          echo "<tr><td>".$opt[0]."</td><td colspan='2'>".$opt[1]."</td><td>".$opt[2]."</td></tr>";
          break;
    }
  }
}
function test_php(){
  output::tr("Testing php...");
  output::cmd("which php");
  output::cmd("which pear");
  output::cmd("pear list | grep Mail");
  output::cmd("pear list | grep Net_SMTP");
}
function test_httpd(){
  output::tr("Testing httpd...");
  output::cmd("rpm -qa | grep 'httpd\(24\)\{0,1\}'");
  output::cmd("netstat -ndlp | grep httpd");
  output::tr("Testing mod_ssl...");
  output::cmd("rpm -qa | grep 'mod\(24\)\{0,1\}_ssl'");
  output::cmd("grep ^DirectoryIndex /etc/httpd/conf/httpd.conf");
}
function test_postgres(){
  global $CONFIG;
  output::tr("Testing postgresql...");
  output::tr(["說明:",
  "<ol>
     <li>目前只撰寫了centos 6.5部分</li>
  </ol>"]);
  output::cmd("grep ^PGPREVMAJORVERSION ".$CONFIG["PG_INIT"]);
  $pgdata = shell_exec("grep ^PGDATA ".$CONFIG["PG_INIT"]." | awk -F = '{print $2}'");
  output::tr(["PGDATA",$pgdata]);
  output::cmd($CONFIG["PG_INIT"]." status");
  output::cmd("netstat -ndlp | grep postmaster");
  output::cmd("grep ^listen_addresses $pgdata/postgresql.conf");
  output::cmd("grep 127.0.0.1 $pgdata/pg_hba.conf");

  output::cmd("rpm -qa | grep 'postgresql' | grep 'contrib'");
  output::cmd("su - postgres -c \"/usr/bin/psql -c '\c grenning' -c '\dx'\" | grep adminpack");
  output::cmd("su - postgres -c \"/usr/bin/psql -c '\c grenning' -c '\dx'\" | grep plpgsql");
  output::cmd("su - postgres -c \"/usr/bin/psql -c '\c grenning' -c '\dx'\" | grep uuid-ossp");
  output::cmd("su - postgres -c \"/usr/bin/psql -c '\c grenning' -c '\df'\" | grep uuid_generate_v1");
  output::cmd("su - postgres -c \"/usr/bin/psql -c '\c grenning' -c '\df'\" | grep uuid_generate_v1mc");
  output::cmd("su - postgres -c \"/usr/bin/psql -c '\c grenning' -c '\df'\" | grep uuid_generate_v3");
  output::cmd("su - postgres -c \"/usr/bin/psql -c '\c grenning' -c '\df'\" | grep uuid_generate_v4");
  output::cmd("su - postgres -c \"/usr/bin/psql -c '\c grenning' -c '\df'\" | grep uuid_generate_v5");
}

function test_auth(){
  test_db_connect();
  test_mail();
  output::tr("Testing oauth g+,fb,....");
  output::tr(["說明:",
    "<ol>
       <li>打開web</li>
       <li>點擊左方G+測試是否正常</li>
       <li>點擊左方FB測試是否正常</li>
       <li>點擊左方Microsoft測試是否正常</li>
       <li>點擊左方Yahoo測試是否正常</li>
    </ol>"]);
}
function test_db_connect(){
  output::tr("Testing db connect");
  $pdo = GetPDO();
  $sql = 'select * from user';
  $stmt = $pdo->prepare($sql);
  $stmt->execute();
  $result = $stmt->fetch(PDO::FETCH_ASSOC);
  output::tr(["select * from user",$result]);
}
function test_mail(){
  global $CONFIG;
  output::tr("Testing mailing...");
  output::tr(["說明:",
    "<ol>
       <li>打開web</li>
       <li>建立一帳號與MAIL_TARGET相同</li>
    </ol>"]);
  session_start();
  session_id("a1b2c3d4");
  $_REQUEST['account'] = $CONFIG["MAIL_TARGET"];
  $_REQUEST['captcha'] = $_SESSION['captcha'] = $captcha = "1";
  ob_start();
  require($CONFIG["AUTH_SITE_ROOT"]."default/sendactivatemail.php");
  $output = ob_get_clean();
  output::tr(["default/sendactivatemail.php",$output]);
  output::tr(["print_r([\$username,\$password]);",print_r([$username,$password],1)]);
  ob_start();
  require($CONFIG["AUTH_SITE_ROOT"]."default/sendpwdresetMail.php");
  $output = ob_get_clean();
  output::tr(["default/sendpwdresetMail.php",$output]);
  output::tr(["print_r([\$username,\$password]);",print_r([$username,$password],1)]);
}

output::table_start();
output::tr(["說明:",
  "<ol>
     <li>若無特殊文字,此欄有值即為正常</li>
     <li>可於bash執行<pre>php test.php</pre>或<pre>php test.php > test.html</pre>測試權限部分</li>
  </ol>"]);
foreach($CONFIG as $key => $value)
{
  output::tr([$key,$value]);
}
test_php();
test_httpd();
test_postgres();
test_auth();
output::table_end();
?>