action.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <?php
  2. /** MACHINE / MACHINE / ENVIRONNEMENT **/
  3. //Récuperation d'une liste de machine / environnement
  4. Action::register('host_machine_search',function(&$response){
  5. global $_,$myUser,$myFirm;
  6. User::check_access('host','read');
  7. Plugin::need('client/Client');
  8. require_once(__DIR__.SLASH.'Machine.class.php');
  9. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  10. $query = 'SELECT m.*,m.id as id,'.Client::joinString('cli').' FROM '.Machine::tableName().' m LEFT JOIN '.Client::tableName().' cli ON m.client = cli.id WHERE 1';
  11. $data = array();
  12. //Recherche simple
  13. if(!empty($_['filters']['keyword'])){
  14. $query .= ' AND m.label LIKE ?';
  15. $data[] = '%'.$_['filters']['keyword'].'%';
  16. }
  17. //Droits
  18. $allowedMachines = array();
  19. if(isset($myUser->rights['host_sheet'])){
  20. if(isset($myUser->rights['host_sheet'][0])){
  21. foreach($myUser->rights['host_sheet'][0] as $machine=>$rights){
  22. if(!$rights['read']) continue;
  23. $allowedMachines[]=$machine;
  24. }
  25. }
  26. if( isset($myUser->rights['host_sheet'][$myFirm->id])){
  27. foreach($myUser->rights['host_sheet'][$myFirm->id] as $machine=>$rights){
  28. if(!$rights['read']) continue;
  29. $allowedMachines[]=$machine;
  30. }
  31. }
  32. }
  33. if(!$myUser->can('host','configure')){
  34. $query .= ' AND (m.creator = ? ';
  35. $data[] = $myUser->login;
  36. if(count($allowedMachines)!=0){
  37. $query .= ' OR m.id IN ('.implode(',',array_fill(0, count($allowedMachines), '?')).')';
  38. foreach($allowedMachines as $id)
  39. $data[] = $id;
  40. }
  41. $query .= ')';
  42. }
  43. //Recherche avancée
  44. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('m.label','m.manager','m.ip','m.client','m.os','m.mac','m.ram','m.cpu','m.comment','m.type'),$query,$data);
  45. //Tri des colonnes
  46. if(isset($_['sort'])) sort_secure_query($_['sort'],array('m.label','m.manager','m.ip','m.client','m.os','m.mac','m.ram','m.cpu','m.comment','m.type'),$query,$data);
  47. //Pagination
  48. //Par défaut pour une recherche, 20 items, pour un export 5000 max
  49. $itemPerPage = !empty($_['itemPerPage']) ? $_['itemPerPage'] : 20;
  50. //force le nombre de page max a 50 coté serveur
  51. $itemPerPage = $itemPerPage>50 ? 50 : $itemPerPage;
  52. if($_['export'] == 'true') $itemPerPage = 5000;
  53. $response['pagination'] = Machine::paginate($itemPerPage,(!empty($_['page'])?$_['page']:0),$query,$data,'m');
  54. $machines = Machine::staticQuery($query,$data,true,1);
  55. $osList = Dictionary::slugToArray('host_machine_os',true);
  56. $response['rows'] = array();
  57. foreach($machines as $machine){
  58. $row = $machine->toArray();
  59. $user = User::byLogin($row['manager']);
  60. $row['manager'] = $user->toArray();
  61. $row['manager']['fullname'] = $user->fullname();
  62. $row['manager']['avatar'] = $user->getAvatar();
  63. $row['client'] = $machine->join('client')->toArray();
  64. $row['client']['label'] = htmlspecialchars_decode($row['client']['label'], ENT_QUOTES);
  65. $row['class'] = '';
  66. if( !$machine->can('edit')) $row['class'] .= ' readonly ';
  67. if(!empty($row['os'])){
  68. $row['os'] = isset($osList[$row['os']]) ? $osList[$row['os']] : new Dictionary();
  69. }else{
  70. unset($row['os']);
  71. }
  72. $row['comment'] = html_entity_decode($row['comment']);
  73. $row['type'] = Machine::types($row['type']);
  74. if($_['export'] == 'true'){
  75. $row['created'] = date('d-m-Y',$row['created']);
  76. $row['updated'] = date('d-m-Y',$row['updated']);
  77. }
  78. $response['rows'][] = $row;
  79. }
  80. /* Mode export */
  81. if($_['export'] == 'true'){
  82. if(empty($response['rows'])) $response['rows'][] = array('Vide'=>'Aucune données');
  83. $fieldsMapping = array();
  84. foreach (Machine::fields(false) as $key => $value)
  85. $fieldsMapping[$value['label']] = $key;
  86. $stream = Excel::exportArray($response['rows'],$fieldsMapping ,'Export');
  87. File::downloadStream($stream,'export-demandes-'.date('d-m-Y').'.xlsx');
  88. exit();
  89. }
  90. });
  91. Action::register('host_application_url_search',function(&$response){
  92. global $_,$myUser;
  93. User::check_access('host','read');
  94. require_once(__DIR__.SLASH.'Machine.class.php');
  95. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  96. Plugin::need('client/Client');
  97. $response['rows'] = array();
  98. foreach(MachineApplication::loadAll(array('url:!='=>''), null, null, array('*'), 2) as $application){
  99. $row = $application->toArray();
  100. $machine = $application->join('machine');
  101. if(!$machine || empty($machine->id)) continue;
  102. $row['machine'] = $machine->toArray();
  103. $client = $machine->join('client');
  104. if(!isset($response['rows'][$machine->id])){
  105. $response['rows'][$machine->id] = $machine->toArray();
  106. $response['rows'][$machine->id]['type'] = Machine::types($machine->type);
  107. $response['rows'][$machine->id]['client'] = $client->toArray();
  108. $response['rows'][$machine->id]['applications'] = array();
  109. }
  110. $response['rows'][$machine->id]['applications'][] = $row;
  111. }
  112. });
  113. Action::register('host_application_url_ping',function(&$response){
  114. global $_,$myUser;
  115. User::check_access('host','read');
  116. require_once(__DIR__.SLASH.'Machine.class.php');
  117. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  118. $application = MachineApplication::getById($_['application']);
  119. if(!empty($application->url) && filter_var($application->url, FILTER_VALIDATE_URL) !== FALSE){
  120. $ping = host_ping_url($application->url);
  121. }else{
  122. $ping = array('code' => 404,'message'=> 'Adresse vide ou malformée');
  123. }
  124. $response['ping'] = $ping;
  125. });
  126. Action::register('host_plan_search',function(&$response){
  127. global $_,$myUser;
  128. User::check_access('host','read');
  129. require_once(__DIR__.SLASH.'Machine.class.php');
  130. $response['rows'] = array();
  131. foreach(Machine::loadAll(array('ip:LIKE'=>$_['root'].'.%')) as $machine){
  132. $row = $machine->toArray();
  133. $row['type'] = Machine::types($row['type']);
  134. $response['rows'][] = $row;
  135. }
  136. });
  137. //Ajout ou modification d'élément machine / environnement
  138. Action::register('host_machine_save',function(&$response){
  139. global $_,$myUser,$myFirm;
  140. User::check_access('host','edit');
  141. require_once(__DIR__.SLASH.'Machine.class.php');
  142. if(!$myUser->can('host','edit')) return;
  143. //Check champs dynamiques
  144. if($myFirm->has_plugin('fr.core.dynamicform')){
  145. Plugin::need('dynamicform/DynamicForm');
  146. $dynamicFields = Dynamicform::check_required('host-sheet',array(),$_);
  147. }
  148. $item = Machine::provide();
  149. if(!empty($item->id) && !$item->can('edit') ) return;
  150. $oldItem = clone $item;
  151. $item->label = $_['label'];
  152. $item->manager = $_['manager'];
  153. $item->ip = $_['ip'];
  154. if(!empty($_['os']) && is_numeric($_['os'])) $item->os = $_['os'];
  155. $item->mac = $_['mac'];
  156. if(is_numeric($_['ram'])) $item->ram = $_['ram'];
  157. if(is_numeric($_['cpu'])) $item->cpu = $_['cpu'];
  158. $item->comment = $_['comment'];
  159. $item->type = $_['type'];
  160. $item->save();
  161. History::entityChange('host_machine',$oldItem,$item);
  162. //save champs dynamiques
  163. if($myFirm->has_plugin('fr.core.dynamicform')){
  164. Plugin::need('dynamicform/DynamicForm');
  165. echo Dynamicform::record('host-sheet',array(
  166. 'scope'=>'host',
  167. 'uid'=>$item->id,
  168. 'fields'=>$dynamicFields
  169. ),$_);
  170. }
  171. $response = $item->toArray();
  172. });
  173. //Récuperation ou edition d'élément machine / environnement
  174. Action::register('host_machine_edit',function(&$response){
  175. global $_,$myUser,$myFirm;
  176. User::check_access('host','read');
  177. require_once(__DIR__.SLASH.'Machine.class.php');
  178. $machine = Machine::provide();
  179. if( !$machine->can('read')) throw new Exception("Vous n'avez pas la permission de voir cet hébergement");
  180. ob_start();
  181. require_once(__DIR__.SLASH.'page.sheet.machine.php');
  182. $response['html'] = ob_get_clean();
  183. $response['id'] = $machine->id;
  184. if(!$machine->can('edit')) $response['readonly'] = true;
  185. });
  186. //Suppression d'élement machine / environnement
  187. Action::register('host_machine_delete',function(&$response){
  188. global $_,$myUser;
  189. User::check_access('host','delete');
  190. require_once(__DIR__.SLASH.'Machine.class.php');
  191. $machine = Machine::getById($_['id']);
  192. if(!$machine->can('delete')) throw new Exception("Vous n'avez pas la permission de supprimer cet hébergement");
  193. if(empty($_['id']) || !is_numeric($_['id'])) throw new Exception("Identifiant incorrect");
  194. $machine = Machine::getById($_['id']);
  195. $machine->remove();
  196. });
  197. //Suppression d'élement machine / environnement
  198. Action::register('host_machine_open_with',function(&$response){
  199. global $_;
  200. User::check_access('host','read');
  201. require_once(__DIR__.SLASH.'Machine.class.php');
  202. if(empty($_['id']) || !is_numeric($_['id'])) throw new Exception("Identifiant incorrect");
  203. $machine = Machine::provide();
  204. $tool = $_['tool'];
  205. $json = array(
  206. 'action' =>$tool.'_open',
  207. 'ip' => $machine->ip
  208. );
  209. $json = json_encode($json);
  210. header('location: dev://'.base64_encode($json));
  211. });
  212. /* permissions
  213. Action::register('host_permission_save',function(&$response){
  214. global $myUser,$_;
  215. if(!$myUser->can('host','edit')) throw new Exception("Permissions insuffisantes",403);
  216. if(!Right::can('host','edit')) throw new Exception("Permissions insuffisantes",403);
  217. $permission = Right::form();
  218. $permission->scope = 'host';
  219. $permission->save();
  220. });
  221. //Suppression d'élement permission
  222. Action::register('host_permission_delete',function(&$response){
  223. $permission = Right::getById($_['id']);
  224. if($permission->scope != 'host') throw new Exception("Erreur de routage des permissions");
  225. if(!Right::can('host','delete')) throw new Exception("Permissions insuffisantes",403);
  226. Right::deleteById($permission->id);
  227. });
  228. */
  229. //Sauvegarde des configurations de Hébergement
  230. Action::register('host_setting_save',function(&$response){
  231. global $_,$conf;
  232. User::check_access('host','configure');
  233. //Si input file "multiple", possibilité de normaliser le
  234. //tableau $_FILES récupéré avec la fonction => normalize_php_files();
  235. foreach(Configuration::setting('host') as $key=>$value){
  236. if(!is_array($value)) continue;
  237. $allowed[] = $key;
  238. }
  239. foreach ($_['fields'] as $key => $value) {
  240. if(in_array($key, $allowed))
  241. $conf->put($key,$value);
  242. }
  243. });
  244. /** MACHINEAPPLICATION / APPLICATION SUR LA MACHINE **/
  245. //Récuperation d'une liste de application sur la machine
  246. Action::register('host_machine_application_search',function(&$response){
  247. global $_,$myUser;
  248. User::check_access('host','read');
  249. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  250. require_once(__DIR__.SLASH.'Machine.class.php');
  251. if(isset($_['filters']['advanced'])){
  252. foreach ($_['filters']['advanced'] as $key => $value) {
  253. if($value['column']!='main.machine') continue;
  254. $machine = Machine::getById($value['value'][0]);
  255. if( !$machine->can('read')) throw new Exception("Vous n'avez pas la permission de visualiser cet hébergement");
  256. }
  257. }
  258. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  259. $query = 'SELECT main.*,main.id as id, '.Machine::joinString('Machine').' FROM '.MachineApplication::tableName().' main LEFT JOIN '.Machine::tableName().' Machine ON main.machine=Machine.id WHERE 1';
  260. $data = array();
  261. //Recherche simple
  262. if(!empty($_['filters']['keyword'])){
  263. $query .= ' AND main.label LIKE ?';
  264. $data[] = '%'.$_['filters']['keyword'].'%';
  265. }
  266. if(!empty($_['machine'])){
  267. $query .= ' AND main.machine = ?';
  268. $data[] = $_['machine'];
  269. }
  270. //Recherche avancée
  271. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('main.label','main.version','main.url','main.monitored','main.machine'),$query,$data);
  272. //Tri des colonnes
  273. if(isset($_['sort'])) sort_secure_query($_['sort'],array('main.label','main.version','main.url','main.monitored','main.machine'),$query,$data);
  274. //Pagination
  275. //Par défaut pour une recherche, 20 items, pour un export 5000 max
  276. $itemPerPage = !empty($_['itemPerPage']) ? $_['itemPerPage'] : 20;
  277. //force le nombre de page max a 50 coté serveur
  278. $itemPerPage = $itemPerPage>50 ? 50 : $itemPerPage;
  279. if($_['export'] == 'true') $itemPerPage = 5000;
  280. $response['pagination'] = MachineApplication::paginate($itemPerPage,(!empty($_['page'])?$_['page']:0),$query,$data,'main');
  281. $machineapplications = MachineApplication::staticQuery($query,$data,true,1);
  282. $response['rows'] = array();
  283. foreach($machineapplications as $machineapplication){
  284. $row = $machineapplication->toArray();
  285. $row['machine'] = $machineapplication->join('machine')->toArray();
  286. if($row['monitored'] =='0') unset($row['monitored']);
  287. if($_['export'] == 'true'){
  288. $row['created'] = date('d-m-Y',$row['created']);
  289. $row['updated'] = date('d-m-Y',$row['updated']);
  290. }
  291. $response['rows'][] = $row;
  292. }
  293. /* Mode export */
  294. if($_['export'] == 'true'){
  295. if(empty($response['rows'])) $response['rows'][] = array('Vide'=>'Aucune données');
  296. $fieldsMapping = array();
  297. foreach (MachineApplication::fields(false) as $key => $value)
  298. $fieldsMapping[$value['label']] = $key;
  299. $stream = Excel::exportArray($response['rows'],$fieldsMapping ,'Export');
  300. File::downloadStream($stream,'export-demandes-'.date('d-m-Y').'.xlsx');
  301. exit();
  302. }
  303. });
  304. //Ajout ou modification d'élément application sur la machine
  305. Action::register('host_machine_application_save',function(&$response){
  306. global $_,$myUser;
  307. User::check_access('host','edit');
  308. require_once(__DIR__.SLASH.'Machine.class.php');
  309. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  310. $machine = Machine::getById($_['machine']);
  311. if( !$machine->can('edit')) throw new Exception("Vous n'avez pas la permission de modifier cet hébergement");
  312. $item = MachineApplication::provide();
  313. $oldItem = clone $item;
  314. $item->label = $_['label'];
  315. if(is_numeric($_['version'])) $item->version = $_['version'];
  316. $item->url = $_['url'];
  317. $item->monitored = $_['monitored'];
  318. $item->machine = $_['machine'];
  319. $item->save();
  320. History::entityChange('host_application',$oldItem,$item);
  321. $response = $item->toArray();
  322. });
  323. //Suppression d'élement application sur la machine
  324. Action::register('host_machine_application_delete',function(&$response){
  325. global $_,$myUser;
  326. User::check_access('host','delete');
  327. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  328. require_once(__DIR__.SLASH.'Machine.class.php');
  329. if(empty($_['id']) || !is_numeric($_['id'])) throw new Exception("Identifiant incorrect");
  330. $application = MachineApplication::getById($_['id'],1);
  331. $machine = $application->join('machine');
  332. if(!$machine->can('delete')) throw new Exception("Vous n'avez pas la permission de modifier cet hébergement");
  333. $application = MachineApplication::getById($_['id']);
  334. $application->remove();
  335. });
  336. //Récuperation ou edition d'élément application
  337. Action::register('host_machine_application_edit',function(&$response){
  338. global $_,$myUser;
  339. User::check_access('host','read');
  340. require_once(__DIR__.SLASH.'Machine.class.php');
  341. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  342. $application = MachineApplication::provide('id',1);
  343. $machine = !empty($_['machine']) && $application->id==0 ? Machine::getById($_['machine']) : $application->join('machine');
  344. if( !$machine->can('read') ) throw new Exception("Vous n'avez pas la permission de visualiser cet hébergement");
  345. ob_start();
  346. require_once(__DIR__.SLASH.'page.sheet.machine.application.php');
  347. $response['html'] = ob_get_clean();
  348. });
  349. //MachineApplication : Gestion upload Certificat SSL
  350. Action::register('host_machine_application_certificate',function(&$response){
  351. File::handle_component(array(
  352. 'namespace' => 'host', //stockés dans file/host/*.*
  353. 'access' => 'host', // crud sur host,
  354. 'size' => '1000000000', // taille max
  355. 'storage' => 'host/machineapplication/{{data.id}}/certificate/*' //chemin complet vers le fichier stocké
  356. ),$response);
  357. });
  358. /** APPLICATIONACCESS / ACCèS à L'APPLICATION **/
  359. Action::register('host_application_access_search_page',function(&$response){
  360. global $_,$myUser;
  361. User::check_access('host','read');
  362. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  363. $application = MachineApplication::getById($_['application']);
  364. ob_start();
  365. require_once(__DIR__.SLASH.'page.list.application.access.php');
  366. $response['html'] = ob_get_clean();
  367. });
  368. Action::register('host_application_access_search',function(&$response){
  369. global $_,$myUser;
  370. User::check_access('host','read');
  371. require_once(__DIR__.SLASH.'ApplicationAccess.class.php');
  372. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  373. require_once(__DIR__.SLASH.'Machine.class.php');
  374. $response['rows'] = array();
  375. if(isset($_['filters']['advanced'])){
  376. foreach ($_['filters']['advanced'] as $key => $value) {
  377. if($value['column']!='main.application') continue;
  378. $application = MachineApplication::getById($value['value'][0],1);
  379. $machine = $application->join('machine');
  380. if( !$machine->can('read')) throw new Exception("Vous n'avez pas la permission de visualiser cet hébergement");
  381. }
  382. }
  383. if(!isset($application)) return $response;
  384. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  385. $query = 'SELECT main.* FROM '.ApplicationAccess::tableName().' main WHERE 1';
  386. $data = array();
  387. //Recherche simple
  388. if(!empty($_['filters']['keyword'])){
  389. $query .= ' AND label LIKE ?';
  390. $data[] = '%'.$_['filters']['keyword'].'%';
  391. }
  392. //Recherche avancée
  393. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('main.label','main.login','main.password','main.application'),$query,$data);
  394. //Tri des colonnes
  395. if(isset($_['sort'])) sort_secure_query($_['sort'],array('main.label','main.login','main.password','main.application'),$query,$data);
  396. //Pagination
  397. //Par défaut pour une recherche, 20 items, pour un export 5000 max
  398. $itemPerPage = !empty($_['itemPerPage']) ? $_['itemPerPage'] : 20;
  399. //force le nombre de page max a 50 coté serveur
  400. $itemPerPage = $itemPerPage>50 ? 50 : $itemPerPage;
  401. if($_['export'] == 'true') $itemPerPage = 5000;
  402. $response['pagination'] = ApplicationAccess::paginate($itemPerPage,(!empty($_['page'])?$_['page']:0),$query,$data,'main');
  403. $applicationaccesss = ApplicationAccess::staticQuery($query,$data,true,0);
  404. foreach($applicationaccesss as $applicationaccess){
  405. $row = $applicationaccess->toArray();
  406. $row['password'] = htmlspecialchars_decode(decrypt($row['password']));
  407. $row['login'] = htmlspecialchars_decode(decrypt($row['login']));
  408. if($_['export'] == 'true'){
  409. $row['created'] = date('d-m-Y',$row['created']);
  410. $row['updated'] = date('d-m-Y',$row['updated']);
  411. }
  412. $response['rows'][] = $row;
  413. }
  414. /* Mode export */
  415. if($_['export'] == 'true'){
  416. $fieldsMapping = array();
  417. foreach (ApplicationAccess::fields(false) as $key => $value)
  418. $fieldsMapping[$value['label']] = $key;
  419. $stream = Excel::exportArray($response['rows'],$fieldsMapping ,'Export');
  420. File::downloadStream($stream,'export-demandes-'.date('d-m-Y').'.xlsx');
  421. exit();
  422. }
  423. });
  424. //Ajout ou modification d'élément accès à l'application
  425. Action::register('host_application_access_save',function(&$response){
  426. global $_,$myUser;
  427. User::check_access('host','edit');
  428. require_once(__DIR__.SLASH.'ApplicationAccess.class.php');
  429. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  430. require_once(__DIR__.SLASH.'Machine.class.php');
  431. $item = ApplicationAccess::provide('id',1);
  432. $application = MachineApplication::getById($_['application'],1);
  433. $machine = $application->join('machine');
  434. if( !$machine->can('edit')) throw new Exception("Vous n'avez pas la permission de modifier cet hébergement");
  435. $item->label = $_['label'];
  436. $item->login = encrypt($_['login']);
  437. $item->password = encrypt($_['password']);
  438. $item->application = $_['application'];
  439. $item->save();
  440. $response = $item->toArray();
  441. });
  442. //Récuperation ou edition d'élément accès à l'application
  443. Action::register('host_application_access_edit',function(&$response){
  444. global $_,$myUser;
  445. User::check_access('host','edit');
  446. require_once(__DIR__.SLASH.'ApplicationAccess.class.php');
  447. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  448. require_once(__DIR__.SLASH.'Machine.class.php');
  449. $access = ApplicationAccess::getById($_['id'],2);
  450. $application = $access->join('application');
  451. $machine = $application->join('machine');
  452. if( !$machine->can('read')) throw new Exception("Vous n'avez pas la permission de visualiser cet hébergement");
  453. $response = $access->toArray();
  454. $response['login'] = decrypt($response['login']);
  455. $response['password'] = decrypt($response['password']);
  456. });
  457. //Suppression d'élement accès à l'application
  458. Action::register('host_application_access_delete',function(&$response){
  459. global $_,$myUser;
  460. require_once(__DIR__.SLASH.'ApplicationAccess.class.php');
  461. require_once(__DIR__.SLASH.'MachineApplication.class.php');
  462. require_once(__DIR__.SLASH.'Machine.class.php');
  463. User::check_access('host','delete');
  464. $access = ApplicationAccess::getById($_['id'],2);
  465. $application = $access->join('application');
  466. $machine = $application->join('machine');
  467. if( !$machine->can('edit')) throw new Exception("Vous n'avez pas la permission de supprimer des élements de cet hébergement");
  468. require_once(__DIR__.SLASH.'ApplicationAccess.class.php');
  469. if(empty($_['id']) || !is_numeric($_['id'])) throw new Exception("Identifiant incorrect");
  470. ApplicationAccess::deleteById($_['id']);
  471. });
  472. ?>