Ejemplo n.º 1
0
/**
 * Prints Html For Export Options Save Dir
 *
 * @return string
 */
function PMA_getHtmlForExportOptionsOutputSaveDir()
{
    global $cfg;
    $html = '<li>';
    $html .= '<input type="checkbox" name="onserver" value="saveit" ';
    $html .= 'id="checkbox_dump_onserver" ';
    $html .= PMA_exportCheckboxCheck('onserver');
    $html .= '/>';
    $html .= '<label for="checkbox_dump_onserver">';
    $html .= sprintf(__('Save on server in the directory <b>%s</b>'), htmlspecialchars(PMA_Util::userDir($cfg['SaveDir'])));
    $html .= '</label>';
    $html .= '</li>';
    $html .= '<li>';
    $html .= '<input type="checkbox" name="onserver_overwrite" value="saveitover"';
    $html .= ' id="checkbox_dump_onserver_overwrite" ';
    $html .= PMA_exportCheckboxCheck('onserver_overwrite');
    $html .= '/>';
    $html .= '<label for="checkbox_dump_onserver_overwrite">';
    $html .= __('Overwrite existing file(s)');
    $html .= '</label>';
    $html .= '</li>';
    return $html;
}
/**
 * return HTML for Sql Query Form Upload
 *
 * @return string
 *
 * @usedby  PMA_getHtmlForSqlQueryForm()
 */
function PMA_getHtmlForSqlQueryFormUpload()
{
    global $timeout_passed, $local_import_file;
    $errors = array();
    // we allow only SQL here
    $matcher = '@\\.sql(\\.(' . PMA_supportedDecompressions() . '))?$@';
    if (!empty($GLOBALS['cfg']['UploadDir'])) {
        $files = PMA_getFileSelectOptions(PMA_Util::userDir($GLOBALS['cfg']['UploadDir']), $matcher, isset($timeout_passed) && $timeout_passed && isset($local_import_file) ? $local_import_file : '');
    } else {
        $files = '';
    }
    // start output
    $html = '<fieldset id="">';
    $html .= '<legend>';
    $html .= __('Browse your computer:') . '</legend>';
    $html .= '<div class="formelement">';
    $html .= '<input type="file" name="sql_file" class="textfield" /> ';
    $html .= PMA_Util::getFormattedMaximumUploadSize($GLOBALS['max_upload_size']);
    // some browsers should respect this :)
    $html .= PMA_Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
    $html .= '</div>';
    if ($files === false) {
        $errors[] = PMA_Message::error(__('The directory you set for upload work cannot be reached.'));
    } elseif (!empty($files)) {
        $html .= '<div class="formelement">';
        $html .= '<strong>' . __('web server upload directory:') . '</strong>';
        $html .= '<select size="1" name="sql_localfile">' . "\n";
        $html .= '<option value="" selected="selected"></option>' . "\n";
        $html .= $files;
        $html .= '</select>' . "\n";
        $html .= '</div>';
    }
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</fieldset>';
    $html .= '<fieldset id="" class="tblFooters">';
    $html .= __('Character set of the file:') . "\n";
    $html .= PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, 'charset_of_file', null, 'utf8', false);
    $html .= '<input type="submit" name="SQL" value="' . __('Go') . '" />' . "\n";
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</fieldset>';
    foreach ($errors as $error) {
        $html .= $error->getDisplay();
    }
    return $html;
}
Ejemplo n.º 3
0
 /**
  * Sets named file to be read from UploadDir.
  *
  * @param string $name file name
  *
  * @return boolean success
  * @access  public
  */
 public function setLocalSelectedFile($name)
 {
     if (empty($GLOBALS['cfg']['UploadDir'])) {
         return false;
     }
     $this->setName(PMA_Util::userDir($GLOBALS['cfg']['UploadDir']) . PMA_securePath($name));
     if (!$this->isReadable()) {
         $this->_error_message = __('File could not be read!');
         $this->setName(null);
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
/**
 * Get HTML select option for upload
 *
 * @param string $vkey   [multi_edit]['row_id']
 * @param array  $column description of column in given table
 *
 * @return string|void an html snippet
 */
function PMA_getSelectOptionForUpload($vkey, $column)
{
    $files = PMA_getFileSelectOptions(PMA_Util::userDir($GLOBALS['cfg']['UploadDir']));
    if ($files === false) {
        return '<font color="red">' . __('Error') . '</font><br />' . "\n" . __('The directory you set for upload work cannot be reached.') . "\n";
    } elseif (!empty($files)) {
        return "<br />\n" . '<i>' . __('Or') . '</i>' . ' ' . __('web server upload directory:') . '<br />' . "\n" . '<select size="1" name="fields_uploadlocal' . $vkey . '[' . $column['Field_md5'] . ']">' . "\n" . '<option value="" selected="selected"></option>' . "\n" . $files . '</select>' . "\n";
    }
    return null;
}
Ejemplo n.º 5
0
    $memory_limit = (int) substr($memory_limit, 0, -1) * 1024;
} elseif (strtolower(substr($memory_limit, -1)) == 'g') {
    $memory_limit = (int) substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
} else {
    $memory_limit = (int) $memory_limit;
}
// Just to be sure, there might be lot of memory needed for uncompression
$read_limit = $memory_limit / 8;
// handle filenames
if (isset($_FILES['import_file'])) {
    $import_file = $_FILES['import_file']['tmp_name'];
}
if (!empty($local_import_file) && !empty($cfg['UploadDir'])) {
    // sanitize $local_import_file as it comes from a POST
    $local_import_file = PMA_securePath($local_import_file);
    $import_file = PMA_Util::userDir($cfg['UploadDir']) . $local_import_file;
} elseif (empty($import_file) || !is_uploaded_file($import_file)) {
    $import_file = 'none';
}
// Do we have file to import?
if ($import_file != 'none' && !$error) {
    // work around open_basedir and other limitations
    $open_basedir = @ini_get('open_basedir');
    // If we are on a server with open_basedir, we must move the file
    // before opening it.
    if (!empty($open_basedir)) {
        /**
         * @todo make use of the config's temp dir with fallback to the
         * system's tmp dir
         */
        $tmp_subdir = ini_get('upload_tmp_dir');
 /**
  * test of generating user dir, globals are defined
  *
  * @param string $a String
  * @param string $e Expected output
  *
  * @return void
  *
  * @dataProvider userDirDataProvider
  */
 public function testUserDirString($a, $e)
 {
     $GLOBALS['cfg']['Server']['user'] = '******';
     $this->assertEquals($e, PMA_Util::userDir($a));
 }
Ejemplo n.º 7
0
/**
 * Open the export file
 *
 * @param string  $filename     the export filename
 * @param boolean $quick_export whether it's a quick export or not
 *
 * @return array the full save filename, possible message and the file handle
 */
function PMA_openExportFile($filename, $quick_export)
{
    $file_handle = null;
    $message = '';
    $save_filename = PMA_Util::userDir($GLOBALS['cfg']['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
    if (file_exists($save_filename) && (!$quick_export && empty($_REQUEST['onserver_overwrite']) || $quick_export && $_REQUEST['quick_export_onserver_overwrite'] != 'saveitover')) {
        $message = PMA_Message::error(__('File %s already exists on server, ' . 'change filename or check overwrite option.'));
        $message->addParam($save_filename);
    } elseif (is_file($save_filename) && !is_writable($save_filename)) {
        $message = PMA_Message::error(__('The web server does not have permission ' . 'to save the file %s.'));
        $message->addParam($save_filename);
    } elseif (!($file_handle = @fopen($save_filename, 'w'))) {
        $message = PMA_Message::error(__('The web server does not have permission ' . 'to save the file %s.'));
        $message->addParam($save_filename);
    }
    return array($save_filename, $message, $file_handle);
}
Ejemplo n.º 8
0
    // If dump is going to be compressed, set correct mime_type and add
    // compression to extension
    if ($compression == 'bzip2') {
        $filename .= '.bz2';
        $mime_type = 'application/x-bzip2';
    } elseif ($compression == 'gzip') {
        $filename .= '.gz';
        $mime_type = 'application/x-gzip';
    } elseif ($compression == 'zip') {
        $filename .= '.zip';
        $mime_type = 'application/zip';
    }
}
// Open file on server if needed
if ($save_on_server) {
    $save_filename = PMA_Util::userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
    unset($message);
    if (file_exists($save_filename) && (!$quick_export && empty($onserverover) || $quick_export && $_REQUEST['quick_export_onserverover'] != 'saveitover')) {
        $message = PMA_Message::error(__('File %s already exists on server, change filename or check overwrite option.'));
        $message->addParam($save_filename);
    } else {
        if (is_file($save_filename) && !is_writable($save_filename)) {
            $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
            $message->addParam($save_filename);
        } else {
            if (!($file_handle = @fopen($save_filename, 'w'))) {
                $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
                $message->addParam($save_filename);
            }
        }
    }
 /**
  * Test for PMA_getHtmlForExportOptions
  *
  * @return void
  */
 public function testPMAGetHtmlForExportOptions()
 {
     global $cfg;
     $cfg['Export']['method'] = "XML";
     $cfg['SaveDir'] = "/tmp";
     $export_type = "server";
     $db = "PMA";
     $table = "PMA_test";
     $multi_values_str = "multi_values_str";
     $num_tables_str = "10";
     $unlim_num_rows_str = "unlim_num_rows_str";
     $single_table = "single_table";
     PMA_Table::$cache[$db][$table]['ENGINE'] = "MERGE";
     $columns_info = array('test_column1' => array('COLUMN_NAME' => 'test_column1'), 'test_column2' => array('COLUMN_NAME' => 'test_column2'));
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->any())->method('getColumnsFull')->will($this->returnValue($columns_info));
     $GLOBALS['dbi'] = $dbi;
     /* Scan for plugins */
     $export_list = PMA_getPlugins("export", 'libraries/plugins/export/', array('export_type' => $export_type, 'single_table' => isset($single_table)));
     //Call the test function
     $html = PMA_getHtmlForExportOptions($export_type, $db, $table, $multi_values_str, $num_tables_str, $export_list, $unlim_num_rows_str);
     //validate 1: PMA_getHtmlForExportOptionHeader
     $this->assertContains('<div class="exportoptions" id="header">', $html);
     $this->assertContains(__('Exporting databases from the current server'), $html);
     //validate 2: PMA_getHtmlForExportOptionsMethod
     $this->assertContains($cfg['Export']['method'], $html);
     $this->assertContains('<div class="exportoptions" id="quick_or_custom">', $html);
     $this->assertContains(__('Export Method:'), $html);
     $this->assertContains(__('Custom - display all possible options'), $html);
     //validate 3: PMA_getHtmlForExportOptionsSelection
     $this->assertContains('<div class="exportoptions" id="databases_and_tables">', $html);
     $this->assertContains('<h3>' . __('Database(s):') . '</h3>', $html);
     $this->assertContains($multi_values_str, $html);
     //validate 4: PMA_getHtmlForExportOptionsQuickExport
     $this->assertContains('<input type="checkbox" name="onserver" value="saveit" ', $html);
     $dir = htmlspecialchars(PMA_Util::userDir($cfg['SaveDir']));
     $this->assertContains('Save on server in the directory <b>' . $dir . '</b>', $html);
     //validate 5: PMA_getHtmlForAliasModalDialog
     $this->assertContains('<div id="alias_modal" class="hide" title="' . 'Rename exported databases/tables/columns">', $html);
     $this->assertContains('Select database', $html);
     $this->assertContains('Select table', $html);
     $this->assertContains('New database name', $html);
     $this->assertContains('New table name', $html);
     $this->assertContains('test_column', $html);
     //validate 6: PMA_getHtmlForExportOptionsOutput
     $this->assertContains('<div class="exportoptions" id="output">', $html);
     $this->assertContains('user value for test', $html);
     //validate 7: PMA_getHtmlForExportOptionsFormat
     $this->assertContains('<div class="exportoptions" id="format">', $html);
     $this->assertContains('<h3>' . __('Format:') . '</h3>', $html);
 }
 /**
  * Test for PMA_getHtmlForExportOptions
  *
  * @return vgetUserValue
  */
 public function testPMAGetHtmlForExportOptions()
 {
     global $cfg;
     $cfg['Export']['method'] = "XML";
     $cfg['SaveDir'] = "/tmp";
     $export_type = "server";
     $db = "PMA";
     $table = "PMA_test";
     $multi_values_str = "multi_values_str";
     $num_tables_str = "10";
     $export_list = null;
     $unlim_num_rows_str = "unlim_num_rows_str";
     $single_table = "single_table";
     PMA_Table::$cache[$db][$table]['ENGINE'] = "MERGE";
     /* Scan for plugins */
     $export_list = PMA_getPlugins("export", 'libraries/plugins/export/', array('export_type' => $export_type, 'single_table' => isset($single_table)));
     //Call the test function
     $html = PMA_getHtmlForExportOptions($export_type, $db, $table, $multi_values_str, $num_tables_str, $export_list, $unlim_num_rows_str);
     //validate 1: PMA_getHtmlForExportOptionHeader
     $this->assertContains('<div class="exportoptions" id="header">', $html);
     $this->assertContains(__('Exporting databases from the current server'), $html);
     //validate 2: PMA_getHtmlForExportOptionsMethod
     $this->assertContains($cfg['Export']['method'], $html);
     $this->assertContains('<div class="exportoptions" id="quick_or_custom">', $html);
     $this->assertContains(__('Export Method:'), $html);
     $this->assertContains(__('Custom - display all possible options'), $html);
     //validate 3: PMA_getHtmlForExportOptionsSelection
     $this->assertContains('<div class="exportoptions" id="databases_and_tables">', $html);
     $this->assertContains('<h3>' . __('Database(s):') . '</h3>', $html);
     $this->assertContains($multi_values_str, $html);
     //validate 4: PMA_getHtmlForExportOptionsQuickExport
     $this->assertContains('<input type="checkbox" name="onserver" value="saveit" ', $html);
     $dir = htmlspecialchars(PMA_Util::userDir($cfg['SaveDir']));
     $this->assertContains('Save on server in the directory <b>' . $dir . '</b>', $html);
     //validate 5: PMA_getHtmlForExportOptionsOutput
     $this->assertContains('<div class="exportoptions" id="output">', $html);
     $this->assertContains('user value for test', $html);
     //validate 6: PMA_getHtmlForExportOptionsFormat
     $this->assertContains('<div class="exportoptions" id="format">', $html);
     $this->assertContains('<h3>' . __('Format:') . '</h3>', $html);
 }
Ejemplo n.º 11
0
echo '<input type="radio" name="output_format" value="sendit" ';
echo 'id="radio_dump_asfile" ';
if (!isset($_GET['repopulate'])) {
    PMA_exportCheckboxCheck('asfile');
}
echo '/>';
echo '<label for="radio_dump_asfile">' . __('Save output to a file') . '</label>';
echo '<ul id="ul_save_asfile">';
if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) {
    echo '<li>';
    echo '<input type="checkbox" name="onserver" value="saveit" ';
    echo 'id="checkbox_dump_onserver" ';
    PMA_exportCheckboxCheck('onserver');
    echo '/>';
    echo '<label for="checkbox_dump_onserver">';
    printf(__('Save on server in the directory <b>%s</b>'), htmlspecialchars(PMA_Util::userDir($cfg['SaveDir'])));
    echo '</label>';
    echo '</li>';
    echo '<li>';
    echo '<input type="checkbox" name="onserverover" value="saveitover"';
    echo ' id="checkbox_dump_onserverover" ';
    PMA_exportCheckboxCheck('onserver_overwrite');
    echo '/>';
    echo '<label for="checkbox_dump_onserverover">';
    echo __('Overwrite existing file(s)');
    echo '</label>';
    echo '</li>';
}
echo '<li>';
echo '<label for="filename_template" class="desc">';
echo __('File name template:');