function OGR2Tab_Update_main()
{
    $strFormat = "MapInfo File";
    $strDataSource = NULL;
    $strDestDataSource = NULL;
    $amAttribute = NULL;
    /* -------------------------------------------------------------------- */
    /*      Register format(s).                                             */
    /* -------------------------------------------------------------------- */
    OGRRegisterAll();
    /* -------------------------------------------------------------------- */
    /*      Processing command line arguments.                              */
    /* -------------------------------------------------------------------- */
    $numArgs = count($_SERVER["argv"]);
    for ($iArg = 1; $iArg < $numArgs; $iArg++) {
        /* Get the feature id and attribute name to update to the new attribute
           value.*/
        if (!strcasecmp($_SERVER["argv"][$iArg], "-fid") && $iArg < $numArgs - 1) {
            $amAttribute[0] = $_SERVER["argv"][++$iArg];
            $amAttribute[1] = $_SERVER["argv"][++$iArg];
            $amAttribute[2] = $_SERVER["argv"][++$iArg];
            printf("FID = %d\n", $amAttribute[0]);
            printf("Attribute name  = %s\n", $amAttribute[1]);
            printf("Attribute value = %d\n", $amAttribute[2]);
        } else {
            if ($_SERVER["argv"][$iArg][0] == '-') {
                Usage();
            } else {
                if ($strDestDataSource == NULL) {
                    $strDestDataSource = $_SERVER["argv"][$iArg];
                    printf("DestDataSource = %s\n", $strDestDataSource);
                } else {
                    if ($strDataSource == NULL) {
                        $strDataSource = $_SERVER["argv"][$iArg];
                        printf("DataSource = %s\n", $strDataSource);
                    }
                }
            }
        }
    }
    if ($strDataSource == NULL) {
        Usage();
    }
    /* -------------------------------------------------------------------- */
    /*      Open data source.                                               */
    /* -------------------------------------------------------------------- */
    $hSFDriver = NULL;
    $hDS = OGROpen($strDataSource, FALSE, $hSFDriver);
    /* -------------------------------------------------------------------- */
    /*      Report failure                                                  */
    /* -------------------------------------------------------------------- */
    if ($hDS == NULL) {
        printf("FAILURE:\nUnable to open datasource `%s' with the following drivers:\n", $strDataSource);
        for ($iDriver = 0; $iDriver < OGRGetDriverCount(); $iDriver++) {
            printf("  -> %s\n", OGR_DR_GetName(OGRGetDriver($iDriver)));
        }
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Find the output driver.                                         */
    /* -------------------------------------------------------------------- */
    for ($iDriver = 0; $iDriver < OGRGetDriverCount() && $hSFDriver == NULL; $iDriver++) {
        if (!strcasecmp(OGR_DR_GetName(OGRGetDriver($iDriver)), $strFormat)) {
            $hSFDriver = OGRGetDriver($iDriver);
        }
    }
    if ($hSFDriver == NULL) {
        printf("Unable to find driver `%s'.\n", $strFormat);
        printf("The following drivers are available:\n");
        for ($iDriver = 0; $iDriver < OGRGetDriverCount(); $iDriver++) {
            printf("  -> %s\n", OGR_DR_GetName(OGRGetDriver($iDriver)));
        }
        return OGRERR_FAILURE;
    }
    if (!OGR_Dr_TestCapability($hSFDriver, ODrCCreateDataSource)) {
        printf("%s driver does not support data source creation.\n", $strFormat);
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Create the output data source.                                  */
    /* -------------------------------------------------------------------- */
    /*Uncomment and add options here. */
    /* $aoptions[0] = 'option1';
        $aoptions[1] = 'option2';
        $hODS = OGR_Dr_CreateDataSource( $hSFDriver, $strDestDataSource, $aoptions );
    */
    /* Or use no option.*/
    $hODS = OGR_Dr_CreateDataSource($hSFDriver, $strDestDataSource, NULL);
    if ($hODS == NULL) {
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Process only first layer in source dataset                      */
    /* -------------------------------------------------------------------- */
    if (OGR_DS_GetLayerCount($hDS) > 0) {
        $hLayer = OGR_DS_GetLayer($hDS, 0);
        if ($hLayer == NULL) {
            printf("FAILURE: Couldn't fetch advertised layer 0!\n");
            return OGRERR_FAILURE;
        }
        if (!TranslateLayer($hDS, $hLayer, $hODS, $amAttribute)) {
            return OGRERR_FAILURE;
        }
    }
    /* -------------------------------------------------------------------- */
    /*      Close down.                                                     */
    /* -------------------------------------------------------------------- */
    OGR_DS_Destroy($hDS);
    OGR_DS_Destroy($hODS);
    return OGRERR_NONE;
}
Esempio n. 2
0
 *  Script to encrypt or decrypt text using our defined key in config/crypt.php 
 *
 *
 *  Usage: ( from the main vulnDB directory )
 *    php bin/util/kb_to_csv_converter.php /path/to/output/file/to.csv
 *
 *
 *
 **/
if (!is_file($init_file = realpath(dirname(__FILE__)) . "/../../init.php")) {
    echo "Could not find init.php, this file is requied for vulnDB to operate\n";
    exit(1);
}
require $init_file;
if (!isset($argv[1]) || !$argv[2]) {
    Usage();
}
$output_file = $argv[1];
if ($argv[2] == "encrypt") {
    $encrypted_text = CryptAES::encrypt($argv[1]) . "\n";
    echo "\nEncrypted Text: {$encrypted_text}\n    ";
} else {
    if ($argv[2] == "decrypt") {
        $decrypted_text = CryptAES::decrypt($argv[1]) . "\n";
        echo "\nDecrypted Text: {$decrypted_text}\n";
    }
}
function Usage()
{
    echo " \nPlease Supply text to be encrypted.\n\n\nUsage:  php {$_SERVER['SCRIPT_NAME']} <text_to_encrypt> <method>('encrypt' or 'decrypt')\n\n";
}
Esempio n. 3
0
    $dGray = "";
    $lBlue = "";
    $lGreen = "";
    $lCyan = "";
    $lRed = "";
    $lPurple = "";
    $Yellow = "";
    $White = "";
    $RST = "";
    $bS = "";
    $bE = $RST;
    $eol = PHP_EOL;
}
//if no args found or arg eq --help show usage
if ($numOfargz < 2 || $scannerOptions == '--help' || $o2s == '--help') {
    Usage($eol);
}
//get the object's info
if (file_exists($o2s)) {
    if (!$htmlMode) {
        // FIXME when output option is silent???
        fwrite(STDOUT, PHP_EOL . "{$blue} " . '* Ghost In the Shell php security file scanner*' . " {$RST}" . PHP_EOL . PHP_EOL);
        fwrite(STDOUT, "please wait while scanning..." . PHP_EOL);
    }
    if (is_dir($o2s)) {
        $scanner = new Scanner($o2s, $eol, $htmlMode, $scannerOptions);
        $scanner->getDirContents($o2s, true);
        $totalFiles = count($scanner->files);
        $output_head = "List: " . $totalFiles . " files " . $eol;
        if (!$htmlMode && $scanner->getOutput() != 'silent') {
            fwrite(STDOUT, "Scanning " . $totalFiles . " files" . PHP_EOL);
Esempio n. 4
0
function InteractiveShell($sExpression, $sQueryId, $sFormat, $sFileName, $sMode)
{
    if ($sMode == 'dialog') {
        $oP = new ajax_page('');
        $oP->add('<div id="interactive_export_dlg">');
        $sExportBtnLabel = json_encode(Dict::S('UI:Button:Export'));
        $sJSTitle = json_encode(htmlentities(utils::ReadParam('dialog_title', '', false, 'raw_data'), ENT_QUOTES, 'UTF-8'));
        $oP->add_ready_script(<<<EOF
\t\t\$('#interactive_export_dlg').dialog({
\t\t\tautoOpen: true,
\t\t\tmodal: true,
\t\t\twidth: '80%',
\t\t\ttitle: {$sJSTitle},
\t\t\tclose: function() { \$('#export-form').attr('data-state', 'cancelled'); \$(this).remove(); },
\t\t\tbuttons: [
\t\t\t\t{text: {$sExportBtnLabel}, id: 'export-dlg-submit', click: function() {} }
\t\t\t]
\t\t});
\t\t\t
\t\tsetTimeout(function() { \$('#interactive_export_dlg').dialog('option', { position: { my: "center", at: "center", of: window }}); \$('#export-btn').hide(); ExportInitButton('#export-dlg-submit'); }, 100);
EOF
);
    } else {
        $oP = new iTopWebPage('iTop Export');
    }
    if ($sExpression === null) {
        // No expression supplied, let's check if phrasebook entry is given
        if ($sQueryId !== null) {
            $oSearch = DBObjectSearch::FromOQL('SELECT QueryOQL WHERE id = :query_id', array('query_id' => $sQueryId));
            $oQueries = new DBObjectSet($oSearch);
            if ($oQueries->Count() > 0) {
                $oQuery = $oQueries->Fetch();
                $sExpression = $oQuery->Get('oql');
                $sFields = trim($oQuery->Get('fields'));
            } else {
                ReportErrorAndExit("Invalid query phrasebook identifier: '{$sQueryId}'");
            }
        } else {
            if (utils::IsModeCLI()) {
                Usage();
                ReportErrorAndExit("No expression or query phrasebook identifier supplied.");
            } else {
                // form to enter an OQL query or pick a query phrasebook identifier
                DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat);
                $oP->output();
                exit;
            }
        }
    }
    if ($sFormat !== null) {
        $oExporter = BulkExport::FindExporter($sFormat);
        if ($oExporter === null) {
            $aSupportedFormats = BulkExport::FindSupportedFormats();
            ReportErrorAndExit("Invalid output format: '{$sFormat}'. The supported formats are: " . implode(', ', array_keys($aSupportedFormats)));
        } else {
            DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat);
        }
    } else {
        DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat);
    }
    if ($sMode == 'dialog') {
        $oP->add('</div>');
    }
    $oP->output();
}
Esempio n. 5
0
<?php

if ($argc < 2) {
    Usage($argv[0]);
}
include dirname(__FILE__) . '/setup.php';
M('Config')->init($argv[1]);
M('Config')->_setValue('trace.driver', 'screen');
M('Language')->compareLanguages();
function _U_helper($urlCode, $object)
{
    return array('fake', array());
}
function Usage($script)
{
    echo "Usage: {$script} <config>\n";
    exit;
}
Esempio n. 6
0
// Database connection
/* Set SYSCONFDIR and set global (for backward compatibility) */
$SysConf = bootstrap();
/* Initialize global system configuration variables $SysConfig[] */
ConfigInit($SYSCONFDIR, $SysConf);
/* Directories */
$GoodDir = "regression/good/";
$PostDir = "regression/post/";
$OutputDirTemplate = "regression/output_";
/* output dir is suffixed with pid */
$OutputDir = $OutputDirTemplate . posix_getpid();
/*  -h webhost
 */
$Options = getopt("hw:");
if (array_key_exists('h', $Options)) {
    Usage($argc, $argv);
    exit(0);
}
if (array_key_exists('w', $Options)) {
    $WebHost = $Options['w'];
} else {
    $WebHost = "localhost";
}
/* Create directory to put results */
if (mkdir($OutputDir, 0777, true) === false) {
    echo "Fatal: Could not create {$OutputDir}\n";
    exit(-1);
}
/* Open $GoodDir */
if (($DirH = opendir($GoodDir)) === false) {
    echo "Fatal: Could not create {$OutputDir}\n";
function OGR2Tab_SQL_main()
{
    /*Assigning initial value.*/
    $strFormat = "MapInfo File";
    $strDataSource = NULL;
    $strDestDataSource = NULL;
    $strWhere = NULL;
    $hSpatialFilter = NULL;
    $strSQLStatement = NULL;
    $strDialect = NULL;
    /* -------------------------------------------------------------------- */
    /*      Register format(s).                                             */
    /* -------------------------------------------------------------------- */
    OGRRegisterAll();
    /* -------------------------------------------------------------------- */
    /*      Processing command line arguments.                              */
    /* -------------------------------------------------------------------- */
    $numArgs = count($_SERVER["argv"]);
    for ($iArg = 1; $iArg < $numArgs; $iArg++) {
        /* Construct a spatial filter.*/
        if ($_SERVER["argv"][$iArg] == "-spat" && $_SERVER["argv"][$iArg + 1] != NULL && $_SERVER["argv"][$iArg + 2] != NULL && $_SERVER["argv"][$iArg + 3] != NULL && $_SERVER["argv"][$iArg + 4] != NULL) {
            $hSpatialFilter = OGR_G_CreateGeometry(wkbLinearRing);
            OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 1]), floatval($_SERVER["argv"][$iArg + 2]), 0.0);
            OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 1]), floatval($_SERVER["argv"][$iArg + 4]), 0.0);
            OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 3]), floatval($_SERVER["argv"][$iArg + 4]), 0.0);
            OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 3]), floatval($_SERVER["argv"][$iArg + 2]), 0.0);
            OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 1]), floatval($_SERVER["argv"][$iArg + 2]), 0.0);
            printf("Xmin = %s Ymin = %s Xmax = %s Ymax = %s\n", $_SERVER["argv"][$iArg + 1], $_SERVER["argv"][$iArg + 2], $_SERVER["argv"][$iArg + 3], $_SERVER["argv"][$iArg + 4]);
            $iArg += 4;
        } else {
            if ($_SERVER["argv"][$iArg] == "-sql" && $_SERVER["argv"][$iArg + 1] != NULL) {
                $strSQLStatement = $_SERVER["argv"][++$iArg];
                printf("SQLStatement = %s\n", $strSQLStatement);
            } else {
                if ($strDestDataSource == NULL) {
                    $strDestDataSource = $_SERVER["argv"][$iArg];
                    printf("DestDataSource = %s\n", $strDestDataSource);
                } else {
                    if ($strDataSource == NULL) {
                        $strDataSource = $_SERVER["argv"][$iArg];
                        printf("DataSource = %s\n", $strDataSource);
                    } else {
                        if ($_SERVER["argv"][$iArg][0] == '-') {
                            Usage();
                        }
                    }
                }
            }
        }
    }
    if ($strDataSource == NULL) {
        Usage();
    }
    /* -------------------------------------------------------------------- */
    /*      Open data source.                                               */
    /* -------------------------------------------------------------------- */
    $hSFDriver = NULL;
    $hDS = OGROpen($strDataSource, FALSE, $hSFDriver);
    /* -------------------------------------------------------------------- */
    /*      Report failure                                                  */
    /* -------------------------------------------------------------------- */
    if ($hDS == NULL) {
        printf("FAILURE:\nUnable to open datasource `%s' with the following drivers:\n", $strDataSource);
        for ($iDriver = 0; $iDriver < OGRGetDriverCount(); $iDriver++) {
            printf("  -> %s\n", OGR_DR_GetName(OGRGetDriver($iDriver)));
        }
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Find the output driver.                                         */
    /* -------------------------------------------------------------------- */
    for ($iDriver = 0; $iDriver < OGRGetDriverCount() && $hSFDriver == NULL; $iDriver++) {
        if (!strcasecmp(OGR_DR_GetName(OGRGetDriver($iDriver)), $strFormat)) {
            $hSFDriver = OGRGetDriver($iDriver);
        }
    }
    if ($hSFDriver == NULL) {
        printf("Unable to find driver `%s'.\n", $strFormat);
        printf("The following drivers are available:\n");
        for ($iDriver = 0; $iDriver < OGRGetDriverCount(); $iDriver++) {
            printf("  -> %s\n", OGR_DR_GetName(OGRGetDriver($iDriver)));
        }
        return OGRERR_FAILURE;
    }
    if (!OGR_Dr_TestCapability($hSFDriver, ODrCCreateDataSource)) {
        printf("%s driver does not support data source creation.\n", $strFormat);
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Create the output data source.                                  */
    /* -------------------------------------------------------------------- */
    /*Uncomment and add options here. */
    /* $aoptions[0] = 'option1';
        $aoptions[1] = 'option2';
        $hODS = OGR_Dr_CreateDataSource( $hSFDriver, $strDestDataSource, $aoptions );
    */
    /* Or use no option.*/
    $hODS = OGR_Dr_CreateDataSource($hSFDriver, $strDestDataSource, NULL);
    if ($hODS == NULL) {
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Fetch source layer using SQL statement.                         */
    /* -------------------------------------------------------------------- */
    $hLayer = OGR_DS_ExecuteSQL($hDS, $strSQLStatement, $hSpatialFilter, NULL);
    /*Copy datasource file to a new data source file*/
    if ($hLayer != NULL) {
        if (!TranslateLayer($hDS, $hLayer, $hODS)) {
            return OGRERR_FAILURE;
        }
        OGR_DS_ReleaseResultSet($hDS, $hLayer);
    }
    /* -------------------------------------------------------------------- */
    /*      Close down.                                                     */
    /* -------------------------------------------------------------------- */
    OGR_DS_Destroy($hDS);
    OGR_DS_Destroy($hODS);
    return OGRERR_NONE;
}
Esempio n. 8
0
function main()
{
    global $_SERVER;
    global $db, $db_server, $output_file, $using_output_file, $fp;
    global $db_file_size, $line;
    echo "main()\n";
    $dbg = 1;
    // default is 0, set to 1 to turn on debugging
    if ($_SERVER["argc"] != 2 && $_SERVER["argc"] != 3) {
        return Usage();
    }
    $db_server = $_SERVER["argv"][1];
    if (3 == $_SERVER["argc"]) {
        $using_output_file = 1;
        $output_file = $_SERVER["argv"][2];
        $output_file = ExpandMacros($output_file);
        $fp = fopen($output_file, "w");
    } else {
        $fp = fopen("php://output", "w");
    }
    echo "db_server: {$db_server}\n";
    $db_total_cols = 0;
    $db_total_tables = 0;
    $db_total_file_size = 0;
    $now = strftime("%Y-%m-%d %H:%M:%S");
    // connect to server and select the database
    // could also use something like: $db = sqlsrv_connect( "\\\\$db_server\\pipe\\sql\\query", "ExampleReports", "" );
    $db = sqlsrv_connect($db_server, array("Database" => "master"));
    echo "db: {$db}\n";
    if (FALSE == $db) {
        print "\r\n";
        print "Unable to make database connection to host: " . $db_server . "\r\n\r\n";
        fclose($fp);
        return;
    }
    $db_list = GetDatabaseNames();
    if (1 == $dbg) {
        print "\r\nDatabases:\r\n";
        print "==========";
        print "\r\n";
        var_dump($db_list);
        print "\r\n\r\n";
    }
    sqlsrv_close($db);
    foreach ($db_list as $current_db) {
        // is there really no way to change databases with the same connection?
        //$valid = sqlsrv_select_db($current_db, $db);
        $db = sqlsrv_connect($db_server, array("Database" => $current_db));
        $tables = GetTableNames();
        if (1 == $dbg) {
            print "\r\n({$current_db}) tables:\r\n";
            print "================================================";
            print "\r\n";
            var_dump($db_list);
            print "\r\n\r\n";
        }
        $db_total_tables += sizeof($tables);
        $max_tbl_len = GetMaxTableNameLength($tables);
        $db_total_cols += PrintRowCount($now, $current_db, $tables, $max_tbl_len);
        $db_total_file_size += $db_file_size;
        sqlsrv_close($db);
    }
    fwrite($fp, $line . "\r\n");
    fwrite($fp, "Total number of databases       : " . sizeof($db_list) . "\r\n");
    fwrite($fp, "Grand total number of tables    : " . number_format($db_total_tables) . "\r\n");
    fwrite($fp, "Grand total number of columns   : " . number_format($db_total_cols) . "\r\n");
    fwrite($fp, "\r\n");
    return;
    if (1 == $using_output_file) {
        fflush($fp);
        fclose($fp);
    }
}
function OGR2OGR_main()
{
    $strFormat = "ESRI Shapefile";
    $strDataSource = NULL;
    $strDestDataSource = NULL;
    $astrLayers = NULL;
    /* -------------------------------------------------------------------- */
    /*      Register format(s).                                             */
    /* -------------------------------------------------------------------- */
    OGRRegisterAll();
    /* -------------------------------------------------------------------- */
    /*      Processing command line arguments.                              */
    /* -------------------------------------------------------------------- */
    $numArgs = count($_SERVER["argv"]);
    for ($iArg = 1; $iArg < $numArgs; $iArg++) {
        if (!strcasecmp($_SERVER["argv"][$iArg], "-f") && $iArg < $numArgs - 1) {
            $strFormat = $_SERVER["argv"][++$iArg];
            printf("Format = %s\n", $strFormat);
        } else {
            if ($_SERVER["argv"][$iArg][0] == '-') {
                Usage();
            } else {
                if ($strDestDataSource == NULL) {
                    $strDestDataSource = $_SERVER["argv"][$iArg];
                    printf("DestDataSource = %s\n", $strDestDataSource);
                } else {
                    if ($strDataSource == NULL) {
                        $strDataSource = $_SERVER["argv"][$iArg];
                        printf("DataSource = %s\n", $strDataSource);
                    } else {
                        $astrLayers[] = $_SERVER["argv"][$iArg];
                    }
                }
            }
        }
    }
    $i = 0;
    while ($astrLayers[$i]) {
        printf("Layers [%d] = %s\n", $i, $astrLayers[$i]);
        $i++;
    }
    if ($strDataSource == NULL) {
        Usage();
    }
    /* -------------------------------------------------------------------- */
    /*      Open data source.                                               */
    /* -------------------------------------------------------------------- */
    $hSFDriver = NULL;
    $hDS = OGROpen($strDataSource, FALSE, $hSFDriver);
    /* -------------------------------------------------------------------- */
    /*      Report failure                                                  */
    /* -------------------------------------------------------------------- */
    if ($hDS == NULL) {
        printf("FAILURE:\nUnable to open datasource `%s' with the following drivers:\n", $strDataSource);
        for ($iDriver = 0; $iDriver < OGRGetDriverCount(); $iDriver++) {
            printf("  -> %s\n", OGR_DR_GetName(OGRGetDriver($iDriver)));
        }
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Find the output driver.                                         */
    /* -------------------------------------------------------------------- */
    for ($iDriver = 0; $iDriver < OGRGetDriverCount() && $hSFDriver == NULL; $iDriver++) {
        if (!strcasecmp(OGR_DR_GetName(OGRGetDriver($iDriver)), $strFormat)) {
            $hSFDriver = OGRGetDriver($iDriver);
        }
    }
    if ($hSFDriver == NULL) {
        printf("Unable to find driver `%s'.\n", $strFormat);
        printf("The following drivers are available:\n");
        for ($iDriver = 0; $iDriver < OGRGetDriverCount(); $iDriver++) {
            printf("  -> %s\n", OGR_DR_GetName(OGRGetDriver($iDriver)));
        }
        return OGRERR_FAILURE;
    }
    if (!OGR_Dr_TestCapability($hSFDriver, ODrCCreateDataSource)) {
        printf("%s driver does not support data source creation.\n", $strFormat);
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Create the output data source.                                  */
    /* -------------------------------------------------------------------- */
    /*Uncomment and add options here. */
    /* $aoptions[0] = 'option1';
        $aoptions[1] = 'option2';
        $hODS = OGR_Dr_CreateDataSource( $hSFDriver, $strDestDataSource, $aoptions );
    */
    /* Or use no option.*/
    $hODS = OGR_Dr_CreateDataSource($hSFDriver, $strDestDataSource, NULL);
    if ($hODS == NULL) {
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Process each data source layer.                                 */
    /* -------------------------------------------------------------------- */
    for ($iLayer = 0; $iLayer < OGR_DS_GetLayerCount($hDS); $iLayer++) {
        $hLayer = OGR_DS_GetLayer($hDS, $iLayer);
        if ($hLayer == NULL) {
            printf("FAILURE: Couldn't fetch advertised layer %d!\n", $iLayer);
            return OGRERR_FAILURE;
        }
        if (count($astrLayers) == 0 || in_array(OGR_FD_GetName(OGR_L_GetLayerDefn($hLayer)), $astrLayers) != FALSE) {
            if (!TranslateLayer($hDS, $hLayer, $hODS)) {
                return OGRERR_FAILURE;
            }
        }
    }
    /* -------------------------------------------------------------------- */
    /*      Close down.                                                     */
    /* -------------------------------------------------------------------- */
    OGR_DS_Destroy($hDS);
    OGR_DS_Destroy($hODS);
    return OGRERR_NONE;
}
Esempio n. 10
0
        UserRights::Login($sAuthUser);
        // Login & set the user's language
    } else {
        ExitError($oP, "Access restricted or wrong credentials ('{$sAuthUser}')");
    }
} else {
    require_once APPROOT . 'application/loginwebpage.class.inc.php';
    LoginWebPage::DoLogin();
    // Check user rights and prompt if needed
    $bDownloadBackup = utils::ReadParam('download', false);
}
if (!UserRights::IsAdministrator()) {
    ExitError($oP, "Access restricted to administors");
}
if (CheckParam('?') || CheckParam('h') || CheckParam('help')) {
    Usage($oP);
    $oP->output();
    exit;
}
$sDefaultBackupFileName = SetupUtils::GetTmpDir() . '/' . "__DB__-%Y-%m-%d";
$sBackupFile = utils::ReadParam('backup_file', $sDefaultBackupFileName, true, 'raw_data');
// Interpret strftime specifications (like %Y) and database placeholders
$oBackup = new MyDBBackup($oP);
$oBackup->SetMySQLBinDir(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''));
$sBackupFile = $oBackup->MakeName($sBackupFile);
$sZipArchiveFile = $sBackupFile . '.zip';
$bSimulate = utils::ReadParam('simulate', false, true);
$res = false;
if ($bSimulate) {
    $oP->p("Simulate: would create file '{$sZipArchiveFile}'");
} elseif (MetaModel::GetConfig()->Get('demo_mode')) {
function OGR_SpatialFilter_main()
{
    /*Assigning initial value.*/
    $strFormat = "ESRI Shapefile";
    $strDataSource = NULL;
    $strDestDataSource = NULL;
    $strWhere = NULL;
    $hSpatialFilter = NULL;
    /* -------------------------------------------------------------------- */
    /*      Register format(s).                                             */
    /* -------------------------------------------------------------------- */
    OGRRegisterAll();
    /* -------------------------------------------------------------------- */
    /*      Processing command line arguments.                              */
    /* -------------------------------------------------------------------- */
    $numArgs = count($_SERVER["argv"]);
    for ($iArg = 1; $iArg < $numArgs; $iArg++) {
        if (!strcasecmp($_SERVER["argv"][$iArg], "-f") && $iArg < $numArgs - 1) {
            $strFormat = $_SERVER["argv"][++$iArg];
            printf("Format = %s\n", $strFormat);
        } else {
            if ($_SERVER["argv"][$iArg] == "-spat" && $_SERVER["argv"][$iArg + 1] != NULL && $_SERVER["argv"][$iArg + 2] != NULL && $_SERVER["argv"][$iArg + 3] != NULL && $_SERVER["argv"][$iArg + 4] != NULL) {
                $hSpatialFilter = OGR_G_CreateGeometry(wkbLinearRing);
                OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 1]), floatval($_SERVER["argv"][$iArg + 2]), 0.0);
                OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 1]), floatval($_SERVER["argv"][$iArg + 4]), 0.0);
                OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 3]), floatval($_SERVER["argv"][$iArg + 4]), 0.0);
                OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 3]), floatval($_SERVER["argv"][$iArg + 2]), 0.0);
                OGR_G_AddPoint($hSpatialFilter, floatval($_SERVER["argv"][$iArg + 1]), floatval($_SERVER["argv"][$iArg + 2]), 0.0);
                printf("Xmin = %s Ymin = %s Xmax = %s Ymax = %s\n", $_SERVER["argv"][$iArg + 1], $_SERVER["argv"][$iArg + 2], $_SERVER["argv"][$iArg + 3], $_SERVER["argv"][$iArg + 4]);
                $iArg += 4;
            } else {
                if ($_SERVER["argv"][$iArg] == "-where" && $_SERVER["argv"][$iArg + 1] != NULL) {
                    $strWhere = $_SERVER["argv"][++$iArg];
                    printf("where = %s\n", $strWhere);
                } else {
                    if ($_SERVER["argv"][$iArg][0] == '-') {
                        Usage();
                    } else {
                        if ($strDestDataSource == NULL) {
                            $strDestDataSource = $_SERVER["argv"][$iArg];
                            printf("DestDataSource = %s\n", $strDestDataSource);
                        } else {
                            if ($strDataSource == NULL) {
                                $strDataSource = $_SERVER["argv"][$iArg];
                                printf("DataSource = %s\n", $strDataSource);
                            }
                        }
                    }
                }
            }
        }
    }
    if ($strDataSource == NULL) {
        Usage();
    }
    /* -------------------------------------------------------------------- */
    /*      Open data source.                                               */
    /* -------------------------------------------------------------------- */
    $hSFDriver = NULL;
    $hDS = OGROpen($strDataSource, FALSE, $hSFDriver);
    /* -------------------------------------------------------------------- */
    /*      Report failure                                                  */
    /* -------------------------------------------------------------------- */
    if ($hDS == NULL) {
        printf("FAILURE:\nUnable to open datasource `%s' with the following drivers:\n", $strDataSource);
        for ($iDriver = 0; $iDriver < OGRGetDriverCount(); $iDriver++) {
            printf("  -> %s\n", OGR_DR_GetName(OGRGetDriver($iDriver)));
        }
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Find the output driver.                                         */
    /* -------------------------------------------------------------------- */
    for ($iDriver = 0; $iDriver < OGRGetDriverCount() && $hSFDriver == NULL; $iDriver++) {
        if (!strcasecmp(OGR_DR_GetName(OGRGetDriver($iDriver)), $strFormat)) {
            $hSFDriver = OGRGetDriver($iDriver);
        }
    }
    if ($hSFDriver == NULL) {
        printf("Unable to find driver `%s'.\n", $strFormat);
        printf("The following drivers are available:\n");
        for ($iDriver = 0; $iDriver < OGRGetDriverCount(); $iDriver++) {
            printf("  -> %s\n", OGR_DR_GetName(OGRGetDriver($iDriver)));
        }
        return OGRERR_FAILURE;
    }
    if (!OGR_Dr_TestCapability($hSFDriver, ODrCCreateDataSource)) {
        printf("%s driver does not support data source creation.\n", $strFormat);
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Create the output data source.                                  */
    /* -------------------------------------------------------------------- */
    /*Uncomment and add options here. */
    /* $aoptions[0] = 'option1';
        $aoptions[1] = 'option2';
        $hODS = OGR_Dr_CreateDataSource( $hSFDriver, $strDestDataSource, $aoptions );
    */
    /* Or use no option.*/
    $hODS = OGR_Dr_CreateDataSource($hSFDriver, $strDestDataSource, NULL);
    if ($hODS == NULL) {
        return OGRERR_FAILURE;
    }
    /* -------------------------------------------------------------------- */
    /*      Process each data source layer.                                 */
    /* -------------------------------------------------------------------- */
    for ($iLayer = 0; $iLayer < OGR_DS_GetLayerCount($hDS); $iLayer++) {
        $hLayer = OGR_DS_GetLayer($hDS, $iLayer);
        if ($hLayer == NULL) {
            printf("FAILURE: Couldn't fetch advertised layer %d!\n", $iLayer);
            return OGRERR_FAILURE;
        }
        if (count($astrLayers) == 0 || in_array(OGR_FD_GetName(OGR_L_GetLayerDefn($hLayer)), $astrLayers) != FALSE) {
            /*Assign spatial filter*/
            if ($hSpatialFilter != NULL) {
                OGR_L_SetSpatialFilter($hLayer, $hSpatialFilter);
            }
            /*Assign attribute filter*/
            if ($strWhere != NULL) {
                $eErr = OGR_L_SetAttributeFilter($hLayer, $strWhere);
            }
            if ($eErr != OGRERR_NONE) {
                printf("Erreur when setting attribute filter", $eErr);
                return $eErr;
            }
            /*Copy datasource file to a new data source file*/
            if (!TranslateLayer($hDS, $hLayer, $hODS)) {
                return OGRERR_FAILURE;
            }
        }
    }
    /* -------------------------------------------------------------------- */
    /*      Close down.                                                     */
    /* -------------------------------------------------------------------- */
    OGR_DS_Destroy($hDS);
    OGR_DS_Destroy($hODS);
    return OGRERR_NONE;
}