Exemple #1
0
 /**
  * Check if the server is up.
  * @return boolean true if the triplestore is up.
  * @access public
  */
 public function check()
 {
     return Net::ping($this->_endpoint) != -1;
 }
 private function runQuery($q, $qt = '', $infos = '')
 {
     /* ep */
     $ep = $this->_arc2_RemoteStore->v('remote_store_endpoint', 0, $this->_arc2_RemoteStore->a);
     if (!$ep) {
         return $this->_arc2_RemoteStore->addError('No Endpoint defined.');
     }
     /* prefixes */
     $q = $this->_arc2_RemoteStore->completeQuery($q);
     /* custom handling */
     $mthd = 'run' . $this->_arc2_RemoteStore->camelCase($qt) . 'Query';
     if (method_exists($this, $mthd)) {
         return $this->_arc2_RemoteStore->{$mthd}($q, $infos);
     }
     if (in_array($qt, array('insert', 'delete'))) {
         if ($this->_readOnly) {
             return $this->_arc2_RemoteStore->addError('No right to write in the triplestore.');
         } else {
             $s = new FourStore_Store($ep, $this->_debug);
             $r = $s->queryUpdate($q);
             if (!$r) {
                 $errmsg = "Error unknown.";
                 if (Net::ping($ep) == -1) {
                     $errmsg = "Could not connect to " . $ep;
                 }
                 return $this->_arc2_RemoteStore->addError($errmsg);
             }
         }
     } else {
         $s = new FourStore_Store($ep, $this->_debug);
         $resp = $s->queryRead($q);
         if ($resp == "") {
             $errmsg = "Error unknown.";
             if (Net::ping($ep) == -1) {
                 $errmsg = "Could not connect to " . $ep;
             }
             return $this->_arc2_RemoteStore->addError($errmsg);
         }
         if (preg_match_all('%<!--(.*error.*)-->%m', $resp, $errorResponse)) {
             $message4s = $errorResponse[1][0];
             return $this->_arc2_RemoteStore->addError("4Store message : " . $message4s . "\n query :\n" . $q);
         }
         $parser = @ARC2::getSPARQLXMLResultParser();
         $parser->parse('', $resp);
         $err = $parser->getErrors();
         if ($err) {
             return $this->_arc2_RemoteStore->addError($err);
         }
         if ($qt == 'ask') {
             $bid = $parser->getBooleanInsertedDeleted();
             $r = $bid['boolean'];
         } elseif ($qt == 'select' && !method_exists($parser, 'getRows')) {
             $r = $resp;
         } elseif ($qt == 'select') {
             $r = array('rows' => $parser->getRows(), 'variables' => $parser->getVariables());
         } else {
             $r = $parser->getSimpleIndex(0);
         }
         unset($parser);
     }
     return $r;
 }
Exemple #3
0
 function network()
 {
     $this->set('title', 'Network');
     $this->expect(is_null($this->get('ERROR')), 'No errors expected at this point', 'ERROR variable is set: ' . $this->get('ERROR.text'));
     $this->expect($this->privateip('127.0.0.59'), 'Localhost identified correctly', 'Localhost detection failed');
     $this->expect($this->privateip('192.168.0.5'), 'Private Network (192.168.0.5) identified correctly', 'Private Network (192.168.0.5) detection failed');
     $this->expect($this->privateip('172.16.3.2'), 'Private Network (172.16.3.2) identified correctly', 'Private Network (172.16.3.2) detection failed');
     $this->expect($this->privateip('10.10.10.10'), 'Private Network (10.10.10.10) identified correctly', 'Private Network (10.10.10.10) detection failed');
     $this->expect(!$this->privateip('4.2.2.1'), 'Public Network (4.2.2.1) identified correctly', 'Public Network (4.2.2.1) detection failed');
     $this->expect(!$this->privateip('169.254.222.111'), 'Public Network (169.254.222.111) identified correctly', 'Public Network (169.254.222.111) detection failed');
     for ($i = 0; $i < 3; $i++) {
         $ping = Net::ping('www.yahoo.com', TRUE, 1);
         $this->expect(!is_bool($ping), 'Ping round-trip time to/from www.yahoo.com: ' . round($ping['avg']) . 'ms', 'No ping reply from www.yahoo.com');
     }
     $this->set('QUIET', TRUE);
     $ping = Net::ping('www.yxy.cc', TRUE, 1);
     $this->expect(is_bool($ping), 'www.yxy.cc: No ping reply expected', 'Huh? Ping reply from www.yay.cc');
     $this->set('QUIET', FALSE);
     $this->expect($result = Net::whois('sourceforge.net'), 'Received response from whois server: <pre>' . $result . '</pre>', 'No response from whois server');
     /*
     $path=Net::traceroute('58.71.0.158',TRUE);
     $this->expect(
     	is_array($path),
     	'Traceroute initiated',
     	'Traceroute failed'
     );
     if (is_array($path))
     	foreach ($path as $node)
     		if (is_bool($node))
     			$this->expect(
     				TRUE,
     				'Traceroute hop skipped'
     			);
     		else
     			$this->expect(
     				TRUE,
     				'Traceroute '.$node['host'].' '.
     					'min: '.$node['min'].'ms '.
     					'avg: '.$node['avg'].'ms '.
     					'max: '.$node['max'].'ms '.
     					'packets: '.$node['packets']
     			);
     */
     echo $this->render('basic/results.htm');
 }