Пример #1
0
 public function exec($params)
 {
     $data = array();
     $module = isset($params['module']) ? $params['module'] : 'servers';
     $view = isset($params['view']) ? $params['view'] : 'index';
     $data['module'] = $module;
     $data['view'] = $view;
     $data['title'] = '';
     $data['uri'] = '/' . $module . '/' . $view;
     $data['uriArray'] = array('/', $module, $view);
     switch ($module) {
         case 'domains':
             $domains = R::find('domain');
             $data['title'] = 'Domains';
             $data['domains'] = $domains;
             $data['template'] = 'design/desktop/templates/domains.tpl.php';
             break;
         case 'accounts':
             $data['title'] = 'Domains to accounts';
             $data['domains'] = getUnrelatedMainDomains();
             $data['template'] = 'design/desktop/templates/accounts.tpl.php';
             break;
         case 'servers':
             $data['title'] = 'Servers';
             $data['hasFieldSelector'] = true;
             $data['avaliableFields'] = getAvaliableFields('servers');
             $data['enabledFields'] = getEnabledFields('servers');
             $data['serversGrouped'] = getGroupedByType();
             $data['template'] = 'design/desktop/templates/servers_list.tpl.php';
             break;
         case 'search':
             $data['title'] = 'Search';
             $data['template'] = 'design/desktop/templates/search.tpl.php';
             break;
         case 'cleanup':
             $data['title'] = 'Cleanup';
             $data['template'] = 'design/desktop/templates/cleanup.tpl.php';
             break;
         default:
             $data['title'] = '404 Page not found';
             $data['template'] = 'design/desktop/templates/error.tpl.php';
             $data['error'] = array('code' => '404', 'msg' => 'Page not found');
             break;
     }
     mvc\render('design/desktop/templates/header.tpl.php', $data);
     mvc\render('design/desktop/templates/top_menu.tpl.php', $data);
     if (isset($data['hasFieldSelector']) && $data['hasFieldSelector']) {
         mvc\render('design/desktop/templates/field_selector.tpl.php', $data);
     }
     if (mvc\retrieve('debug')) {
         $data['values']['params'] = $params;
         mvc\render('design/desktop/templates/debug.tpl.php', $data);
     }
     mvc\render($data['template'], $data);
     mvc\render('design/desktop/templates/footer.tpl.php', $data);
 }
Пример #2
0
 public function exec($params)
 {
     register_shutdown_function(array($this, 'outPutJson'));
     $this->setJsonMsg(array('msg' => 'No data returned'), self::ERROR);
     switch ($params['action']) {
         case 'accountsToDomains':
             if (empty($_GET['account_id']) || empty($_GET['domains'])) {
                 $this->setJsonMsg(array('msg' => 'Some fields are missing'), self::ERROR);
             } else {
                 $owner = false;
                 $owner = R::findOne('owner', 'account_id=?', array($_GET['account_id']));
                 if (!$owner instanceof RedBean_OODBBean) {
                     $owner = R::dispense("owner");
                     $owner->name = $_GET['account_name'];
                     $owner->account_id = $_GET['account_id'];
                     $id = R::store($owner);
                 }
                 foreach ($_GET['domains'] as $id) {
                     $domain = R::load('domain', $id);
                     R::associate($owner, $domain);
                     /*$otherDomainsDefinedInVhost = R::find("domain","vhost_id = ?",array($domain->vhost_id));
                       foreach ($otherDomainsDefinedInVhost as $otherDomain) 
                       {
                         if ( in_array( $otherDomain->id, $_GET['domains'] ) )
                         {
                           continue;
                         }
                         R::associate( $owner, $otherDomain );
                       }*/
                 }
                 $domains = getUnrelatedMainDomains();
                 $html = '';
                 foreach ($domains as $domain) {
                     $html .= '<option value="' . $domain->id . '">' . $domain->name . '</option>';
                 }
                 $this->setJsonMsg(array('msg' => $owner->name . ' set as owner of domains', 'content' => $html));
             }
             break;
         case 'getDomains':
             // TODO: use search
             $serverID = (int) $_GET['serverID'];
             $server = R::load("server", $serverID);
             $linker = mvc\retrieve('beanLinker');
             $vhostEntries = R::find('vhostEntry', 'server_id = ?', array($server->id));
             if (!empty($vhostEntries)) {
                 $html = '<h1>Domains in vhosts on server (excluding www aliases)</h1><div class="domains list">';
                 foreach ($vhostEntries as $entry) {
                     $domain = R::load('domain', $entry->domain_id);
                     // ignore www aliases
                     if ($domain->sub == 'www' && $domain->type == 'alias') {
                         continue;
                     }
                     $html .= '<div class="domain">
           <div class="status">' . (!$entry->is_valid ? '<img src="/design/desktop/images/error.png" title="' . $entry->note . '" class="icon"/>' : '') . '</div>
           <div class="name' . ($domain->is_active ? '' : ' inactive') . '">' . ($entry->type == 'alias' ? '- ' : '') . '<a href="http://' . $domain->getFQDN() . '">' . $domain->name . '</a></div>
           <br class="cls">
           </div>';
                 }
                 $html .= '</div>';
                 $this->setJsonMsg(array('msg' => 'ok', 'content' => $html));
             } else {
                 $this->setJsonMsg(array('msg' => 'No domains found on server'), self::WARNING);
             }
             break;
         case 'search':
             if (isset($_GET['query']) && isset($_GET['type'])) {
                 $type = $_GET['type'];
                 $query = $_GET['query'];
                 $query = $query . '%';
                 if (isset($_GET['wildcards']) && $_GET['wildcards'] == 'both') {
                     $query = '%' . $query;
                 }
                 $handler = new searchHandler($type);
                 $json = $handler->query($query);
                 $this->setJsonData($json);
             } else {
                 $this->setJsonMsg(array('msg' => 'Missing paramaters'), self::ERROR);
             }
             break;
         case 'missingDomRelation':
             $servers = R::find("server", "type = ?", array('xenu'));
             $content = array();
             foreach ($servers as $server) {
                 $dom0 = false;
                 $dom0 = R::getParent($server);
                 if (!$dom0 instanceof RedBean_OODBBean || empty($dom0->name)) {
                     $content[] = $server->name;
                 }
             }
             if (empty($content)) {
                 $this->setJsonMsg(array('msg' => 'No servers found', 'msg_type' => self::OK), self::ERROR);
             } else {
                 $this->setJsonMsg(array('msg' => 'ok', 'content' => implode('<br>', $content)));
             }
             break;
         case 'missingFieldsOnServer':
             $servers = R::find("server");
             $content = array();
             $allowedMissing = array('comment');
             foreach ($servers as $server) {
                 $missingFields = array();
                 foreach ($server->getIterator() as $key => $value) {
                     if (in_array($key, $allowedMissing)) {
                         continue;
                     }
                     if (empty($value) || is_null($value)) {
                         $missingFields[] = $key;
                     }
                 }
                 if (!empty($missingFields)) {
                     $content[] = 'Id: ' . $server->id . (!empty($server->name) ? ' (' . $server->name . ')' : '') . ' is missing: ' . implode(', ', $missingFields);
                 }
             }
             $this->setJsonMsg(array('msg' => 'ok', 'content' => implode('<br>', $content)));
             break;
         case 'inactiveDomains':
             $domains = R::find("domain", "is_active=?", array(false));
             $content = array();
             foreach ($domains as $domain) {
                 $server = R::load("server", $domain->server_id);
                 $content[] = $domain->name . ' on ' . $server->name . ' last updated ' . date('d-m-Y H:i:s', $domain->updated);
             }
             if (empty($content)) {
                 $this->setJsonMsg(array('msg' => 'No inactive domains found', 'msg_type' => self::OK), self::ERROR);
             } else {
                 $this->setJsonMsg(array('msg' => 'ok', 'content' => implode('<br>', $content)));
             }
             break;
         case 'notUpdatedRecently':
             $content = array();
             $type = $params['segments'][0][0];
             $ts = mktime();
             switch ($type) {
                 case 'domains':
                     $results = R::find("domain", "updated < ?", array($ts));
                     foreach ($results as $domain) {
                         $content[] = $domain->getFQDN();
                     }
                     break;
                 case 'servers':
                     $results = R::find("server", "updated < ?", array($ts));
                     foreach ($results as $result) {
                         $content[] = $result->name;
                     }
                     break;
             }
             if (empty($content)) {
                 $this->setJsonMsg(array('msg' => 'No ' . $type . ' not updated the last 3 days', 'msg_type' => self::OK), self::ERROR);
             } else {
                 $this->setJsonMsg(array('msg' => 'ok', 'content' => implode('<br>', $content)));
             }
             break;
         case 'domainsWithForeignDNS':
             $dnsServers = mvc\retrieve('config')->dnsServers;
             if (is_array($dnsServers)) {
                 $content = array();
                 $ipAddresses = R::find('ip_address', " type = 'NS' AND value NOT IN ('" . implode("', '", $dnsServers) . "') ");
                 foreach ($ipAddresses as $ip) {
                     $domains = R::related($ip, 'domain');
                     foreach ($domains as $domain) {
                         $content[$domain->name] = $domain->name . ' (' . $ip->value . ')';
                     }
                 }
                 $this->setJsonMsg(array('msg' => 'ok', 'content' => implode('<br>', $content)));
             } else {
                 $this->setJsonMsg(array('msg' => 'Please set "dnsServers" as an array in the config file'), self::ERROR);
             }
             break;
             // TODO: should be generalized to allow editing of other fields
         // TODO: should be generalized to allow editing of other fields
         case 'editServerComment':
             $serverID = (int) $_GET['serverID'];
             $server = R::load("server", $serverID);
             if ($server instanceof RedBean_OODBBean) {
                 $content = '<form action="/service/ajax/saveServerComment/?serverID=' . $serverID . '" method="post" id="serverCommentForm">
         <p>
         <textarea name="comment" rows="10" cols="50">' . $server->comment . '</textarea><br>
         <input type="submit" name="serverCommentSaveAction" value="Save" />
         </p>
         </form';
                 $this->setJsonMsg(array('msg' => 'ok', 'content' => $content));
             } else {
                 $this->setJsonMsg(array('msg' => 'Unknown server'), self::ERROR);
             }
             break;
             // TODO: should be generalized to allow editing of other fields
         // TODO: should be generalized to allow editing of other fields
         case 'saveServerComment':
             $comment = $_GET['comment'];
             $serverID = (int) $_GET['serverID'];
             $server = R::load("server", $serverID);
             $server->comment = $comment;
             R::store($server);
             $this->setJsonMsg(array('msg' => 'Comment stored'));
             break;
         case 'setEnabledFields':
             $type = $_GET['type'];
             $availableFields = getAvaliableFields($type);
             $enabledFields = array();
             foreach ($_GET['field'] as $key) {
                 if (isset($availableFields[$key])) {
                     $enabledFields[$key] = $availableFields[$key];
                 }
             }
             setcookie('enabledFields', serialize(array($type => $enabledFields)), time() + 36000, '/');
             $this->setJsonMsg(array('msg' => 'Enabled fields set'));
             break;
         case 'getServerList':
             $data['hasFieldSelector'] = true;
             $data['avaliableFields'] = getAvaliableFields('servers');
             $data['enabledFields'] = getEnabledFields('servers');
             $data['serversGrouped'] = getGroupedByType();
             $data['template'] = 'design/desktop/templates/servers_list.tpl.php';
             ob_start();
             mvc\render($data['template'], $data);
             $content = ob_get_clean();
             $this->setJsonMsg(array('msg' => 'ok', 'content' => $content));
             break;
         case 'getFieldList':
             // TODO: should not be hardcoded
             $avaliableFields = getAvaliableFields('servers');
             $enabledFields = getEnabledFields('servers');
             $avaliableLi = '';
             $enabledLi = '';
             $enabledFieldKeys = array_keys($enabledFields);
             foreach ($avaliableFields as $key => $prettyName) {
                 if (in_array($key, $enabledFieldKeys)) {
                     $enabledLi .= '<li id="field=' . $key . '">' . $prettyName . '</li>';
                 } else {
                     $avaliableLi .= '<li id="field=' . $key . '">' . $prettyName . '</li>';
                 }
             }
             $content = '<div class="sortableListContainer first">
       <h2>Enabled fields</h2>
       <ul class="connectedSortable" id="enabledFields">
       ' . $enabledLi . '
       </ul>
       </div>
       <div class="sortableListContainer last">
       <h2>Avaliable fields</h2>
       <ul class="connectedSortable" id="avaliableFields">
       ' . $avaliableLi . '
       </ul>
       </div>';
             $this->setJsonMsg(array('msg' => 'ok', 'content' => $content));
             break;
         default:
             $this->setJsonMsg(array('msg' => 'Unknown action'), self::ERROR);
             break;
     }
 }
Пример #3
0
                    mvc\render('design/desktop/templates/server_group_table_heading.tpl.php', $data);
                    echo '<tbody>';
                    $data['server'] = $xen0['xen0'];
                    mvc\render('design/desktop/templates/server_table_row.tpl.php', $data);
                    foreach ($xen0['xenu'] as $xenu) {
                        $data['server'] = $xenu;
                        mvc\render('design/desktop/templates/server_table_row.tpl.php', $data);
                    }
                    echo '</tbody>
            </table>';
                }
                break;
            case 'physical':
                $data = array();
                $data['enabledFields'] = $enabledFields;
                echo '<table class="tablesorter">';
                mvc\render('design/desktop/templates/server_group_table_heading.tpl.php', $data);
                echo '<tbody>';
                $data['server'] = $group;
                mvc\render('design/desktop/templates/server_table_row.tpl.php', $data);
                echo '</tbody>
            </table>';
                break;
        }
    }
} else {
    echo 'Ingen servere registeret';
}
?>
</div>
Пример #4
0
 public function exec($params)
 {
     $data = array();
     $methods = array('domains.list' => function ($request) {
         if (isset($request->params['filter'])) {
         } else {
             $data['domains'] = R::find('domain');
             ob_start();
             mvc\render('design/desktop/templates/domains.tpl.php', $data);
             $html = ob_get_clean();
         }
         $request->returnResult(array('html' => $html, 'callbacks' => array('display.content', 'table.sorter')));
         return true;
     }, 'data.backup' => function ($request) {
         $owners = R::find('owner');
         foreach ($owners as $owner) {
             $related = R::related($owner, 'domain');
             $backup = R::dispense('backup');
             $backup->type = "owner_to_domain";
             $domains = array();
             foreach ($related as $rel) {
                 $domains[] = $rel->name;
             }
             $backup->data = serialize(array('owner_name' => $owner->name, 'owner_account_id' => $owner->account_id, 'domains' => $domains));
             R::store($backup);
         }
         $request->returnResult(array('html' => 'ok'));
         return true;
     }, 'data.restore' => function ($request) {
         $backups = R::find('backup');
         foreach ($backups as $backup) {
             switch ($backup->type) {
                 case 'owner_to_domain':
                     $data = unserialize($backup->data);
                     $owner = R::findOne('owner', 'account_id = ?', array($data['owner_account_id']));
                     if (!$owner instanceof RedBean_OODBBean) {
                         $owner = R::dispense('owner');
                         $owner->account_id = $data['owner_account_id'];
                     }
                     $owner->name = $data['owner_name'];
                     /*foreach ( $data['domains'] as $domain )
                       {
                         $domain  ;
                       }*/
                     R::store($owner);
                     break;
             }
         }
         $request->returnResult(array('html' => 'ok'));
         return true;
     }, 'demo.substract' => function ($request) {
         if (!is_array($request->params)) {
             $request->returnError(-32602);
             return FALSE;
         }
         $tmp = array_keys($request->params);
         if (!count($request->params) == 2 || !is_numeric($request->params[array_pop($tmp)]) || !is_numeric($request->params[array_pop($tmp)])) {
             $request->returnError(-32602);
             return False;
         }
         $request->returnResult(intval($request->params[0]) - intval($request->params[1]));
         return TRUE;
     });
     $proxy = new Tivoka_ServerArrayHost($methods);
     $server = new Tivoka_ServerServer($proxy);
     $server->process();
 }