diff --git a/webservice/atompub/auth.php b/webservice/atompub/auth.php deleted file mode 100644 index d0a8da8..0000000 --- a/webservice/atompub/auth.php +++ /dev/null @@ -1,49 +0,0 @@ -. - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, - * California 94120-7775, or email info@knowledgetree.com. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. - * Contributor( s): - * Mark Holtzhausen - * - */ - -/** - * Automatic Login bypassing HTTP Basic Auth - * TODO: Thest HTTP Basic Auth - Try Library From Home - */ - -$SessionId=KT_atom_service_helper::login('admin','admin'); -$SessionId=$SessionId['session_id']; - - -?> \ No newline at end of file diff --git a/webservice/atompub/demodms/KT_atom_server.default_dms_services.inc.php b/webservice/atompub/demodms/KT_atom_server.default_dms_services.inc.php index 423b733..37c5732 100644 --- a/webservice/atompub/demodms/KT_atom_server.default_dms_services.inc.php +++ b/webservice/atompub/demodms/KT_atom_server.default_dms_services.inc.php @@ -23,6 +23,7 @@ class KT_atom_service_fulltree extends KT_atom_service { $feed->newField($property,$value,$entry); } } + $this->setStatus(self::STATUS_OK); //Expose the responseFeed $this->responseFeed=$feed; } @@ -90,4 +91,24 @@ class KT_atom_service_document extends KT_atom_service { $this->responseFeed=$feed; } } + +class KT_atom_service_test extends KT_atom_service{ + public function GET_action(){} + public function PUT_action(){} + public function POST_action(){} + public function DELETE_action(){} +} + +class KT_atom_service_logout extends KT_atom_service{ + public function GET_action(){ + //$this->setStatus(self::STATUS_OK); + KT_atom_HTTPauth::logout(); + ob_end_clean(); + KT_atom_HTTPauth::login('KnowledgeTree AtomPub','You are not allowed on this realm'); + exit; + } + public function PUT_action(){} + public function POST_action(){} + public function DELETE_action(){} +} ?> \ No newline at end of file diff --git a/webservice/atompub/demodms/KT_atom_service_helper.inc.php b/webservice/atompub/demodms/KT_atom_service_helper.inc.php index 0095fa5..aca586f 100644 --- a/webservice/atompub/demodms/KT_atom_service_helper.inc.php +++ b/webservice/atompub/demodms/KT_atom_service_helper.inc.php @@ -32,7 +32,7 @@ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. - * Contributor( s): + * Contributor( s): * Mark Holtzhausen * */ @@ -42,17 +42,17 @@ class KT_atom_service_helper{ protected static $FILE_LIST_PROPERTIES=array('id','title','document_type','created_by','created_date','checked_out_by','checked_out_date','modified_by','modified_date','owned_by','mime_type','mime_icon_path','mime_display'); protected static $FOLDER_RECURSION_LEVEL=100; protected static $kt=NULL; - + /** * Make sure the class is always treated statically and never instantiated. - * + * * @return void */ public function __construct(){ die('KT_atom_service_helper should not be instantiated. Only use as a static class'); } - + /** * Get the KT singleton instance * @@ -65,8 +65,8 @@ class KT_atom_service_helper{ } return self::$kt; } - - + + /** * Get the subfolders of the indicated folder * @@ -82,10 +82,10 @@ class KT_atom_service_helper{ $subfolders[$item[id]]=self::extractFromArray($item,self::$FOLDER_LIST_PROPERTIES); } } - return $subfolders; + return $subfolders; } - - + + /** * Get every folder & document in the repository * @@ -109,20 +109,20 @@ class KT_atom_service_helper{ } return $appTree; } - - + + /** * Get detail about the folder * * @param integer $folderId The id of the folder to get detail on. - * @return array + * @return array */ public static function getFolderDetail($folderId=NULL){ $ktInfo=self::getKT()->get_folder_by_id($folderId); return $ktInfo->get_detail(); } - - + + /** * Get detail about the indicated document * @@ -133,8 +133,8 @@ class KT_atom_service_helper{ $ktInfo=self::getKT()->get_document_detail($docId); return $ktInfo; } - - + + /** * Get a list of all the documents in a folder. * @@ -151,8 +151,8 @@ class KT_atom_service_helper{ } return $folderFiles; } - - + + /** * Returns an array containing only the associated values from $array where the keys were found in $keyArray * @@ -167,7 +167,7 @@ class KT_atom_service_helper{ } return $newArray; } - + /** * Log in to KT easily * @@ -178,11 +178,12 @@ class KT_atom_service_helper{ */ function login($username, $password, $ip=null){ $kt = self::getKt(); - + $session = $kt->start_session($username,$password, $ip); if (PEAR::isError($session)){ $response['status_code']=KT_atom_server_FAILURE; $response['session_id']=''; + $response['error']=$session; }else{ $session= $session->get_session(); $response['status_code'] = KT_atom_server_SUCCESS; @@ -190,8 +191,8 @@ class KT_atom_service_helper{ } return $response; } - - + + /** * Log out of KT using the session id * @@ -199,9 +200,9 @@ class KT_atom_service_helper{ * @return object Containing the status_code of the logout attempt */ function logout($session_id){ - $kt = self::getKt(); + $kt = self::getKt(); $session = $kt->get_active_session($session_id, null); - + if (PEAR::isError($session)){ $response['status_code']=KT_atom_server_FAILURE; }else{ @@ -210,7 +211,16 @@ class KT_atom_service_helper{ } return $response; } - + + function sessionLogout(){ + $session=self::getKt()->get_session(); + if($session){ + try{ + self::getKT()->session_logout(); + }catch(Exception $e){}; + } + } + /** * Check whether the session_id is logged into KT * @@ -223,5 +233,9 @@ class KT_atom_service_helper{ return !PEAR::isError($session); } + function getSessionId(){ + return self::getKt()->get_session()->session; + } + } ?> \ No newline at end of file diff --git a/webservice/atompub/index.php b/webservice/atompub/index.php index a694f8b..40b66b6 100644 --- a/webservice/atompub/index.php +++ b/webservice/atompub/index.php @@ -63,7 +63,6 @@ define('KT_ATOM_LIB_FOLDER','../classes/atompub/'); //define('KT_APP_WEB_OUTPUT',false); //defunct - /** * Includes */ @@ -76,7 +75,18 @@ include_once(KT_ATOM_LIB_FOLDER.'KT_atom_serviceDoc.inc.php'); //Containing include_once(KT_ATOM_LIB_FOLDER.'KT_atom_responseFeed.inc.php'); //Containing the response feed class allowing easy atom feed generation include_once(KT_ATOM_LIB_FOLDER.'KT_atom_service.inc.php'); include_once('demodms/KT_atom_server.default_dms_services.inc.php'); -include_once('auth.php'); //Containing the authentication protocols + + +/** + * Check Realm Authentication + */ +require_once(KT_ATOM_LIB_FOLDER.'KT_atom_HTTPauth.inc.php'); + +if(!KT_atom_HTTPauth::isLoggedIn()){ + KT_atom_HTTPauth::login('KnowledgeTree AtomPub','You are not authorized to enter this realm'); +} + + //Start the AtomPubProtocol Routing Engine @@ -97,14 +107,11 @@ $APP->addWorkspaceTag('dms','atom:title','Standard DMS'); $APP->registerService('DMS','fulltree','KT_atom_service_fulltree','Full Document Tree'); $APP->registerService('DMS','folder','KT_atom_service_folder','Folder Detail'); $APP->registerService('DMS','document','KT_atom_service_document','Document Detail'); +$APP->registerService('DMS','logout','KT_atom_service_logout','Forceful Logout'); //Execute the current url/header request $APP->execute(); -//echo '
'.print_r($APP,true).'
'; - //Render the resulting feed response $APP->render(); -//print_r($APP); - ?> \ No newline at end of file diff --git a/webservice/classes/atompub/KT_atom_HTTPauth.inc.php b/webservice/classes/atompub/KT_atom_HTTPauth.inc.php new file mode 100644 index 0000000..a97e3fb --- /dev/null +++ b/webservice/classes/atompub/KT_atom_HTTPauth.inc.php @@ -0,0 +1,57 @@ +'','pass'=>'','method'=>''); + if(isset($_SERVER['PHP_AUTH_USER'])){ + $credentials['user']=$_SERVER['PHP_AUTH_USER']; + $credentials['pass']=isset($_SERVER['PHP_AUTH_PW'])?$_SERVER['PHP_AUTH_PW']:''; + $credentials['method']=isset($_SERVER['AUTH_TYPE'])?$_SERVER['AUTH_TYPE']:''; + }else{ + if(isset($_SERVER['kt_auth']) || isset($_SERVER['REDIRECT_kt_auth'])){ + $ktauth=isset($_SERVER['kt_auth'])?$_SERVER['kt_auth']:$_SERVER['REDIRECT_kt_auth']; + list($authMethod,$authCred)=split(' ',$ktauth); + $authMethod=strtolower(trim($authMethod)); + $authCred=base64_decode(trim($authCred)); + list($authUser,$authPass)=split(':',$authCred); + $credentials['method']=$authMethod; + $credentials['user']=$authUser; + $credentials['pass']=$authPass; + } + } + return $credentials; + } + + public static function requireBasicAuth($realm='default',$message=''){ + $realm=$realm?$realm:'default'; + header('WWW-Authenticate: Basic Realm="'.$realm.'"'); + header('HTTP/1.0 401 Unauthorized'); + echo $message; + exit; + } + + public static function isLoggedIn(){ + $kt=new KTAPI(); + $session=$kt->get_active_session(session_id()); + return !PEAR::isError($session); + } + + public static function logout(){ + $kt=new KTAPI(); + $session=$kt->get_active_session(session_id()); + if(!PEAR::isError($session)){ + $session->logout(); + } + } + + public static function login($realm,$msg){ + $kt=new KTAPI(); + $session=$kt->get_active_session(session_id()); + if(PEAR::isError($session)){ + $cred=self::getCredentials(); + $kt->login($cred['user'],$cred['pass']); + if(self::isLoggedIn())return; + } + self::requireBasicAuth($realm,$msg); + } +} +?> \ No newline at end of file