/** * Enter description here... * * @param unknown_type $userId * @param unknown_type $props * @return unknown */ public static function createNetwork($userId, $props) { if (empty($userId) || Api_Dao_User::isUserAdmin($userId)) { //create unique network key $uniqueKey = false; $netKey = ''; while (!$uniqueKey) { $netKey = ''; for ($k = 0; $k < 32; $k++) { $netKey .= dechex(mt_rand(1, 15)); } $uniqueKey = Api_Dao_Network::checkUniqueKey($netKey); } $eprops = array(); foreach ($props as $name => $val) { $eprops[$name] = $val; } if (!isset($eprops['name'])) { $eprops['name'] = $netKey; } $ret = Api_Dao_Network::createNetwork($userId, $netKey, $eprops); $netSecret = ''; for ($k = 0; $k < 32; $k++) { $netSecret .= dechex(mt_rand(1, 15)); } $ret = $ret && Api_Bo_DomainService::create()->createDomain($netKey, $eprops['web_url'], $netKey, $netSecret); if ($ret !== false) { return array($netKey, $netSecret); } return false; } throw new Exception('Only the administrator can create networks. (' . $userId . ')'); }
/** * Process API request to get an applications properties. * */ public function execute() { $response = array(); $ds = Api_Bo_DomainService::create(); $ks = Api_Bo_KeyService::create(); $domain = null; if (!isset($this->m_nid)) { $this->m_nid = $ds->getNativeIdByApiKey($this->m_apiKey); } $domain = $ds->getDomain($this->m_nid); $domain_keys = $ks->getKeyset($this->m_nid, $this->m_nid); $domain = array_merge($domain, $domain_keys); error_log("Retrieved domain for " . $this->m_nid . ":" . var_export($domain, true)); if (!empty($domain)) { foreach ($this->m_properties as $prop) { if (!isset(self::$map[$prop])) { throw new OpenFBAPIException(FB_ERROR_MSG_PARAMETER_MISSING, FB_ERROR_CODE_PARAMETER_MISSING); } $key = self::$map[$prop]; if (!isset($domain[$key])) { $response[$prop] = ''; } else { $response[$prop] = $domain[$key]; } } } return array('result' => json_encode($response)); }
/** * Process API request to get an applications properties. * */ public function execute() { $appService = Api_ServiceFactory::create('AppService'); $response = array(); if ($this->m_canvasName != null) { $ids = $appService->getNativeIdsByProperty('canvas_url', $this->m_canvasName); if ($ids == NULL || count($ids) == 0) { throw new OpenFBAPIException("No such application known, canvas name is '{$this->m_canvasName}'", FB_ERROR_CODE_NO_APP); } $this->m_aid = $ids[0]; } else { if ($this->m_apiKey != null) { $id = $appService->getNativeIdByApiKey($this->m_apiKey); if ($id == NULL) { throw new OpenFBAPIException("No such application known, API key is '{$this->m_apiKey}' on '{$this->m_nid}' network.", FB_ERROR_CODE_NO_APP); } $this->m_aid = $id; } } /* * You can only cross check application information if * the calling application is a default application */ // TODO: SECURITY: This disables cross-app calling security if uncommented! if (false && $this->m_aid != $this->getAppId()) { $isDefault = $this->checkDefaultApp($this->m_aid); if (!$isDefault) { throw new OpenFBAPIException('Application with id ' . $this->getAppId() . ' is not a default app: ' . FB_ERROR_MSG_GRAPH_EXCEPTION, FB_ERROR_CODE_GRAPH_EXCEPTION); } } $app = $appService->getApp($this->m_aid); $domainService = Api_Bo_DomainService::create(); $did = $domainService->getNativeIdByApiKey($this->m_nid); $keyService = Api_Bo_KeyService::create(); $keyset = $keyService->getKeyset($this->m_aid, $did); $app['api_key'] = isset($keyset['api_key']) ? $keyset['api_key'] : ''; $app['secret_key'] = isset($keyset['secret']) ? $keyset['secret'] : ''; $response = array(); if ($app != NULL) { foreach ($this->m_properties as $prop) { if (!isset(self::$map[$prop])) { throw new OpenFBAPIException(FB_ERROR_MSG_PARAMETER_MISSING, FB_ERROR_CODE_PARAMETER_MISSING); } $key = self::$map[$prop]; if (!isset($app[$key])) { $response[$prop] = ''; } else { $response[$prop] = $app[$key]; } } } return array('result' => json_encode($response)); }