diff --git a/bin/schedulerTask.sh b/bin/schedulerTask.sh new file mode 100755 index 0000000..a2080b4 --- /dev/null +++ b/bin/schedulerTask.sh @@ -0,0 +1,6 @@ +#!/bin/sh +cd /var/www/installers/knowledgetree/bin/ +while true; do +php -Cq scheduler.php +sleep 30 +done \ No newline at end of file diff --git a/setup/wizard/dbUtil.php b/setup/wizard/dbUtil.php index 8c11855..2977855 100644 --- a/setup/wizard/dbUtil.php +++ b/setup/wizard/dbUtil.php @@ -111,7 +111,7 @@ class dbUtil { $this->dbconnection = mysql_connect($dhost, $duname, $dpassword); if($dbname != '') { $this->setDb($dbname); - $this->useBD($dbname); + $this->useDb($dbname); } if($this->dbconnection) return $this->dbconnection; @@ -128,7 +128,7 @@ class dbUtil { * @access public * @return boolean */ - public function useBD($dbname) { + public function useDb($dbname) { if($dbname != '') { $this->setDb($dbname); } @@ -152,8 +152,7 @@ class dbUtil { * @access public * @return object The result of the query. */ - public function query($query) - { + public function query($query) { $result = mysql_query($query, $this->dbconnection); if($result) { return $result; @@ -230,10 +229,33 @@ class dbUtil { * * @param none. * @access public - * @return string. + * @return array. */ public function getErrors() { return $this->error; } + + /** + * Fetches the last generated error + + * @return string + */ + function getLastError() { + return end($this->error); + } + + /** + * Start a database transaction + */ + public function startTransaction() { + $this->query("START TRANSACTION"); + } + + /** + * Roll back a database transaction + */ + public function rollback() { + $this->query("ROLLBACK"); + } } ?> \ No newline at end of file diff --git a/setup/wizard/installUtil.php b/setup/wizard/installUtil.php index f2f62a5..9fc62b0 100644 --- a/setup/wizard/installUtil.php +++ b/setup/wizard/installUtil.php @@ -385,18 +385,13 @@ class InstallUtil { * @return mixed */ function getJava() { -// $javaSpecified = $this->javaSpecified(); -// if($javaSpecified) { -// return $javaSpecified; -// } else { - $response = $this->tryJava1(); - if(!is_array($response)) { - $response = $this->tryJava2(); - if(!is_array($response)) { - $response = $this->tryJava3(); - } - } -// } + $response = $this->tryJava1(); + if(!is_array($response)) { + $response = $this->tryJava2(); + if(!is_array($response)) { + $response = $this->tryJava3(); + } + } return $response; } diff --git a/setup/wizard/output/outJV b/setup/wizard/output/outJV new file mode 100644 index 0000000..9c8921a --- /dev/null +++ b/setup/wizard/output/outJV @@ -0,0 +1,3 @@ +java version "1.6.0_14" +Java(TM) SE Runtime Environment (build 1.6.0_14-b08) +Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing) diff --git a/setup/wizard/resources/graphics/indicator.pxm b/setup/wizard/resources/graphics/indicator.pxm deleted file mode 100644 index c8b9f87..0000000 --- a/setup/wizard/resources/graphics/indicator.pxm +++ /dev/null diff --git a/setup/wizard/shells/javaVersion.sh b/setup/wizard/shells/javaVersion.sh new file mode 100644 index 0000000..bf7922f --- /dev/null +++ b/setup/wizard/shells/javaVersion.sh @@ -0,0 +1,2 @@ +#!/bin/bash +java -version > output/outJV 2>&1 echo $! \ No newline at end of file diff --git a/setup/wizard/steps/complete.php b/setup/wizard/steps/complete.php index 3b6f9c0..99e0bb6 100644 --- a/setup/wizard/steps/complete.php +++ b/setup/wizard/steps/complete.php @@ -40,15 +40,361 @@ * @version Version 0.1 */ -class complete extends Step -{ +class complete extends Step { + + /** + * Reference to Database object + * + * @author KnowledgeTree Team + * @access private + * @var object + */ + private $_dbhandler = null; + + /** + * List of services to check + * + * @access private + * @var array + */ + private $_services = array('Lucene', 'Scheduler'); + + public function __construct() { + $this->_dbhandler = new dbUtil(); + } function configure() { $this->temp_variables = array("step_name"=>"complete"); } function doStep() { + $this->doRun(); return 'landing'; } + + function doRun() { + // check filesystem (including location of document directory and logging) + $this->checkFileSystem(); + // check database + $this->checkDb(); + // check services + $this->checkServices(); + } + + private function checkFileSystem() + { + // defaults + $this->temp_variables['varDirectory'] = ''; + $this->temp_variables['documentRoot'] = ''; + $this->temp_variables['logDirectory'] = ''; + $this->temp_variables['tmpDirectory'] = ''; + $this->temp_variables['uploadDirectory'] = ''; + $this->temp_variables['config'] = ''; + $this->temp_variables['docLocation'] = ''; + + $docRoot = ''; + + // retrieve path information from session + $config = $this->getDataFromSession("configuration"); + $paths = $config['paths']; + + $html = '
' + . '%s' + . '%s'; + + // check paths are writeable + foreach ($paths as $path) + { + $output = ''; + + $result = $this->checkPermission($path['path']); + $output = sprintf($html, $result['class'], + $path['path'], + (($result['class'] == 'tick') ? '' : 'error' ), + (($result['class'] == 'tick') ? 'Writeable' : 'Not Writeable' )); + + $this->temp_variables[($path['setting'] != '') ? $path['setting'] : 'config'] = $output; + + // for document location check + if ($path['setting'] == 'documentRoot') { + $docRoot = $path['path']; + } + } + + // check document path internal/external to web root + // compare SYSTEM_DIR to root path of documentRoot + $sysDir = preg_replace('/\\\\+|\/+/', '\/', SYSTEM_DIR); + $docRoot = preg_replace('/\\\\+|\/+/', '\/', $docRoot); + if (($pos = strpos($docRoot, $sysDir)) !== false) { + $this->temp_variables['docLocation'] = '
' + . 'Your document directory is set to the default, which is inside the web root. ' + . 'This may present a security problem if your documents can be accessed from the web, ' + . 'working around the permission system in KnowledgeTree.'; + } + else { + $this->temp_variables['docLocation'] = '
' + . 'Your document directory is outside the web root.'; + } + } + + private function checkDb() + { + // defaults + $this->temp_variables['dbConnectAdmin'] = ''; + $this->temp_variables['dbConnectUser'] = ''; + $this->temp_variables['dbPrivileges'] = ''; + $this->temp_variables['dbTransaction'] = ''; + +// $html = '
' +// . '%s' +// . '%s'; + + // retrieve database information from session + $dbconf = $this->getDataFromSession("database"); + //print_r($dbconf); + // make db connection - admin + $loaded = $this->_dbhandler->load($dbconf['dhost'], $dbconf['dmsname'], $dbconf['dmspassword'], $dbconf['dname']); + if (!$loaded) { + $this->temp_variables['dbConnectAdmin'] .= /*sprintf($html, 'cross', + $path['path'], + (($result['class'] == 'tick') ? '' : 'error' ), + (($result['class'] == 'tick') ? 'Writeable' : 'Not Writeable' ));*/ + '
' + . 'Unable to connect to database (user: ' . $dbconf['dmsname'] . ')'; + } + else + { + $this->temp_variables['dbConnectAdmin'] .= '
' + . 'Database connectivity successful (user: ' . $dbconf['dmsname'] . ')'; + } + + // make db connection - user + $loaded = $this->_dbhandler->load($dbconf['dhost'], $dbconf['dmsusername'], $dbconf['dmsuserpassword'], $dbconf['dname']); + // if we can log in to the database, check access + // TODO check write access? + if ($loaded) + { + $this->temp_variables['dbConnectUser'] .= '
' + . 'Database connectivity successful (user: ' . $dbconf['dmsusername'] . ')'; + + $qresult = $this->_dbhandler->query('SELECT COUNT(id) FROM documents'); + if (!$qresult) + { + $this->temp_variables['dbPrivileges'] .= '
' + . '' + . 'Unable to do a basic database query
Error: ' . $this->_dbhandler->getLastError() + . ''; + } + else + { + $this->temp_variables['dbPrivileges'] .= '
Basic database query successful'; + } + + // check transaction support + $sTable = 'system_settings'; + $this->_dbhandler->startTransaction(); + $this->_dbhandler->query('INSERT INTO ' . $sTable . ' (name, value) VALUES ("transactionTest", "1")'); + $this->_dbhandler->rollback(); + $res = $this->_dbhandler->query("SELECT id FROM $sTable WHERE name = 'transactionTest' LIMIT 1"); + if (!$res) { + $this->temp_variables['dbTransaction'] = '
' + . 'Transaction support not available in database'; + } else { + $this->temp_variables['dbTransaction'] = '
Database has transaction support'; + } + $this->_dbhandler->query('DELETE FROM ' . $sTable . ' WHERE name = "transactionTest"'); + } + else + { + $this->temp_variables['dbConnectUser'] .= '
' + . 'Unable to connect to database (user: ' . $dbconf['dmsusername'] . ')'; + } + } + + private function checkServices() + { + // defaults + $this->temp_variables['luceneServiceStatus'] = ''; + $this->temp_variables['schedulerServiceStatus'] = ''; + + return null; + + $processOrder = array(); + if (strtolower(OS) == 'windows') + { + $processOrder[] = 'Start'; + $processOrder[] = 'Stop'; + } + else if (strtolower(OS) == 'unix') + { + $processOrder[] = 'Stop'; + $processOrder[] = 'Start'; + } + + // loop through services and attempt to stop and then start them (in the case of Linux,) or start and stop them (in the case of Windows) + // (Linux service is started after install, Windows is not) + foreach ($this->_services as $serviceName) + { + // check installed + $statusCheck = OS."ServiceInstalled"; + $className = OS.$serviceName; + $service = new $className(); + $installed = $this->$statusCheck($service); + if ($installed) { + + } + else { + + } + + // check start/stop - different orders dependant on system + foreach($processOrder as $operation) + { +// $opExec = 'service' . $operation; +// $opSuccess = $this->$opExec(); +// if ($opSuccess) { +// +// } +// else { +// +// } + } + } + } + + // these next function are dupes of ones in steps/service.php and steps/configuration.php - abstract these to another class (parent or helper) + // and remove from here and original classes + + /** + * Check whether a given directory / file path exists and is writable + * + * @author KnowledgeTree Team + * @access private + * @param string $dir The directory / file to check + * @param boolean $create Whether to create the directory if it doesn't exist + * @return array The message and css class to use + */ + private function checkPermission($dir, $create=false) + { + $exist = 'Directory does not exist'; + $write = 'Directory is not writable'; + $ret = array('class' => 'cross'); + + if(!file_exists($dir)){ + if($create === false){ + $this->done = false; + $ret['msg'] = $exist; + return $ret; + } + $par_dir = dirname($dir); + if(!file_exists($par_dir)){ + $this->done = false; + $ret['msg'] = $exist; + return $ret; + } + if(!is_writable($par_dir)){ + $this->done = false; + $ret['msg'] = $exist; + return $ret; + } + mkdir($dir, '0755'); + } + + if(is_writable($dir)){ + $ret['class'] = 'tick'; + return $ret; + } + + $this->done = false; + $ret['msg'] = $write; + return $ret; + } + + /** + * Check if windows service installed + * + * @author KnowledgeTree Team + * @param object + * @access public + * @return boolean + */ + public function windowsServiceInstalled($service) { +// print_r($service, true)."
"; + $status = $service->status(); // Check if service has been installed + echo "STAT: ".$status."
"; + if($status != 'STOPPED') { // Check service status + $this->error[] = $service->getName()." Could not be added as a WINDOWS Service"; + return false; + } + return true; + } + + /** + * Check if unix service installed + * + * @author KnowledgeTree Team + * @param object + * @access public + * @return boolean + */ + public function unixServiceInstalled($service) { + $status = $service->status(); // Check if service has been installed + if($status != 'STARTED') { // Check service status + $this->error[] = $service->getName()." Could not be added as a UNIX Service"; + return false; + } + return true; + } + + /** + * Starts all services + * + * @author KnowledgeTree Team + * @param object + * @access public + * @return mixed + */ + public function installStep() { + foreach ($this->services as $serviceName) { + $className = OS.$serviceName; + $service = new $className(); + $status = $this->serviceStart($service); + + } + + return true; + } + + /** + * Starts service + * + * @author KnowledgeTree Team + * @param object + * @access private + * @return string + */ + private function serviceStart($service) { + if(OS == 'windows') { + $service->load(); // Load Defaults + $service->start(); // Start Service + return $service->status(); // Get service status + } + } + /** + * Stops service + * + * @author KnowledgeTree Team + * @param object + * @access private + * @return string + */ + private function serviceStop($service) { + if(OS == 'windows') { + $service->load(); // Load Defaults + $service->stop(); // Stop Service + return $service->status(); // Get service status + } + } + } ?> \ No newline at end of file diff --git a/setup/wizard/steps/database.php b/setup/wizard/steps/database.php index 9f74c50..d73bb68 100644 --- a/setup/wizard/steps/database.php +++ b/setup/wizard/steps/database.php @@ -635,7 +635,7 @@ class database extends Step * @return boolean */ private function usedb($con) { - if($this->_dbhandler->useBD($this->dname)) { + if($this->_dbhandler->useDb($this->dname)) { return true; } else { $this->error[] = "Error using database: "; diff --git a/setup/wizard/steps/services.php b/setup/wizard/steps/services.php index 63b306a..b9ba340 100644 --- a/setup/wizard/steps/services.php +++ b/setup/wizard/steps/services.php @@ -86,7 +86,7 @@ class services extends Step * @access private * @var mixed */ - private $java_ext_check = 'cross'; + private $java_ext_check = 'cross_orange'; /** * Service Installed @@ -129,12 +129,6 @@ class services extends Step $this->util = new InstallUtil(); } - - -// function getJavaResponse() { -// return $this->response; -// } - /** * Main control of services setup * @@ -179,81 +173,70 @@ class services extends Step $this->temp_variables['services'][] = array('class'=>'cross', 'msg'=>$serviceName." Could not be added as a Service"); } } - $this->temp_variables['java_check'] = $this->java_check; - $this->temp_variables['java_ext_check'] = $this->java_ext_check; - $this->temp_variables['service_check'] = $this->service_check; + $this->storeSilent(); + $errors = $this->getErrors(); if(!empty($errors)) return false; return true; } - - private function detSettings() { -// $cmd = $this->java." -version > output/outJV 2>&1 echo $!"; -// echo $cmd; -// die('bb'); -// $response = $this->util->pexec(SHELL_DIR."javaVersion.sh"); -// if(file_exists(OUTPUT_DIR.'outJV')) { -// $tmp = file_get_contents(OUTPUT_DIR.'outJV'); -// echo $tmp; -// preg_match('/"(.*)"/',$tmp, $matches); -// var_dump($matches); -// $fp-> -// echo 'a'; -// } -// var_dump($response); -// die('aa'); -// var_dump($this->util->pexec($this->java."")); -// var_dump($this->util->pexec($this->java." -version")); - } public function javaChecks() { - $this->temp_variables['extensions']['class'] = 'cross'; - $this->temp_variables['extensions']['found'] = "Zend Java Bridge Required"; - $this->temp_variables['version']['class'] = 'cross'; - $this->temp_variables['version']['found'] = "Java Runtime Version Incorrect"; - $this->temp_variables['java']['class'] = 'cross'; - $this->temp_variables['java']['found'] = "Java runtime environment required"; + $this->zendBridgeNotInstalled(); + $this->javaVersionInCorrect(); // Set version to incorrect + $this->javaNotInstalled(); // Set java to not installed if($this->util->javaSpecified()) { - $this->detSettings(); + $this->detSettings(); // AutoDetect java settings } else { - $this->useBridge(); + $this->useBridge(); // Use Bridge to get java settings } } - function useBridge() { + private function detSettings() { + $javaExecutable = $this->util->javaSpecified();// Retrieve java bin + $cmd = "$javaExecutable -version > output/outJV 2>&1 echo $!"; + $response = $this->util->pexec($cmd); + if(file_exists(OUTPUT_DIR.'outJV')) { + $tmp = file_get_contents(OUTPUT_DIR.'outJV'); + preg_match('/"(.*)"/',$tmp, $matches); + if($matches[1] < $this->javaVersion) { // Check Version of java + $this->javaVersionInCorrect(); + $this->error[] = "Requires Java 1.5+ to be installed"; + } else { + $this->javaVersionCorrect(); + $this->javaInstalled(); + $this->java_check = 'tick'; + } + } + } + + private function useBridge() { $zendBridge = $this->zendBridge(); // Find Zend Bridge if($zendBridge) { - $this->temp_variables['extensions']['class'] = 'tick'; - $this->temp_variables['extensions']['found'] = "Java Bridge Installed"; + $this->zendBridgeInstalled(); if($this->checkZendBridge()) { // Make sure the Zend Bridge is functional $javaSystem = new Java('java.lang.System'); $version = $javaSystem->getProperty('java.version'); $ver = substr($version, 0, 3); if($ver < $this->javaVersion) { - $this->temp_variables['version']['class'] = 'cross'; - $this->temp_variables['version']['found'] = "Requires Java 1.5+ to be installed"; + $this->javaVersionInCorrect(); $this->error[] = "Requires Java 1.5+ to be installed"; } else { - $this->temp_variables['version']['class'] = 'tick'; - $this->temp_variables['version']['found'] = "Java Version 1.5+ Installed"; + $this->javaVersionCorrect(); } } else { - $this->warnings[] = "Zend Java Bridge Error"; - $this->temp_variables['version']['class'] = 'cross_orange'; - $this->temp_variables['version']['found'] = "Java Runtime Version Cannot be detected"; - $this->temp_variables['extensions']['class'] = 'cross_orange'; - $this->temp_variables['extensions']['found'] = "Zend Java Bridge Error"; + $this->javaVersionWarning(); + $this->zendBridgeWarning(); + $this->warnings[] = "Zend Java Bridge Error"; $this->java_ext_check = 'cross_orange'; } } else { $this->warnings[] = "Zend Java Bridge Required"; } if($this->java != '') { // Find Java JRE - $this->temp_variables['java']['class'] = 'tick'; - $this->temp_variables['java']['found'] = "Java Runtime Installed"; - $this->java_check = 'tick'; + $this->javaInstalled(); + $this->java_check = 'tick'; } else { $this->error[] = "Java runtime environment required"; } @@ -436,5 +419,53 @@ class services extends Step { return $this->temp_variables; } + + /* Helpers */ + + private function javaInstalled() { + $this->temp_variables['java']['class'] = 'tick'; + $this->temp_variables['java']['found'] = "Java Runtime Installed"; + } + + private function javaNotInstalled() { + $this->temp_variables['java']['class'] = 'cross'; + $this->temp_variables['java']['found'] = "Java runtime environment required"; + } + + private function javaVersionCorrect() { + $this->temp_variables['version']['class'] = 'tick'; + $this->temp_variables['version']['found'] = "Java Version 1.5+ Installed"; + } + + private function javaVersionWarning() { + $this->temp_variables['version']['class'] = 'cross_orange'; + $this->temp_variables['version']['found'] = "Java Runtime Version Cannot be detected"; + } + + private function javaVersionInCorrect() { + $this->temp_variables['version']['class'] = 'cross'; + $this->temp_variables['version']['found'] = "Requires Java 1.5+ to be installed"; + } + + private function zendBridgeInstalled() { + $this->temp_variables['extensions']['class'] = 'tick'; + $this->temp_variables['extensions']['found'] = "Java Bridge Installed"; + } + + private function zendBridgeNotInstalled() { + $this->temp_variables['extensions']['class'] = 'cross_orange'; + $this->temp_variables['extensions']['found'] = "Zend Java Bridge Not Installed"; + } + + private function zendBridgeWarning() { + $this->temp_variables['extensions']['class'] = 'cross_orange'; + $this->temp_variables['extensions']['found'] = "Zend Java Bridge Error"; + } + + private function storeSilent() { + $this->temp_variables['java_check'] = $this->java_check; + $this->temp_variables['java_ext_check'] = $this->java_ext_check; + $this->temp_variables['service_check'] = $this->service_check; + } } ?> \ No newline at end of file diff --git a/setup/wizard/templates/complete.tpl b/setup/wizard/templates/complete.tpl index 1c3aea0..efba539 100644 --- a/setup/wizard/templates/complete.tpl +++ b/setup/wizard/templates/complete.tpl @@ -1,5 +1,11 @@

Installation Completed

+

KnowledgeTree post-configuration checkup

+ +

This allows you to check that your KnowledgeTree configuration is set +up correctly. You can run this at any time after configuration to check +that things are still set up correctly.

+
$e) { @@ -8,9 +14,49 @@ }?>
+
+

Paths and Permissions

+ + + + + + + + +
+
+
+
+

Database connectivity

+ + + +
+

Privileges

+ + + +
+
+
+
+

Services

+ + + +
+
+
+ Refresh Goto Login + Zend Server Configuration'; + } + ?>
\ No newline at end of file