| Total Complexity | 20 |
| Total Lines | 193 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class ServersController extends BaseController |
||
| 15 | { |
||
| 16 | public $controller_name = 'ServersController'; |
||
| 17 | public $table_place = 'servers-servers'; |
||
| 18 | public $section = 'servers'; |
||
| 19 | public $query = ''; |
||
| 20 | public $subject = ''; |
||
| 21 | public $start_time; |
||
| 22 | public $duration; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Default method to render the controller according to the action parameter. |
||
| 26 | */ |
||
| 27 | public function render() |
||
| 28 | { |
||
| 29 | $lang = $this->lang; |
||
| 30 | |||
| 31 | $action = $this->action; |
||
| 32 | |||
| 33 | if ('tree' == $action) { |
||
| 34 | return $this->doTree(); |
||
| 35 | } |
||
| 36 | |||
| 37 | $msg = $this->msg; |
||
| 38 | |||
| 39 | $server_html = $this->printHeader($this->lang['strservers'], null, false); |
||
| 40 | $server_html .= $this->printBody(false); |
||
| 41 | $server_html .= $this->printTrail('root', false); |
||
| 42 | |||
| 43 | ob_start(); |
||
| 44 | switch ($action) { |
||
| 45 | case 'logout': |
||
| 46 | $this->doLogout(); |
||
| 47 | |||
| 48 | break; |
||
| 49 | default: |
||
| 50 | $this->doDefault($msg); |
||
| 51 | |||
| 52 | break; |
||
| 53 | } |
||
| 54 | |||
| 55 | $server_html .= ob_get_clean(); |
||
| 56 | |||
| 57 | $server_html .= $this->printFooter(false); |
||
| 58 | |||
| 59 | if (null === $this->container->requestobj->getAttribute('route')) { |
||
| 60 | echo $server_html; |
||
| 61 | } else { |
||
| 62 | $body = $this->container->responseobj->getBody(); |
||
| 63 | $body->write($server_html); |
||
| 64 | |||
| 65 | return $this->container->responseobj; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | public function doDefault($msg = '') |
||
|
1 ignored issue
–
show
|
|||
| 70 | { |
||
| 71 | $lang = $this->lang; |
||
| 72 | |||
| 73 | $this->printTabs('root', 'servers'); |
||
| 74 | $this->printMsg($msg); |
||
| 75 | $group = isset($_GET['group']) ? $_GET['group'] : false; |
||
| 76 | |||
| 77 | $groups = $this->misc->getServersGroups(true, $group); |
||
| 78 | $columns = [ |
||
| 79 | 'group' => [ |
||
| 80 | 'title' => $lang['strgroup'], |
||
| 81 | 'field' => Decorator::field('desc'), |
||
| 82 | 'url' => 'servers.php?', |
||
| 83 | 'vars' => ['group' => 'id'], |
||
| 84 | ], |
||
| 85 | ]; |
||
| 86 | $actions = []; |
||
| 87 | if ((false !== $group) && (isset($this->conf['srv_groups'][$group])) && ($groups->recordCount() > 0)) { |
||
| 88 | $this->printTitle(sprintf($lang['strgroupgroups'], htmlentities($this->conf['srv_groups'][$group]['desc'], ENT_QUOTES, 'UTF-8'))); |
||
| 89 | } |
||
| 90 | $this->printTable($groups, $columns, $actions, $this->table_place); |
||
| 91 | $servers = $this->misc->getServers(true, $group); |
||
| 92 | |||
| 93 | $columns = [ |
||
| 94 | 'server' => [ |
||
| 95 | 'title' => $lang['strserver'], |
||
| 96 | 'field' => Decorator::field('desc'), |
||
| 97 | 'url' => \SUBFOLDER . '/redirect/server?', |
||
| 98 | 'vars' => ['server' => 'id'], |
||
| 99 | ], |
||
| 100 | 'host' => [ |
||
| 101 | 'title' => $lang['strhost'], |
||
| 102 | 'field' => Decorator::field('host'), |
||
| 103 | ], |
||
| 104 | 'port' => [ |
||
| 105 | 'title' => $lang['strport'], |
||
| 106 | 'field' => Decorator::field('port'), |
||
| 107 | ], |
||
| 108 | 'username' => [ |
||
| 109 | 'title' => $lang['strusername'], |
||
| 110 | 'field' => Decorator::field('username'), |
||
| 111 | ], |
||
| 112 | 'actions' => [ |
||
| 113 | 'title' => $lang['stractions'], |
||
| 114 | ], |
||
| 115 | ]; |
||
| 116 | |||
| 117 | $actions = [ |
||
| 118 | 'logout' => [ |
||
| 119 | 'content' => $lang['strlogout'], |
||
| 120 | 'attr' => [ |
||
| 121 | 'href' => [ |
||
| 122 | 'url' => 'servers.php', |
||
| 123 | 'urlvars' => [ |
||
| 124 | 'action' => 'logout', |
||
| 125 | 'logoutServer' => Decorator::field('id'), |
||
| 126 | ], |
||
| 127 | ], |
||
| 128 | ], |
||
| 129 | ], |
||
| 130 | ]; |
||
| 131 | |||
| 132 | $svPre = function (&$rowdata) use ($actions) { |
||
| 133 | $actions['logout']['disable'] = empty($rowdata->fields['username']); |
||
| 134 | |||
| 135 | return $actions; |
||
| 136 | }; |
||
| 137 | |||
| 138 | if ((false !== $group) and isset($this->conf['srv_groups'][$group])) { |
||
| 139 | $this->printTitle(sprintf($lang['strgroupservers'], htmlentities($this->conf['srv_groups'][$group]['desc'], ENT_QUOTES, 'UTF-8')), null); |
||
| 140 | $actions['logout']['attr']['href']['urlvars']['group'] = $group; |
||
| 141 | } |
||
| 142 | echo $this->printTable($servers, $columns, $actions, $this->table_place, $lang['strnoobjects'], $svPre); |
||
| 143 | } |
||
| 144 | |||
| 145 | public function doTree() |
||
|
1 ignored issue
–
show
|
|||
| 146 | { |
||
| 147 | $nodes = []; |
||
| 148 | $group_id = isset($_GET['group']) ? $_GET['group'] : false; |
||
| 149 | |||
| 150 | // root with srv_groups |
||
| 151 | if (isset($this->conf['srv_groups']) and count($this->conf['srv_groups']) > 0 |
||
| 152 | and false === $group_id) { |
||
|
1 ignored issue
–
show
|
|||
| 153 | $nodes = $this->misc->getServersGroups(true); |
||
| 154 | } elseif (isset($this->conf['srv_groups']) and false !== $group_id) { |
||
| 155 | // group subtree |
||
| 156 | if ('all' !== $group_id) { |
||
| 157 | $nodes = $this->misc->getServersGroups(false, $group_id); |
||
| 158 | } |
||
| 159 | |||
| 160 | $nodes = array_merge($nodes, $this->misc->getServers(false, $group_id)); |
||
| 161 | $nodes = new \PHPPgAdmin\ArrayRecordSet($nodes); |
||
| 162 | } else { |
||
| 163 | // no srv_group |
||
| 164 | $nodes = $this->misc->getServers(true, false); |
||
| 165 | } |
||
| 166 | |||
| 167 | $reqvars = $this->misc->getRequestVars('server'); |
||
| 168 | |||
| 169 | //$this->prtrace($reqvars); |
||
| 170 | |||
| 171 | $attrs = [ |
||
| 172 | 'text' => Decorator::field('desc'), |
||
| 173 | // Show different icons for logged in/out |
||
| 174 | 'icon' => Decorator::field('icon'), |
||
| 175 | 'toolTip' => Decorator::field('id'), |
||
| 176 | 'action' => Decorator::field('action'), |
||
| 177 | // Only create a branch url if the user has |
||
| 178 | // logged into the server. |
||
| 179 | 'branch' => Decorator::field('branch'), |
||
| 180 | ]; |
||
| 181 | /*$this->prtrace([ |
||
| 182 | 'nodes' => $nodes, |
||
| 183 | 'attrs' => $attrs, |
||
| 184 | 'section' => $this->section, |
||
| 185 | ]);*/ |
||
| 186 | return $this->printTree($nodes, $attrs, $this->section); |
||
| 187 | } |
||
| 188 | |||
| 189 | public function doLogout() |
||
| 207 | } |
||
| 208 | } |
||
| 209 |