Example #1
0
 function __construct()
 {
     $this->db = \app\inc\Input::getPath()->part(2);
     $dbSplit = explode("@", $this->db);
     if (sizeof($dbSplit) == 2) {
         $this->db = $dbSplit[1];
     }
     if ($_SESSION['http_auth'] != $this->db) {
         //error_log("WMS-C auth");
         \app\models\Database::setDb($this->db);
         $postgisObject = new \app\inc\Model();
         if ($_SERVER["QUERY_STRING"]) {
             $auth = $postgisObject->getGeometryColumns(\app\inc\Input::get("LAYERS"), "authentication");
         } else {
             $parts = explode("/", $_SERVER['REQUEST_URI']);
             $auth = $postgisObject->getGeometryColumns($parts[4], "authentication");
         }
         if ($auth == "Read/write" || $auth == "Write") {
             include 'inc/http_basic_authen.php';
         }
         $_SESSION['http_auth'] = $this->db;
     }
     if ($_SERVER["QUERY_STRING"]) {
         $this->get_wms();
     } else {
         $this->get_tms();
     }
 }
Example #2
0
 function __construct()
 {
     if (\app\inc\Input::getPath()->part(3) == "tilecache") {
         $postgisschema = \app\inc\Input::getPath()->part(4);
     } else {
         $postgisschema = \app\inc\Input::getPath()->part(3);
     }
     $db = \app\inc\Input::getPath()->part(2);
     $dbSplit = explode("@", $db);
     if (sizeof($dbSplit) == 2) {
         $db = $dbSplit[1];
     }
     $path = App::$param['path'] . "/app/wms/mapfiles/";
     $name = $db . "_" . $postgisschema . ".map";
     $oMap = new \mapObj($path . $name);
     $request = new \OWSRequestObj();
     if ($_SERVER['REQUEST_METHOD'] === 'GET') {
         foreach ($_GET as $k => $v) {
             if (strtolower($k) == "layers" || strtolower($k) == "layer" || strtolower($k) == "typename" || strtolower($k) == "typenames") {
                 $layers = $v;
             }
             $request->setParameter($k, $v);
         }
     } else {
         $request->loadParams();
     }
     if ($_SESSION['http_auth'] != $db) {
         \app\models\Database::setDb($db);
         $postgisObject = new \app\inc\Model();
         foreach (explode(",", $layers) as $layer) {
             $auth = $postgisObject->getGeometryColumns($layer, "authentication");
             $layerSplit = explode(".", $layer);
             $HTTP_FORM_VARS["TYPENAME"] = $layerSplit[1];
             if ($auth == "Read/write") {
                 include 'inc/http_basic_authen.php';
             } else {
                 include 'inc/http_basic_authen_subuser.php';
             }
         }
     }
     ms_ioinstallstdouttobuffer();
     $oMap->owsdispatch($request);
     $contenttype = ms_iostripstdoutbuffercontenttype();
     if ($contenttype == 'image/png') {
         header('Content-type: image/png');
     } else {
         header('Content-type: text/xml');
     }
     ms_iogetStdoutBufferBytes();
     print "<!--\n";
     include "README";
     print "\n-->\n";
     ms_ioresethandlers();
 }
Example #3
0
    } else {
        $HTTP_FORM_VARS = array("");
    }
}
//HTTP_FORM_VARS is set in script if POST is used
$HTTP_FORM_VARS = array_change_key_case($HTTP_FORM_VARS, CASE_UPPER);
// Make keys case
$HTTP_FORM_VARS["TYPENAME"] = dropAllNameSpaces($HTTP_FORM_VARS["TYPENAME"]);
$tables = explode(",", $HTTP_FORM_VARS["TYPENAME"]);
$properties = explode(",", dropAllNameSpaces($HTTP_FORM_VARS["PROPERTYNAME"]));
$featureids = explode(",", $HTTP_FORM_VARS["FEATUREID"]);
$bbox = explode(",", $HTTP_FORM_VARS["BBOX"]);
$resultType = $HTTP_FORM_VARS["RESULTTYPE"];
// Start HTTP basic authentication
//if(!$_SESSION["oauth_token"]) {
$auth = $postgisObject->getGeometryColumns($postgisschema . "." . $HTTP_FORM_VARS["TYPENAME"], "authentication");
if ($auth == "Read/write") {
    include 'inc/http_basic_authen.php';
}
//}
// End HTTP basic authentication
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
//ob_start();
if (!empty($properties[0])) {
    foreach ($properties as $property) {
        $__u = explode(".", $property);
        // Is it "/" for get method?
        // We first check if typeName is namespace
        if ($__u[1]) {
            foreach ($tables as $table) {
                if ($table == $__u[0]) {
Example #4
0
 function __construct()
 {
     if (\app\inc\Input::getPath()->part(3) == "tilecache") {
         $postgisschema = \app\inc\Input::getPath()->part(4);
     } else {
         $postgisschema = \app\inc\Input::getPath()->part(3);
     }
     $db = \app\inc\Input::getPath()->part(2);
     $dbSplit = explode("@", $db);
     if (sizeof($dbSplit) == 2) {
         $db = $dbSplit[1];
     }
     $path = App::$param['path'] . "/app/wms/mapfiles/";
     $name = $db . "_" . $postgisschema . ".map";
     $oMap = new \mapObj($path . $name);
     $request = new \OWSRequestObj();
     if ($_SERVER['REQUEST_METHOD'] === 'GET') {
         foreach ($_GET as $k => $v) {
             if (strtolower($k) == "layers" || strtolower($k) == "layer" || strtolower($k) == "typename" || strtolower($k) == "typenames") {
                 $layers = $v;
             }
             $request->setParameter($k, $v);
         }
     } else {
         $request->loadParams();
     }
     if ($_SESSION['http_auth'] != $db) {
         \app\models\Database::setDb($db);
         $postgisObject = new \app\inc\Model();
         foreach (explode(",", $layers) as $layer) {
             $auth = $postgisObject->getGeometryColumns($layer, "authentication");
             $layerSplit = explode(".", $layer);
             $HTTP_FORM_VARS["TYPENAME"] = $layerSplit[1];
             if ($auth == "Read/write") {
                 include 'inc/http_basic_authen.php';
             } else {
                 include 'inc/http_basic_authen_subuser.php';
             }
         }
     }
     if ($_GET['sql_layer']) {
         include '../libs/functions.php';
         include '../conf/main.php';
         $postgisdb = "mydb";
         $request->setParameter("SLD_BODY", "<StyledLayerDescriptor version='1.1.0'><NamedLayer><Name>sql</Name><UserStyle><Title>xxx</Title><FeatureTypeStyle><Rule><LineSymbolizer><Stroke><CssParameter name='stroke'>#FFFF00</CssParameter><CssParameter name='stroke-width'>15</CssParameter></Stroke></LineSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>\n                ");
         $postgisObj = new postgis();
         $postgisObj2 = new postgis();
         $view = "public.hello";
         $sqlView = "CREATE VIEW {$view} as " . urldecode($_GET['sql_layer']);
         $postgisObj->connect();
         $postgisObj->execQuery($sqlView);
         $postgisObj->execQuery("CREATE SEQUENCE _serial START 1");
         $arrayWithFields = $postgisObj2->getMetaData($view);
         foreach ($arrayWithFields as $key => $arr) {
             if ($arr['type'] == "geometry") {
                 $fieldsArr[] = "transform(" . $key . ",900913) as the_geom";
             } else {
                 $fieldsArr[] = $key;
             }
         }
         $fieldsArr[] = "nextval('_serial') as _serial";
         $sql = implode(",", $fieldsArr);
         $sql = "SELECT {$sql} FROM {$view}";
         $request->setParameter("LAYERS", $_GET['LAYERS'] . ",sql");
         $layer = ms_newLayerObj($oMap);
         $layer->updateFromString("\n\tLAYER\n\t\tNAME 'sql'\n\t\tSTATUS off\n\t\tPROCESSING 'CLOSE_CONNECTION=DEFER'\n\t\tDATA \"the_geom from ({$sql}) as foo using unique _serial using srid=900913\"\n\t\tTYPE POLYGON\n\t\tCONNECTIONTYPE POSTGIS\n\t\tCONNECTION 'user=postgres dbname=mydb host=127.0.0.1'\n\t\tMETADATA\n\t\t  'wms_title'    'sql'\n\t\t  'wms_srs'    'EPSG:4326'\n\t\t  'wms_name'    'sql'\n\t\tEND\n\t\tPROJECTION\n\t\t  'init=epsg:900913'\n\t\tEND\n\t\tCLASS\n\t\t  NAME 'New style'\n\t\t  STYLE\n\t\t\tOUTLINECOLOR 255 0 0\n\t\t  END\n  \t\tEND\n  \tEND\n\t");
     }
     ms_ioinstallstdouttobuffer();
     $oMap->owsdispatch($request);
     if ($_GET['sql_layer']) {
         $sql = "DROP VIEW {$view}";
         $result = $postgisObj->execQuery($sql);
     }
     $contenttype = ms_iostripstdoutbuffercontenttype();
     if ($contenttype == 'image/png') {
         header('Content-type: image/png');
     } else {
         header('Content-type: text/xml');
     }
     ms_iogetStdoutBufferBytes();
     ms_ioresethandlers();
 }
Example #5
0
 public function get_index()
 {
     $dir = App::$param['path'] . "app/tmp/" . Connection::$param["postgisdb"] . "/__vectors";
     $safeName = \app\inc\Model::toAscii($_REQUEST['name'], array(), "_");
     $skipFailures = $_REQUEST["ignoreerrors"] == "true" ? true : false;
     $append = $_REQUEST["append"] == "true" ? true : false;
     $overwrite = $_REQUEST["overwrite"] == "true" ? true : false;
     if (is_numeric($safeName[0])) {
         $safeName = "_" . $safeName;
     }
     //Check if file is .zip
     $zipCheck1 = explode(".", $_REQUEST['file']);
     $zipCheck2 = array_reverse($zipCheck1);
     if (strtolower($zipCheck2[0]) == "zip" || strtolower($zipCheck2[0]) == "rar") {
         $ext = array("shp", "tab", "geojson", "gml", "kml", "mif", "gdb");
         $folderArr = array();
         $safeNameArr = array();
         for ($i = 0; $i < sizeof($zipCheck1) - 1; $i++) {
             $folderArr[] = $zipCheck1[$i];
         }
         $folder = implode(".", $folderArr);
         if (strtolower($zipCheck2[0]) == "zip") {
             // ZIP start
             $zip = new \ZipArchive();
             $res = $zip->open($dir . "/" . $_REQUEST['file']);
             if ($res === false) {
                 $response['success'] = false;
                 $response['message'] = "Could not unzip file";
                 return Response::json($response);
             }
             $zip->extractTo($dir . "/" . $folder);
             $zip->close();
             // ZIP end
         }
         if (strtolower($zipCheck2[0]) == "rar") {
             // RAR start
             $rar_file = rar_open($dir . "/" . $_REQUEST['file']);
             if (!$rar_file) {
                 $response['success'] = false;
                 $response['message'] = "Could not unrar file";
                 return Response::json($response);
             }
             $list = rar_list($rar_file);
             foreach ($list as $file) {
                 $entry = rar_entry_get($rar_file, $file);
                 $file->extract($dir . "/" . $folder);
                 // extract to the current dir
             }
             rar_close($rar_file);
             // RAR end
         }
         if ($handle = opendir($dir . "/" . $folder)) {
             while (false !== ($entry = readdir($handle))) {
                 if ($entry !== "." && $entry !== "..") {
                     $zipCheck1 = explode(".", $entry);
                     $zipCheck2 = array_reverse($zipCheck1);
                     if (in_array(strtolower($zipCheck2[0]), $ext)) {
                         $_REQUEST['file'] = $folder . "/" . $entry;
                         for ($i = 0; $i < sizeof($zipCheck1) - 1; $i++) {
                             $safeNameArr[] = $zipCheck1[$i];
                         }
                         $safeName = \app\inc\Model::toAscii(implode(".", $safeNameArr), array(), "_");
                         break;
                     }
                     $_REQUEST['file'] = $folder;
                 }
             }
         }
     }
     $srid = $_REQUEST['srid'] ?: "4326";
     $encoding = $_REQUEST['encoding'] ?: "LATIN1";
     switch ($_REQUEST['type']) {
         case "Point":
             $type = "point";
             break;
         case "Polygon":
             $type = "multipolygon";
             break;
         case "Line":
             $type = "multilinestring";
             break;
         case "Geometry":
             $type = "geometry";
             break;
         default:
             $type = "PROMOTE_TO_MULTI";
             break;
     }
     $model = new \app\inc\Model();
     $tableExist = $model->isTableOrView(Connection::$param["postgisschema"] . "." . $safeName);
     $tableExist = $tableExist["success"];
     if ($tableExist == true && $overwrite == false && $append == false) {
         $response['success'] = false;
         $response['message'] = "'{$safeName}' exists already, use 'Overwrite'";
         $response['code'] = 406;
         return $response;
     }
     if ($_REQUEST["append"] == "true") {
         $sql = "DELETE FROM " . Connection::$param["postgisschema"] . "." . $safeName;
         $res = $model->prepare($sql);
         try {
             $res->execute();
         } catch (\PDOException $e) {
             $response['success'] = false;
             $response['message'] = "Could not delete from {$safeName}";
             $response['code'] = 406;
             return $response;
         }
     }
     $cmd = "PGCLIENTENCODING={$encoding} ogr2ogr " . ($skipFailures ? "-skipfailures " : " ") . ($append ? "-append " : " ") . ($overwrite == true && $append == false ? "-overwrite " : " ") . "-dim 2 " . ($append ? "" : "-lco 'GEOMETRY_NAME=the_geom' ") . ($append ? "" : "-lco 'FID=gid' ") . ($append ? "" : "-lco 'PRECISION=NO' ") . ($append ? "" : "-lco 'PG_USE_COPY=YES' ") . "-a_srs 'EPSG:{$srid}' " . "-f 'PostgreSQL' PG:'host=" . Connection::$param["postgishost"] . " user="******"postgisuser"] . " password="******"postgispw"] . " dbname=" . Connection::$param["postgisdb"] . " active_schema=" . Connection::$param["postgisschema"] . "' " . "'" . $dir . "/" . $_REQUEST['file'] . "' " . "-nln {$safeName} " . "-nlt {$type}";
     exec($cmd . ' 2>&1', $out, $err);
     $geoType = $model->getGeometryColumns(Connection::$param["postgisschema"] . "." . $safeName, "type");
     $key = Connection::$param["postgisschema"] . "." . $safeName . ".the_geom";
     $class = new \app\models\Classification($key);
     $arr = $class->getAll();
     // Set layer editable
     $join = new \app\models\Table("settings.geometry_columns_join");
     $json = '{"data":{"editable":true,"_key_":"' . $key . '"}}';
     $data = (array) json_decode(urldecode($json));
     $join->updateRecord($data, "_key_");
     if (empty($arr['data'])) {
         $class->insert();
         $class->update("0", \app\models\Classification::createClass($geoType));
     }
     $def = new \app\models\Tile($key);
     $arr = $def->get();
     if (empty($arr['data'][0])) {
         $json = '{
         "theme_column":"",
         "label_column":"",
         "query_buffer":"",
         "opacity":"",
         "label_max_scale":"",
         "label_min_scale":"",
         "meta_tiles":false,
         "meta_size":"3",
         "meta_buffer":"10",
         "ttl":""}';
         $def->update($json);
     }
     if ($out[0] == "") {
         $response['success'] = true;
         $response['message'] = "Layer <b>{$safeName}</b> is created";
         $response['type'] = $geoType;
         // Bust cache, in case of layer already exist
         \app\controllers\Tilecache::bust(Connection::$param["postgisschema"] . "." . $safeName);
     } else {
         $response['success'] = false;
         $response['message'] = $safeName . ": Some thing went wrong. Check the log.";
         $response['out'] = $out[0];
         Session::createLog($out, $_REQUEST['file']);
         // Make sure the table is dropped if not skipping failures and it didn't exists before
         if ($skipFailures == false && $tableExist == false) {
             $sql = "DROP TABLE " . Connection::$param["postgisschema"] . "." . $safeName;
             $res = $model->prepare($sql);
             try {
                 $res->execute();
             } catch (\PDOException $e) {
             }
         }
     }
     $response['cmd'] = $cmd;
     return $response;
 }