Esempio n. 1
0
 function testCollection()
 {
     $ktapi = new KTAPI();
     $session = $ktapi->start_session('admin', 'admin');
     $this->assertNotError($session);
     $columns = $ktapi->get_columns_for_view();
     $this->assertIsA($columns, 'array');
 }
 function testSystemLogin()
 {
     $ktapi = new KTAPI();
     $session = $ktapi->start_system_session();
     $this->assertTrue(is_a($session, 'KTAPI_SystemSession'));
     $this->assertTrue($session->is_active());
     $session->logout();
     $this->assertFalse($session->is_active());
 }
 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);
 }
Esempio n. 4
0
 /**
  * Test the bulk delete functionality
  */
 function testDelete()
 {
     // Create documents
     $doc1 = $this->createDocument('Test Doc One', 'testdoc1.txt');
     $doc2 = $this->createDocument('Test Doc Two', 'testdoc2.txt');
     $doc3 = $this->createDocument('Test Doc Three', 'testdoc3.txt');
     $folder1 = $this->root->add_folder("New test folder");
     $this->assertNotError($newFolder);
     if (PEAR::isError($newFolder)) {
         return;
     }
     $doc4 = $this->createDocument('Test Doc Four', 'testdoc4.txt', $folder1);
     $aItems = array($doc1, $doc2, $doc3, $folder1);
     // Delete documents and folder
     $res = $this->bulk->delete($aItems, 'Testing bulk delete');
     $this->assertTrue(empty($res));
     // Check documents have been deleted
     $this->assertTrue($doc1->is_deleted());
     $this->assertTrue($doc2->is_deleted());
     $this->assertTrue($doc3->is_deleted());
     // refresh the doc4 document object to reflect changes
     $doc4 = KTAPI_Document::get($this->ktapi, $doc4->get_documentid());
     $this->assertTrue($doc4->is_deleted());
     // Check folder has been deleted
     $folder = $this->ktapi->get_folder_by_name('New test folder');
     $this->assertError($folder);
     // Expunge documents
     $doc1->expunge();
     $doc2->expunge();
     $doc3->expunge();
     $doc4->expunge();
 }
Esempio n. 5
0
 /**
  * Test KTAPI_PermissionAllocation getAllocation(), add(), remove(), save()
  *
  */
 function testPermissionAllocation()
 {
     $root = $this->ktapi->get_root_folder();
     $folder = $this->ktapi->get_folder_by_name('test123');
     if (!$folder instanceof KTAPI_Folder) {
         $folder = $root->add_folder('test123');
     }
     $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $folder);
     $group = KTAPI_Group::getByName('System Administrators');
     $user = KTAPI_User::getByUsername('anonymous');
     $role = KTAPI_Role::getByName('Publisher');
     $read = KTAPI_Permission::getByNamespace('ktcore.permissions.read');
     $write = KTAPI_Permission::getByNamespace('ktcore.permissions.write');
     $addFolder = KTAPI_Permission::getByNamespace('ktcore.permissions.addFolder');
     $security = KTAPI_Permission::getByNamespace('ktcore.permissions.security');
     $allocation->add($user, $read);
     $allocation->add($user, $write);
     $allocation->add($user, $addFolder);
     $allocation->add($user, $security);
     $allocation->add($role, $read);
     $allocation->add($role, $write);
     $allocation->remove($group, $write);
     $allocation->save();
     // refresh object and check permission allocations
     $folder2 = $this->ktapi->get_folder_by_name('test123');
     $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $folder2);
     $this->assertTrue($allocation->isMemberPermissionSet($user, $read));
     $this->assertTrue($allocation->isMemberPermissionSet($user, $write));
     $this->assertTrue($allocation->isMemberPermissionSet($role, $write));
     $this->assertFalse($allocation->isMemberPermissionSet($group, $write));
     $folder->delete('Testing permission allocation');
 }
Esempio n. 6
0
 /**
  * Setup the session, add and index the document
  *
  */
 function setUp()
 {
     $this->ktapi = new KTAPI();
     $this->session = $this->ktapi->start_system_session();
     $this->root = $this->ktapi->get_root_folder();
     $doc = array();
     $docId = array();
     // Add documents to DB and lucene index
     $filename = 'Test987.txt';
     $title = 'Test987';
     $this->addNewDocument($title, $filename, 0);
     $filename = 'Test654.txt';
     $title = 'Test654';
     $content = 'Searchable text: abcde ghijk 4567';
     $this->addNewDocument($title, $filename, 1, $content);
     $filename = 'Test321.txt';
     $title = 'Test321';
     $content = 'Searchable text: abcde mnopqr 891011';
     $this->addNewDocument($title, $filename, 2, $content);
 }
Esempio n. 7
0
 /**
  * Method to test the document subscriptions for webservices
  *
  */
 public function testSubscriptions_KTAPI()
 {
     $this->ktapi->session_logout();
     $this->session = $this->ktapi->start_session('admin', 'admin');
     $randomFile = APIDocumentHelper::createRandomFile();
     $this->assertTrue(is_file($randomFile));
     $document = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
     $this->assertIsA($document, 'KTAPI_Document');
     $this->assertNoErrors();
     @unlink($randomFile);
     $documentid = $document->get_documentid();
     // case no subscription
     $response = $this->ktapi->is_document_subscribed($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['subscribed'], 'FALSE');
     $this->assertNoErrors();
     //case add subscription
     $response = $this->ktapi->subscribe_to_document($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     //case add DUPLICATE subscription
     $response = $this->ktapi->subscribe_to_document($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     // case subscription exists
     $response = $this->ktapi->is_document_subscribed($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['subscribed'], 'TRUE');
     $this->assertNoErrors();
     //case delete subscription
     $response = $this->ktapi->unsubscribe_from_document($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     //case delete NOT EXISTANT subscription
     $response = $this->ktapi->unsubscribe_from_document($documentid);
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     $document->delete('Test');
     $document->expunge();
 }
Esempio n. 8
0
 /**
  * Method to test the folder subscriptions for webservices
  *
  */
 public function testSubscriptions_KTAPI()
 {
     $this->ktapi->session_logout();
     $this->session = $this->ktapi->start_session('admin', 'admin');
     $root = $this->ktapi->get_root_folder();
     $folder = $root->add_folder('testXXXXX');
     $this->assertIsA($folder, 'KTAPI_Folder');
     $this->assertNotA($folder, 'PEAR_Error');
     $this->assertNoErrors();
     // case no subscription
     $response = $this->ktapi->is_folder_subscribed($folder->get_folderid());
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['subscribed'], 'FALSE');
     $this->assertNoErrors();
     //case add subscription
     $response = $this->ktapi->subscribe_to_folder($folder->get_folderid());
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     //case add DUPLICATE subscription
     $response = $this->ktapi->subscribe_to_folder($folder->get_folderid());
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     // case subscription exists
     $response = $this->ktapi->is_folder_subscribed($folder->get_folderid());
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['subscribed'], 'TRUE');
     $this->assertNoErrors();
     //case delete subscription
     $response = $this->ktapi->unsubscribe_from_folder($folder->get_folderid());
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     //case delete NOT EXISTANT subscription
     $response = $this->ktapi->unsubscribe_from_folder($folder->get_folderid());
     $this->assertIsA($response, 'array');
     $this->assertEqual($response['results']['action_result'], 'TRUE');
     $this->assertNoErrors();
     $folder->delete('testXXXXX');
 }
Esempio n. 9
0
 /**
  * This returns a metadata tree or an error object.
  *
  * @author KnowledgeTree Team
  * @access public
  * @param integer $fieldid The id of the tree field to get the metadata for
  * @return array|object $results SUCCESS - the array of metadata for the field | FAILURE - an error object
  */
 public function get_metadata_tree($fieldid)
 {
     $results = KTAPI::_load_metadata_tree($fieldid);
     return $results;
 }
Esempio n. 10
0
}
//$session_id = $_POST['session_id'];
if (count($_FILES) == 0) {
    respond(5, 'No files have been uploaded.');
}
if ($action == 'C') {
    if (!array_key_exists('document_id', $_POST)) {
        respond(6, 'Document ID not specified.');
    }
    $document_id = $_POST['document_id'];
}
require_once '../ktapi/ktapi.inc.php';
require_once 'KTUploadManager.inc.php';
$apptype = isset($_POST['apptype']) ? $_POST['apptype'] : 'ws';
$session_id = $_POST['session_id'];
$ktapi = new KTAPI();
$session = $ktapi->get_active_session($session_id, null, $apptype);
if (PEAR::isError($session)) {
    respond(4, $session->getMessage());
}
$upload_manager = new KTUploadManager();
$upload_manager->cleanup();
$upload_manager->set_session($session);
$failed = 0;
$added = array();
$lastMessage = '';
foreach ($_FILES as $key => $file) {
    $filename = $file['name'];
    $tempfile = $file['tmp_name'];
    $error = $file['error'];
    if ($error == UPLOAD_ERR_OK) {
Esempio n. 11
0
            case 'help':
                print "Usage: search.php [verbose] user=username pass=password [output=simple|xml|csv] 'search criteria'\n";
                exit;
        }
    }
}
if ($verbose) {
    print _kt('Command line search') . "...\n";
}
if (empty($username)) {
    die(_kt("Please specify a username!"));
}
if (empty($expr)) {
    die(_kt("Please specify search criteria!"));
}
$ktapi = new KTAPI();
$result = $ktapi->start_session($username, $password);
if (PEAR::isError($result)) {
    print _kt("Cannot locate user:"******" {$username}\n";
    exit;
}
try {
    $expr = parseExpression($expr);
    $result = $expr->evaluate();
    switch ($output) {
        case 'simple':
            foreach ($result['docs'] as $item) {
                print 'Document ID: ' . $item->DocumentID . ' Title:' . $item->Title . ' Relevance:' . $item->Rank . "\n";
            }
            break;
        case 'csv':
Esempio n. 12
0
 /**
  * This returns all metadata for the document.
  *
  * <code>
  * $ktapi = new KTAPI();
  * $session = $ktapi->start_system_session();
  * $document = $ktapi->get_document_by_id($documentid);
  * $metadata = $document->get_metadata();
  * foreach($metadata as $fieldset){
  *     echo '<br><br>Fieldset: '.$fieldset['fieldset'];
  *
  *     foreach($fieldset['fields'] as $field){
  *         echo '<br>Field name: '.$field['name'] . ' Value: '. $field['value'];
  *     }
  * }
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @return array An array of metadata fieldsets and fields
  */
 function get_metadata()
 {
     $doctypeid = $this->document->getDocumentTypeID();
     $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->document, $doctypeid);
     if (is_null($fieldsets) || PEAR::isError($fieldsets)) {
         return array();
     }
     $results = array();
     foreach ($fieldsets as $fieldset) {
         if ($fieldset->getIsConditional()) {
             /* this is not implemented...*/
             continue;
         }
         $fields = $fieldset->getFields();
         $result = array('fieldset' => $fieldset->getName(), 'description' => $fieldset->getDescription());
         $fieldsresult = array();
         foreach ($fields as $field) {
             $value = '';
             $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field);
             if (!is_null($fieldvalue) && !PEAR::isError($fieldvalue)) {
                 $value = $fieldvalue->getValue();
             }
             $controltype = 'string';
             if ($field->getHasLookup()) {
                 $controltype = 'lookup';
                 if ($field->getHasLookupTree()) {
                     $controltype = 'tree';
                 }
             }
             switch ($controltype) {
                 case 'lookup':
                     $selection = KTAPI::get_metadata_lookup($field->getId());
                     break;
                 case 'tree':
                     $selection = KTAPI::get_metadata_tree($field->getId());
                     break;
                 default:
                     $selection = array();
             }
             $fieldsresult[] = array('name' => $field->getName(), 'required' => $field->getIsMandatory(), 'value' => $value == '' ? 'n/a' : $value, 'blankvalue' => $value == '' ? '1' : '0', 'description' => $field->getDescription(), 'control_type' => $controltype, 'selection' => $selection);
         }
         $result['fields'] = $fieldsresult;
         $results[] = $result;
     }
     return $results;
 }
Esempio n. 13
0
 /**
  * Creates a new session for the user.
  *
  * @param string $username
  * @param string $password
  * @param string $ip
  * @return kt_response
  */
 public function login()
 {
     if (isset($_REQUEST['type'])) {
         $this->setType($_REQUEST['type']);
     }
     if (isset($_REQUEST['username'])) {
         $this->setUsername($_REQUEST['username']);
     }
     if (isset($_REQUEST['password'])) {
         $this->setPassword($_REQUEST['password']);
     }
     $kt = new KTAPI();
     $session = $kt->start_session($this->username, $this->password, $ip);
     if (PEAR::isError($session)) {
         $this->status_code = 1;
         $this->message = $session->getMessage();
         return $this->login_fail();
     }
     $session = $session->get_session();
     $this->status_code = 0;
     $this->message = "";
     $this->results = $session;
     return $this->login_pass($response);
 }
Esempio n. 14
0
 /**
  * Instantiate KTAPI and get the active session, if the session id is supplied
  *
  * @author KnowledgeTree Team
  * @access protected
  * @param string $session_id
  * @return KTAPI
  */
 protected function &get_ktapi($session_id = null)
 {
     if (!is_null($this->ktapi)) {
         return $this->ktapi;
     }
     $kt = new KTAPI();
     // if the session id has been passed through - get the active session.
     if (!empty($session_id)) {
         $session = $kt->get_active_session($session_id, null);
         if (PEAR::isError($session)) {
             // return error / exception
             return $session;
         }
     }
     $this->ktapi = $kt;
     return $kt;
 }
Esempio n. 15
0
 /**
  * This adds a document to the current folder.
  *
  * <code>
  * $kt = new KTAPI();
  * $kt->start_session("admin", "admin");
  * $folder = $kt->get_folder_by_name("My New folder");
  * $res = $folder->add_document("Test Document", "test.txt", "Default", $tmpfname);
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $title This is the title for the file in the repository.
  * @param string $filename This is the filename in the system for the file.
  * @param string $documenttype This is the name or id of the document type. It first looks by name, then by id.
  * @param string $tempfilename This is a reference to the file that is accessible locally on the file system.
  * @return KTAPI_Document
  */
 function add_document($title, $filename, $documenttype, $tempfilename)
 {
     if (!is_file($tempfilename)) {
         return new PEAR_Error('File does not exist.');
     }
     $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE);
     if (PEAR::isError($user)) {
         return $user;
     }
     //KTS-4016: removed the replacing of special characters from the title as they should be allowed there
     //$title = KTUtil::replaceInvalidCharacters($title);
     $filename = basename($filename);
     $filename = KTUtil::replaceInvalidCharacters($filename);
     $documenttypeid = KTAPI::get_documenttypeid($documenttype);
     if (PEAR::isError($documenttypeid)) {
         $config = KTCache::getSingleton();
         $defaultToDefaultDocType = $config->get('webservice/useDefaultDocumentTypeIfInvalid', true);
         if ($defaultToDefaultDocType) {
             $documenttypeid = KTAPI::get_documenttypeid('Default');
         } else {
             return new KTAPI_DocumentTypeError('The document type could not be resolved or is disabled: ' . $documenttype);
         }
     }
     $options = array('contents' => new KTFSFileLike($tempfilename), 'temp_file' => $tempfilename, 'novalidate' => true, 'documenttype' => DocumentType::get($documenttypeid), 'description' => $title, 'metadata' => array(), 'cleanup_initial_file' => true);
     DBUtil::startTransaction();
     $document =& KTDocumentUtil::add($this->folder, $filename, $user, $options);
     if (PEAR::isError($document)) {
         DBUtil::rollback();
         return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ' : ' . $document->getMessage());
     }
     DBUtil::commit();
     KTUploadManager::temporary_file_imported($tempfilename);
     return new KTAPI_Document($this->ktapi, $this, $document);
 }
Esempio n. 16
0
 /**
  * Creates a new session for the user.
  *
  * @param string $username
  * @param string $password
  * @param string $ip
  * @return kt_response
  */
 function login($username, $password, $ip = null)
 {
     $response = KTWebService::_status(KTWS_ERR_AUTHENTICATION_ERROR);
     $kt = new KTAPI();
     $session = $kt->start_session($username, $password, $ip);
     if (PEAR::isError($session)) {
         $response['message'] = $session->getMessage();
         $this->debug($session->getMessage(), 'login');
         return new SOAP_Value('return', "{urn:{$this->namespace}}kt_response", $response);
     }
     $session = $session->get_session();
     $response['status_code'] = KTWS_SUCCESS;
     $response['message'] = $session;
     $this->debug("login('{$username}','{$password}','{$ip}')", $session);
     return new SOAP_Value('return', "{urn:{$this->namespace}}kt_response", $response);
 }
<?php

require_once '../../ktapi/ktapi.inc.php';
if ($_GET['user']) {
    $kt = new KTAPI();
    $user = $kt->get_user_object_by_username($_GET['user']);
    echo '<pre>' . print_r($user, true) . '</pre>';
    echo '<hr /><pre>' . print_r(get_class_methods(get_class($user)), true) . '</pre>';
    //echo '<hr /><pre>'.$user->getPassword().'</pre>';
}
Esempio n. 18
0
 * [autoexpunge]
 * admin=admin
 * password=admin
 * maximum=50
 *
 * admin and password is required to expunge documents from the system.
 *
 * maximum is the maximum number of documents that should be expunged from the system in one run.
 *
 */
$start_time = time();
$config = KTConfig::getSingleton();
$user = $config->get('autoexpunge/admin', 'admin');
$password = $config->get('autoexpunge/password', 'admin');
$maximum = $config->get('autoexpunge/maximum', 50);
$ktapi = new KTAPI();
$session = $ktapi->start_session($user, $password);
if (PEAR::isError($session)) {
    $default->log->debug('Expunge_all task: Can\'t create session: ' . $session->getMessage());
    return;
}
$sql = sprintf("SELECT id FROM documents WHERE status_id=%d LIMIT %d", DELETED, $maximum);
$rows = DBUtil::getResultArray($sql);
$count = count($rows);
if ($count == 0) {
    $default->log->debug('Expunge_all task: Nothing to do.');
    $session->logout();
    return;
}
foreach ($rows as $row) {
    $id = $row['id'];
Esempio n. 19
0
    respond(3, 'Invalid action specified.');
}
//$session_id = $_POST['session_id'];
if (count($_FILES) == 0) {
    respond(5, 'No files have been uploaded.');
}
if ($action == 'C') {
    if (!array_key_exists('document_id', $_POST)) {
        respond(6, 'Document ID not specified.');
    }
    $document_id = $_POST['document_id'];
}
require_once '../ktapi/ktapi.inc.php';
require_once 'KTUploadManager.inc.php';
$session_id = $_POST['session_id'];
$ktapi = new KTAPI();
$session = $ktapi->get_active_session($session_id);
if (PEAR::isError($session)) {
    respond(4, $session->getMessage());
}
$upload_manager = new KTUploadManager();
$upload_manager->cleanup();
$upload_manager->set_session($session);
$failed = 0;
$added = array();
$lastMessage = '';
foreach ($_FILES as $key => $file) {
    $filename = $file['name'];
    $tempfile = $file['tmp_name'];
    $error = $file['error'];
    if ($error == UPLOAD_ERR_OK) {