<?php /** * @file DDserverWeb.php * @brief PHP SoapServer for DD WebServices * * @date 27.05.2008 * @version $Id: DDserverWeb.php,v 1.11 2013/04/18 06:54:39 benjamin Exp $ */ class DDService { private $alias = array(baseDir => webAlias); private $extAlias = array(extBaseDir => extWebAlias); /** * Checks if Remote Data Set has been already added */ function isRemoteViAdded($baseId, $viId) { $referXML = baseDir."/DDsys.xml"; $DDsys = new DOMDocument("1.0"); $DDsys->load($referXML); $xp = new domxpath($DDsys); $VI = $xp->query("//NAME[.='".$viId."']"); if ($VI->item(0)->nodeValue != NULL) { $base = $VI->item(0)->getAttribute("base"); if ($base != $baseId) return false; return true; } return false; } /** * Returns contents of 'Version' file from VI Location dir */ function getVersion($dataSet) { $referXML = baseDir."/DDsys.xml"; $DDsys = new DOMDocument("1.0"); $DDsys->load($referXML); $xp = new domxpath($DDsys); $VI = $xp->query("//NAME[.='".$dataSet."']"); if ($VI->item(0)->nodeValue != NULL) { $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue; } if (file_exists($location."Version")) return file_get_contents($location."Version"); return null; } /** * Returns restricted TimeRestriction and GlobalStop in case of time restriction */ function getTimeRestriction($dataSet) { $referXML = baseDir."/DDsys.xml"; $DDsys = new DOMDocument("1.0"); $DDsys->load($referXML); $xp = new domxpath($DDsys); $VI = $xp->query("//NAME[.='".$dataSet."']"); if ($VI->item(0)->nodeValue != NULL) { $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue; } else { return array("success" => FALSE, "days" => "NOSUCHVI", "globalstop" => NULL ); } if (file_exists($location."TimeRestriction")) { $restr = file($location."TimeRestriction", FILE_IGNORE_NEW_LINES); $infoXmlRestr = $location.$restr[1].".xml"; if (file_exists($infoXmlRestr)) { if (!$DDsys->load($infoXmlRestr)) { $currDir = getcwd(); chdir($location); $DDsys->loadXML(file_get_contents($restr[1].".xml")); // NFS connection doesn't load chdir($currDir); } $globalStop = $DDsys->getElementsByTagName("GlobalStop")->item(0)->nodeValue; } else { $globalStop = NULL; } return array("success" => TRUE, "days" => $restr[0], "globalstop" => $globalStop ); } return array("success" => FALSE, "days" => "NORESTRICTIONFILE", "globalstop" => NULL ); } /** Just returns URL addres of AMDA_Users.xml - * droits d'access */ function getUserGroups() { if (file_exists(extBaseDir."/AMDA_Users.xml")) return extWebAlias."AMDA_Users.xml"; else return NOUSERGROUPSSPECIFIED; } /* * Return info about a user */ function getUserInfo($login,$hash) { if (md5(PRIVATEKEY.$login.__FUNCTION__) != $hash) return array("success" => FALSE, "login" => $login, "name" => "undefined", "first_name" => "undefined", "group" => "undefined", "email" => "undefined", "date" => "undefined", "news" => "0"); $UsrDom = new DomDocument("1.0"); $UsrDom->load(extWebAlias."AMDA_Users_Info.xml"); $xp = new domxpath($UsrDom); $theUser = $xp->query("//user[@login='".$login."']"); return array("success" => TRUE, "login" => $login, "name" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("name") : "undefined", "first_name" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("first_name") : "undefined", "group" => $this->getUserMemberGroups($login), "email" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("email") : "undefined", "date" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("date") : "undefined", "news" => ($theUser->length > 0) ? $theUser->item(0)->getAttribute("news") : "0"); } /* * Return a list of group for which a user is a member */ function getUserMemberGroups($user) { //get user $user_dom = new DomDocument("1.0"); if (!file_exists(extBaseDir."/AMDA_Users.xml")) return array(); $user_dom->load(extBaseDir."/AMDA_Users.xml"); $user_nodes = $user_dom->getElementsByTagName('user'); foreach ($user_nodes as $user_node) { if ($user_node->nodeValue == $user) return $user_node->getAttribute('group'); } return ""; } /** Return the list of available local missions for * a given user */ function getUserAvailableLocalMissions($user) { //get user groups $user_groups = explode(",",preg_replace('/\s+/', '',$this->getUserMemberGroups($user))); //get local missions $mis_dom = new DomDocument("1.0"); if (!file_exists(extBaseDir."/Missions.xml")) return array(); $mis_dom->load(extBaseDir."/Missions.xml"); $local_nodes = $mis_dom->getElementsByTagName('Local'); if ($local_nodes->length < 1) return array(); $mis_nodes = $local_nodes->item(0)->getElementsByTagName("MissionID"); $user_missions = array(); foreach ($mis_nodes as $mis_node) { if (!$mis_node->hasAttribute('group') || ($mis_node->getAttribute('group') == '')) { //public mission array_push($user_missions,$mis_node->nodeValue); } else { // private mission $mis_group = $mis_node->getAttribute('group'); if (array_search($mis_group,$user_groups) === FALSE) continue; array_push($user_missions,$mis_node->nodeValue); } } return $user_missions; } /** Return the list of available external missions for * a given user */ function getUserAvailableExternalMissions($user) { //get user groups $user_groups = explode(",",$this->getUserMemberGroups($user)); //get external missions $mis_dom = new DomDocument("1.0"); if (!file_exists(extBaseDir.extBaseXml)) return array(); $mis_dom->load(extBaseDir.extBaseXml); $external_nodes = $mis_dom->getElementsByTagName('External'); if ($external_nodes->length < 1) return array(); $mis_nodes = $external_nodes->item(0)->getElementsByTagName("CenterID"); $user_missions = array(); foreach ($mis_nodes as $mis_node) { if (!$mis_node->hasAttribute('group') || ($mis_node->getAttribute('group') == '')) { //public mission array_push($user_missions,$mis_node->nodeValue); } else { // private mission $mis_group = $mis_node->getAttribute('group'); if (array_search($mis_group,$user_groups) === FALSE) continue; array_push($user_missions,$mis_node->nodeValue); } } return $user_missions; } /** Just returns URL addres of Missions.xml - * description of AMDA local data */ function getAvailableMissions() { if (file_exists(extBaseDir."Missions.xml")) return extWebAlias."Missions.xml"; else return NOLOCALDATA; } /** Just returns URL addres of Bases.xml - * description of available external bases */ function getAvailableExternalBases() { if (file_exists(extBaseDir.extBaseXml)) return extWebAlias.extBaseXml; else return NOEXTERNALBASES; } /** Just returns URL addres of base.xml - * description of available data for particular External Base * produced by DataCenterMgr */ function getAvailableExternalData($baseID) { if (file_exists(extBaseDir.$baseID."/base.xml")) return extWebAlias.$baseID."/base.xml"; else return NOEXTERNALDATA; } /** Returns URL addres of dataSet.xml - * description of particular external DataSet * if there is no such a description * contacts External Base and gets it */ function getDataSetDescription($baseID, $remDataSetID) { if (file_exists(extBaseDir.$baseID."/".$remDataSetID.".xml")) return extWebAlias.$baseID."/".$remDataSetID.".xml"; else { } } /** * Returns date of last modif of *times.nc in DD Base */ function getLastUpdate($dataSet) { $referXML = baseDir."/DDsys.xml"; $DDsys = new DOMDocument("1.0"); $DDsys->load($referXML); $xp = new domxpath($DDsys); $VI = $xp->query("//NAME[.='".$dataSet."']"); if ($VI->item(0)->nodeValue != NULL) { $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue; $times = $VI->getElementsByTagName("TIMES")->item(0)->nodeValue; if (!file_exists($location.$times)) return null; $cmd = 'date "+%Y-%m-%dT%H:%M:%SZ" -u -r '. $location.$times; // for NFS $dateModif = exec($cmd); return $dateModif; } return null; } /** * Returns modif date of the last modified data file (*.nc.gz) for a given DataSet */ function getLastRealUpdate($dataSet) { $referXML = baseDir."/DDsys.xml"; $DDsys = new DOMDocument("1.0"); $DDsys->load($referXML); $xp = new domxpath($DDsys); $VI = $xp->query("//NAME[.='".$dataSet."']"); if ($VI->item(0)->nodeValue != NULL) { $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue; $find = 'find '.$location.'*.nc.gz -type f -printf \'%T@ %p\n\' | sort -n | tail -1 | cut -f2- -d" "'; $lastFile = exec($find); if (!file_exists($lastFile)) exit('NO SUCH FILE '.$lastFile); $cmd = 'date "+%Y-%m-%dT%H:%M:%SZ" -u -r '.$lastFile; // for NFS $dateModif = exec($cmd); return $dateModif; } return null; } /** * Returns String Start-Stop for local DataSet in DD Base */ function getStartStop($dataSet) { $referFile = baseDir."/refer.nc"; $cmd = DDBASEBIN."/StartStop ".$referFile." ".$dataSet; $res = system($cmd); return $res; } /** * Returns String INFO for local DataSet in DD Base */ function getInfo($dataSet, $infoID) { $referFile = baseDir."/refer.nc"; $cmd = DDBASEBIN."/GetInfo ".$referFile." ".$dataSet." ".$infoID; $res = system($cmd); return $res; } /** * Returns Desc attribute for Remote DataSet in DD Base */ function getRemoteStartStop($baseID, $dataSet) { $domName = extBaseDir.$baseID."/base.xml"; if (!file_exists($domName)) return NOEXTERNALDATA; $dom = new DomDocument("1.0"); $dom->load($domName); $vi = $dom->getElementById($dataSet); if (!$vi) return NODATASET; $res = $vi->getAttribute('desc'); return $res; } /** * Check Remote Connection */ function checkRemoteConnection($extBaseID){ switch ($extBaseID) { case "THEMIS" : return is_dir(THEMIS_DIR); case "MAPSKP" : if (fsockopen(MAPSKP_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; case "CDAWEB" : if (ftp_connect(CDAWEB_FTP_SERVER)) return true; else return false; case "VEXGRAZ" : if (fsockopen(VEXGRAZ_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; case "LATMOS" : if (fsockopen(LATMOS_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; case "LESIA" : if (fsockopen(LESIA_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; case "SINP" : if (fsockopen(SINP_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; case "FMI_HYBRID" : if (fsockopen(FMI_HYBRID_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; case "FMI_GUMICS" : if (fsockopen(FMI_GUMICS_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; case "CCMC" : if (fsockopen(CCMC_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; case "CLWeb" : if (fsockopen(CLWeb_HTTP_SERVER, 80, $errno, $errstr, 30)) return true; else return false; default: return false; } } /** * Returns Array of Data Urls for a given DataSet * in StartTime - StopTime interval */ function getDataUrl($dataSet, $StartTime, $StopTime) { $tempFile = uniqid("temp"); if (file_exists($tempFile)) unlink($tempFile); $referXML = baseDir."/DDsys.xml"; $DDsys = new DOMDocument("1.0"); $DDsys->load($referXML); $xp = new domxpath($DDsys); $VI = $xp->query("//NAME[.='".$dataSet."']"); if ($VI->item(0)->nodeValue != NULL) { $location = $VI->item(0)->parentNode->getElementsByTagName("LOCATION")->item(0)->nodeValue; $times = $VI->item(0)->parentNode->getElementsByTagName("TIMES")->item(0)->nodeValue; $timesFile = $location.$times; $cmd = DDBASEBIN."/GetFileNames ".$timesFile." ".strtotime($StartTime)." ".strtotime($StopTime)." > $tempFile"; system($cmd); if (!file_exists($tempFile)) return 'ERROR'; $res = file($tempFile); if ($res[0] == OUTOFTIME) { unlink($tempFile); return $res; } $urls = explode(";",$res[0]); $url_location = strtr($location, $this->alias); if (count($urls) > 0) { unset($urls[count($urls)-1]); for ($i = 0; $i < count($urls); $i++) $urls[$i] = $url_location.$urls[$i].".gz"; } unlink($tempFile); return $urls; } return NODATASET; } } require_once 'DDserverWeb_ini.php'; ini_set("soap.wsdl_cache_enabled", "0"); // use_soap_error_handler(false); $server = new SoapServer("./dd.wsdl"); $server->setClass("DDService"); $server->handle(); ?>