diff --git a/dmsctl.bat b/dmsctl.bat
index 8159e73..01b49fa 100644
--- a/dmsctl.bat
+++ b/dmsctl.bat
@@ -6,6 +6,7 @@ rem KnowledgeTree Control Script
rem ============= SET ENVIRONMENT VARIABLES ==============
set INSTALL_PATH=%CD%
cd ..
+cd ..
set ZEND_PATH=%CD%
cd %INSTALL_PATH%
set JAVA_BIN=%ZEND_PATH%\jre\bin\java.exe
@@ -82,4 +83,4 @@ echo The Scheduler automatic service was successfully installed
IF EXIST "%INSTALL_PATH%\var\bin\luceneinstall.bat" call "%INSTALL_PATH%\var\bin\luceneinstall.bat"
goto end
-:end
\ No newline at end of file
+:end
diff --git a/setup/wizard/installUtil.php b/setup/wizard/installUtil.php
index 3f8a399..dbe57fe 100644
--- a/setup/wizard/installUtil.php
+++ b/setup/wizard/installUtil.php
@@ -47,7 +47,7 @@ class InstallUtil {
private $salt = 'installers';
public $dbUtilities = null;
public $iniUtilities = null;
-
+
/**
* Constructs installation object
*
@@ -83,9 +83,9 @@ class InstallUtil {
include($file);
$contents = ob_get_contents();
ob_end_clean();
- echo $contents;
+ echo $contents;
}
-
+
return false;
}
@@ -460,7 +460,7 @@ class InstallUtil {
return preg_replace('/java:/', '', $r);
}
}
-
+
return '';
}
@@ -530,10 +530,10 @@ class InstallUtil {
return true;
}
}
-
+
return false;
}
-
+
/**
* Check if system needs to be migrated
*
@@ -548,10 +548,10 @@ class InstallUtil {
return true;
}
}
-
+
return false;
}
-
+
/**
* Check if system needs to be migrated
*
@@ -566,10 +566,10 @@ class InstallUtil {
return true;
}
}
-
+
return false;
}
-
+
/**
* Check if system needs to be migrated
*
@@ -584,10 +584,10 @@ class InstallUtil {
return true;
}
}
-
+
return false;
}
-
+
/**
* Get session data from package
*
@@ -600,10 +600,10 @@ class InstallUtil {
if(empty($_SESSION[$package][$class])) {
return false;
}
-
+
return $_SESSION[$package][$class];
}
-
+
/**
* Get session data from post
*
@@ -688,7 +688,7 @@ class InstallUtil {
/**
* Deletes migration lock file if a clean install is chosen
* This is in case someone changes their mind after choosing upgrade/migrate and clicks back up to this step
- *
+ *
* @author KnowledgeTree Team
* @access public
* @return void
@@ -710,10 +710,10 @@ class InstallUtil {
return true;
return false;
}
-
+
/**
* Determine type of installation
- *
+ *
* @author KnowledgeTree Team
* @access public
* @return string
@@ -732,10 +732,10 @@ class InstallUtil {
}
}
}
-
+
/**
* Determine if zend php exists
- *
+ *
* @author KnowledgeTree Team
* @access public
* @return string
@@ -746,6 +746,7 @@ class InstallUtil {
$sysdir = explode(DS, SYSTEM_DIR);
array_pop($sysdir);
array_pop($sysdir);
+ array_pop($sysdir);
$zendsys = '';
foreach ($sysdir as $v) {
$zendsys .= $v.DS;
@@ -757,13 +758,58 @@ class InstallUtil {
return DS."usr".DS."local".DS."zend".DS."bin".DS;
}
}
-
+
return false;
}
-
+
+ public function useZendJVM() {
+ if($this->util->installEnvironment() == 'Zend') {
+ if(WINDOWS_OS) { // For Zend Installation only
+ $sysdir = explode(DS, SYSTEM_DIR);
+ array_pop($sysdir);
+ array_pop($sysdir);
+ array_pop($sysdir);
+ $zendsys = '';
+ foreach ($sysdir as $v) {
+ $zendsys .= $v.DS;
+ }
+ $jvm = $zendsys."jre".DS."bin".DS."client".DS."jvm.dll";
+ if(file_exists($jvm))
+ return $jvm;
+ }
+ }
+
+ return false;
+ }
+
+ public function useZendJava() {
+ if($this->installEnvironment() == 'Zend') {
+ if(WINDOWS_OS) { // For Zend Installation only
+ $sysdir = explode(DS, SYSTEM_DIR);
+ array_pop($sysdir);
+ array_pop($sysdir);
+ array_pop($sysdir);
+ $zendsys = '';
+ foreach ($sysdir as $v) {
+ $zendsys .= $v.DS;
+ }
+ $jvm = $zendsys."jre".DS."bin".DS."client".DS."jvm.dll";
+ if(file_exists($jvm))
+ return $jvm;
+ } else {
+ $java = "/usr/bin/java";
+ if(file_exists($java)) {
+ return $java;
+ }
+ }
+ }
+
+ return false;
+ }
+
/**
* Determine if mysql exists
- *
+ *
* @author KnowledgeTree Team
* @access public
* @return string
@@ -780,14 +826,14 @@ class InstallUtil {
}
}
}
-
+
return "mysql"; // Assume its linux and can be executed from command line
}
public function sqlInstallDir() {
return SYSTEM_DIR."sql".DS."mysql".DS."install".DS;
}
-
+
public function getFileByLine($file) {
$fileLines = array();
$file_handle = fopen($file, "rb");
@@ -799,7 +845,7 @@ class InstallUtil {
fclose($file_handle);
return $fileLines;
}
-
+
/**
* Portably execute a command on any of the supported platforms.
*
@@ -893,5 +939,8 @@ class InstallUtil {
return join(" ", $aSafeArgs);
}
+ /*
+ Just Because.
+ */
}
?>
diff --git a/setup/wizard/lib/services/windowsLucene.php b/setup/wizard/lib/services/windowsLucene.php
index 10ecbe6..dab8003 100644
--- a/setup/wizard/lib/services/windowsLucene.php
+++ b/setup/wizard/lib/services/windowsLucene.php
@@ -45,19 +45,19 @@ class windowsLucene extends windowsService {
*
* @author KnowledgeTree Team
* @access private
- * @var string
+ * @var string
*/
private $javaBin;
-
+
/**
* Java JVM path
*
* @author KnowledgeTree Team
* @access private
- * @var string
+ * @var string
*/
private $javaJVM;
-
+
/**
* Java System object
*
@@ -66,61 +66,61 @@ class windowsLucene extends windowsService {
* @var object
*/
private $javaSystem;
-
+
/**
* Lucene executable path
*
* @author KnowledgeTree Team
* @access private
- * @var string
+ * @var string
*/
private $luceneExe;
-
+
/**
* Lucene jar path
*
* @author KnowledgeTree Team
* @access private
- * @var string
+ * @var string
*/
private $luceneSource;
-
+
/**
* Lucene package name
*
* @author KnowledgeTree Team
* @access private
- * @var string
+ * @var string
*/
private $luceneServer;
-
+
/**
* Lucene output log path
*
* @author KnowledgeTree Team
* @access private
- * @var string
+ * @var string
*/
private $luceneOut;
-
+
/**
* Lucene error log path
*
* @author KnowledgeTree Team
* @access private
- * @var string
+ * @var string
*/
private $luceneError;
-
+
/**
* Lucene directory path
*
* @author KnowledgeTree Team
* @access private
- * @var string
+ * @var string
*/
private $luceneDir;
-
+
/**
* Service name
@@ -129,9 +129,9 @@ class windowsLucene extends windowsService {
* @access public
* @param none
* @return string
- */
+ */
public $name = "KTLucene";
-
+
/**
* Load defaults needed by service
*
@@ -150,7 +150,7 @@ class windowsLucene extends windowsService {
$this->setLuceneOut("lucene-out.txt");
$this->setLuceneError("lucene-err.txt");
}
-
+
/**
* Set Java Directory path
*
@@ -164,7 +164,7 @@ class windowsLucene extends windowsService {
if($this->util->javaBridge()) {
$this->javaSystem = new Java('java.lang.System');
$this->javaBin = $this->javaSystem->getProperty('java.home').DS."bin";
-
+
return true;
}
}
@@ -173,7 +173,7 @@ class windowsLucene extends windowsService {
$this->javaBin = file_get_contents($this->varDir.'outJVHome');
if($this->javaBin != '') return true;
}
-
+
return false;
}
@@ -188,7 +188,7 @@ class windowsLucene extends windowsService {
public function getJavaBin() {
return $this->javaBin;
}
-
+
/**
* Set Lucene directory path
*
@@ -200,7 +200,7 @@ class windowsLucene extends windowsService {
private function setLuceneDIR($luceneDir) {
$this->luceneDir = $luceneDir;
}
-
+
/**
* Get Lucene directory path
*
@@ -226,7 +226,7 @@ class windowsLucene extends windowsService {
private function setLuceneExe($luceneExe) {
$this->luceneExe = $this->getluceneDir().DS.$luceneExe;
}
-
+
/**
* Get Lucene executable path
*
@@ -240,7 +240,7 @@ class windowsLucene extends windowsService {
return $this->luceneExe;
return false;
}
-
+
/**
* Set Lucene source path
*
@@ -252,7 +252,7 @@ class windowsLucene extends windowsService {
private function setLuceneSource($luceneSource) {
$this->luceneSource = $this->getluceneDir().DS.$luceneSource;
}
-
+
/**
* Get Lucene source path
*
@@ -266,7 +266,7 @@ class windowsLucene extends windowsService {
return $this->luceneSource;
return false;
}
-
+
/**
* Set Lucene package name
*
@@ -278,7 +278,7 @@ class windowsLucene extends windowsService {
private function setLuceneServer($luceneServer) {
$this->luceneServer = $luceneServer;
}
-
+
/**
* Get Lucene package name
*
@@ -290,7 +290,7 @@ class windowsLucene extends windowsService {
public function getLuceneServer() {
return $this->luceneServer;
}
-
+
/**
* Set Lucene output file path
*
@@ -302,7 +302,7 @@ class windowsLucene extends windowsService {
private function setLuceneOut($luceneOut) {
$this->luceneOut = $this->outputDir.$luceneOut;
}
-
+
/**
* Get Lucene output file path
*
@@ -314,7 +314,7 @@ class windowsLucene extends windowsService {
public function getLuceneOut() {
return $this->luceneOut;
}
-
+
/**
* Set Lucene error file path
*
@@ -326,7 +326,7 @@ class windowsLucene extends windowsService {
private function setLuceneError($luceneError) {
$this->luceneError = $this->outputDir.$luceneError;
}
-
+
/**
* Get Lucene error file path
*
@@ -338,7 +338,7 @@ class windowsLucene extends windowsService {
public function getLuceneError() {
return $this->luceneError;
}
-
+
/**
* Set Java JVM path
*
@@ -357,32 +357,13 @@ class windowsLucene extends windowsService {
} elseif (file_exists($this->getJavaBin().DS."bin".DS."server".DS."jvm.dll")) {
$this->javaJVM = $this->getJavaBin().DS."bin".DS."server".DS."jvm.dll";
} else {
- $javaJVM = $this->useZendJVM();
+ $javaJVM = $this->util->useZendJVM();
if(file_exists($javaJVM)) {
$this->javaJVM = $javaJVM;
}
}
}
-
- public function useZendJVM() {
- if($this->util->installEnvironment() == 'Zend') {
- if(WINDOWS_OS) { // For Zend Installation only
- $sysdir = explode(DS, SYSTEM_DIR);
- array_pop($sysdir);
- array_pop($sysdir);
- $zendsys = '';
- foreach ($sysdir as $v) {
- $zendsys .= $v.DS;
- }
- $jvm = $zendsys."jre".DS."bin".DS."client".DS."jvm.dll";
- if(file_exists($jvm))
- return $jvm;
- }
- }
-
- return false;
- }
-
+
/**
* Get Java JVM path
*
@@ -394,7 +375,7 @@ class windowsLucene extends windowsService {
public function getJavaJVM() {
return $this->javaJVM;
}
-
+
private function writeLuceneInstall($cmd) {
$luceneInstallFile = SYS_VAR_DIR."bin".DS."luceneinstall.bat";
$fp = fopen($luceneInstallFile, "w+");
@@ -428,10 +409,10 @@ class windowsLucene extends windowsService {
}
return $state;
}
-
+
return $state;
}
-
+
/**
* Start Service
*
@@ -459,7 +440,7 @@ class windowsLucene extends windowsService {
$state = preg_replace('/^STATE *\: *\d */', '', trim($response['out'][3])); // Status store in third key
return $state;
}
-
+
return '';
}
}
diff --git a/setup/wizard/lib/validation/luceneValidation.php b/setup/wizard/lib/validation/luceneValidation.php
index 89dd3a3..9c1c79b 100644
--- a/setup/wizard/lib/validation/luceneValidation.php
+++ b/setup/wizard/lib/validation/luceneValidation.php
@@ -49,7 +49,7 @@ class luceneValidation extends serviceValidation {
* @var string
*/
private $java = "";
-
+
/**
* Minumum Java Version
*
@@ -67,7 +67,7 @@ class luceneValidation extends serviceValidation {
* @var mixed
*/
private $providedJava = false;
-
+
/**
* Flag, if java is specified and an error has been encountered
*
@@ -76,7 +76,7 @@ class luceneValidation extends serviceValidation {
* @var booelean
*/
private $javaExeError = false;
-
+
/**
* Holds path error, if java is specified
*
@@ -85,16 +85,16 @@ class luceneValidation extends serviceValidation {
* @var string
*/
private $javaExeMessage = '';
-
+
/**
- * Java Installed
+ * Java Installed
*
* @author KnowledgeTree Team
* @access private
* @var mixed
*/
private $javaCheck = 'cross';
-
+
/**
* Flag if bridge extension needs to be disabled
*
@@ -105,14 +105,14 @@ class luceneValidation extends serviceValidation {
private $disableExtension = false;
/**
- * Java Bridge Installed
+ * Java Bridge Installed
*
* @author KnowledgeTree Team
* @access private
* @var mixed
*/
private $javaExtCheck = 'cross_orange';
-
+
public function preset() {
/* Rely on Script */
$this->zendBridgeInstalled();
@@ -124,7 +124,7 @@ class luceneValidation extends serviceValidation {
// $this->javaNotInstalled(); // Set java to not installed
// $this->setJava(); // Check if java has been auto detected
}
-
+
/**
* Check if java executable was found
*
@@ -140,7 +140,7 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['java']['location'] = $this->java;
return ;
}
-
+
$this->temp_variables['java']['location'] = $this->java;
}
@@ -156,7 +156,7 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['java']['class'] = 'tick';
$this->temp_variables['java']['found'] = "Java Runtime Installed";
}
-
+
/**
* Store Java state as not installed
*
@@ -169,7 +169,7 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['java']['class'] = 'cross';
$this->temp_variables['java']['found'] = "Java runtime environment required";
}
-
+
/**
* Store Java version state as correct
*
@@ -182,7 +182,7 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['version']['class'] = 'tick';
$this->temp_variables['version']['found'] = "Java Version 1.5+ Installed";
}
-
+
/**
* Store Java version state as warning
* @author KnowledgeTree Team
@@ -194,7 +194,7 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['version']['class'] = 'cross_orange';
$this->temp_variables['version']['found'] = "Java Runtime Version Cannot be detected";
}
-
+
/**
* Store Java version as state incorrect
*
@@ -207,7 +207,7 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['version']['class'] = 'cross';
$this->temp_variables['version']['found'] = "Requires Java 1.5+ to be installed";
}
-
+
/**
* Store Zend Bridge state as installed
*
@@ -220,10 +220,10 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['extensions']['class'] = 'tick';
$this->temp_variables['extensions']['found'] = "Java Bridge Installed";
}
-
+
/**
* Store Zend Bridge state as not installed
- *
+ *
* @author KnowledgeTree Team
* @param none
* @access private
@@ -233,7 +233,7 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['extensions']['class'] = 'cross_orange';
$this->temp_variables['extensions']['found'] = "Zend Java Bridge Not Installed";
}
-
+
/**
* Store Zend Bridge state as warning
*
@@ -246,18 +246,18 @@ class luceneValidation extends serviceValidation {
$this->temp_variables['extensions']['class'] = 'cross_orange';
$this->temp_variables['extensions']['found'] = "Zend Java Bridge Not Functional";
}
-
+
public function installed() {
$this->disableExtension = true; // Disable the use of the php bridge extension
$this->javaVersionCorrect();
$this->javaInstalled();
$this->javaCheck = 'tick';
}
-
+
public function getBinary() {
$this->java = $this->util->getJava();
}
-
+
/**
* Do some basic checks to help the user overcome java problems
*
@@ -267,7 +267,7 @@ class luceneValidation extends serviceValidation {
* @return boolean
*/
public function binaryChecks() {
- $java = $this->useZendJava();
+ $java = $this->util->useZendJava();
if(!$java) {
if($this->util->javaSpecified()) {
$this->disableExtension = true; // Disable the use of the php bridge extension
@@ -292,10 +292,10 @@ class luceneValidation extends serviceValidation {
return $auto;
}
}
-
+
return $java;
}
-
+
/**
* Set template view to specify java
*
@@ -307,7 +307,7 @@ class luceneValidation extends serviceValidation {
private function specifyJava() {
$this->javaExeError = true;
}
-
+
/**
* Attempts to use bridge and configure java settings
*
@@ -348,7 +348,7 @@ class luceneValidation extends serviceValidation {
return false;
}
}
-
+
/**
* Check if Zend Bridge is functional
*
@@ -362,33 +362,9 @@ class luceneValidation extends serviceValidation {
return true;
} else {
return false;
- }
- }
-
- public function useZendJava() {
- if($this->util->installEnvironment() == 'Zend') {
- if(WINDOWS_OS) { // For Zend Installation only
- $sysdir = explode(DS, SYSTEM_DIR);
- array_pop($sysdir);
- array_pop($sysdir);
- $zendsys = '';
- foreach ($sysdir as $k=>$v) {
- $zendsys .= $v.DS;
- }
- $java = $zendsys."jre".DS."bin".DS."java.exe";
- if(file_exists($java))
- return $java;
- } else {
- $java = "/usr/bin/java";
- if(file_exists($java)) {
- return $java;
- }
- }
- }
-
- return false;
+ }
}
-
+
/**
* Attempts to use user input and configure java settings
*
@@ -405,13 +381,13 @@ class luceneValidation extends serviceValidation {
}
$javaExecutable = $this->java;
}
- if(WINDOWS_OS) {
+ if(WINDOWS_OS) {
$cmd = "\"$javaExecutable\" -cp \"".SYS_DIR.";\" javaVersion \"".$this->outputDir."outJV\""." \"".$this->outputDir."outJVHome\"";
$func = OS."ReadJVFromFile";
if($this->$func($cmd)) {
return true;
} else {
- $this->java = $this->useZendJava(); // Java not installed
+ $this->java = $this->util->useZendJava(); // Java not installed
$javaExecutable = $this->java;
$cmd = "\"$javaExecutable\" -cp \"".SYS_DIR.";\" javaVersion \"".$this->outputDir."outJV\""." \"".$this->outputDir."outJVHome\"";
if($this->$func($cmd)) {
@@ -422,7 +398,7 @@ class luceneValidation extends serviceValidation {
$cmd = "\"$javaExecutable\" -version > ".$this->outputDir."outJV 2>&1 echo $!";
$func = OS."ReadJVFromFile";
if($this->$func($cmd)) {
- return true;
+ return true;
} else {
// TODO: Not sure
}
@@ -433,7 +409,7 @@ class luceneValidation extends serviceValidation {
$this->error[] = "Requires Java 1.5+ to be installed";
return false;
}
-
+
function windowsReadJVFromFile($cmd) {
$response = $this->util->pexec($cmd);
if(file_exists($this->outputDir.'outJV')) {
@@ -443,14 +419,14 @@ class luceneValidation extends serviceValidation {
$this->javaVersionInCorrect();
$this->javaCheck = 'cross';
$this->error[] = "Requires Java 1.5+ to be installed";
-
+
return false;
} else {
$this->javaVersionCorrect();
$this->javaInstalled();
$this->javaCheck = 'tick';
$this->providedJava = true;
-
+
return true;
}
} else {
@@ -461,12 +437,12 @@ class luceneValidation extends serviceValidation {
$this->javaExeError = true;
$this->error[] = "Requires Java 1.5+ to be installed";
}
-
+
return false;
}
}
}
-
+
function unixReadJVFromFile($cmd) {
$response = $this->util->pexec($cmd);
if(file_exists($this->outputDir.'outJV')) {
@@ -477,14 +453,14 @@ class luceneValidation extends serviceValidation {
$this->javaVersionInCorrect();
$this->javaCheck = 'cross';
$this->error[] = "Requires Java 1.5+ to be installed";
-
+
return false;
} else {
$this->javaVersionCorrect();
$this->javaInstalled();
$this->javaCheck = 'tick';
$this->providedJava = true;
-
+
return true;
}
} else {
@@ -495,12 +471,12 @@ class luceneValidation extends serviceValidation {
$this->javaExeError = true;
$this->error[] = "Requires Java 1.5+ to be installed";
}
-
+
return false;
}
}
}
-
+
/**
* Set all silent mode varibles
*
diff --git a/webservice/clienttools/ajaxhandler.php b/webservice/clienttools/ajaxhandler.php
index 4e3e9a5..1538e47 100644
--- a/webservice/clienttools/ajaxhandler.php
+++ b/webservice/clienttools/ajaxhandler.php
@@ -1,5 +1,9 @@
ret=&$response;
+ }else{
+ $this->ret=new jsonResponseObject();
+ }
+ $this->log("[__construct]ENTERING PREPARATIONS");
+
+ $this->remoteIp = (getenv(HTTP_X_FORWARDED_FOR)) ? getenv(HTTP_X_FORWARDED_FOR) : getenv(REMOTE_ADDR);
+ $this->log("[__construct]Remote IP determined as: {$this->remoteIp}");
- public function __construct(&$ret=NULL,&$kt,$noAuthRequests=''){
- // set a local copy of the json request wrapper
$noAuthRequests=is_array($noAuthRequests)?$noAuthRequests:split(',',(string)$noAuthRequests);
$this->registerNoAuthRequest($noAuthRequests);
- $this->req=new jsonWrapper(isset($_GET['request'])?$_GET['request']:(isset($_POST['request'])?$_POST['request']:''));
+
+ $this->rawRequestObject=isset($_GET['request'])?$_GET['request']:(isset($_POST['request'])?$_POST['request']:'');
+ $this->digestToken=isset($_GET['msgAuth'])?$_GET['msgAuth']:(isset($_POST['msgAuth'])?$_POST['msgAuth']:'');
+ $this->log("[__construct]DigestToken Found: {$this->digestToken}");
+
+ $this->ret->addDebug('Raw Request',$this->rawRequestObject);
+ $this->ret->addDebug('DigestToken Received',$this->digestToken);
+ $this->ret->addDebug('Remote IP',$this->remoteIp);
+
+
+ if($this->auth['session'])session_id($this->auth['session']);
+ $this->session=session_id();
+ $this->log("[__construct]Session Restarted as: {$this->session}");
+ // session_id('BLANK_SESSION');
+
+
+
+ //========================= 1. Parse Json
+ $this->log("[__construct]ENTERING Parse Json");
+ $this->req=new jsonWrapper($this->rawRequestObject);
$this->auth=$this->structArray('user,pass,passhash,appType,session,token,version',$this->req->jsonArray['auth']);
$this->request=$this->structArray('service,function,parameters',$this->req->jsonArray['request']);
+ //Add additional parameters
$add_params=array_merge($_GET,$_POST);
unset($add_params['request'],$add_params['datasource']);
$this->request['parameters']=array_merge($this->request['parameters'],$add_params);
-
-
- // set the response object
- if(get_class($ret)=='jsonResponseObject'){
- $this->ret=&$ret;
- }else{
- $this->ret=new jsonResponseObject();
- }
+
+ if(!$this->auth['debug'])$this->ret->includeDebug=false;
+
$this->ret->setRequest($this->req->jsonArray);
$this->ret->setTitle($this->request['service'].'::'.$this->request['function']);
$this->ret->setDebug('Server Versions',$this->getServerVersions());
-
+
+
+
+
+
+ //========================= 2. Test System Requirements
+ $this->log("[__construct]ENTERING Test System Requirements");
if(get_class($kt)=='KTAPI'){
$this->kt=&$kt;
}else{
$this->ret->addError('KnowledgeTree Object not Received in '.__CLASS__.' constructor. Quitting.');
return $this->render();
}
+
+
+ //TODO: Get rid of this service
+ $this->loadService('auth');
+ $this->authenticator=new auth($this,$this->ret,$this->kt,$this->request,$this->auth);
+
+
+
+ //========================= 3. Check Request Validity
+ $this->log("[__construct]ENTERING Check Request Validity");
+ if(!$this->checkRequestValidity())return $this->render();
+ if(!$this->checkTokenValidity())return $this->render();
+
+
+
+
+ //========================= 4. Preliminary Session Check
+ $this->log("[__construct]ENTERING Preliminary Session Check");
+ if(!$this->checkSessionValidity()){
+ $this->creatNewSession(); //(login) This may fail, be the user is still allowed to dispatch to the
+ }
+
+
+
+
+
+ //========================= 5. Authentication Check
+ $this->log("[__construct]ENTERING Authentication Check");
+ if(!$this->isStandardService() && !$this->isNoAuthRequiredRequest()){
+ //Authentication is Required
+ $this->log("[__construct]Determined Authentication is required");
+ if(!$this->checkCredentials()){
+ throw new Exception('User Credentials Necessary for Requested Service');
+ return $this->render();
+ }
+ }
+
+
+
+
+
+
+ //========================= 6. Service Dispatch
+ $this->log("[__construct]ENTERING Service Dispatch");
+ $this->dispatch();
+ return $this->render();
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+ protected function checkRequestValidity(){
+ $this->log("[checkRequestvalidity]Entering...");
+ $securityHash=md5(md5($this->rawRequestObject).'_'.$this->auth['token'].'_'.$this->getUserPass());
+ $digestToken=$this->digestToken;
+ $this->log("[checkRequestvalidity]comparing {$securityHash} with {$digestToken} as received");
- // Prepare
- if(!$this->isStandardService()){
- $this->loadService('auth');
- $this->authenticator=new auth($this,$this->ret,$this->kt,$this->request,$this->auth);
-
+ $passed=$securityHash==$digestToken;
+
+ $data=array(
+ 'Received Token' =>$digestToken,
+ 'Expected Token' =>$securityHash,
+ 'Passed' =>$passed,
+ ''
+ );
+ $this->ret->addDebug('Message Digest Security',$data);
+
+ if(!$passed){
+ $this->log("[checkRequestvalidity]Failed Validity Test");
+ throw new Exception('Message Integrity Was Compromised.');
+ }
+ return $passed;
+ }
- //Make sure a token exists before continuing
- if(!$this->verifyToken())return $this->render();
+ protected function checkSessionValidity(){
+ $valid=$this->start_session();
+ $this->auth['session']=session_id();
+ $this->ret->setStatus('session_id',session_id());
+ $this->ret->addDebug('Auth',array('Session Check'=>$valid));
+// echo $valid?'true':'false'.'
';
+ return $valid;
+ }
- if(!$this->verifySession()){
- $this->doLogin();
- $isAuthRequired=$this->isNoAuthRequiredRequest();
- $isAuthenticated=$this->isAuthenticated();
- if(!$isAuthRequired && !$isAuthenticated)return $this->render();
- }
+ //TODO: Alter this to verify whether token was used before or whether it is new
+ protected function checkTokenValidity(){
+ $token=$this->auth['token'];
+ $tokenList=$_SESSION['JAPI_TOKEN_STORE']?$_SESSION['JAPI_TOKEN_STORE']:array();
+ $valid=!in_array($token,$tokenList);
+ if($valid){
+ $tokenList[$token]=$token;
+ $_SESSION['JAPI_TOKEN_STORE']=$tokenList;
+ }else{
+ $this->error('Invalid Token - Already Used');
+ $this->log('Invalid Token - Already Used');
}
- $this->dispatch();
-
- return $this->render();
+ return $valid;
+ }
+
+
+ protected function creatNewSession(){
+ $this->ret->addDebug('Auth',array('Attempting to Create a New Session'));
+ if($this->checkCredentials()){
+ $ssession=KTAPI_UserSession::_check_session($this->getUserObject(),$this->remoteIp,$this->auth['appType']);
+ $session=$ssession[0];
+ $this->ret->addDebug('####################################Session Created : '.$session);
+ $this->auth['session']=session_id();
+ $this->ret->setStatus('session_id',session_id());
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ protected function start_session(){
+ $app_type=$this->auth['appType'];
+ $session_id=$this->auth['session'];
+ $ip=$this->remoteIp;
+
+ $session=$this->kt->get_session();
+
+ if(get_class($session)=='KTAPI_UserSession'){
+ return true;
+ }else{
+ $session = $this->kt->get_active_session($session_id, $ip, $app_type);
+
+ if (PEAR::isError($session)){
+ return false;
+ }
+ $this->auth['session']=session_id();
+ $this->ret->setStatus('session_id',session_id());
+ return true;
+ }
+
+
+ }
+
+
+ protected function getUserPass(){
+ $l_pass=md5('@NO_AUTH_NEEDED@');
+ $u=$this->getUserObject();
+ if($u){
+ $l_pass=$this->getUserObject()->getPassword();
+ }
+ return $l_pass;
+ }
+
+ protected function getUserObject(){
+ $kt=$this->kt;
+ $user=$this->auth['user'];
+ $o_user=$kt->get_user_object_by_username($user);
+
+ if(PEAR::isError($o_user)){
+ if(!isset($this->errors['usernotfound']))$this->ret->addError('User '.$user.' not found');
+ $this->errors['usernotfound']=true;
+ return false;
+ }else{
+ $this->log("[getUserObject] Found User: ".$o_user->getName());
+ }
+ return $o_user;
+ }
+
+ protected function checkCredentials(){
+ $user=$this->auth['user'];
+ $passHash=$this->auth['passhash'];
+
+ $kt=$this->kt;
+
+ $o_user=$kt->get_user_object_by_username($user);
+
+ if(PEAR::isError($o_user)){
+ if(!isset($this->errors['usernotfound']))$this->ret->addError('User '.$user.' not found');
+ $this->errors['usernotfound']=true;
+ return false;
+ }
+
+ try{
+ $l_pass=$o_user->getPassword();
+ $l_passHash=md5($l_pass.$this->auth['token']);
+
+ $passed=$passHash==$l_passHash;
+
+ $this->ret->setDebug('Auth',array(
+ 'User Real Password'=>$l_pass,
+ 'User Real Password Hash'=>$l_passHash,
+ 'Received Password Hash'=>$passHash,
+ 'passed'=>$passed
+ ));
+
+ return $passed;
+
+ }catch(Exception $e){
+ throw new Exception('Unknown credentialCheck error encountered');
+ return false;
+ }
+
+ return ture;
+ }
+
+
+
+ protected function log($str=''){
+ $this->ret->log($str);
+ }
+
+
+ protected function error($errMsg=NULL){
+ $this->ret->addError($errMsg);
}
+
+
+
+
+
+
+
+
+
private function structArray($structString=NULL,$arr=NULL){
$struct=array_flip(split(',',(string)$structString));
return array_merge($struct,is_array($arr)?$arr:array());
@@ -91,7 +345,17 @@ class ajaxHandler{
}
public function isStandardService(){
- return in_array($this->request['service'],$this->standardServices);
+ $isStandardService=in_array($this->request['service'],$this->standardServices);
+
+ $debug=array(
+ 'requested service' =>$this->request['service'],
+ 'standard services' =>$this->standardServices,
+ 'isStandardService' =>$isStandardService
+ );
+
+ $this->ret->addDebug('ajaxhandler::isStandardService',$debug);
+
+ return $isStandardService;
}
@@ -188,7 +452,17 @@ class ajaxHandler{
public function isNoAuthRequiredRequest(){
$req=$this->request;
$reqString=strtolower("{$req['service']}.{$req['function']}");
- return in_array($reqString,$this->noAuthRequireList);
+ $requiresAuth=in_array($reqString,$this->noAuthRequireList);
+
+ $debug=array(
+ 'requested service method' =>$reqString,
+ 'no auth required list' =>$this->noAuthRequireList,
+ 'requires auth' =>$requiresAuth
+ );
+
+ $this->ret->addDebug('ajaxhandler::isNoAuthRequiredRequest',$debug);
+
+ return $requiresAuth;
}
}
diff --git a/webservice/clienttools/comms.php b/webservice/clienttools/comms.php
index b62270e..5cd541e 100644
--- a/webservice/clienttools/comms.php
+++ b/webservice/clienttools/comms.php
@@ -50,7 +50,7 @@ if($_GET['datasource'])$RET->isDataSource=true;
$noAuthRequests=array(
'auth.ping',
- 'auth.japiLogin',
+ //'auth.japiLogin',
'kt.get_all_client_policies',
'kt.get_languages',
'kt.switchlang'
diff --git a/webservice/clienttools/jsonWrapper.php b/webservice/clienttools/jsonWrapper.php
index b8b1c94..9173c52 100644
--- a/webservice/clienttools/jsonWrapper.php
+++ b/webservice/clienttools/jsonWrapper.php
@@ -9,6 +9,7 @@ class jsonResponseObject{
protected $errors=array();
protected $status=array('session_id'=>'','random_token'=>'');
protected $data=array();
+ protected $log=array();
protected $request=array();
protected $debug=array();
public $additional=array();
@@ -28,7 +29,8 @@ class jsonResponseObject{
),
'data' =>array(),
'request' =>array(),
- 'debug' =>array()
+ 'debug' =>array(),
+ 'log' =>array()
);
@@ -49,9 +51,12 @@ class jsonResponseObject{
}
public function setDebug($varName=NULL,$value=NULL){
+ if(is_array($this->debug[$varName]) && is_array($value))$value=array_merge($this->debug[$varName],$value);
$this->debug[$varName]=$value;
}
+ public function addDebug($varName=NULL,$value=NULL){$this->setDebug($varName,$value);}
+
public function setRequest($request=NULL){
$this->request=$request;
}
@@ -61,6 +66,10 @@ class jsonResponseObject{
$this->title=$title;
}
+ public function log($str){
+ $this->log[]='['.date('h:i:s').'] '.$str;
+ }
+
public function getJson(){
$response=array_merge(array(
'requestName' =>$this->title,
@@ -72,6 +81,7 @@ class jsonResponseObject{
'data' =>$this->data,
'request' =>$this->request,
'debug' =>$this->debug,
+ 'log' =>$this->log
),$this->additional);
if(!$this->includeDebug) unset($response['debug']);
@@ -91,7 +101,6 @@ class jsonWrapper{
public $jsonArray=array();
public function __construct($content=NULL){
-// $content=stripslashes($content);
$this->raw=$content;
$content=@json_decode($content,true);
if(!is_array($content))throw new jsonContentException('Invalid JSON input',jsonContentException::INPUT_ERROR);