Commit 314339bb4207fc88e7c65a5e1da6de07cb53c546

Authored by Jarrett Jordaan
2 parents 890b3b79 97a4f118

Merge branch 'edge' of git@github.com:ktgit/knowledgetree into edge

webservice/clienttools/ajaxhandler.php
... ... @@ -8,6 +8,7 @@ class ajaxHandler{
8 8 public $kt=NULL;
9 9 public $authenticator=NULL;
10 10 public $noAuthRequireList=array();
  11 + public $standardServices=array('system');
11 12  
12 13 public function __construct(&$ret=NULL,&$kt,$noAuthRequests=''){
13 14 // set a local copy of the json request wrapper
... ... @@ -30,6 +31,7 @@ class ajaxHandler{
30 31 }
31 32 $this->ret->setRequest($this->req->jsonArray);
32 33 $this->ret->setTitle($this->request['service'].'::'.$this->request['function']);
  34 + $this->ret->setDebug('Server Versions',$this->getServerVersions());
33 35  
34 36 if(get_class($kt)=='KTAPI'){
35 37 $this->kt=&$kt;
... ... @@ -38,20 +40,22 @@ class ajaxHandler{
38 40 return $this->render();
39 41 }
40 42  
41   - // Prepar
42   - $this->loadService('auth');
43   - $this->authenticator=new auth($this->ret,$this->kt,$this->request,$this->auth);
44   -
45   -
46   - //Make sure a token exists before continuing
47   - if(!$this->verifyToken())return $this->render();
48   -
49   -
50   - if(!$this->verifySession()){
51   - $this->doLogin();
52   - $isAuthRequired=$this->isNoAuthRequiredRequest();
53   - $isAuthenticated=$this->isAuthenticated();
54   - if(!$isAuthRequired && !$isAuthenticated)return $this->render();
  43 + // Prepare
  44 + if(!$this->isStandardService()){
  45 + $this->loadService('auth');
  46 + $this->authenticator=new auth($this,$this->ret,$this->kt,$this->request,$this->auth);
  47 +
  48 +
  49 + //Make sure a token exists before continuing
  50 + if(!$this->verifyToken())return $this->render();
  51 +
  52 +
  53 + if(!$this->verifySession()){
  54 + $this->doLogin();
  55 + $isAuthRequired=$this->isNoAuthRequiredRequest();
  56 + $isAuthenticated=$this->isAuthenticated();
  57 + if(!$isAuthRequired && !$isAuthenticated)return $this->render();
  58 + }
55 59 }
56 60  
57 61 $this->dispatch();
... ... @@ -70,11 +74,15 @@ class ajaxHandler{
70 74 $service=$this->authenticator;
71 75 }else{
72 76 $this->loadService($request['service']);
73   - $service=new $request['service']($this->ret,$this->kt,$this->request,$this->auth);
  77 + if(class_exists($request['service'])){
  78 + $service=new $request['service']($this,$this->ret,$this->kt,$this->request,$this->auth);
  79 + }else{
  80 + $this->ret->setDebug('Service could not be loaded',$request['service']);
  81 + }
74 82 }
75 83 $this->ret->setdebug('dispatch_request','The service class loaded');
76 84 if(method_exists($service,$request['function'])){
77   - $this->ret->setdebug('dispatch_execution','The service method was found. Executing');
  85 + $this->ret->setDebug('dispatch_execution','The service method was found. Executing');
78 86 $service->$request['function']($request['parameters']);
79 87 }else{
80 88 $this->ret->addError("Service {$request['service']} does not contain the method: {$request['function']}");
... ... @@ -82,16 +90,34 @@ class ajaxHandler{
82 90 }
83 91 }
84 92  
  93 + public function isStandardService(){
  94 + return in_array($this->request['service'],$this->standardServices);
  95 + }
  96 +
85 97  
86 98 public function loadService($serviceName=NULL){
87   - $version=$this->getVersion();
88   - if(!class_exists($serviceName)){
89   - if(file_exists('services/'.$version.'/'.$serviceName.'.php')){
90   - require_once('services/'.$version.'/'.$serviceName.'.php');
91   - return true;
92   - }else{
93   - throw new Exception('Service could not be found: '.$serviceName);
94   - return false;
  99 + if(in_array($serviceName,$this->standardServices)){
  100 + $fileName=dirname(__FILE__).'/standardservices/'.$serviceName.'.php';
  101 + $this->ret->setDebug('standardService Found',$fileName);
  102 + if(!class_exists($serviceName)){
  103 + if(file_exists($fileName)){
  104 + require_once($fileName);
  105 + return true;
  106 + }else{
  107 + throw new Exception('Standard Service could not be found: '.$serviceName);
  108 + return false;
  109 + }
  110 + }
  111 + }else{
  112 + $version=$this->getVersion();
  113 + if(!class_exists($serviceName)){
  114 + if(file_exists('services/'.$version.'/'.$serviceName.'.php')){
  115 + require_once('services/'.$version.'/'.$serviceName.'.php');
  116 + return true;
  117 + }else{
  118 + throw new Exception('Service could not be found: '.$serviceName);
  119 + return false;
  120 + }
95 121 }
96 122 }
97 123 }
... ... @@ -106,10 +132,22 @@ class ajaxHandler{
106 132 return true;
107 133 }
108 134  
109   - protected function getVersion(){
  135 + public function getVersion(){
110 136 if(!$this->version)$this->version=$this->req->getVersion();
111 137 return $this->version;
112 138 }
  139 +
  140 + public function getServerVersions(){
  141 + $folder='services/';
  142 + $contents=scandir($folder);
  143 + $dir=array();
  144 + foreach($contents as $item){
  145 + if(is_dir($folder.$item) && $item!='.' && $item!=='..'){
  146 + $dir[]=$item;
  147 + }
  148 + }
  149 + return $dir;
  150 + }
113 151  
114 152 protected function verifySession(){
115 153 return $this->authenticator->pickup_session();
... ...
webservice/clienttools/client_service.php
... ... @@ -5,8 +5,9 @@ class client_service{
5 5 public $KT;
6 6 public $Request;
7 7 public $AuthInfo;
  8 + public $handler;
8 9  
9   - public function __construct(&$ResponseObject,&$KT_Instance,&$Request,&$AuthInfo){
  10 + public function __construct(&$handler,&$ResponseObject,&$KT_Instance,&$Request,&$AuthInfo){
10 11 // set the response object
11 12 // if(get_class($ResponseObject)=='jsonResponseObject'){
12 13 // $this->Response=&$ResponseObject;
... ... @@ -14,7 +15,7 @@ class client_service{
14 15 // $this->Response=new jsonResponseObject();
15 16 // }
16 17  
17   -
  18 + $this->handler=$handler;
18 19 $this->Response=&$ResponseObject;
19 20 $this->KT=&$KT_Instance;
20 21 $this->AuthInfo=&$AuthInfo;
... ...
webservice/clienttools/jsonWrapper.php
... ... @@ -14,7 +14,7 @@ class jsonResponseObject{
14 14 public $additional=array();
15 15 public $isDataSource=false;
16 16  
17   - public $includeDebug=false;
  17 + public $includeDebug=true;
18 18  
19 19 public $response=array(
20 20 'requestName' =>'',
... ...
webservice/clienttools/services/0.1/auth.php
... ... @@ -100,17 +100,25 @@ class auth extends client_service {
100 100 public function ping(){
101 101 global $default;
102 102 $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  103 + $versions=$this->handler->getServerVersions();
  104 + $bestVer=$versions[count($versions)-1];
  105 + $clientVer=$this->handler->getVersion();
103 106 $ret=array(
104 107 'response' =>'pong',
105 108 'loginLocation' => '/index.html',
106   - 'currentversion' =>$default->systemVersion,
107   - 'requiredversion' =>$default->systemVersion,
108   - 'versionok' =>true,
109   - 'fullName' =>PEAR::isError($user)?'':$user->getName()
  109 + 'versionok' =>in_array($clientVer,$versions),
  110 + 'fullName' =>PEAR::isError($user)?'':$user->getName(),
  111 + 'serverVersions' =>$versions,
  112 + 'serverBestVersion' =>$bestVer,
  113 + 'clientVersion' =>$clientVer,
  114 + 'canUpgradeClient' =>($clientVer<$bestVer?true:false),
  115 + 'canUpgradeServer' =>($clientVer>$bestVer?true:false)
  116 +
110 117 );
111 118 $this->setResponse($ret);
112 119 return true;
113 120 }
  121 +
114 122  
115 123 function logout($params){
116 124 $params=$this->AuthInfo;
... ...
webservice/clienttools/services/0.2/auth.php
... ... @@ -100,13 +100,20 @@ class auth extends client_service {
100 100 public function ping(){
101 101 global $default;
102 102 $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  103 + $versions=$this->handler->getServerVersions();
  104 + $bestVer=$versions[count($versions)-1];
  105 + $clientVer=$this->handler->getVersion();
103 106 $ret=array(
104 107 'response' =>'pong',
105 108 'loginLocation' => '/index.html',
106   - 'currentversion' =>$default->systemVersion,
107   - 'requiredversion' =>$default->systemVersion,
108   - 'versionok' =>true,
109   - 'fullName' =>PEAR::isError($user)?'':$user->getName()
  109 + 'versionok' =>in_array($clientVer,$versions),
  110 + 'fullName' =>PEAR::isError($user)?'':$user->getName(),
  111 + 'serverVersions' =>$versions,
  112 + 'serverBestVersion' =>$bestVer,
  113 + 'clientVersion' =>$clientVer,
  114 + 'canUpgradeClient' =>($clientVer<$bestVer?true:false),
  115 + 'canUpgradeServer' =>($clientVer>$bestVer?true:false)
  116 +
110 117 );
111 118 $this->setResponse($ret);
112 119 return true;
... ...
webservice/clienttools/services/0.2/kt.php
... ... @@ -140,6 +140,7 @@ class kt extends client_service {
140 140  
141 141 $folder=&$kt->get_folder_by_id($arr['node']);
142 142 if (PEAR::isError($folder)){
  143 + echo '<pre>'.print_r($arr,true).'</pre>';
143 144 $this->addError('Folder Not found');
144 145 return false;
145 146 }
... ... @@ -430,6 +431,7 @@ class kt extends client_service {
430 431 }
431 432 }
432 433 $this->setResponse(array('items'=>$items, 'count'=>count($items)));
  434 + return true;
433 435 }
434 436  
435 437 function update_document_type($params) {
... ...
webservice/clienttools/standardservices/system.php 0 → 100644
  1 +<?php
  2 +class system extends client_service{
  3 + public function checkVersion(){
  4 + global $default;
  5 + $user=$this->KT->get_user_object_by_username($this->AuthInfo['user']);
  6 + $versions=$this->handler->getServerVersions();
  7 + $bestVer=$versions[count($versions)-1];
  8 + $clientVer=$this->handler->getVersion();
  9 + $ret=array(
  10 + 'response' =>'pong',
  11 + 'loginLocation' => '/index.html',
  12 + 'versionok' =>in_array($clientVer,$versions),
  13 + 'fullName' =>PEAR::isError($user)?'':$user->getName(),
  14 + 'serverVersions' =>$versions,
  15 + 'serverBestVersion' =>$bestVer,
  16 + 'clientVersion' =>$clientVer,
  17 + 'canUpgradeClient' =>($clientVer<$bestVer?true:false),
  18 + 'canUpgradeServer' =>($clientVer>$bestVer?true:false)
  19 +
  20 + );
  21 + $this->setResponse($ret);
  22 + return true;
  23 + }
  24 +}
  25 +
  26 +?>
0 27 \ No newline at end of file
... ...