Example #1
0
/**
 * Zip & TarGzip Functions
 */
function archive_items($dir)
{
    if (($GLOBALS["permissions"] & 01) != 01) {
        show_error($GLOBALS["error_msg"]["accessfunc"]);
    }
    if (!$GLOBALS["zip"] && !$GLOBALS["tgz"]) {
        show_error($GLOBALS["error_msg"]["miscnofunc"]);
    }
    $allowed_types = array('zip', 'tgz', 'tbz', 'tar');
    $actionURL = str_replace("index2.php", "index3.php", make_link("arch", $dir, NULL));
    // If we have something to archive, let's do it now
    if (isset($GLOBALS['__POST']["name"])) {
        $saveToDir = $GLOBALS['__POST']['saveToDir'];
        if (!file_exists(get_abs_dir($saveToDir))) {
            echo nx_scriptTag('', '$(\'loadingindicator\').style.display=\'none\';');
            echo nx_alertBox('The Save-To Directory you have specified does not exist.');
            die('The Save-To Directory you have specified does not exist.');
        }
        if (!is_writable(get_abs_dir($saveToDir))) {
            echo nx_scriptTag('', '$(\'loadingindicator\').style.display=\'none\';');
            echo nx_alertBox('Please specify a writable directory to save the archive to.');
            die('Please specify a writable directory to save the archive to.');
        }
        require_once _QUIXPLORER_PATH . '/libraries/Archive.php';
        if (!in_array(strtolower($GLOBALS['__POST']["type"]), $allowed_types)) {
            echo 'Unknown Archive Format: ' . htmlspecialchars($GLOBALS['__POST']["type"]);
            nx_exit();
        }
        while (@ob_end_clean()) {
        }
        header('Status: 200 OK');
        echo '<?xml version="1.0" ?>' . "\n";
        $files_per_step = 2500;
        $cnt = count($GLOBALS['__POST']["selitems"]);
        $abs_dir = get_abs_dir($dir);
        $name = basename(stripslashes($GLOBALS['__POST']["name"]));
        if ($name == "") {
            show_error($GLOBALS["error_msg"]["miscnoname"]);
        }
        $download = JArrayHelper::getValue($_REQUEST, 'download', "n");
        $startfrom = JArrayHelper::getValue($_REQUEST, 'startfrom', 0);
        $archive_name = get_abs_item($saveToDir, $name);
        $fileinfo = pathinfo($archive_name);
        if (empty($fileinfo['extension'])) {
            $archive_name .= "." . $GLOBALS['__POST']["type"];
            $fileinfo['extension'] = $GLOBALS['__POST']["type"];
        }
        foreach ($allowed_types as $ext) {
            if ($GLOBALS['__POST']["type"] == $ext && @$fileinfo['extension'] != $ext) {
                $archive_name .= "." . $ext;
            }
        }
        for ($i = 0; $i < $cnt; $i++) {
            $selitem = stripslashes($GLOBALS['__POST']["selitems"][$i]);
            if (is_dir($abs_dir . "/" . $selitem)) {
                $items = JFolder::files($abs_dir . "/" . $selitem, '.', true, true);
                foreach ($items as $item) {
                    if (is_dir($item) || !is_readable($item) || $item == $archive_name) {
                        continue;
                    }
                    $v_list[] = $item;
                }
            } else {
                $v_list[] = $abs_dir . "/" . $selitem;
            }
        }
        $cnt_filelist = count($v_list);
        $remove_path = $GLOBALS["home_dir"];
        if ($dir) {
            $remove_path .= $dir . $GLOBALS['separator'];
        }
        for ($i = $startfrom; $i < $cnt_filelist && $i < $startfrom + $files_per_step; $i++) {
            $filelist[] = File_Archive::read($v_list[$i], str_replace($remove_path, '', $v_list[$i]));
        }
        //echo '<strong>Starting from: '.$startfrom.'</strong><br />';
        //echo '<strong>Files to process: '.$cnt_filelist.'</strong><br />';
        //print_r( $filelist );exit;
        // Do some setup stuff
        ini_set('memory_limit', '128M');
        @set_time_limit(0);
        error_reporting(E_ERROR | E_PARSE);
        $result = File_Archive::extract($filelist, $archive_name);
        if (PEAR::isError($result)) {
            echo $name . ": Failed saving Archive File. Error: " . $result->getMessage();
            nx_exit();
        }
        if ($cnt_filelist > $startfrom + $files_per_step) {
            echo "\n <script type=\"text/javascript\">document.archform.startfrom.value = '" . ($startfrom + $files_per_step) . "';</script>\n";
            echo '<script type="text/javascript"> doArchiving( \'' . $actionURL . '\' );</script>';
            printf($GLOBALS['messages']['processed_x_files'], $startfrom + $files_per_step, $cnt_filelist);
        } else {
            if ($GLOBALS['__POST']["type"] == 'tgz' || $GLOBALS['__POST']["type"] == 'tbz') {
                chmod($archive_name, 0644);
            }
            if ($download == "y") {
                echo '<script type="text/javascript">document.location=\'' . make_link('download', dirname($archive_name), basename($archive_name)) . '\';</script>';
            } else {
                echo '<script type="text/javascript">document.location=\'' . str_replace("index3.php", "index2.php", make_link("list", $dir, NULL)) . '&mosmsg=The%20Archive%20File%20has%20been%20created\';</script>';
            }
        }
        nx_exit();
    }
    ?>
	<script type="text/javascript" src="components/com_osefileman/scripts/functions.js"></script>
	<script type="text/javascript">
	function doArchiving( url ) {
		showLoadingIndicator( $('loadingindicator'), true );
		$('loadingindicator').style.display = '';

		var controller = new Ajax( url, { 	postBody: $('adminform'),
											evalScripts: true,
											update: 'statustext'
											}
								);
		controller.request();
		return false;
	}</script>
	<?php 
    show_header($GLOBALS["messages"]["actarchive"]);
    ?>
<br/>

	<form name="archform" method="post" action="<?php 
    echo $actionURL;
    ?>
" onsubmit="return doArchiving(this.action);" id="adminform">

	<input type="hidden" name="no_html" value="1" />
	<input type="hidden" name="startfrom" value="0" />
	<?php 
    $cnt = count($GLOBALS['__POST']["selitems"]);
    for ($i = 0; $i < $cnt; ++$i) {
        echo '<input type="hidden" name="selitems[]" value="' . stripslashes($GLOBALS['__POST']["selitems"][$i]) . '">';
    }
    ?>
	<table class="adminform" style="width:600px;">
		<tr><td colspan="2" style="text-align:center;display:none;" id="loadingindicator"><strong><?php 
    echo $GLOBALS['messages']['creating_archive'];
    ?>
</strong></td></tr>
		<tr><td colspan="2" style="font-weight:bold;text-align:center" id="statustext">&nbsp;</td></tr>
		<tr><td><?php 
    echo $GLOBALS['messages']['archive_name'];
    ?>
:</td>
			<td align="left">
				<input type="text" name="name" size="25" value="<?php 
    echo $dir != '' ? basename($dir) : $GLOBALS['__POST']["selitems"][0];
    ?>
" />
			</td>
		</tr>
		<tr><td><?php 
    echo $GLOBALS["messages"]["typeheader"];
    ?>
:</td>
			<td align="left">
				<select name="type">
				<?php 
    if (extension_loaded("zlib")) {
        echo '<option value="zip">Zip (' . $GLOBALS["messages"]['normal_compression'] . ')</option>' . "\n";
        echo '<option value="tgz">Tar/Gz (' . $GLOBALS["messages"]['good_compression'] . ')</option>' . "\n";
    }
    if (extension_loaded("bz2")) {
        echo '<option value="tbz">Tar/Bzip2 (' . $GLOBALS["messages"]['best_compression'] . ')</option>' . "\n";
    }
    echo '<option value="" disabled="disabled"> - - - - - - -</option>' . "\n";
    echo '<option value="tar">Tar (' . $GLOBALS["messages"]['no_compression'] . ')</option>' . "\n";
    ?>
				</select>
			</td>
		</tr>
		<tr><td><?php 
    echo $GLOBALS['messages']['archive_saveToDir'];
    ?>
:</td>
			<td align="left">
				<input type="text" name="saveToDir" size="50" value="<?php 
    echo $dir;
    ?>
" />
			</td>
		</tr>
		<tr><td><?php 
    echo $GLOBALS["messages"]["downlink"];
    ?>
?:</td>
			<td align="left">
				<input type="checkbox" checked="checked" name="download" value="y" />
			</td>
		</tr>
		<tr>
			<td colspan="2" style="text-align:center;">
				<input type="submit" value="<?php 
    echo $GLOBALS["messages"]["btncreate"];
    ?>
">
				<input type="button" value="<?php 
    echo $GLOBALS["messages"]["btncancel"];
    ?>
" onclick="javascript:location='<?php 
    echo make_link("list", $dir, NULL);
    ?>
';">
			</td>
		</tr>
		<tr><td colspan="2">&nbsp;</td></tr>
	</table>
	</form>
	<br/>
	<script type="text/javascript">if(document.archform) document.archform.name.focus();</script>
	<?php 
}
Example #2
0
/**
 * Adds a new bookmark to the bookmark ini file
 *
 * @param string $dir
 */
function modify_bookmark($task, $dir)
{
    $my =& JFactory::getUser();
    $alias = substr(JArrayHelper::getValue($_REQUEST, 'alias'), 0, 150);
    $bookmarks = read_bookmarks();
    $bookmarkfile = _QUIXPLORER_PATH . '/config/bookmarks_' . $GLOBALS['file_mode'] . '_' . $my->id . '.php';
    header("Status: 200 OK");
    switch ($task) {
        case 'add':
            if (in_array($dir, $bookmarks)) {
                echo nx_alertBox($GLOBALS['messages']['already_bookmarked']);
                exit;
            }
            $alias = preg_replace('~[^\\w-.\\/\\\\]~', '', $alias);
            // Make the alias ini-safe by removing all non-word characters
            $bookmarks[$alias] = $dir;
            //we deal with the flippped array here
            $msg = nx_alertBox($GLOBALS['messages']['bookmark_was_added']);
            break;
        case 'remove':
            if (!in_array($dir, $bookmarks)) {
                echo nx_alertBox($GLOBALS['messages']['not_a_bookmark']);
                exit;
            }
            $bookmarks = array_flip($bookmarks);
            unset($bookmarks[$dir]);
            $bookmarks = array_flip($bookmarks);
            $msg = nx_alertBox($GLOBALS['messages']['bookmark_was_removed']);
    }
    $inifile = "; <?php if( !defined( '_JEXEC' )  die( 'Restricted access' ); ?>\n";
    $inifile .= $GLOBALS['messages']['homelink'] . "=\n";
    foreach ($bookmarks as $alias => $directory) {
        //changed by pokemon
        if (empty($directory) || empty($alias)) {
            continue;
        }
        $inifile .= "{$alias}={$directory}\n";
    }
    if (!is_writable($bookmarkfile)) {
        echo nx_alertBox(sprintf($GLOBALS['messages']['bookmarkfile_not_writable'], $task, $bookmarkfile));
        exit;
    }
    file_put_contents($bookmarkfile, $inifile);
    echo $msg;
    echo list_bookmarks($dir);
    nx_exit();
}
/**
 * @author soeren
 * @copyright soeren (C) 2006
 *
 * This file handles ftp authentication
 */
function ftp_authentication($ftp_login = '', $ftp_pass = '')
{
    global $dir;
    if ($ftp_login != '' || $ftp_pass != '') {
        while (@ob_end_clean()) {
        }
        @header("Status: 200 OK");
        $ftp_host = JArrayHelper::get($_POST, 'ftp_host', 'localhost:21');
        $url = @parse_url('ftp://' . $ftp_host);
        if (empty($url)) {
            echo nx_alertBox('Unable to parse the specified Host Name. Please use a hostname in this format: hostname:21');
            echo nx_scriptTag('', '$(\'loadingindicator\').innerHTML = \'\';');
            echo 'Unable to parse the specified Host Name. Please use a hostname in this format: hostname:21';
            exit;
        }
        $port = empty($url['port']) ? 21 : $url['port'];
        $ftp = new Net_FTP($url['host'], $port, 20);
        $res = $ftp->connect();
        if (PEAR::isError($res)) {
            echo nx_alertBox($GLOBALS['messages']['ftp_connection_failed']);
            echo nx_scriptTag('', '$(\'loadingindicator\').innerHTML = \'\';');
            echo $GLOBALS['messages']['ftp_connection_failed'] . '<br />[' . $res->getMessage() . ']';
            exit;
        } else {
            $res = $ftp->login($ftp_login, $ftp_pass);
            $ftp->disconnect();
            if (PEAR::isError($res)) {
                echo nx_alertBox($GLOBALS['messages']['ftp_login_failed']);
                echo nx_scriptTag('', '$(\'loadingindicator\').innerHTML = \'\';');
                echo $GLOBALS['messages']['ftp_login_failed'] . '<br />[' . $res->getMessage() . ']';
                exit;
            }
            echo nx_alertBox('Login OK!');
            $_SESSION['ftp_login'] = $ftp_login;
            $_SESSION['ftp_pass'] = $ftp_pass;
            $_SESSION['ftp_host'] = $_POST['ftp_host'];
            session_write_close();
            echo nx_docLocation(str_replace('index3.php', 'index2.php', make_link('list', '') . '&file_mode=ftp'));
            exit;
        }
    } else {
        ?>
		<script type="text/javascript" src="components/com_osefileman/scripts/mootools.ajax.js"></script>
		<script type="text/javascript" src="components/com_osefileman/scripts/functions.js"></script>
		<script type="text/javascript">
		function checkFTPAuth( url ) {
			showLoadingIndicator( $('loadingindicator'), true );
			$('loadingindicator').innerHTML += ' <strong><?php 
        echo $GLOBALS['messages']['ftp_login_check'];
        ?>
</strong>';

			var controller = new ajax( url, { 	postBody: $('adminform'),
												evalScripts: true,
												update: 'statustext'
												}
									);
			controller.request();
			return false;
		}
		</script>

		<?php 
        show_header($GLOBALS["messages"]["ftp_header"]);
        ?>
<br/>

	<form name="ftp_auth_form" method="post" action="<?php 
        echo JURI::root();
        ?>
"/administrator/index3.php" onsubmit="return checkFTPAuth('<?php 
        echo JURI::root();
        ?>
/administrator/index3.php');" id="adminform">

	<input type="hidden" name="no_html" value="1" />
	<table class="adminform" style="width:400px;">
		<tr><th colspan="3"><?php 
        echo $GLOBALS["messages"]["ftp_login_lbl"];
        ?>
</th></tr>

		<tr><td colspan="3" style="text-align:center;" id="loadingindicator"></td></tr>
		<tr><td colspan="3" style="font-weight:bold;text-align:center" id="statustext">&nbsp;</td></tr>

		<tr>
			<td width="50" style="text-align:center;" rowspan="3"><img align="absmiddle" src="images/security_f2.png" alt="Login!" /></td>
			<td><?php 
        echo $GLOBALS["messages"]["ftp_login_name"];
        ?>
:</td>
			<td align="left">
				<input type="text" name="ftp_login_name" size="25" title="<?php 
        echo $GLOBALS["messages"]["ftp_login_name"];
        ?>
" />
			</td>
		</tr>
		<tr>
			<td><?php 
        echo $GLOBALS["messages"]["ftp_login_pass"];
        ?>
:</td>
			<td align="left">
				<input type="password" name="ftp_login_pass" size="25" title="<?php 
        echo $GLOBALS["messages"]["ftp_login_pass"];
        ?>
" />
			</td>
		</tr>
		<tr>
			<td><?php 
        echo $GLOBALS["messages"]["ftp_hostname_port"];
        ?>
:</td>
			<td align="left">
				<input type="text" name="ftp_host" size="25" title="<?php 
        echo $GLOBALS["messages"]["ftp_hostname"];
        ?>
" value="<?php 
        echo JArrayHelper::getValue($_SESSION, 'ftp_host', 'localhost:21');
        ?>
" />
			</td>
		</tr>
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr>
			<td style="text-align:center;" colspan="3">
			<input type="hidden" name="action" value="ftp_authentication" />
			<input type="hidden" name="option" value="com_osefileman" />
			<input type="submit" name="submit" value="<?php 
        echo $GLOBALS['messages']['btnlogin'];
        ?>
" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" name="cancel" value="<?php 
        echo $GLOBALS['messages']['btncancel'];
        ?>
" onclick="javascript:document.location='<?php 
        echo make_link('list', $dir);
        ?>
';" />
			</td>
		</tr>
		<tr><td colspan="3">&nbsp;</td></tr>
	</table>
	</form>
	<?php 
    }
}