<commit_before>QGIS Web Client (qgis-web-client):
==================================

Purpose:
--------
A WMS based webgis client that makes use of QGIS specific WMS extensions (e.g. highlighting, printing, metadata, etc.). QGIS webclient reads the configuration from the WMS GetCapabilities command and builds the layer tree accordingly. Supports legend graphic, feature info requests and printing.

The client builds on existing Web-GIS libraries OpenLayers and GeoExt, as well as ExtJS 3 for the GUI widgets.

All major browsers should be supported.

Installation
------------
Requirements (Server):
* Apache2 - Webserver (Ubuntu: apache2)
* mod-fcgid (Ubuntu: libapache2-mod-fcgid)
* QGIS and QGIS Server (best installed from source)

The QGIS server compilation and installation will be covered in the QGIS manual.

For searching:
* python-wsgi for searching (Ubuntu: libapache2-mod-wsgi)
* psycopg2 PostgreSQL db driver (Ubuntu: python-psycopg2)
* webob - Python module providing WSGI request and response objects (Ubuntu: python-webob)

The client part can be downloaded from:
https://github.com/qgis/qgis-web-client/archives/master
Or you can clone the git repositroy with the following command:
git clone https://github.com/qgis/qgis-web-client.git

Configuration of Client
-----------------------
Global Settings for all projects:
js/GlobalConfiguration.js

Translations (additional languages):
js/Translations.js

Project settings and index:
index.xml

Stylesheet of project index:
gis-project_listing.xsl

Thumbnails for individual projects:
thumbnails/projectname.png

URL Rewriting
-------------

Using a standard installation of QGIS server, GlobalOptions.js will have a WMS server configuration like

var serverAndCGI = "/cgi-bin/qgis_mapserv.fcgi";

A sample URL for QGIS Web Client installed in /var/www/qgis-web-client:

http://localhost/qgis-web-client/qgiswebclient.html?map=/opt/geodata/maps/NaturalEarth.qgs&visibleLayers=HYP_50M_SR_W

With the following rules for Apache mod_rewrite you can shorten the URLs to

var serverAndCGI = "/wms";

and

http://localhost/maps/NaturalEarth?visibleLayers=HYP_50M_SR_W

Rules in VirtualHost configuration:

# Forbid direct access
RewriteRule ^/cgi-bin/.*$ - [F]

# Rewrite /wms/mapname to qgis_mapserv.fcgi?map=mappath/mapname.qgs
RewriteRule ^/wms/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps/$1.qgs [QSA,PT]
# Rewrite /maps/mapname to qgis-web-client main page. mapname will be extracted for wms calls in Javascript code.
RewriteRule ^/maps/([^\.]+)$ /qgis-web-client/qgiswebclient.html [PT]
# Rewrite /maps/* to qgis-web-client (e.g. /maps/icons/mActionZoomNext.png -> /qgis-web-client/icons/mActionZoomNext.png)
RewriteRule ^/maps/(.*) /qgis-web-client/$1 [PT]

For supporting qgs files in subdirectories (e.g. /maps/subdir/mapnampe) replace last rule with:

RewriteRule ^/maps/[^/]+/(.*) /qgis-web-client/$1 [PT]

For adding zones in different subdirecories (e.g. maps and maps-protected) add the following rules:

RewriteRule ^/wms-protected/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps-protected/$1.qgs [QSA,PT]
RewriteRule ^/maps-protected/([^\.]+)$ /qgis-web-client/qgiswebclient.html [PT]
RewriteRule ^/maps-protected/(.*) /qgis-web-client/$1 [PT]


Configuration of search python script
-------------------------------------
Searching is handled by two separate python-wsgi scripts: "search.wsgi" lists back a hit list while the user is typing in the searchbox. It groups the results and returns a bounding box of the result. "getSearchGeom.wsgi" returns the actual wkt geometry for a selected search result. It is recommended to install the wsgi scripts in a separate directory, e.g. /home/www/wsgi, a place that is not reachable by regular web traffic.

You need to enable mod_wsgi as root. (Ubuntu: a2enmod mod_wsgi).

You need to configure apache with the following lines (e.g. in file /etc/apache2/sites-available/default):

#mod_wsgi
WSGIDaemonProcess gis processes=5 threads=15 display-name=%{GROUP}
WSGIScriptAlias /wsgi/ /home/www/wsgi/
WSGIScriptAliasMatch ^/wsgi/([^/]+) /home/www/wsgi/$1.wsgi

In the files "search.wsgi" and "getSearchGeom.wsgi" please edit the line containing the db connection strings. Search for the line
conn = psycopg2.connect("db='yourdb' port='5432' user='yourusername' password='<PASSWORD>'")
and adapt the parameters according to your server/db.

PostgreSQL table setup for searching:

.................................

CREATE TABLE cadastre.searchtable
(
  searchstring text, --the search string (all lower case), e.g. "zürichstrasse 46, 8610 uster"
  displaytext text NOT NULL, --the display text for the search combobox, e.g. "Zürichstrasse 46, 8610 Uster (address)"
  search_category text, --should have a leading two digit number:, e.g. "03_parcels", where 03 is the order of the search categories, the number should be unique across all search tables
  the_geom geometry, --the actual geometry
  geometry_type text, --the geometry type as returned by ST_GeometryType(the_geom)
  searchstring_tsvector tsvector,
  CONSTRAINT searchtable_pkey PRIMARY KEY (displaytext)
)
WITH (
  OIDS=FALSE
);
GRANT SELECT ON TABLE cadastre.searchtable TO alle;

-- Index: cadastre.in_cadastre_searchstring_tsvector_gin

CREATE INDEX in_cadastre_searchstring_tsvector_gin
  ON cadastre.searchtable
  USING gin
  (searchstring_tsvector);
........................................................

The above search table can also be a view or materialized view. One can combine several search tables by specifying the "searchtables=searchtable1,searchtable2,searchtable3" parameter when requesting the "search.wsgi" script.


License
-------
BSD

Acknowledgements:
----------------

We'd like to thank the OpenLayers and GeoExt team for providing their base libraries.

<commit_msg>Rewrite rules with HTTP Basic Authentication<commit_after>QGIS Web Client (qgis-web-client):
==================================

Purpose:
--------
A WMS based webgis client that makes use of QGIS specific WMS extensions (e.g. highlighting, printing, metadata, etc.). QGIS webclient reads the configuration from the WMS GetCapabilities command and builds the layer tree accordingly. Supports legend graphic, feature info requests and printing.

The client builds on existing Web-GIS libraries OpenLayers and GeoExt, as well as ExtJS 3 for the GUI widgets.

All major browsers should be supported.

Installation
------------
Requirements (Server):
* Apache2 - Webserver (Ubuntu: apache2)
* mod-fcgid (Ubuntu: libapache2-mod-fcgid)
* QGIS and QGIS Server (best installed from source)

The QGIS server compilation and installation will be covered in the QGIS manual.

For searching:
* python-wsgi for searching (Ubuntu: libapache2-mod-wsgi)
* psycopg2 PostgreSQL db driver (Ubuntu: python-psycopg2)
* webob - Python module providing WSGI request and response objects (Ubuntu: python-webob)

The client part can be downloaded from:
https://github.com/qgis/qgis-web-client/archives/master
Or you can clone the git repositroy with the following command:
git clone https://github.com/qgis/qgis-web-client.git

Configuration of Client
-----------------------
Global Settings for all projects:
js/GlobalConfiguration.js

Translations (additional languages):
js/Translations.js

Project settings and index:
index.xml

Stylesheet of project index:
gis-project_listing.xsl

Thumbnails for individual projects:
thumbnails/projectname.png

URL Rewriting
-------------

Using a standard installation of QGIS server, GlobalOptions.js will have a WMS server configuration like

var serverAndCGI = "/cgi-bin/qgis_mapserv.fcgi";

A sample URL for QGIS Web Client installed in /var/www/qgis-web-client:

http://localhost/qgis-web-client/qgiswebclient.html?map=/opt/geodata/maps/NaturalEarth.qgs&visibleLayers=HYP_50M_SR_W

With the following rules for Apache mod_rewrite you can shorten the URLs to

var serverAndCGI = "/wms";

and

http://localhost/maps/NaturalEarth?visibleLayers=HYP_50M_SR_W

Rules in VirtualHost configuration:

# Forbid direct access
RewriteRule ^/cgi-bin/.*$ - [F]

# Rewrite /wms/mapname to qgis_mapserv.fcgi?map=mappath/mapname.qgs
RewriteRule ^/wms/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps/$1.qgs [QSA,PT]
# Rewrite /maps/mapname to qgis-web-client main page. mapname will be extracted for wms calls in Javascript code.
RewriteRule ^/maps/([^\.]+)$ /qgis-web-client/qgiswebclient.html [PT]
# Rewrite /maps/* to qgis-web-client (e.g. /maps/icons/mActionZoomNext.png -> /qgis-web-client/icons/mActionZoomNext.png)
RewriteRule ^/maps/(.*) /qgis-web-client/$1 [PT]

For supporting qgs files in subdirectories (e.g. /maps/subdir/mapnampe) replace last rule with:

RewriteRule ^/maps/[^/]+/(.*) /qgis-web-client/$1 [PT]

For adding zones in different subdirecories (e.g. maps and maps-protected) add the following rules:

RewriteRule ^/wms-protected/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps-protected/$1.qgs [QSA,PT]
RewriteRule ^/maps-protected/([^\.]+)$ /qgis-web-client/qgiswebclient.html [PT]
RewriteRule ^/maps-protected/(.*) /qgis-web-client/$1 [PT]

If you want to protect a zone with HTTP Basic Authentication, you have rewrite to a different location:

RewriteRule ^/wms-protected/(.+)$ /cgi-bin/qgis_mapserv-protected.fcgi?map=/opt/geodata/maps-protected/$1.qgs [QSA,PT]
RewriteRule ^/maps-protected/([^\.]+)$ /qgis-web-client-protected/qgiswebclient.html [PT]
RewriteRule ^/maps-protected/(.*) /qgis-web-client-protected/$1 [PT]

<LocationMatch "/qgis-web-client-protected/|/qgis_mapserv-protected.fcgi">
  AuthType Basic
  AuthName "Authorization Required"
  AuthUserFile /etc/apache2/htpasswd
  Require valid-user
</LocationMatch>

These locations are usually symlinks to the non-protected files/directory:

ln -s qgis-web-client /var/www/qgis-web-client-protected
ln -s qgis_mapserv.fcgi /usr/lib/cgi-bin/qgis_mapserv-protected.fcgi


Configuration of search python script
-------------------------------------
Searching is handled by two separate python-wsgi scripts: "search.wsgi" lists back a hit list while the user is typing in the searchbox. It groups the results and returns a bounding box of the result. "getSearchGeom.wsgi" returns the actual wkt geometry for a selected search result. It is recommended to install the wsgi scripts in a separate directory, e.g. /home/www/wsgi, a place that is not reachable by regular web traffic.

You need to enable mod_wsgi as root. (Ubuntu: a2enmod mod_wsgi).

You need to configure apache with the following lines (e.g. in file /etc/apache2/sites-available/default):

#mod_wsgi
WSGIDaemonProcess gis processes=5 threads=15 display-name=%{GROUP}
WSGIScriptAlias /wsgi/ /home/www/wsgi/
WSGIScriptAliasMatch ^/wsgi/([^/]+) /home/www/wsgi/$1.wsgi

In the files "search.wsgi" and "getSearchGeom.wsgi" please edit the line containing the db connection strings. Search for the line
conn = psycopg2.connect("db='yourdb' port='5432' user='yourusername' password='<PASSWORD>'")
and adapt the parameters according to your server/db.

PostgreSQL table setup for searching:

.................................

CREATE TABLE cadastre.searchtable
(
  searchstring text, --the search string (all lower case), e.g. "zürichstrasse 46, 8610 uster"
  displaytext text NOT NULL, --the display text for the search combobox, e.g. "Zürichstrasse 46, 8610 Uster (address)"
  search_category text, --should have a leading two digit number:, e.g. "03_parcels", where 03 is the order of the search categories, the number should be unique across all search tables
  the_geom geometry, --the actual geometry
  geometry_type text, --the geometry type as returned by ST_GeometryType(the_geom)
  searchstring_tsvector tsvector,
  CONSTRAINT searchtable_pkey PRIMARY KEY (displaytext)
)
WITH (
  OIDS=FALSE
);
GRANT SELECT ON TABLE cadastre.searchtable TO alle;

-- Index: cadastre.in_cadastre_searchstring_tsvector_gin

CREATE INDEX in_cadastre_searchstring_tsvector_gin
  ON cadastre.searchtable
  USING gin
  (searchstring_tsvector);
........................................................

The above search table can also be a view or materialized view. One can combine several search tables by specifying the "searchtables=searchtable1,searchtable2,searchtable3" parameter when requesting the "search.wsgi" script.


License
-------
BSD

Acknowledgements:
----------------

We'd like to thank the OpenLayers and GeoExt team for providing their base libraries.


{'fraction_non_alphanumeric': 0.12962962962962962, 'fraction_numerical': 0.007648953301127214, 'mean_word_length': 4.008467741935484, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 9, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6130795', 'n_tokens_mistral': 4129, 'n_tokens_neox': 3815, 'n_words': 1284}