Beispiel #1
1
function parse_server_status_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $node = $dom->getElementsByTagname('server')->item(0);
    if (is_null($node)) {
        return false;
    }
    if (!$node->hasAttribute('name')) {
        return false;
    }
    if (!$node->hasAttribute('status')) {
        return false;
    }
    return array('name' => $node->getAttribute('name'), 'status' => $node->getAttribute('status'));
}
Beispiel #2
0
function parse_session_status_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $node = $dom->getElementsByTagname('session')->item(0);
    if (is_null($node)) {
        return false;
    }
    if (!$node->hasAttribute('id')) {
        return false;
    }
    if (!$node->hasAttribute('status')) {
        return false;
    }
    $ret = array('id' => $node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $node->getAttribute('status'), 'reason' => NULL, 'role' => NULL);
    if ($node->hasAttribute('reason')) {
        $ret['reason'] = $node->getAttribute('reason');
    }
    if ($node->hasAttribute('role')) {
        $ret['role'] = $node->getAttribute('role');
    }
    return $ret;
}
Beispiel #3
0
 /**
  * From http://stackoverflow.com/questions/14553547/what-is-the-best-php-dom-2-array-function
  *
  * @param \DomDocument $root
  * @return array
  */
 protected function domToArray($root)
 {
     $result = [];
     if ($root->hasAttributes()) {
         $attrs = $root->attributes;
         foreach ($attrs as $attr) {
             $name = str_replace('cas:', '', $attr->name);
             $result['attributes'][$name] = $attr->value;
         }
     }
     if ($root->hasChildNodes()) {
         $children = $root->childNodes;
         if ($children->length == 1) {
             $child = $children->item(0);
             if ($child->nodeType == XML_TEXT_NODE) {
                 $result['value'] = $child->nodeValue;
                 return count($result) == 1 ? $result['value'] : $result;
             }
         }
         $groups = [];
         foreach ($children as $child) {
             $childName = str_replace('cas:', '', $child->nodeName);
             if (!isset($result[$childName])) {
                 $result[$childName] = $this->domToArray($child);
             } else {
                 if (!isset($groups[$childName])) {
                     $result[$childName] = [$result[$childName]];
                     $groups[$childName] = 1;
                 }
                 $result[$childName][] = $this->domToArray($child);
             }
         }
     }
     return $result;
 }
Beispiel #4
0
 protected function compile()
 {
     $this->templateDocument = new DOMDocument();
     if (!empty($this->templateString)) {
         libxml_use_internal_errors(true);
         $this->templateDocument->loadHTML($this->templateString, LIBXML_HTML_NODEFDTD);
         libxml_use_internal_errors(false);
     }
     $this->templateXPath = new DOMXPath($this->templateDocument);
     if ($this->templateDocument->hasChildNodes()) {
         foreach ($this->templateDocument->childNodes as $node) {
             $this->compileNode($node, $this->templateDocument);
         }
         $removals = $this->templateXPath->query('//*[@delete="1"]');
         foreach ($removals as $remove) {
             $remove->parentNode->removeChild($remove);
         }
     }
 }
 /**
  * Renders the element to string
  * @return string
  */
 public function renderElement()
 {
     if (isset($this->tag) && $this->tag instanceof DOMElement) {
         if ($this->dom->hasChildNodes()) {
             $this->dom->insertBefore($this->tag, $this->dom->firstChild);
         } else {
             $this->dom->appendChild($this->tag);
         }
     }
     $out = '';
     foreach ($this->dom->childNodes as $node) {
         $out .= $this->dom->saveXml($node);
     }
     return $out;
 }
Beispiel #6
0
function parse_premium_sign_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $node = $dom->getElementsByTagname('message')->item(0);
    if (is_null($node)) {
        return false;
    }
    return $node->textContent;
}
Beispiel #7
0
function init_saml2_auth()
{
    global $sessionmanager_url;
    $sm = new SessionManager($sessionmanager_url);
    $ret = $sm->query('auth_params');
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($ret);
    if (!$buf) {
        send_error("Unable to retrieve the SAML parameters");
    }
    if (!$dom->hasChildNodes()) {
        send_error("Unable to retrieve the SAML parameters");
    }
    $saml2 = $dom->getElementsByTagname('SAML2')->item(0);
    $url = $saml2->getElementsByTagname('idp_url')->item(0)->textContent;
    $fingerprint = $saml2->getElementsByTagname('idp_fingerprint')->item(0)->textContent;
    $cert = $saml2->getElementsByTagname('idp_cert')->item(0)->textContent;
    $settings = build_saml_settings($url, $fingerprint, $cert);
    return new OneLogin_Saml2_Auth($settings);
}
Beispiel #8
0
function parse_session_dump_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $node = $dom->getElementsByTagname('session')->item(0);
    if (is_null($node)) {
        return false;
    }
    if (!$node->hasAttribute('id')) {
        return false;
    }
    $ret = array('id' => $node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'dump' => array());
    foreach ($dom->getElementsByTagname('dump') as $node) {
        if (!$node->hasAttribute('name')) {
            return false;
        }
        $name = $node->getAttribute('name');
        $textNode = null;
        foreach ($node->childNodes as $child_node) {
            if ($child_node->nodeType != XML_TEXT_NODE) {
                continue;
            }
            $textNode = $child_node;
            break;
        }
        if ($textNode === null) {
            return false;
        }
        $ret['dump'][$name] = trim($textNode->wholeText);
    }
    return $ret;
}
Beispiel #9
0
function parse_logout_XML($xml_, &$mode_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $node = $dom->getElementsByTagname('logout')->item(0);
    if (is_null($node)) {
        return false;
    }
    if ($node->hasAttribute('mode')) {
        $mode_ = $node->getAttribute('mode');
    }
    return true;
}
Beispiel #10
0
function parse_icon_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $ret = array('server' => $_SERVER['REMOTE_ADDR'], 'application' => array());
    $application_node = $dom->getElementsByTagName('application')->item(0);
    if (is_null($application_node)) {
        return false;
    }
    if (!$application_node->hasAttribute('id')) {
        return false;
    }
    $ret['application']['id'] = $application_node->getAttribute('id');
    return $ret;
}
Beispiel #11
0
function get_users_list()
{
    if (!defined('SESSIONMANAGER_HOST')) {
        return false;
    }
    global $sessionmanager_url;
    $sm = new SessionManager($sessionmanager_url);
    $ret = $sm->query('userlist');
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($ret);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $users_node = $dom->getElementsByTagname('users')->item(0);
    if (is_null($users_node)) {
        return false;
    }
    $users = array();
    foreach ($users_node->childNodes as $user_node) {
        if ($user_node->hasAttribute('login')) {
            $users[$user_node->getAttribute('login')] = strlen($user_node->getAttribute('displayname')) > 32 ? substr($user_node->getAttribute('displayname'), 0, 32) . '...' : $user_node->getAttribute('displayname');
        }
    }
    natcasesort($users);
    if (count($users) == 0) {
        return false;
    }
    return $users;
}
Beispiel #12
0
function wait_ready($tr, $sessionmanager_url, $cookie)
{
    add($tr['wait_aps']);
    flush();
    $count = 20;
    while ($count-- > 0) {
        $cookies = array('PHPSESSID' => $cookie);
        $xml = query_sm($sessionmanager_url . '/session_status', "", $cookies);
        if (!$xml) {
            error($tr['unable_to_reach_sm']);
        }
        $dom = new DomDocument('1.0', 'utf-8');
        $buf = @$dom->loadXML($xml);
        if (!$buf) {
            error($tr['internal_error']);
        }
        if (!$dom->hasChildNodes()) {
            error($tr['internal_error']);
        }
        $session_node = $dom->getElementsByTagName('session');
        if (count($session_node) != 1) {
            error($tr['internal_error']);
        }
        $session_node = $session_node->item(0);
        if (!is_object($session_node)) {
            error($tr['internal_error']);
        }
        $status = $session_node->getAttribute('status');
        if ($status == 'ready') {
            return;
        }
        sleep(2);
    }
    add('Result=' . $tr['session_end_unexpected']);
    die;
}
Beispiel #13
0
 public function orderAction($action_)
 {
     $server = Abstract_Server::load($this->server);
     if (!$server) {
         Logger::error('main', 'VDI_VM::orderAction unable to load Server \'' . $this->server . '\'');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $node = $dom->createElement('vm');
     $node->setAttribute('id', $this->id);
     $node->setAttribute('action', $action_);
     $dom->appendChild($node);
     $xml = $dom->saveXML();
     $xml = query_url_post_xml($server->getBaseURL() . '/hypervisor/vm/manage', $xml);
     if (!$xml) {
         $server->isUnreachable();
         Logger::error('main', 'VDI_VM::orderAction server \'' . $server->fqdn . '\' is unreachable');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $buf = @$dom->loadXML($xml);
     if (!$buf) {
         return false;
     }
     if (!$dom->hasChildNodes()) {
         return false;
     }
     $node = $dom->getElementsByTagname('vm')->item(0);
     if (is_null($node)) {
         return false;
     }
     $status = $node->getAttribute('status');
     if ($status != 'OK') {
         Logger::error('main', 'VDI_VM::orderAction failed');
         return false;
     }
     return true;
 }
Beispiel #14
0
 public function deleteNetworkFolder($name_, $force_ = false)
 {
     if (!is_array($this->roles) || !array_key_exists(Server::SERVER_ROLE_FS, $this->roles)) {
         Logger::critical('main', 'SERVER::deleteNetworkFolder - Not an FS');
         return false;
     }
     if (!$this->isOnline()) {
         Logger::debug('main', 'Server::deleteNetworkFolder("' . $name_ . '") server "' . $this->fqdn . ':' . $this->web_port . '" is not online');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $node = $dom->createElement('share');
     $node->setAttribute('id', $name_);
     $node->setAttribute('force', $force_);
     $dom->appendChild($node);
     $xml = $dom->saveXML();
     $xml = query_url_post_xml($this->getBaseURL() . '/fs/share/delete', $xml);
     if (!$xml) {
         $this->isUnreachable();
         Logger::error('main', 'Server::deleteNetworkFolder server \'' . $this->fqdn . '\' is unreachable');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $buf = @$dom->loadXML($xml);
     if (!$buf) {
         return false;
     }
     if (!$dom->hasChildNodes()) {
         return false;
     }
     $node = $dom->getElementsByTagname('share')->item(0);
     if (is_null($node)) {
         return false;
     }
     if (!$node->hasAttribute('id')) {
         return false;
     }
     return true;
 }
 public function parseSessionCreate($xml_)
 {
     if (!$xml_ || strlen($xml_) == 0) {
         Logger::error('main', 'SessionManagement::parseSessionCreate - Empty content');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $buf = @$dom->loadXML($xml_);
     if (!$buf) {
         Logger::error('main', 'SessionManagement::parseSessionCreate - Not an XML');
         return false;
     }
     if (!$dom->hasChildNodes()) {
         Logger::error('main', 'SessionManagement::parseSessionCreate - Empty XML');
         return false;
     }
     $node = $dom->getElementsByTagname('session')->item(0);
     if (is_null($node)) {
         Logger::error('main', 'SessionManagement::parseSessionCreate - No "session" node');
         return false;
     }
     if (!$node->hasAttribute('id')) {
         Logger::error('main', 'SessionManagement::parseSessionCreate - No "id" attribute in "session" node');
         return false;
     }
     return true;
 }
Beispiel #16
0
 public function refresh()
 {
     $server = Abstract_Server::load($this->server);
     if (!is_object($server)) {
         Logger::error('apt-get', 'TASK::refresh for task ' . $this->id . ' returned an error (unknown server ' . $this->server . ')');
         return false;
     }
     $xml = query_url($server->getBaseURL() . '/aps/debian/' . $this->job_id . '/status');
     if (!$xml) {
         Logger::error('apt-get', 'TASK::refresh for task ' . $this->id . ' on server ' . $this->server . ' returned an error');
         $this->status = 'error';
         return true;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $buf = @$dom->loadXML($xml);
     if (!$buf) {
         return false;
     }
     if (!$dom->hasChildNodes()) {
         return false;
     }
     $node = $dom->getElementsByTagname('debian_request')->item(0);
     if (is_null($node)) {
         return false;
     }
     $this->status = $node->getAttribute('status');
     $ret = true;
     switch ($this->status) {
         case 'created':
             Logger::warning('apt-get', 'TASK::refresh for task ' . $this->id . ' on server ' . $this->server . ' is created');
             $ret = false;
             break;
         case 'in progress':
             Logger::warning('apt-get', 'TASK::refresh for task ' . $this->id . ' on server ' . $this->server . ' is in progress');
             $ret = false;
             break;
         case 'success':
             Logger::info('apt-get', 'TASK::refresh for task ' . $this->id . ' on server ' . $this->server . ' is now finished');
             $this->t_end = time();
             $server->updateApplications();
             $ret = true;
             break;
         case 'error':
             Logger::error('apt-get', 'TASK::refresh for task ' . $this->id . ' on server ' . $this->server . ' returned an error');
             $ret = true;
             break;
     }
     return $ret;
 }
function parse_monitoring_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $server_node = $dom->getElementsByTagName('server')->item(0);
    if (is_null($server_node)) {
        return false;
    }
    if (!$server_node->hasAttribute('name')) {
        return false;
    }
    $server = webservices_load_server($_SERVER['REMOTE_ADDR']);
    if (!$server) {
        Logger::error('main', '(webservices/server/monitoring) Server does not exist (error_code: 2)');
        webservices_return_error(2, 'Server does not exist');
    }
    if (!$server->isAuthorized()) {
        return false;
    }
    $ret = array('server' => $server_node->getAttribute('name'));
    $cpu_node = $dom->getElementsByTagName('cpu')->item(0);
    if (is_null($cpu_node)) {
        return false;
    }
    if (!$cpu_node->hasAttribute('load')) {
        return false;
    }
    $ret['cpu_load'] = $cpu_node->getAttribute('load');
    $ram_node = $dom->getElementsByTagName('ram')->item(0);
    if (is_null($ram_node)) {
        return false;
    }
    if (!$ram_node->hasAttribute('used')) {
        return false;
    }
    $ret['ram_used'] = $ram_node->getAttribute('used');
    $role_nodes = $dom->getElementsByTagName('role');
    foreach ($role_nodes as $role_node) {
        if (!$role_node->hasAttribute('name')) {
            return false;
        }
        switch ($role_node->getAttribute('name')) {
            case 'ApplicationServer':
                $ret['sessions'] = array();
                $session_nodes = $dom->getElementsByTagName('session');
                foreach ($session_nodes as $session_node) {
                    $ret['sessions'][$session_node->getAttribute('id')] = array('id' => $session_node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $session_node->getAttribute('status'), 'instances' => array());
                    $childnodes = $session_node->childNodes;
                    foreach ($childnodes as $childnode) {
                        if ($childnode->nodeName != 'instance') {
                            continue;
                        }
                        $ret['sessions'][$session_node->getAttribute('id')]['instances'][$childnode->getAttribute('id')] = $childnode->getAttribute('application');
                    }
                }
                $sri = ServerReportItem::create_from_server_report($ret['server'], $xml_);
                if ($sri !== null) {
                    Abstract_ReportServer::save($sri);
                }
                break;
            case 'FileServer':
                $size_node = $dom->getElementsByTagName('size')->item(0);
                if (is_null($size_node)) {
                    break;
                }
                $ret['disk_size'] = array('total' => NULL, 'free' => NULL);
                if ($size_node->hasAttribute('total')) {
                    $ret['disk_size']['total'] = $size_node->getAttribute('total');
                }
                if ($size_node->hasAttribute('free')) {
                    $ret['disk_size']['free'] = $size_node->getAttribute('free');
                }
                $ret['shares'] = array();
                $share_nodes = $dom->getElementsByTagName('share');
                foreach ($share_nodes as $share_node) {
                    $ret['shares'][$share_node->getAttribute('id')] = array('id' => $share_node->getAttribute('id'), 'status' => $share_node->getAttribute('status'), 'users' => array());
                    $user_nodes = $share_node->getElementsByTagName('user');
                    foreach ($user_nodes as $user_node) {
                        $ret['shares'][$share_node->getAttribute('id')]['users'][] = $user_node->getAttribute('login');
                    }
                }
                break;
        }
    }
    return $ret;
}
Beispiel #18
0
if (!array_key_exists('mode', $_POST)) {
    $_POST['mode'] = 'logout';
}
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$logout_node = $dom->createElement('logout');
$logout_node->setAttribute('mode', $_POST['mode']);
$dom->appendChild($logout_node);
$xml = $dom->saveXML();
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML(query_sm_post_xml($sessionmanager_url . '/logout.php', $xml));
if (!$buf) {
    echo return_error(0, 'Invalid XML');
    die;
}
if (!$dom->hasChildNodes()) {
    echo return_error(0, 'Invalid XML');
    die;
}
$logout_nodes = $dom->getElementsByTagName('logout');
if (count($logout_nodes) != 1) {
    echo return_error(1, 'Invalid XML: No session node');
    die;
}
$logout_node = $logout_nodes->item(0);
if (!is_object($logout_node)) {
    echo return_error(1, 'Invalid XML: No session node');
    die;
}
$logout = array('mode' => $logout_node->getAttribute('mode'));
$dom = new DomDocument('1.0', 'utf-8');
Beispiel #19
0
function parse_monitoring_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $server_node = $dom->getElementsByTagName('server')->item(0);
    if (is_null($server_node)) {
        return false;
    }
    if (!$server_node->hasAttribute('name')) {
        return false;
    }
    if (!Abstract_Server::exists($server_node->getAttribute('name'))) {
        die;
    }
    // An unknown Server should not send monitoring, so we reject it...
    $server = Abstract_Server::load($server_node->getAttribute('name'));
    if (!$server) {
        return false;
    }
    if (!$server->isAuthorized()) {
        return false;
    }
    $ret = array('server' => $server_node->getAttribute('name'));
    $cpu_node = $dom->getElementsByTagName('cpu')->item(0);
    if (is_null($cpu_node)) {
        return false;
    }
    if (!$cpu_node->hasAttribute('load')) {
        return false;
    }
    $ret['cpu_load'] = $cpu_node->getAttribute('load');
    $ram_node = $dom->getElementsByTagName('ram')->item(0);
    if (is_null($ram_node)) {
        return false;
    }
    if (!$ram_node->hasAttribute('used')) {
        return false;
    }
    $ret['ram_used'] = $ram_node->getAttribute('used');
    $role_nodes = $dom->getElementsByTagName('role');
    foreach ($role_nodes as $role_node) {
        if (!$role_node->hasAttribute('name')) {
            return false;
        }
        switch ($role_node->getAttribute('name')) {
            case 'ApplicationServer':
                $ret['sessions'] = array();
                $session_nodes = $dom->getElementsByTagName('session');
                foreach ($session_nodes as $session_node) {
                    $ret['sessions'][$session_node->getAttribute('id')] = array('id' => $session_node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $session_node->getAttribute('status'), 'instances' => array());
                    $childnodes = $session_node->childNodes;
                    foreach ($childnodes as $childnode) {
                        if ($childnode->nodeName != 'instance') {
                            continue;
                        }
                        $ret['sessions'][$session_node->getAttribute('id')]['instances'][$childnode->getAttribute('id')] = $childnode->getAttribute('application');
                    }
                    $token = $session_node->getAttribute('id');
                    if (Abstract_ReportSession::exists($session_node->getAttribute('id'))) {
                        $report = Abstract_ReportSession::load($session_node->getAttribute('id'));
                        if (is_object($report)) {
                            $report->update($session_node);
                        }
                    }
                }
                $sri = new ServerReportItem($ret['server'], $xml_);
                $sri->save();
                break;
            case 'FileServer':
                $size_node = $dom->getElementsByTagName('size')->item(0);
                if (is_null($size_node)) {
                    break;
                }
                $ret['disk_size'] = array('total' => NULL, 'free' => NULL);
                if ($size_node->hasAttribute('total')) {
                    $ret['disk_size']['total'] = $size_node->getAttribute('total');
                }
                if ($size_node->hasAttribute('free')) {
                    $ret['disk_size']['free'] = $size_node->getAttribute('free');
                }
                $ret['shares'] = array();
                $share_nodes = $dom->getElementsByTagName('share');
                foreach ($share_nodes as $share_node) {
                    $ret['shares'][$share_node->getAttribute('id')] = array('id' => $share_node->getAttribute('id'), 'status' => $share_node->getAttribute('status'), 'users' => array());
                    $user_nodes = $share_node->getElementsByTagName('user');
                    foreach ($user_nodes as $user_node) {
                        $ret['shares'][$share_node->getAttribute('id')]['users'][] = $user_node->getAttribute('login');
                    }
                }
                break;
        }
    }
    return $ret;
}