U
    TGhc                  	   @   s  d Z dZdZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZmZ ddlmZmZmZ ddlmZ e   ej de!d ddl"m#Z# W 5 Q R X ddl$m%Z% dZ&dZ'dZ(dZ)G dd deZ*dS )zCopyright 2022, 3LizzGPL version 3zinfo@3liz.org    N)Union)Qgis)QtQRegularExpression)QFontDatabase)QgsServerOgcApiQgsServerOgcApiHandler)ServiceError)check_environment_variableto_bool)BING_KEY
GOOGLE_KEYstrict_tos_check   )create_server_contextignore)category)gdal)Logger)nameversionZcommitNumberZ
commitSha1ZdateTimeZ
repositoryhomepageZ
DataPlotly)ZwfsOutputExtensionlizmap_serverZ
atlasprint)WMSWFSWCSWMTS
EXPRESSIONLIZMAPc                       sz   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zedef dddZdd Z  ZS )ServerInfoHandlerc                    s,   t    t | _td| jj d d S )Nz*Server information handler using context '')super__init__r   _contextr   infor   self	__class__ C/var/www/lizmap/lizmap/plugins/lizmap_server/server_info_handler.pyr#   B   s    
zServerInfoHandler.__init__c                 C   s   t dS )Nzserver.jsonr   r&   r*   r*   r+   pathG   s    zServerInfoHandler.pathc                 C   s   dS )NzServer informationr*   r&   r*   r*   r+   summaryJ   s    zServerInfoHandler.summaryc                 C   s   dS )Nz&Get info about the current QGIS serverr*   r&   r*   r*   r+   descriptionM   s    zServerInfoHandler.descriptionc                 C   s   dS )Nserverr*   r&   r*   r*   r+   operationIdP   s    zServerInfoHandler.operationIdc                 C   s   dS )NzHandler Lizmap API server infor*   r&   r*   r*   r+   	linkTitleS   s    zServerInfoHandler.linkTitlec                 C   s   t jS N)r   datar&   r*   r*   r+   linkTypeV   s    zServerInfoHandler.linkTypec                 C   s8   z|  | W n$ tk
r2   tt   Y nX d S r2   )_handleRequest	Exceptionr   critical	traceback
format_exc)r'   contextr*   r*   r+   handleRequestY   s
    zServerInfoHandler.handleRequestc              
   C   s  t  stddd| jj}t| jt}tD ]}||kr.d|d||< q.t	dd}|dkrt
| kr|dkrxd	}nd
}|t
dd|t
< tjdd\}}g }	tD ] }
|  |
r|	|
 qt dkrt }nd}zd|dd }W n tk
r   d}Y nX |rFtd|j|j|j|j|j| jj| jjd}ntddd}||||tjd|t  t!tt"  t!t"i|	|t# $ dt%&dt'jt(j)dd}| *|| d S )NzBad request errorzInvalid requesti  z	Not found)r   r   ZLZM_ALLOCATION_MODE Zsharedz.Not available on the "Basic" Lizmap Cloud planzNot installedz:https://github.com/ghtmtt/DataPlotly/blob/master/README.md)r   r   r   -r   Zexportedzfinal-._T)foundr   r   build_id	commit_idZstablegit_repository_urldocumentation_urlFznot used)r@   r   )r   tagr   rB   version_int)metadataZpy_qgis_serverZexternal_providers_tos_checksservicespluginsZfontsVERSION_NUM)r   pythonZqt)Zqgis_serverZenvironment)+r   r
   r$   rG   dictZinstalled_pluginsPLUGIN_METADATA_KEYSEXPECTED_PLUGINSosgetenvDATA_PLOTLYkeysr   QGIS_VERSIONsplitEXPECTED_SERVICESserverInterfaceserviceRegistry
getServiceappend
devVersionreplacer6   r   r   rA   rB   Z	is_stablerC   rD   QGIS_VERSION_INTr   lowerr   r   r   Zfamiliesr   VersionInfosysr   QT_VERSION_STRwrite)r'   r:   Zserver_metadatarI   ZexpectedZallocated_ressourcesr   Zhuman_versionZ
human_nameZservices_availableservicerB   rE   Zqgis_server_metar3   r*   r*   r+   r5   e   s    


  z ServerInfoHandler._handleRequestN)returnc                 C   s<   |    }| }t|ds&dS | }|ddk	S )z Check if this QGIS Server supports custom headers.

         Returns None if the check is not requested with the GET parameter CHECK_CUSTOM_HEADERS

         If requested, returns boolean if X-Check-Custom-Headers is found in headers.
         CHECK_CUSTOM_HEADERSNzX-Check-Custom-Headers)serverIfacerequestHandlerparameterMapr   getrequestHeaders)r'   handlerparamsheadersr*   r*   r+   support_custom_headers   s    z(ServerInfoHandler.support_custom_headersc                 C   s    ddl m} |dd|jjdgS )Nr   )QgsServerQueryStringParameterrd   FzIf we check custom headers)qgis.serverrn   TypeString)r'   r:   rn   r*   r*   r+   
parameters   s    zServerInfoHandler.parameters)__name__
__module____qualname__r#   r,   r-   r.   r0   r1   r4   r;   r5   r   boolrm   rr   __classcell__r*   r*   r(   r+   r    @   s   ]r    )+__copyright____license__	__email__rO   r_   r8   warningstypingr   	qgis.corer   	qgis.PyQtr   Zqgis.PyQt.QtCorer   qgis.PyQt.QtGuir   ro   r   r	   lizmap_server.exceptionr
   lizmap_server.toolsr   r   lizmap_server.tos_definitionsr   r   r   r:   r   catch_warningsfilterwarningsDeprecationWarningosgeor   loggerr   rM   rQ   rN   rU   r    r*   r*   r*   r+   <module>   s2   

