|
22 | 22 | #include "qgsconfig.h"
|
23 | 23 | #include "qgsserver.h"
|
24 | 24 |
|
| 25 | +#include "qgsauthmanager.h" |
25 | 26 | #include "qgscapabilitiescache.h"
|
26 | 27 | #include "qgsfontutils.h"
|
27 | 28 | #include "qgsgetrequesthandler.h"
|
|
40 | 41 | #include "qgseditorwidgetregistry.h"
|
41 | 42 |
|
42 | 43 | #include <QDomDocument>
|
| 44 | +#include <QFile> |
43 | 45 | #include <QNetworkDiskCache>
|
44 | 46 | #include <QImage>
|
45 | 47 | #include <QSettings>
|
46 | 48 | #include <QDateTime>
|
47 | 49 | #include <QScopedPointer>
|
| 50 | +#include <QTextStream> |
48 | 51 | // TODO: remove, it's only needed by a single debug message
|
49 | 52 | #include <fcgi_stdio.h>
|
50 | 53 | #include <stdlib.h>
|
@@ -350,10 +353,54 @@ bool QgsServer::init( int & argc, char ** argv )
|
350 | 353 | QgsDebugMsg( "Plugin PATH: " + QgsApplication::pluginPath() );
|
351 | 354 | QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() );
|
352 | 355 | QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() );
|
| 356 | + QgsDebugMsg( "Auth DB PATH: " + QgsApplication::qgisAuthDbFilePath() ); |
353 | 357 | QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) );
|
354 | 358 |
|
355 | 359 | QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs)
|
356 | 360 |
|
| 361 | + // Instantiate authentication system |
| 362 | + // creates or uses qgis-auth.db in ~/.qgis2/ or directory defined by QGIS_AUTH_DB_DIR_PATH env variable |
| 363 | + QgsAuthManager::instance()->init( QgsApplication::pluginPath() ); |
| 364 | + // set the master password from first line of file defined by QGIS_AUTH_PASSWORD_FILE env variable |
| 365 | + const char* passenv = "QGIS_AUTH_PASSWORD_FILE"; |
| 366 | + if ( getenv( passenv ) ) |
| 367 | + { |
| 368 | + QString passpath( getenv( passenv ) ); |
| 369 | + // clear the env variable, so it can not be accessed from plugins, etc. |
| 370 | +#ifdef Q_OS_WIN |
| 371 | + putenv( passenv ); |
| 372 | +#else |
| 373 | + unsetenv( passenv ); |
| 374 | +#endif |
| 375 | + QString masterpass; |
| 376 | + QFile passfile( passpath ); |
| 377 | + if ( passfile.exists() && passfile.open( QIODevice::ReadOnly | QIODevice::Text ) ) |
| 378 | + { |
| 379 | + QTextStream passin( &passfile ); |
| 380 | + while ( !passin.atEnd() ) |
| 381 | + { |
| 382 | + masterpass = passin.readLine(); |
| 383 | + break; |
| 384 | + } |
| 385 | + passfile.close(); |
| 386 | + } |
| 387 | + if ( !masterpass.isEmpty() ) |
| 388 | + { |
| 389 | + if ( QgsAuthManager::instance()->setMasterPassword( masterpass, true ) ) |
| 390 | + { |
| 391 | + QgsDebugMsg( "Authentication master password set" ); |
| 392 | + } |
| 393 | + else |
| 394 | + { |
| 395 | + QgsDebugMsg( "Setting authentication master password FAILED using file: " + passpath ); |
| 396 | + } |
| 397 | + } |
| 398 | + else |
| 399 | + { |
| 400 | + QgsDebugMsg( "QGIS_AUTH_PASSWORD_FILE set, but FAILED to read file: " + passpath ); |
| 401 | + } |
| 402 | + } |
| 403 | + |
357 | 404 | QString defaultConfigFilePath;
|
358 | 405 | QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs file in the server directory
|
359 | 406 | if ( projectFileInfo.exists() )
|
|
0 commit comments