} } return $arguments; } // First: check if LDAP plugin is active // Ensure LDAP plugin is active $pluginManager = PluginManager::instance(); $ldapPlugin = $pluginManager->getPluginByName('ldap'); if ($ldapPlugin && $pluginManager->isPluginAvailable($ldapPlugin)) { // -h --help help // --ldapid="" ldap_id(required) // --realname="" realname (required) // --email="" email (required) // --uid="" uid (required); //print_r($_SERVER['argv']); $arg = extract_params($_SERVER['argv']); //print_r($arg); if (isset($arg['ldapid']) && isset($arg['realname']) && isset($arg['email']) && isset($arg['uid'])) { // Check if user exists $user = UserManager::instance()->getUserByLdapId($arg['ldapid']); if ($user) { echo "Error: ldap id already in the database\n"; exit; } else { $ldapUm = $ldapPlugin->getLdapUserManager(); $user = $ldapUm->createAccount($arg['ldapid'], $arg['uid'], $arg['realname'], $arg['email']); if ($user) { echo "ID=" . $user->getId() . ":STATUS=" . $user->getStatus() . "\n"; return 0; } }
if ($ticket && !auth::check_ticket($ticket)) { $resobj->set(array('code' => 403, 'body' => "ticket invalid!")); goto RES_CLIENT; } /*extract a clean and standard path like /rest/xxx/xxx/xxx*/ function filter_path() { $path = preg_replace('/\\|\\\\|\\/\\//', '/', $_SERVER["REQUEST_URI"]); $path = preg_replace('/\\?[^\\/]*$/', '', $path); $path = preg_replace('/\\/$/', '', $path); return $path; } /*find the api handler method*/ $handler = find_handler(filter_path()); if ($handler) { $params = check_method_params($handler['method'], extract_params()); if (!$params && !is_array($params)) { $resobj->set(array('code' => 500, 'body' => "params invalid!")); goto RES_CLIENT; } try { $resobj = $handler['method']->invokeArgs($handler['class'], $params); } catch (ForbiddenException $e) { $resobj->set(array('code' => 403, 'body' => $e->getMessage())); } catch (Exception $e) { // Will be caught $resobj->set(array('code' => 500, 'body' => $e->getMessage())); } } else { $resobj->set(array('code' => 404)); }