action.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <?php
  2. /** DOCKERENVIRONMENT / DOCKERENVIRONMENT **/
  3. //Récuperation d'une liste de DockerEnvironment
  4. Action::register('docker_environment_search',function(&$response){
  5. global $_;
  6. User::check_access('docker','read');
  7. Plugin::need('client/Client');
  8. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  9. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  10. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  11. $query = 'SELECT {{table}}.*,'.Client::joinString('c').' FROM '.DockerEnvironment::tableName().' LEFT JOIN '.Client::tableName().' c ON {{table}}.client = c.id WHERE 1';
  12. $data = array();
  13. //Recherche simple
  14. if(!empty($_['filters']['keyword'])){
  15. $query .= ' AND label LIKE ?';
  16. $data[] = '%'.$_['filters']['keyword'].'%';
  17. }
  18. //Recherche avancée
  19. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('machine','client','domain','port','git','memory','cpu','ssl','state'),$query,$data);
  20. //Tri des colonnes
  21. if(isset($_['sort'])) sort_secure_query($_['sort'],array('machine','client','domain','port','mysqlRootPassword','mysqlPassword','git','memory','cpu','ssl','state','certificate'),$query,$data);
  22. //Pagination
  23. $response['pagination'] = DockerEnvironment::paginate(20,(!empty($_['page'])?$_['page']:0),$query,$data);
  24. $DockerEnvironments = DockerEnvironment::staticQuery($query,$data,true,1);
  25. foreach($DockerEnvironments as $dockerEnvironment){
  26. $row = $dockerEnvironment->toArray();
  27. $row['state'] = DockerEnvironment::states($row['state']);
  28. $row['client'] = $dockerEnvironment->join('client')->toArray();
  29. $response['rows'][] = $row;
  30. }
  31. /* Mode export */
  32. if($_['export'] == 'true'){
  33. $stream = Excel::exportArray($response['rows'],null,'Export');
  34. File::downloadStream($stream,'export-demandes-'.date('d-m-Y').'.xlsx');
  35. exit();
  36. }
  37. });
  38. //Affichage d'un tab
  39. Action::register('docker_environment_tab',function(&$response){
  40. User::check_access('docker','read');
  41. global $myUser,$_;
  42. global $conf;
  43. User::check_access('docker','read');
  44. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  45. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  46. $environment = DockerEnvironment::provide();
  47. $machine = new DockerMachine();
  48. if($environment->id == 0){
  49. $environment->memory = '256';
  50. $environment->cpu = '0.5';
  51. $environment->port = DockerEnvironment::lastPort()+2;
  52. }else{
  53. $machine = DockerMachine::getById($environment->machine);
  54. }
  55. $_['tab'] = str_replace('.', '', $_['tab']);
  56. $tab = __DIR__.SLASH.'tab.environment.'.$_['tab'].'.php';
  57. if(!file_exists($tab)) throw new Exception("$tab n'existe pas");
  58. require_once($tab);
  59. exit();
  60. });
  61. //Ajout ou modification d'élément DockerEnvironment
  62. Action::register('docker_environment_save',function(&$response){
  63. global $myUser,$_;
  64. User::check_access('docker','edit');
  65. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  66. $item = DockerEnvironment::provide();
  67. //if(empty($_['domain'])) throw new Exception("Domaine obligatoire");
  68. if(empty($_['machine'])) throw new Exception("Machine obligatoire");
  69. //if(empty($_['memory'])) throw new Exception("Mémoire obligatoire");
  70. //if(!is_numeric($_['memory'])) throw new Exception("La mémoire doit être numérique");
  71. $item->client = $_['client'];
  72. if($item->id==0) $item->state = DockerEnvironment::ACTIVE;
  73. $item->machine = $_['machine'];
  74. if(!empty($_['memory'])) $item->memory = $_['memory'];
  75. if(!empty($_['ssl'])){
  76. $item->ssl = $_['ssl'];
  77. $item->certificate = $_['certificate'];
  78. }
  79. $item->comment = $_['comment'];
  80. //déduction automatique du port interne, on laisse un interval de deux (port web + port phpmyadmin)
  81. if($item->id==0){
  82. $item->port = DockerEnvironment::lastPort()+2;
  83. //génération des mots de passes mysql
  84. $item->mysqlPassword = sha1('mysql'.mt_rand(0,10000).'hash');
  85. $item->mysqlRootPassword = sha1('root'.time().$item->mysqlPassword.'hash');
  86. if(strlen($item->mysqlPassword)>10) $item->mysqlPassword = substr($item->mysqlPassword, 0,9);
  87. if(strlen($item->mysqlRootPassword)>10) $item->mysqlRootPassword = substr($item->mysqlRootPassword, 0,9);
  88. }else{
  89. if(!empty($_['port'])) $item->port = $_['port'];
  90. if(!empty($_['mysqlRootPassword'])) $item->mysqlRootPassword = $_['mysqlRootPassword'];
  91. if(!empty($_['mysqlPassword'])) $item->mysqlPassword = $_['mysqlPassword'];
  92. }
  93. $item->mysqlRootPassword = encrypt($item->mysqlRootPassword);
  94. $item->mysqlPassword = encrypt($item->mysqlPassword);
  95. if(!empty($_['domain'])){
  96. $item->domain = $_['domain'];
  97. //suppression du http ou https si existant
  98. $item->domain = trim(mb_strtolower(preg_replace('/http[s]?:\/\//iU', '', $item->domain)));
  99. ///suppression du www. si existant
  100. $item->domain = preg_replace('/www\./iU', '', $item->domain);
  101. }
  102. $item->save();
  103. $response = $item->toArray();
  104. });
  105. //Suppression d'élement DockerEnvironment
  106. Action::register('docker_environment_delete',function(&$response){
  107. global $_;
  108. User::check_access('docker','delete');
  109. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  110. if(empty($_['id']) || !is_numeric($_['id'])) throw new Exception("Identifiant incorrect");
  111. DockerEnvironment::deleteById($_['id']);
  112. });
  113. //Recherche des certificats installés sur l'utm
  114. Action::register('docker_environment_certificate_search',function(&$response){
  115. global $myUser,$_,$conf;
  116. User::check_access('docker','read');
  117. require_once(__DIR__.SLASH.'SophosUtm.class.php');
  118. $utm = new SophosUtm();
  119. $utm->host = $conf->get('docker_sophos_host');
  120. $utm->port = $conf->get('docker_sophos_port');
  121. $utm->login = $conf->get('docker_sophos_login');
  122. $utm->password = $conf->get('docker_sophos_password');
  123. foreach ($utm->getCertificates() as $line) {
  124. $response['rows'][] = array(
  125. 'ref' => $line['_ref'],
  126. 'label' => $line['name']
  127. );
  128. };
  129. });
  130. //Ajout ou modification d'élément DockerEnvironment
  131. Action::register('docker_environment_docker_create',function(&$response){
  132. global $myUser,$_,$conf;
  133. User::check_access('docker','edit');
  134. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  135. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  136. require_once(__DIR__.SLASH.'SshClient.class.php');
  137. if(empty($_['id'])) throw new Exception("Environnement obligatoire");
  138. $environment = DockerEnvironment::provide();
  139. if(!$environment) throw new Exception("Environnement introuvable");
  140. if(empty($environment->domain)) throw new Exception("Veuillez spécifier un nom de domaine dans l'onglet domaine et enregistrer avant de génerer un environnement");
  141. $ssh = new SshClient();
  142. $logs = array();
  143. $machine = DockerMachine::getById($environment->machine);
  144. $logs[]= $ssh->connect(
  145. $machine->ip,
  146. $machine->port,
  147. File::dir().'docker'.SLASH.'machine'.SLASH.$machine->id.SLASH.'id_rsa.pub',
  148. File::dir().'docker'.SLASH.'machine'.SLASH.$machine->id.SLASH.'id_rsa',
  149. !empty($machine->password)? decrypt($machine->password) : ''
  150. );
  151. $logs[]= $environment->createContainer($ssh);
  152. $logs[]= $environment->execute($ssh);
  153. $ssh->disconnect();
  154. $response['logs'] = implode('<br>',$logs);
  155. });
  156. //Suppression de l'environnement docker
  157. Action::register('docker_environment_docker_remove',function(&$response){
  158. global $myUser,$_,$conf;
  159. User::check_access('docker','edit');
  160. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  161. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  162. require_once(__DIR__.SLASH.'SshClient.class.php');
  163. if(empty($_['id'])) throw new Exception("Environnement obligatoire");
  164. $environment = DockerEnvironment::provide();
  165. if(!$environment) throw new Exception("Environnement introuvable");
  166. $ssh = new SshClient();
  167. $logs = array();
  168. $machine = DockerMachine::getById($environment->machine);
  169. $logs[]= $ssh->connect(
  170. $machine->ip,
  171. $machine->port,
  172. File::dir().'docker'.SLASH.'machine'.SLASH.$machine->id.SLASH.'id_rsa.pub',
  173. File::dir().'docker'.SLASH.'machine'.SLASH.$machine->id.SLASH.'id_rsa',
  174. !empty($machine->password)? decrypt($machine->password) : ''
  175. );
  176. $logs[]= $environment->removeContainer($ssh);
  177. $ssh->disconnect();
  178. $response['logs'] = implode('<br>',$logs);
  179. });
  180. //Ajout ou modification d'élément DockerEnvironment
  181. Action::register('docker_environment_pma_create',function(&$response){
  182. global $myUser,$_,$conf;
  183. User::check_access('docker','edit');
  184. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  185. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  186. require_once(__DIR__.SLASH.'SshClient.class.php');
  187. if(empty($_['id'])) throw new Exception("Environnement obligatoire");
  188. $environment = DockerEnvironment::provide();
  189. if(!$environment) throw new Exception("Environnement introuvable");
  190. $ssh = new SshClient();
  191. $logs = array();
  192. $machine = DockerMachine::getById($environment->machine);
  193. $logs[]= $ssh->connect(
  194. $machine->ip,
  195. $machine->port,
  196. File::dir().'docker'.SLASH.'machine'.SLASH.$machine->id.SLASH.'id_rsa.pub',
  197. File::dir().'docker'.SLASH.'machine'.SLASH.$machine->id.SLASH.'id_rsa',
  198. !empty($machine->password)? decrypt($machine->password) : ''
  199. );
  200. $logs[]= $environment->createPma($ssh);
  201. $ssh->disconnect();
  202. $response['logs'] = implode('<br>',$logs);
  203. });
  204. //Ajout ou modification d'élément DockerEnvironment
  205. Action::register('docker_environment_pma_remove',function(&$response){
  206. global $myUser,$_,$conf;
  207. User::check_access('docker','edit');
  208. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  209. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  210. require_once(__DIR__.SLASH.'SshClient.class.php');
  211. if(empty($_['id'])) throw new Exception("Environnement obligatoire");
  212. $environment = DockerEnvironment::provide();
  213. if(!$environment) throw new Exception("Environnement introuvable");
  214. $ssh = new SshClient();
  215. $logs = array();
  216. $machine = DockerMachine::getById($environment->machine);
  217. $logs[]= $ssh->connect(
  218. $machine->ip,
  219. $machine->port,
  220. File::dir().'docker'.SLASH.'machine'.SLASH.$machine->id.SLASH.'id_rsa.pub',
  221. File::dir().'docker'.SLASH.'machine'.SLASH.$machine->id.SLASH.'id_rsa',
  222. !empty($machine->password)? decrypt($machine->password) : ''
  223. );
  224. $logs[]= $environment->removePma($ssh);
  225. $ssh->disconnect();
  226. $response['logs'] = implode('<br>',$logs);
  227. });
  228. //Ajout ou modification d'élément DockerEnvironment
  229. Action::register('docker_environment_utm_create',function(&$response){
  230. global $myUser,$_,$conf;
  231. User::check_access('docker','edit');
  232. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  233. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  234. require_once(__DIR__.SLASH.'SophosUtm.class.php');
  235. Plugin::need('client/Client');
  236. if(empty($_['id'])) throw new Exception("Environnement obligatoire");
  237. $environment = DockerEnvironment::provide('id',1);
  238. if(!$environment) throw new Exception("Environnement introuvable");
  239. $machine = $environment->join('machine');
  240. $utm = new SophosUtm();
  241. $utm->host = $conf->get('docker_sophos_host');
  242. $utm->port = $conf->get('docker_sophos_port');
  243. $utm->login = $conf->get('docker_sophos_login');
  244. $utm->password = $conf->get('docker_sophos_password');
  245. $hostReference = $machine->sophosReference; // ex : REF_RevFroDockeWordpMulti
  246. if(empty($hostReference)) throw new Exception("Référence du vhost ciblé non renseignée, merci de templir dans réglages ce parametre", 1);
  247. $domains = array($environment->domain,'www.'.$environment->domain);
  248. $response = $utm->createVHost($environment->domain.' ('.($environment->ssl?'443':'80').') ',$domains,$environment->ssl?443:80,$hostReference, $environment->certificate);
  249. $logs = array('<pre>'.json_encode($response,JSON_PRETTY_PRINT).'</pre>' );
  250. $history = new History();
  251. $history->scope = 'docker';
  252. $history->uid = $environment->id;
  253. $history->comment = 'Création du host utm : '.$environment->domain;
  254. $history->type = 'utm-save';
  255. $history->save();
  256. $response['logs'] = implode('<br>',$logs);
  257. });
  258. Action::register('docker_ovh_consumerKey_generate',function(&$response){
  259. global $myUser,$_,$conf;
  260. User::check_access('docker','edit');
  261. require_once(__DIR__.SLASH.'Ovh.class.php');
  262. $ovh = new Ovh();
  263. $ovh->host = $conf->get('docker_ovh_host');
  264. $ovh->applicationKey = $conf->get('docker_ovh_application_key');
  265. $ovh->applicationSecret = $conf->get('docker_ovh_application_secret');
  266. $consumerKey= $ovh->consumerKey();
  267. //pour genrer cette clé, executer la méthode $ovh->consumerKey() puis aller manuellement sur l'url retournée et valider en mode illimité
  268. $conf->put('docker_ovh_consumer_key',$consumerKey['consumerKey']);
  269. header('location: '.$consumerKey['validationUrl']);
  270. });
  271. Action::register('docker_environment_domain_create',function(&$response){
  272. global $myUser,$_,$conf;
  273. User::check_access('docker','edit');
  274. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  275. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  276. require_once(__DIR__.SLASH.'Ovh.class.php');
  277. Plugin::need('client/Client');
  278. if(empty($_['id'])) throw new Exception("Environnement obligatoire");
  279. $environment = DockerEnvironment::provide('id',1);
  280. if(!$environment) throw new Exception("Environnement introuvable");
  281. $machine = $environment->join('machine');
  282. $ovh = new Ovh();
  283. $ovh->host = $conf->get('docker_ovh_host');
  284. //generée grace à https://eu.api.ovh.com/createApp/
  285. $ovh->applicationKey = $conf->get('docker_ovh_application_key');
  286. $ovh->applicationSecret = $conf->get('docker_ovh_application_secret');
  287. //pour genrer cette clé, executer la méthode $ovh->consumerKey() puis aller manuellement sur l'url retournée et valider en mode illimité
  288. $ovh->consumerKey= $conf->get('docker_ovh_consumer_key');
  289. $subdomain = '';
  290. $domain = $environment->domain;
  291. $infos = explode('.',$domain);
  292. if(count($infos)>2){
  293. $subdomain = array_shift($infos);
  294. $domain = implode('.',$infos);
  295. }
  296. $existingDomains = $ovh->getDomain($domain);
  297. if(isset($existingDomains['message'])) throw new Exception("Erreur de creation : ".$existingDomains['message']);
  298. //ex pour test.kiss.biz CNAME vers docker-wordpress.kiss.fr => 'kiss.byz','test','docker-wordpress.kiss.fr'
  299. $response = $ovh->setDomain($domain,$subdomain,$machine->domain);
  300. //$response = $ovh->domain();
  301. $logs = array('<pre>'.json_encode($response,JSON_PRETTY_PRINT).'</pre>' );
  302. $history = new History();
  303. $history->scope = 'docker';
  304. $history->uid = $environment->id;
  305. $history->comment = 'Création du host ovh : '.$environment->domain;
  306. $history->type = 'ovh-save';
  307. $history->save();
  308. $response['logs'] = implode('<br>',$logs);
  309. });
  310. Action::register('docker_environment_git_create',function(&$response){
  311. global $myUser,$_,$conf;
  312. User::check_access('docker','edit');
  313. require_once(__DIR__.SLASH.'DockerEnvironment.class.php');
  314. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  315. require_once(__DIR__.SLASH.'GitLab.class.php');
  316. Plugin::need('client/Client');
  317. if(empty($_['id'])) throw new Exception("Environnement obligatoire");
  318. $environment = DockerEnvironment::provide();
  319. if(!$environment) throw new Exception("Environnement introuvable");
  320. if(empty($environment->client)) throw new Exception("Vous devez spécifier un client pour créer un dépot");
  321. $client = Client::getById($environment->client);
  322. if(!$client) throw new Exception("Client introuvable");
  323. $git = new Gitlab();
  324. $git->host = $conf->get('docker_git_host');
  325. $git->token = $conf->get('docker_git_token');
  326. $groupName = mb_strtolower($client->getSlug());
  327. $groups = $git->groups();
  328. $clientGroup = null;
  329. foreach ($groups as $group) {
  330. if($group['path'] == $groupName){
  331. $clientGroup = $group;
  332. break;
  333. }
  334. }
  335. if(!isset($clientGroup)){
  336. $clientGroup = $git->groupe_save($client->label,$groupName);
  337. }
  338. $projects = $git->projects();
  339. foreach ($projects as $project) {
  340. if($project['name'] == $environment->domain && $project['namespace']['id'] == $clientGroup['id']) throw new Exception("Ce dépot existe déja");
  341. }
  342. $project = $git->project_save($clientGroup['id'],$environment->domain,$environment->domain);
  343. $environment->git = $project['ssh_url_to_repo'];
  344. $environment->save();
  345. $logs = array('<pre>'.json_encode($response,JSON_PRETTY_PRINT).'</pre>' );
  346. $history = new History();
  347. $history->scope = 'docker';
  348. $history->uid = $environment->id;
  349. $history->comment = 'Création du dépot git : '.$environment->domain;
  350. $history->type = 'git-save';
  351. $history->save();
  352. $response['logs'] = implode('<br>',$logs);
  353. });
  354. /** machine / MACHINE **/
  355. //Récuperation d'une liste de machine
  356. Action::register('docker_machine_search',function(&$response){
  357. global $_;
  358. User::check_access('docker','read');
  359. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  360. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  361. $query = 'SELECT * FROM '.DockerMachine::tableName().' WHERE 1';
  362. $data = array();
  363. //Recherche simple
  364. if(!empty($_['filters']['keyword'])){
  365. $query .= ' AND label LIKE ?';
  366. $data[] = '%'.$_['filters']['keyword'].'%';
  367. }
  368. //Recherche avancée
  369. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('label','ip','port','private_key','public_key','domain','sophosReference','description'),$query,$data);
  370. //Tri des colonnes
  371. if(isset($_['sort'])) sort_secure_query($_['sort'],array('label','ip','port','private_key','public_key','domain','sophosReference','description'),$query,$data);
  372. //Pagination
  373. $response['pagination'] = DockerMachine::paginate(20,(!empty($_['page'])?$_['page']:0),$query,$data);
  374. $machines = DockerMachine::staticQuery($query,$data,true,0);
  375. foreach($machines as $machine){
  376. $row = $machine->toArray();
  377. $publicKey = File::dir().'docker'.SLASH.'machine'.SLASH.$row['id'].SLASH.'id_rsa.pub';
  378. $row['public_key'] = file_exists($publicKey)? file_get_contents($publicKey):'';
  379. $row['description'] = html_entity_decode($row['description']);
  380. $response['rows'][] = $row;
  381. }
  382. /* Mode export */
  383. if($_['export'] == 'true'){
  384. $stream = Excel::exportArray($response['rows'],null,'Export');
  385. File::downloadStream($stream,'export-demandes-'.date('d-m-Y').'.xlsx');
  386. exit();
  387. }
  388. });
  389. //Ajout ou modification d'élément machine
  390. Action::register('docker_machine_save',function(&$response){
  391. global $_;
  392. User::check_access('docker','edit');
  393. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  394. $item = DockerMachine::provide();
  395. $item->label = $_['label'];
  396. $item->ip = $_['ip'];
  397. $item->port = $_['port'];
  398. $item->domain = $_['domain'];
  399. $item->sophosReference = $_['sophosReference'];
  400. $item->description = $_['description'];
  401. $item->save();
  402. //Ajout upload Clé privée
  403. if(!empty($_['private_key']))
  404. File::save_component('private_key', 'docker/machine/'.$item->id.'/id_rsa');
  405. //Ajout upload Clé publique
  406. if(!empty($_['public_key']))
  407. File::save_component('public_key', 'docker/machine/'.$item->id.'/id_rsa.pub');
  408. $response = $item->toArray();
  409. });
  410. //Suppression d'élement machine
  411. Action::register('docker_machine_delete',function(&$response){
  412. global $_;
  413. User::check_access('docker','delete');
  414. require_once(__DIR__.SLASH.'DockerMachine.class.php');
  415. if(empty($_['id']) || !is_numeric($_['id'])) throw new Exception("Identifiant incorrect");
  416. DockerMachine::deleteById($_['id']);
  417. });
  418. //machine : Gestion upload Clé privée
  419. Action::register('docker_machine_private_key',function(&$response){
  420. File::handle_component(array(
  421. 'namespace' => 'docker', //stockés dans file/docker/*.*
  422. 'access' => 'docker', // crud sur docker,
  423. 'size' => '1000000000', // taille max
  424. 'extension' => 'ppk,id_rsa', // extension
  425. 'storage' => 'docker/machine/{{data.id}}/id_rsa' //chemin complet vers le fichier stocké
  426. ),$response);
  427. });
  428. //machine : Gestion upload Clé publique
  429. Action::register('docker_machine_public_key',function(&$response){
  430. File::handle_component(array(
  431. 'namespace' => 'docker', //stockés dans file/docker/*.*
  432. 'access' => 'docker', // crud sur docker,
  433. 'size' => '1000000000', // taille max
  434. 'extension' => 'pub,id_rsa', // extension
  435. 'storage' => 'docker/machine/{{data.id}}/id_rsa.pub' //chemin complet vers le fichier stocké
  436. ),$response);
  437. });
  438. //Sauvegarde des configurations de Docker
  439. Action::register('docker_setting_save',function(&$response){
  440. global $_,$conf;
  441. User::check_access('docker','configure');
  442. //Si input file "multiple", possibilité de normaliser le
  443. //tableau $_FILES récupéré avec la fonction => normalize_php_files();
  444. foreach(Configuration::setting('docker') as $key=>$value){
  445. if(!is_array($value)) continue;
  446. $allowed[] = $key;
  447. }
  448. foreach ($_['fields'] as $key => $value) {
  449. if(in_array($key, $allowed))
  450. $conf->put($key,$value);
  451. }
  452. });
  453. ?>