Skip to content
Permalink
Browse files

Return code for session check for every request to QGIS Server in qgi…

…sproxy.php, some needed refactoring

When QGIS server GetMap returns error (due to some project issue or session timeout) redirection to login page happens (gisportal handles then the rest)
  • Loading branch information
uprel committed Mar 8, 2020
1 parent 33274a7 commit bb500d0cdf7d1480adc9a2993eeba62ec79e9c4c
@@ -595,6 +595,22 @@ public static function hasPortal() {
return $ret;
}

public function isValidUserProj($project)
{
$valid = isset($_SESSION['user_is_logged_in']);
$sess = isset($_SESSION['project']) ? $_SESSION['project'] : null;

if (($valid === true) && ($project === $sess)) {
return TRUE;
}
return FALSE;
}

/**
* Obsolete, not in use!
* @param $project
* @return bool
*/
public function checkReferer($project) {
//disabling referer check due to some issues
//should take also port number
@@ -179,7 +179,7 @@ public function changeProject($user, $project) {
return true;
}

public function isValidUserProj($project)
public function setUserProj($project)
{
$valid = isset($_SESSION['user_is_logged_in']);
$sess = isset($_SESSION['project']) ? $_SESSION['project'] : null;
@@ -323,8 +323,7 @@ function sendFile($ctype, $key)
}

//check user session and permissions
$login_check =new GisApp\Login();
if (!($login_check->isValidUserProj($map))) {
if (!(Helpers::isValidUserProj($map))) {
throw new Exception("Session time out or unathorized access!");
}

@@ -277,22 +277,19 @@ function doGetRequest($query_arr, $map, $client, $http_ver, $user)
$map = explode(".", $query_arr["map"])[0];
}

//if (!(Helpers::isValidUserProj($map))) {
// throw new Exception\ClientException("Session time out or unathorized access!", new Request('GET', QGISSERVERURL));
//}

$helpers = new Helpers();

if(!($helpers->checkReferer($map))) {
throw new Exception\ClientException("Invalid referer!", new Request('GET', QGISSERVERURL));
//session check
session_start();

if (!($helpers->isValidUserProj($map))) {
throw new Exception\ClientException("Session time out or unathorized access!", new Request('GET', QGISSERVERURL));
}

//get project path from cache
$sep = "_x_";
$projectPath = $helpers->readFromCache($map . $sep . "PROJECT_PATH");

//session check
session_start();
$user = null;
if (isset($_SESSION["user_name"])) {
$user = $_SESSION["user_name"];
@@ -249,8 +249,7 @@ function sendText($type, $layer_name, $project_path, $query, $format)
}

//check user session and permissions
$login_check =new GisApp\Login();
if (!($login_check->isValidUserProj($map))) {
if (!(Helpers::isValidUserProj($map))) {
throw new Exception("Session time out or unathorized access!");
}

@@ -88,8 +88,13 @@ function showFeatureInfo(evt) {
//temp array for storing target element ids for tooltips, recreate on each featureinfocall
Eqwc._temp_ids = [];

parseFIResult(xmlDoc);
featureInfoResultLayers.reverse();
if(evt.request.status == 200) {
parseFIResult(xmlDoc);
featureInfoResultLayers.reverse();
} else {
text += "<b><span style='color:red'>" + evt.text + "</span></b>";
}

//highLightGeometry.reverse();

// if (hoverPopup) {
@@ -111,15 +116,15 @@ function showFeatureInfo(evt) {
//featureInfoHighlightLayer.addFeatures(highLightGeometry[i]);
}
}

popupItems.push({
id: "fi_qgis",
xtype: 'box',
//margins: '3 0 3 3',
html: text
});
}

popupItems.push({
id: "fi_qgis",
xtype: 'box',
//margins: '3 0 3 3',
html: text
});

//new way GeoExt Popup
clickPopup = new GeoExt.Popup({
title: clickPopupTitleString[lang],
@@ -646,15 +646,7 @@ function postLoading() {
// console.log('loadend '+selectedQueryableLayers.length);
//});
thematicLayer.events.register('tileerror', this, function () {
//loadMask.hide();
Ext.Msg.show({
title: 'Error!',
msg: "Map loading error",
//width: 300,
buttons: Ext.MessageBox.OK,
//multiline: true,
fn: home
});
Eqwc.common.redirect();
});

//set crs values
@@ -2847,19 +2839,14 @@ function exceptionLoading(res) {
//width: 300,
buttons: Ext.MessageBox.OK,
//multiline: true,
fn: logout
fn: Eqwc.common.redirect
});
}

function logout() {
window.location.href = "./admin/login.php?action=logout";
}

function home() {
//don't redirect, do what?
//Eqwc.settings.useGisPortal ? window.location.href = Eqwc.settings.gisPortalRoot + "login?ru="+Eqwc.common.getProjectUrl() : window.location.href="/";
}

function getExternalWMSDefinition(layer) {

var layerName = layer.id;
@@ -211,6 +211,10 @@ Eqwc.common.reverseArray = function(arr) {
return newArray;
};

Eqwc.common.redirect = function() {
Eqwc.settings.useGisPortal ? window.location.href = Eqwc.settings.gisPortalRoot + "login?ru="+Eqwc.common.getProjectUrl() : window.location.href = "/";
};

String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
@@ -134,7 +134,7 @@ FeatureInfo.prototype.handleEvent = function (e) {
Map.toggleClickHandling(true);
})
.fail(function (xhr, status, error) {
//todo what with error here
this.resultsCallback(status,xhr.responseText);
Map.toggleClickHandling(true);
});
};
@@ -770,17 +770,15 @@ Gui.selectLayer = function(layer) {

// show feature info results
Gui.showFeatureInfoResults = function(status, data) {
if(status != 'success') {
Map.toggleClickMarker(true);
alert(data);
return;
}

if (Config.featureInfo.format === 'text/xml') {
Gui.showXMLFeatureInfoResults(data);
}
else {
$('#featureInfoResults').html(data.join(''));
if(status == 'success') {
if (Config.featureInfo.format === 'text/xml') {
Gui.showXMLFeatureInfoResults(data);
} else {
$('#featureInfoResults').html(data.join(''));
}
} else {
$('#featureInfoResults').html("<span style='color:red'>"+data+"</span>");
}

$('#panelFeatureInfo').panel('open');
@@ -212,8 +212,7 @@ Map.setTopicLayer = function() {
if (Map.useTiledWMS) {
source = new ol.source.TileWMS(wmsOptions);
source.on('tileloaderror', function(evt) {
alert('Error loading image from QGIS!');
//Eqwc.settings.useGisPortal ? window.location.href = Eqwc.settings.gisPortalRoot + "login?ru="+Eqwc.common.getProjectUrl() : window.location.href="/";
Eqwc.common.redirect();
});
Map.topicLayer = new ol.layer.Tile({
//extent: Config.map.extent,
@@ -231,8 +230,7 @@ Map.setTopicLayer = function() {
});
source.on('imageloaderror', function() {
Map.progress.addLoaded();
//alert('Error loading image from QGIS!');
//Eqwc.settings.useGisPortal ? window.location.href = Eqwc.settings.gisPortalRoot + "login?ru="+Eqwc.common.getProjectUrl() : window.location.href="/";
Eqwc.common.redirect();
});
Map.topicLayer = new ol.layer.Image({
//extent: Config.map.extent,
@@ -216,7 +216,7 @@ function goMobile($lang, $scanner) {

$login_check = new Login();

if ($login_check->isValidUserProj($helpers->getMapFromUrl())) {
if ($login_check->setUserProj($helpers->getMapFromUrl())) {

$edit = $helpers->checkModulexist("editing") && $helpers->hasPluginAccess("editing");
$scanner = FALSE;

0 comments on commit bb500d0

Please sign in to comment.
You can’t perform that action at this time.