1<?php 2 3/** 4 * 5 * bareos-webui - Bareos Web-Frontend 6 * 7 * @link https://github.com/bareos/bareos for the canonical source repository 8 * @copyright Copyright (c) 2013-2017 Bareos GmbH & Co. KG (http://www.bareos.org/) 9 * @license GNU Affero General Public License (http://www.gnu.org/licenses/) 10 * 11 * This program is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Affero General Public License as published by 13 * the Free Software Foundation, either version 3 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Affero General Public License for more details. 20 * 21 * You should have received a copy of the GNU Affero General Public License 22 * along with this program. If not, see <http://www.gnu.org/licenses/>. 23 * 24 */ 25 26namespace Director\Model; 27 28class DirectorModel 29{ 30 /** 31 * Get Available Commands 32 * 33 * @param $bsock 34 * 35 * @return array 36 */ 37 public function getAvailableCommands(&$bsock=null) 38 { 39 if(isset($bsock)) { 40 $cmd = '.help'; 41 $result = $bsock->send_command($cmd, 2); 42 $messages = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); 43 return $messages['result']; 44 } 45 else { 46 throw new \Exception('Missing argument.'); 47 } 48 } 49 50 /** 51 * Get Director Version 52 * 53 * @param $bsock 54 * 55 * @return array 56 */ 57 public function getDirectorVersion(&$bsock=null) 58 { 59 if(isset($bsock)) { 60 $cmd = 'version'; 61 $result = $bsock->send_command($cmd, 2); 62 $version = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); 63 return $version['result']['version']; 64 } 65 else { 66 throw new \Exception('Missing argument.'); 67 } 68 } 69 70 /** 71 * Get Director Status 72 * 73 * @param $bsock 74 * 75 * @return string 76 */ 77 public function getDirectorStatus(&$bsock=null) 78 { 79 if(isset($bsock)) { 80 $cmd = 'status director'; 81 $result = $bsock->send_command($cmd, 0); 82 return $result; 83 } 84 else { 85 throw new \Exception('Missing argument.'); 86 } 87 } 88 89 /** 90 * Get Director Messages 91 * 92 * @param $bsock 93 * @param $limit 94 * @param $offset 95 * @param $reverse 96 * 97 * @return array 98 */ 99 public function getDirectorMessages(&$bsock=null, $limit=null, $offset=null, $reverse=null) 100 { 101 if(isset($bsock, $limit)) { 102 if($reverse && $offset == null) { 103 $cmd = 'list log limit='.$limit.' reverse'; 104 } 105 else if($reverse && $offset != null) { 106 $cmd = 'list log limit='.$limit.' offset='.$offset.' reverse'; 107 } 108 else if(!$reverse && $offset != null) { 109 $cmd = 'list log limit='.$limit.' offset='.$offset; 110 } 111 else if(!$reverse && $offset == null) { 112 $cmd = 'list log limit='.$limit; 113 } 114 $result = $bsock->send_command($cmd, 2); 115 $messages = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); 116 return $messages['result']['log']; 117 } 118 else { 119 throw new \Exception('Missing argument.'); 120 } 121 } 122 123 /** 124 * Send Director Command 125 * 126 * @param $bsock 127 * @param $cmd 128 * 129 * @return string 130 */ 131 public function sendDirectorCommand(&$bsock=null, $cmd=null) 132 { 133 if(isset($bsock, $cmd)) { 134 $result = $bsock->send_command($cmd, 0); 135 return $result; 136 } 137 else { 138 throw new \Exception('Missing argument.'); 139 } 140 } 141} 142