From c2a5b1880c19c1490c42eb40a6a15ce2bc64b9e9 Mon Sep 17 00:00:00 2001 From: EoleDev Date: Fri, 5 Feb 2016 00:07:31 +0100 Subject: [PATCH] Request Analyse reviewed, Server Initialisation Reviewed, Core Class Interface Created, App created --- server/core/App.php | 68 +++++++++++++++++++++ server/core/CoreInterface.php | 7 +++ server/core/Identity.php | 27 +++++--- server/core/LibOverride/genTokenOptions.php | 22 +++++-- server/index.php | 52 ++++++++-------- server/init.php | 54 +++++----------- 6 files changed, 147 insertions(+), 83 deletions(-) create mode 100755 server/core/App.php create mode 100755 server/core/CoreInterface.php mode change 100644 => 100755 server/core/Identity.php diff --git a/server/core/App.php b/server/core/App.php new file mode 100755 index 0000000..45f6922 --- /dev/null +++ b/server/core/App.php @@ -0,0 +1,68 @@ +tokenPost = NULL; + $this->tokenClass = new genTokenOptions($args); + $this->openstack = new OpenStack\OpenStack([]); + $this->pluginsApi = plugin_api::getInstance(); + $this->output = array(); + + } + + public function setToken($token){ + + $this->tokenPost = $token; + $this->tokenClass->loadBackup($his->tokenPost); + + } + + public function getLibClass($service){ + + switch($service){ + case "Identity": + if($tokenPost == NULL) $tokenClass->genIdentityToken(); + $opt = $tokenClass->getOptions($service); + return $this->openstack->identityV3($opt); + break; + } + + } + + public function authenticate(){ + + try{ + $this->tokenClass->genIdentityToken(); + $this->tokenClass->genComputeToken(); + $this->tokenClass->genImageToken(); + $this->tokenClass->genNetworkToken(); + + $this->setOutput("token", $this->tokenClass->getBackup()); + }catch(Exception $e){ + echo $e; + exit(); + } + + } + + public function setOutput($key, $out){ + + $this->output[$key] = $out; + + } + + public function show(){ + echo json_encode($this->output); + } + +} \ No newline at end of file diff --git a/server/core/CoreInterface.php b/server/core/CoreInterface.php new file mode 100755 index 0000000..ed0d959 --- /dev/null +++ b/server/core/CoreInterface.php @@ -0,0 +1,7 @@ +oidentity = $ostack->identityV3(); - $this->plugins = $apiP; + $this->app = $app; + if($app->getOptions("Identity")) + $this->libClass = $app->getLibClass("Identity"); } + public function action($action){ + + //To be Complete + + } + public function genToken(){ - global $Args; - $token = $this->oidentity->generateToken($Args); - return $token; - } + + //To be Complete + + } } diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index 81ecfc8..58b87c1 100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -81,7 +81,7 @@ class genTokenOptions $options['catalogType'] = 'false'; $options['region'] = 'RegionOne'; - $this->backup['Identity'] = unserialize($opt); + $this->backup['Identity'] = $opt; $token = $this->unserializeToken($this->backup['Identity']['token']); $baseUrl = $this->backup['Identity']['baseUrl']; @@ -129,7 +129,7 @@ class genTokenOptions $options['catalogType'] = 'image'; $options['region'] = 'RegionOne'; - $this->backup['Image'] = unserialize($opt); + $this->backup['Image'] = $opt; $token = $this->unserializeToken($this->backup['Image']['token']); $baseUrl = $this->backup['Image']['baseUrl']; @@ -176,7 +176,7 @@ class genTokenOptions $options['catalogType'] = 'network'; $options['region'] = 'RegionOne'; - $this->backup['Network'] = unserialize($opt); + $this->backup['Network'] = $opt; $token = $this->unserializeToken($this->backup['Network']['token']); $baseUrl = $this->backup['Network']['baseUrl']; @@ -224,7 +224,7 @@ class genTokenOptions $options['catalogType'] = 'compute'; $options['region'] = 'RegionOne'; - $this->backup['Compute'] = unserialize($opt); + $this->backup['Compute'] = $opt; $token = $this->unserializeToken($this->backup['Compute']['token']); $baseUrl = $this->backup['Compute']['baseUrl']; @@ -242,8 +242,18 @@ class genTokenOptions $this->optionsGlobal['Compute'] = $options; } - public function getBackup($service){ - return serialize($this->backup[$service]); + public function getBackup(){ + return serialize($this->backup); + } + + public function loadBackup($back){ + + $backup = unserialize($back); + loadComputeBackup($backup["Compute"]); + loadIdentityBackup($backup["Identity"]); + loadImageBackup($backup["Image"]); + loadNetworkBackup($backup["Network"]); + } public function getOptions($service){ diff --git a/server/index.php b/server/index.php index b3c061a..41f77b8 100755 --- a/server/index.php +++ b/server/index.php @@ -3,33 +3,29 @@ include_once("config.inc.php"); include_once("init.php"); -// $task = $_POST["task"]; -// $action = $_POST["action"]; - - - //$id = new identity($openstack_api, $pluginApi); - -// var_dump($id->genToken()); -// $identity = $openstack_api->identityV3($Args); - //$tmp = $identity->listEndpoints(); - //foreach($tmp as $cred){ -// echo $cred->id." %%%%%% "; - //} - //$servers = $compute->listServers(true); - //var_dump($servers); - //foreach($servers as $server){ - // echo $server->id." !!!!!!!!! "; - //} - - $tmp = new genTokenOptions($Args); - $tmp->loadIdentityBackup($identityBack); - $array = $tmp->getOptions("Identity"); - - $openstackTest = new OpenStack\OpenStack([]); - $identityTest = $openstackTest->identityV3($array); - $domainsTest = $identityTest->listDomains(); - foreach($domainsTest as $domain){ - echo $domain->id." %%%%%% "; + if(isset($_POST["task"]) && isset($_POST["action"])){ + $task = $_POST["task"]; + $action = $_POST["action"]; + }else if(isset($_POST["task"]) && $_POST["task"] == "Authenticate"){ + $task = $_POST["task"]; + }else{ + //Gestion Erreur + } + + if($task == "Authenticate"){ + + $App->authenticate(); + $App->show(); + + } + + switch($task) + { + case "identity": + include_once("core/Identity.php"); + $identityObject = new identity($App); + $identityObject->action($action); + $App->show(); + break; } - // var_dump($openstack_api->getBuilderOptions()); diff --git a/server/init.php b/server/init.php index 2c07947..cf08523 100755 --- a/server/init.php +++ b/server/init.php @@ -1,13 +1,15 @@ Array( - "name" => $user, - "password" => $password, - "domain" => Array( - "name" => "Default") - ), - "scope" => Array( - "project" => Array( - "name" => $project, - "domain" => Array( - "name" => "Default") - ) - ), - "authUrl" => $config["urlAuth"] - ); - } else { + } /*else { // Test Backend $user = "admin"; $password = "ae5or6cn"; $project = "admin"; - $Args = Array( + }*/ + + $Args = Array( "user" => Array( "name" => $user, "password" => $password, @@ -52,21 +40,7 @@ ), "authUrl" => $config["urlAuth"] ); - } - - $pluginApi = plugin_api::getInstance(); - //$openstack_api = new OpenStack\OpenStack($Args); - //$id = new identity($openstack_api, $pluginApi); - - //$token = $id->genToken(); - - $tmp = new genTokenOptions($Args); - $tmp->genIdentityToken(); - $array = $tmp->getOptions("Identity"); - $openstack_api = new OpenStack\OpenStack([]); - - $identityBack = $tmp->getBackup("Identity"); - //file_put_contents("token", serialize($tmp)); + $App = new App($Args); ?>