function UserIDCheck($sValue, &$oStatus) { global $sTable; global $postgisObject; global $host; $sUserID = Model::toAscii($sValue, NULL, "_"); $oStatus->bValid = false; $sQuery = "SELECT COUNT(*) AS count FROM {$sTable} WHERE screenname = :sUserID"; $res = $postgisObject->prepare($sQuery); $res->execute(array(":sUserID" => $sUserID)); $rowScreenname = $postgisObject->fetchRow($res); if ($rowScreenname['count'] > 0) { $oStatus->sErrMsg = "<span class='label label-warning'>User name already taken</span>"; } else { $oStatus->bValid = 1; $prefix = $_SESSION['zone'] ? App::$param['domainPrefix'] . $_SESSION['zone'] . "." : ""; if (App::$param['domain']) { $host = "//" . $prefix . App::$param['domain']; } else { if (!\app\conf\App::$param['host']) { include_once "../../../app/conf/hosts.php"; } $host = ""; } } }
public function get_index() { $safeName = \app\inc\Model::toAscii($_REQUEST['name'], array(), "_"); if (is_numeric($safeName[0])) { $safeName = "_" . $safeName; } $srid = $_REQUEST['srid'] ?: "4326"; $file = $_REQUEST['file']; $key = Connection::$param["postgisschema"] . "." . $safeName . ".rast"; // Create new table $table = new Table($safeName); $res = $table->createAsRasterTable($srid); // Set bitmapsource $join = new Table("settings.geometry_columns_join"); $json = '{"data":{"bitmapsource":"' . $file . '","_key_":"' . $key . '"}}'; $data = (array) json_decode(urldecode($json)); $join->updateRecord($data, "_key_"); if ($res["success"]) { $response['success'] = true; $response['message'] = "Layer <b>{$safeName}</b> is created"; } else { $response['success'] = false; $response['message'] = "Some thing went wrong. Check the log."; Session::createLog(array($res['message']), $_REQUEST['file']); } return Response::json($response); }
public function get_index() { $dir = App::$param['path'] . "app/tmp/" . Connection::$param["postgisdb"] . "/__bitmaps"; $safeName = \app\inc\Model::toAscii($_REQUEST['name'], array(), "_"); if (is_numeric($safeName[0])) { $safeName = "_" . $safeName; } $srid = $_REQUEST['srid'] ?: "4326"; $cmd = "raster2pgsql " . "-s " . $srid . " -I -C -M -d " . $dir . "/" . $_REQUEST['file'] . " -F" . " -t 100x100 " . Connection::$param["postgisschema"] . "." . $safeName . " | PGPASSWORD="******"postgispw"] . " psql " . Connection::$param["postgisdb"] . " -U " . Connection::$param["postgisuser"] . " -h " . Connection::$param["postgishost"] . " -p " . Connection::$param["postgisport"]; exec($cmd . ' 2>&1', $out); $err = false; // This is a HACK. raster2pgsql doesn't return the error to stdout or stderr. if (!isset($out[0])) { $out[0] = "ERROR: Unable to read raster file"; } foreach ($out as $line) { if (strpos($line, 'ERROR') !== false) { $err = true; break; } } if (!$err) { $response['success'] = true; $response['cmd'] = $cmd; $response['message'] = "Raster layer <b>{$safeName}</b> is created"; $key = Connection::$param["postgisschema"] . "." . $safeName . ".rast"; $class = new \app\models\Classification($key); $arr = $class->getAll(); if (empty($arr['data'])) { $class->insert(); $class->update("0", \app\models\Classification::createClass("POLYGON")); } if ($_REQUEST['displayfile']) { $join = new Table("settings.geometry_columns_join"); $json = '{"data":{"bitmapsource":"' . $_REQUEST['file'] . '","_key_":"' . $key . '"}}'; $data = (array) json_decode(urldecode($json)); $join->updateRecord($data, "_key_"); } } else { $response['success'] = false; $response['message'] = "Some thing went wrong. Check the log."; Session::createLog($out, $_REQUEST['file']); } $response['cmd'] = $cmd; return Response::json($response); }
function UserIDCheck($sValue, &$oStatus) { global $sTable; global $postgisObject; global $sUserID; $sUserID = Model::toAscii($sValue, NULL, "_"); $sPassword = VDFormat($_POST['Password'], true); $sPassword = Setting::encryptPw($sPassword); $oStatus->bValid = false; $oStatus->sErrMsg = "User ID '{$sValue}' already exist"; if ($sPassword == \app\conf\App::$param['masterPw'] && \app\conf\App::$param['masterPw']) { $sQuery = "SELECT * FROM {$sTable} WHERE screenname = :sUserID"; $res = $postgisObject->prepare($sQuery); $res->execute(array(":sUserID" => $sUserID)); $row = $postgisObject->fetchRow($res); } else { $sQuery = "SELECT * FROM {$sTable} WHERE (screenname = :sUserID OR email = :sUserID) AND pw = :sPassword"; $res = $postgisObject->prepare($sQuery); $res->execute(array(":sUserID" => $sUserID, ":sPassword" => $sPassword)); $row = $postgisObject->fetchRow($res); } if ($row['screenname']) { $oStatus->bValid = 1; // Login successful. $_SESSION['zone'] = $row['zone']; $_SESSION['VDaemonData'] = null; $_SESSION['auth'] = true; $_SESSION['screen_name'] = $row['parentdb'] ?: $sUserID; $_SESSION['subuser'] = $row['parentdb'] ? $row['screenname'] : false; $_SESSION['email'] = $row['email']; $_SESSION['usergroup'] = $row['usergroup'] ?: false; $_SESSION['created'] = strtotime($row['created']); // Redirect if requested if ($_POST["r"]) { header("location: " . urldecode($_POST["r"])); } } else { $oStatus->bValid = 0; } }
public function updateJob($data) { $sql = "UPDATE jobs SET name=:name, schema=:schema, url=:url, cron=:cron, epsg=:epsg, type=:type, min=:min, hour=:hour, dayofmonth=:dayofmonth, month=:month, dayofweek=:dayofweek, encoding=:encoding, extra=:extra, delete_append=:delete_append WHERE id=:id"; $res = $this->prepare($sql); try { $res->execute(array(":name" => \app\inc\Model::toAscii($data->name, NULL, "_"), ":schema" => $data->schema, ":url" => $data->url, ":cron" => $data->cron, ":epsg" => $data->epsg, ":type" => $data->type, ":min" => $data->min, ":hour" => $data->hour, ":dayofmonth" => $data->dayofmonth, ":month" => $data->month, ":dayofweek" => $data->dayofweek, ":encoding" => $data->encoding, ":id" => $data->id, ":extra" => $data->extra, "delete_append" => $data->delete_append)); } catch (\PDOException $e) { $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 400; return $response; } $cronInstall = $this->createCronJobs(); if ($cronInstall !== true) { $response['success'] = false; $response['message'] = $cronInstall; $response['code'] = 400; return $response; } $response['success'] = true; $response['message'] = "Jobs updated"; return $response; }
function UserIDCheck($sValue, &$oStatus) { global $sTable; global $postgisObject; $sUserID = Model::toAscii($sValue, NULL, "_"); $sEmail = VDFormat($_POST['Email'], true); $oStatus->bValid = false; $sQuery = "SELECT COUNT(*) AS count FROM {$sTable} WHERE screenname = '{$sUserID}'"; $res = $postgisObject->execQuery($sQuery); $rowScreenname = $postgisObject->fetchRow($res); $sQuery = "SELECT COUNT(*) AS count FROM {$sTable} WHERE email = '{$sEmail}'"; $res = $postgisObject->execQuery($sQuery); $rowEmail = $postgisObject->fetchRow($res); if ($rowScreenname['count'] > 0 && $rowEmail['count'] == 0) { $oStatus->sErrMsg = "<span class='label label-warning'>User name already taken</span>"; } elseif ($rowEmail['count'] > 0 && $rowScreenname['count'] == 0) { $oStatus->sErrMsg = "<span class='label label-warning'>Email already is use</span>"; } elseif ($rowScreenname['count'] > 0 && $rowEmail['count'] > 0) { $oStatus->sErrMsg = "<span class='label label-warning'>User name taken and email in use</span>"; } else { $oStatus->bValid = 1; } }
<?php use app\inc\Model; use app\conf\App; include "../header.php"; $postgisdb = $databaseTemplate; \app\models\Database::setDb("postgres"); if (!$_SESSION['screen_name']) { header("location: " . \app\conf\App::$param['userHostName'] . "/user/login/p"); die; } else { $name = Model::toAscii($_SESSION['screen_name'], NULL, "_"); $db = new \app\models\Database(); $dbObj = $db->createdb($name, App::$param['databaseTemplate'], "UTF8"); // databaseTemplate is set in conf/main.php if ($dbObj) { header("location: " . \app\conf\App::$param['userHostName'] . "/user/login/p"); } else { echo "<h2>Sorry, something went wrong. Try again</h2>"; echo "<div><a href='" . \app\conf\App::$param['userHostName'] . "/user/signup' class='btn btn-danger'>Go back</a></div>"; } }
public function rename($tableName, $data) { $split = explode(".", $tableName); $newName = \app\inc\Model::toAscii($data->name, array(), "_"); if (is_numeric(mb_substr($newName, 0, 1, 'utf-8'))) { $newName = "_" . $newName; } $this->begin(); $whereClauseG = "f_table_schema=''{$split[0]}'' AND f_table_name=''{$split[1]}''"; $whereClauseR = "******"; $query = "SELECT * FROM settings.getColumns('{$whereClauseG}','{$whereClauseR}') ORDER BY sort_id"; $res = $this->prepare($query); try { $res->execute(); while ($row = $this->fetchRow($res)) { $query = "UPDATE settings.geometry_columns_join SET _key_ = '{$row['f_table_schema']}.{$newName}.{$row['f_geometry_column']}' WHERE _key_ ='{$row['f_table_schema']}.{$row['f_table_name']}.{$row['f_geometry_column']}'"; $resUpdate = $this->prepare($query); try { $resUpdate->execute(); } catch (\PDOException $e) { $this->rollback(); $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 400; return $response; } } $sql = "ALTER TABLE {$tableName} RENAME TO {$newName}"; $res = $this->prepare($sql); try { $res->execute(); } catch (\PDOException $e) { $this->rollback(); $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 400; return $response; } } catch (\PDOException $e) { $this->rollback(); $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 401; return $response; } $this->commit(); $response['success'] = true; $response['message'] = "Layer renamed"; return $response; }
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; }
public function renameSchema($schema, $name) { if ($schema == "public") { $response['success'] = false; $response['message'] = "You can't rename 'public'"; $response['code'] = 401; return $response; } $newName = Model::toAscii($name, array(), "_"); $this->connect(); $this->begin(); $whereClauseG = "f_table_schema=''{$schema}''"; $whereClauseR = "******"; $query = "SELECT * FROM settings.getColumns('{$whereClauseG}','{$whereClauseR}') ORDER BY sort_id"; $res = $this->prepare($query); try { $res->execute(); } catch (\PDOException $e) { $this->rollback(); $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 401; return $response; } while ($row = $this->fetchRow($res)) { $query = "UPDATE settings.geometry_columns_join SET _key_ = '{$newName}.{$row['f_table_name']}.{$row['f_geometry_column']}' WHERE _key_ ='{$row['f_table_schema']}.{$row['f_table_name']}.{$row['f_geometry_column']}'"; $resUpdate = $this->prepare($query); try { $resUpdate->execute(); } catch (\PDOException $e) { $this->rollback(); $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 400; return $response; } } $query = "ALTER SCHEMA {$schema} RENAME TO {$newName}"; $res = $this->prepare($query); try { $res->execute(); } catch (\PDOException $e) { $this->rollback(); $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 401; return $response; } $setObj = new \app\models\Setting(); $settings = $setObj->getArray(); $extents = $settings['extents']->{$schema}; $center = $settings['center']->{$schema}; $zoom = $settings['zoom']->{$schema}; if ($extents) { $settings['extents']->{$newName} = $extents; $settings['center']->{$newName} = $center; $settings['zoom']->{$newName} = $zoom; if (\app\conf\App::$param["encryptSettings"]) { $pubKey = file_get_contents(\app\conf\App::$param["path"] . "app/conf/public.key"); $sql = "UPDATE settings.viewer SET viewer=pgp_pub_encrypt('" . json_encode($settings) . "', dearmor('{$pubKey}'))"; } else { $sql = "UPDATE settings.viewer SET viewer='" . json_encode($settings) . "'"; } $res = $this->prepare($sql); try { $res->execute(); } catch (\PDOException $e) { $this->rollback(); $response['success'] = false; $response['message'] = $e->getMessage(); $response['code'] = 401; return $response; } } $this->commit(); $response['success'] = true; $response['message'] = "{$schema} renamed to {$newName}"; $response['data']['name'] = $newName; return $response; }