]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/cmd.php
cli: import python modules for commands on demand
[nominatim.git] / lib / cmd.php
index 72b666088d1248b601d3edcfad521e99c89da139..5a12f99a06c527e2c33f5faf981f3f964f9c64bb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-require_once(CONST_BasePath.'/lib/Shell.php');
+require_once(CONST_LibDir.'/Shell.php');
 
 function getCmdOpt($aArg, $aSpec, &$aResult, $bExitOnError = false, $bExitOnUnknown = false)
 {
@@ -147,7 +147,7 @@ function repeatWarnings()
 function runSQLScript($sScript, $bfatal = true, $bVerbose = false, $bIgnoreErrors = false)
 {
     // Convert database DSN to psql parameters
-    $aDSNInfo = \Nominatim\DB::parseDSN(CONST_Database_DSN);
+    $aDSNInfo = \Nominatim\DB::parseDSN(getSetting('DATABASE_DSN'));
     if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
 
     $oCmd = new \Nominatim\Shell('psql');
@@ -195,3 +195,30 @@ function runSQLScript($sScript, $bfatal = true, $bVerbose = false, $bIgnoreError
         fail("pgsql returned with error code ($iReturn)");
     }
 }
+
+function setupHTTPProxy()
+{
+    if (!getSettingBool('HTTP_PROXY')) {
+        return;
+    }
+
+    $sProxy = 'tcp://'.getSetting('HTTP_PROXY_HOST').':'.getSetting('HTTP_PROXY_PROT');
+    $aHeaders = array();
+
+    $sLogin = getSetting('HTTP_PROXY_LOGIN');
+    $sPassword = getSetting('HTTP_PROXY_PASSWORD');
+
+    if ($sLogin && $sPassword) {
+        $sAuth = base64_encode($sLogin.':'.$sPassword);
+        $aHeaders = array('Proxy-Authorization: Basic '.$sAuth);
+    }
+
+    $aProxyHeader = array(
+                     'proxy' => $sProxy,
+                     'request_fulluri' => true,
+                     'header' => $aHeaders
+                    );
+
+    $aContext = array('http' => $aProxyHeader, 'https' => $aProxyHeader);
+    stream_context_set_default($aContext);
+}