[ Index ]
 

Code source de osCommerce 2.2ms2-060817

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/catalog/admin/ -> file_manager.php (source)

   1  <?php
   2  /*
   3    $Id: file_manager.php,v 1.42 2003/06/29 22:50:52 hpdl Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2003 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    require ('includes/application_top.php');
  14  
  15    if (!tep_session_is_registered('current_path')) {
  16      $current_path = DIR_FS_DOCUMENT_ROOT;
  17      tep_session_register('current_path');
  18    }
  19  
  20    if (isset($HTTP_GET_VARS['goto'])) {
  21      $current_path = $HTTP_GET_VARS['goto'];
  22      tep_redirect(tep_href_link(FILENAME_FILE_MANAGER));
  23    }
  24  
  25    if (strstr($current_path, '..')) $current_path = DIR_FS_DOCUMENT_ROOT;
  26  
  27    if (!is_dir($current_path)) $current_path = DIR_FS_DOCUMENT_ROOT;
  28  
  29    if (!ereg('^' . DIR_FS_DOCUMENT_ROOT, $current_path)) $current_path = DIR_FS_DOCUMENT_ROOT;
  30  
  31    $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  32  
  33    if (tep_not_null($action)) {
  34      switch ($action) {
  35        case 'reset':
  36          tep_session_unregister('current_path');
  37          tep_redirect(tep_href_link(FILENAME_FILE_MANAGER));
  38          break;
  39        case 'deleteconfirm':
  40          if (strstr($HTTP_GET_VARS['info'], '..')) tep_redirect(tep_href_link(FILENAME_FILE_MANAGER));
  41  
  42          tep_remove($current_path . '/' . $HTTP_GET_VARS['info']);
  43          if (!$tep_remove_error) tep_redirect(tep_href_link(FILENAME_FILE_MANAGER));
  44          break;
  45        case 'insert':
  46          if (mkdir($current_path . '/' . $HTTP_POST_VARS['folder_name'], 0777)) {
  47            tep_redirect(tep_href_link(FILENAME_FILE_MANAGER, 'info=' . urlencode($HTTP_POST_VARS['folder_name'])));
  48          }
  49          break;
  50        case 'save':
  51          if ($fp = fopen($current_path . '/' . $HTTP_POST_VARS['filename'], 'w+')) {
  52            fputs($fp, stripslashes($HTTP_POST_VARS['file_contents']));
  53            fclose($fp);
  54            tep_redirect(tep_href_link(FILENAME_FILE_MANAGER, 'info=' . urlencode($HTTP_POST_VARS['filename'])));
  55          }
  56          break;
  57        case 'processuploads':
  58          for ($i=1; $i<6; $i++) {
  59            if (isset($GLOBALS['file_' . $i]) && tep_not_null($GLOBALS['file_' . $i])) {
  60              new upload('file_' . $i, $current_path);
  61            }
  62          }
  63  
  64          tep_redirect(tep_href_link(FILENAME_FILE_MANAGER));
  65          break;
  66        case 'download':
  67          header('Content-type: application/x-octet-stream');
  68          header('Content-disposition: attachment; filename=' . urldecode($HTTP_GET_VARS['filename']));
  69          readfile($current_path . '/' . urldecode($HTTP_GET_VARS['filename']));
  70          exit;
  71          break;
  72        case 'upload':
  73        case 'new_folder':
  74        case 'new_file':
  75          $directory_writeable = true;
  76          if (!is_writeable($current_path)) {
  77            $directory_writeable = false;
  78            $messageStack->add(sprintf(ERROR_DIRECTORY_NOT_WRITEABLE, $current_path), 'error');
  79          }
  80          break;
  81        case 'edit':
  82          if (strstr($HTTP_GET_VARS['info'], '..')) tep_redirect(tep_href_link(FILENAME_FILE_MANAGER));
  83  
  84          $file_writeable = true;
  85          if (!is_writeable($current_path . '/' . $HTTP_GET_VARS['info'])) {
  86            $file_writeable = false;
  87            $messageStack->add(sprintf(ERROR_FILE_NOT_WRITEABLE, $current_path . '/' . $HTTP_GET_VARS['info']), 'error');
  88          }
  89          break;
  90        case 'delete':
  91          if (strstr($HTTP_GET_VARS['info'], '..')) tep_redirect(tep_href_link(FILENAME_FILE_MANAGER));
  92          break;
  93      }
  94    }
  95  
  96    $in_directory = substr(substr(DIR_FS_DOCUMENT_ROOT, strrpos(DIR_FS_DOCUMENT_ROOT, '/')), 1);
  97    $current_path_array = explode('/', $current_path);
  98    $document_root_array = explode('/', DIR_FS_DOCUMENT_ROOT);
  99    $goto_array = array(array('id' => DIR_FS_DOCUMENT_ROOT, 'text' => $in_directory));
 100    for ($i=0, $n=sizeof($current_path_array); $i<$n; $i++) {
 101      if ((isset($document_root_array[$i]) && ($current_path_array[$i] != $document_root_array[$i])) || !isset($document_root_array[$i])) {
 102        $goto_array[] = array('id' => implode('/', array_slice($current_path_array, 0, $i+1)), 'text' => $current_path_array[$i]);
 103      }
 104    }
 105  ?>
 106  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 107  <html <?php echo HTML_PARAMS; ?>>
 108  <head>
 109  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 110  <title><?php echo TITLE; ?></title>
 111  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
 112  <script language="javascript" src="includes/general.js"></script>
 113  </head>
 114  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
 115  <!-- header //-->
 116  <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
 117  <!-- header_eof //-->
 118  
 119  <!-- body //-->
 120  <table border="0" width="100%" cellspacing="2" cellpadding="2">
 121    <tr>
 122      <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
 123  <!-- left_navigation //-->
 124  <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
 125  <!-- left_navigation_eof //-->
 126      </table></td>
 127  <!-- body_text //-->
 128      <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 129        <tr>
 130          <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
 131            <tr><?php echo tep_draw_form('goto', FILENAME_FILE_MANAGER, '', 'get'); ?>
 132              <td class="pageHeading"><?php echo HEADING_TITLE . '<br><span class="smallText">' . $current_path . '</span>'; ?></td>
 133              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '1', HEADING_IMAGE_HEIGHT); ?></td>
 134              <td class="pageHeading" align="right"><?php echo tep_draw_pull_down_menu('goto', $goto_array, $current_path, 'onChange="this.form.submit();"'); ?></td>
 135            </form></tr>
 136          </table></td>
 137        </tr>
 138  <?php
 139    if ( (($action == 'new_file') && ($directory_writeable == true)) || ($action == 'edit') ) {
 140      if (isset($HTTP_GET_VARS['info']) && strstr($HTTP_GET_VARS['info'], '..')) tep_redirect(tep_href_link(FILENAME_FILE_MANAGER));
 141  
 142      if (!isset($file_writeable)) $file_writeable = true;
 143      $file_contents = '';
 144      if ($action == 'new_file') {
 145        $filename_input_field = tep_draw_input_field('filename');
 146      } elseif ($action == 'edit') {
 147        if ($file_array = file($current_path . '/' . $HTTP_GET_VARS['info'])) {
 148          $file_contents = addslashes(implode('', $file_array));
 149        }
 150        $filename_input_field = $HTTP_GET_VARS['info'] . tep_draw_hidden_field('filename', $HTTP_GET_VARS['info']);
 151      }
 152  ?>
 153        <tr>
 154          <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
 155        </tr>
 156        <tr><?php echo tep_draw_form('new_file', FILENAME_FILE_MANAGER, 'action=save'); ?>
 157          <td><table border="0" cellspacing="0" cellpadding="2">
 158            <tr>
 159              <td class="main"><?php echo TEXT_FILE_NAME; ?></td>
 160              <td class="main"><?php echo $filename_input_field; ?></td>
 161            </tr>
 162            <tr>
 163              <td class="main" valign="top"><?php echo TEXT_FILE_CONTENTS; ?></td>
 164              <td class="main"><?php echo tep_draw_textarea_field('file_contents', 'soft', '80', '20', $file_contents, (($file_writeable) ? '' : 'readonly')); ?></td>
 165            </tr>
 166            <tr>
 167              <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
 168            </tr>
 169            <tr>
 170              <td align="right" class="main" colspan="2"><?php if ($file_writeable == true) echo tep_image_submit('button_save.gif', IMAGE_SAVE) . '&nbsp;'; echo '<a href="' . tep_href_link(FILENAME_FILE_MANAGER, (isset($HTTP_GET_VARS['info']) ? 'info=' . urlencode($HTTP_GET_VARS['info']) : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
 171            </tr>
 172          </table></td>
 173        </form></tr>
 174  <?php
 175    } else {
 176      $showuser = (function_exists('posix_getpwuid') ? true : false);
 177      $contents = array();
 178      $dir = dir($current_path);
 179      while ($file = $dir->read()) {
 180        if ( ($file != '.') && ($file != 'CVS') && ( ($file != '..') || ($current_path != DIR_FS_DOCUMENT_ROOT) ) ) {
 181          $file_size = number_format(filesize($current_path . '/' . $file)) . ' bytes';
 182  
 183          $permissions = tep_get_file_permissions(fileperms($current_path . '/' . $file));
 184          if ($showuser) {
 185            $user = @posix_getpwuid(fileowner($current_path . '/' . $file));
 186            $group = @posix_getgrgid(filegroup($current_path . '/' . $file));
 187          } else {
 188            $user = $group = array();
 189          }
 190  
 191          $contents[] = array('name' => $file,
 192                              'is_dir' => is_dir($current_path . '/' . $file),
 193                              'last_modified' => strftime(DATE_TIME_FORMAT, filemtime($current_path . '/' . $file)),
 194                              'size' => $file_size,
 195                              'permissions' => $permissions,
 196                              'user' => $user['name'],
 197                              'group' => $group['name']);
 198        }
 199      }
 200  
 201      function tep_cmp($a, $b) {
 202        return strcmp( ($a['is_dir'] ? 'D' : 'F') . $a['name'], ($b['is_dir'] ? 'D' : 'F') . $b['name']);
 203      }
 204      usort($contents, 'tep_cmp');
 205  ?>
 206  
 207        <tr>
 208          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 209            <tr>
 210              <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 211                <tr class="dataTableHeadingRow">
 212                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_FILENAME; ?></td>
 213                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_SIZE; ?></td>
 214                  <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_PERMISSIONS; ?></td>
 215                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_USER; ?></td>
 216                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_GROUP; ?></td>
 217                  <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_LAST_MODIFIED; ?></td>
 218                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
 219                </tr>
 220  <?php
 221    for ($i=0, $n=sizeof($contents); $i<$n; $i++) {
 222      if ((!isset($HTTP_GET_VARS['info']) || (isset($HTTP_GET_VARS['info']) && ($HTTP_GET_VARS['info'] == $contents[$i]['name']))) && !isset($fInfo) && ($action != 'upload') && ($action != 'new_folder')) {
 223        $fInfo = new objectInfo($contents[$i]);
 224      }
 225  
 226      if ($contents[$i]['name'] == '..') {
 227        $goto_link = substr($current_path, 0, strrpos($current_path, '/'));
 228      } else {
 229        $goto_link = $current_path . '/' . $contents[$i]['name'];
 230      }
 231  
 232      if (isset($fInfo) && is_object($fInfo) && ($contents[$i]['name'] == $fInfo->name)) {
 233        if ($fInfo->is_dir) {
 234          echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";
 235          $onclick_link = 'goto=' . $goto_link;
 236        } else {
 237          echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";
 238          $onclick_link = 'info=' . urlencode($fInfo->name) . '&action=edit';
 239        }
 240      } else {
 241        echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";
 242        $onclick_link = 'info=' . urlencode($contents[$i]['name']);
 243      }
 244  
 245      if ($contents[$i]['is_dir']) {
 246        if ($contents[$i]['name'] == '..') {
 247          $icon = tep_image(DIR_WS_ICONS . 'previous_level.gif', ICON_PREVIOUS_LEVEL);
 248        } else {
 249          $icon = (isset($fInfo) && is_object($fInfo) && ($contents[$i]['name'] == $fInfo->name) ? tep_image(DIR_WS_ICONS . 'current_folder.gif', ICON_CURRENT_FOLDER) : tep_image(DIR_WS_ICONS . 'folder.gif', ICON_FOLDER));
 250        }
 251        $link = tep_href_link(FILENAME_FILE_MANAGER, 'goto=' . $goto_link);
 252      } else {
 253        $icon = tep_image(DIR_WS_ICONS . 'file_download.gif', ICON_FILE_DOWNLOAD);
 254        $link = tep_href_link(FILENAME_FILE_MANAGER, 'action=download&filename=' . urlencode($contents[$i]['name']));
 255      }
 256  ?>
 257                  <td class="dataTableContent" onclick="document.location.href='<?php echo tep_href_link(FILENAME_FILE_MANAGER, $onclick_link); ?>'"><?php echo '<a href="' . $link . '">' . $icon . '</a>&nbsp;' . $contents[$i]['name']; ?></td>
 258                  <td class="dataTableContent" align="right" onclick="document.location.href='<?php echo tep_href_link(FILENAME_FILE_MANAGER, $onclick_link); ?>'"><?php echo ($contents[$i]['is_dir'] ? '&nbsp;' : $contents[$i]['size']); ?></td>
 259                  <td class="dataTableContent" align="center" onclick="document.location.href='<?php echo tep_href_link(FILENAME_FILE_MANAGER, $onclick_link); ?>'"><tt><?php echo $contents[$i]['permissions']; ?></tt></td>
 260                  <td class="dataTableContent" onclick="document.location.href='<?php echo tep_href_link(FILENAME_FILE_MANAGER, $onclick_link); ?>'"><?php echo $contents[$i]['user']; ?></td>
 261                  <td class="dataTableContent" onclick="document.location.href='<?php echo tep_href_link(FILENAME_FILE_MANAGER, $onclick_link); ?>'"><?php echo $contents[$i]['group']; ?></td>
 262                  <td class="dataTableContent" align="center" onclick="document.location.href='<?php echo tep_href_link(FILENAME_FILE_MANAGER, $onclick_link); ?>'"><?php echo $contents[$i]['last_modified']; ?></td>
 263                  <td class="dataTableContent" align="right"><?php if ($contents[$i]['name'] != '..') echo '<a href="' . tep_href_link(FILENAME_FILE_MANAGER, 'info=' . urlencode($contents[$i]['name']) . '&action=delete') . '">' . tep_image(DIR_WS_ICONS . 'delete.gif', ICON_DELETE) . '</a>&nbsp;'; if (isset($fInfo) && is_object($fInfo) && ($fInfo->name == $contents[$i]['name'])) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif'); } else { echo '<a href="' . tep_href_link(FILENAME_FILE_MANAGER, 'info=' . urlencode($contents[$i]['name'])) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
 264                </tr>
 265  <?php
 266    }
 267  ?>
 268                <tr>
 269                  <td colspan="7"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 270                    <tr valign="top">
 271                      <td class="smallText"><?php echo '<a href="' . tep_href_link(FILENAME_FILE_MANAGER, 'action=reset') . '">' . tep_image_button('button_reset.gif', IMAGE_RESET) . '</a>'; ?></td>
 272                      <td class="smallText" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_FILE_MANAGER, (isset($HTTP_GET_VARS['info']) ? 'info=' . urlencode($HTTP_GET_VARS['info']) . '&' : '') . 'action=upload') . '">' . tep_image_button('button_upload.gif', IMAGE_UPLOAD) . '</a>&nbsp;<a href="' . tep_href_link(FILENAME_FILE_MANAGER, (isset($HTTP_GET_VARS['info']) ? 'info=' . urlencode($HTTP_GET_VARS['info']) . '&' : '') . 'action=new_file') . '">' . tep_image_button('button_new_file.gif', IMAGE_NEW_FILE) . '</a>&nbsp;<a href="' . tep_href_link(FILENAME_FILE_MANAGER, (isset($HTTP_GET_VARS['info']) ? 'info=' . urlencode($HTTP_GET_VARS['info']) . '&' : '') . 'action=new_folder') . '">' . tep_image_button('button_new_folder.gif', IMAGE_NEW_FOLDER) . '</a>'; ?></td>
 273                    </tr>
 274                  </table></td>
 275                </tr>
 276              </table></td>
 277  <?php
 278      $heading = array();
 279      $contents = array();
 280  
 281      switch ($action) {
 282        case 'delete':
 283          $heading[] = array('text' => '<b>' . $fInfo->name . '</b>');
 284  
 285          $contents = array('form' => tep_draw_form('file', FILENAME_FILE_MANAGER, 'info=' . urlencode($fInfo->name) . '&action=deleteconfirm'));
 286          $contents[] = array('text' => TEXT_DELETE_INTRO);
 287          $contents[] = array('text' => '<br><b>' . $fInfo->name . '</b>');
 288          $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_FILE_MANAGER, (tep_not_null($fInfo->name) ? 'info=' . urlencode($fInfo->name) : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 289          break;
 290        case 'new_folder':
 291          $heading[] = array('text' => '<b>' . TEXT_NEW_FOLDER . '</b>');
 292  
 293          $contents = array('form' => tep_draw_form('folder', FILENAME_FILE_MANAGER, 'action=insert'));
 294          $contents[] = array('text' => TEXT_NEW_FOLDER_INTRO);
 295          $contents[] = array('text' => '<br>' . TEXT_FILE_NAME . '<br>' . tep_draw_input_field('folder_name'));
 296          $contents[] = array('align' => 'center', 'text' => '<br>' . (($directory_writeable == true) ? tep_image_submit('button_save.gif', IMAGE_SAVE) : '') . ' <a href="' . tep_href_link(FILENAME_FILE_MANAGER, (isset($HTTP_GET_VARS['info']) ? 'info=' . urlencode($HTTP_GET_VARS['info']) : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 297          break;
 298        case 'upload':
 299          $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_UPLOAD . '</b>');
 300  
 301          $contents = array('form' => tep_draw_form('file', FILENAME_FILE_MANAGER, 'action=processuploads', 'post', 'enctype="multipart/form-data"'));
 302          $contents[] = array('text' => TEXT_UPLOAD_INTRO);
 303  
 304          $file_upload = '';
 305          for ($i=1; $i<6; $i++) $file_upload .= tep_draw_file_field('file_' . $i) . '<br>';
 306  
 307          $contents[] = array('text' => '<br>' . $file_upload);
 308          $contents[] = array('align' => 'center', 'text' => '<br>' . (($directory_writeable == true) ? tep_image_submit('button_upload.gif', IMAGE_UPLOAD) : '') . ' <a href="' . tep_href_link(FILENAME_FILE_MANAGER, (isset($HTTP_GET_VARS['info']) ? 'info=' . urlencode($HTTP_GET_VARS['info']) : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 309          break;
 310        default:
 311          if (isset($fInfo) && is_object($fInfo)) {
 312            $heading[] = array('text' => '<b>' . $fInfo->name . '</b>');
 313  
 314            if (!$fInfo->is_dir) $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_FILE_MANAGER, 'info=' . urlencode($fInfo->name) . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a>');
 315            $contents[] = array('text' => '<br>' . TEXT_FILE_NAME . ' <b>' . $fInfo->name . '</b>');
 316            if (!$fInfo->is_dir) $contents[] = array('text' => '<br>' . TEXT_FILE_SIZE . ' <b>' . $fInfo->size . '</b>');
 317            $contents[] = array('text' => '<br>' . TEXT_LAST_MODIFIED . ' ' . $fInfo->last_modified);
 318          }
 319      }
 320  
 321      if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
 322        echo '            <td width="25%" valign="top">' . "\n";
 323  
 324        $box = new box;
 325        echo $box->infoBox($heading, $contents);
 326  
 327        echo '            </td>' . "\n";
 328      }
 329  ?>
 330            </tr>
 331          </table></td>
 332        </tr>
 333  <?php
 334    }
 335  ?>
 336      </table></td>
 337  <!-- body_text_eof //-->
 338    </tr>
 339  </table>
 340  <!-- body_eof //-->
 341  
 342  <!-- footer //-->
 343  <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
 344  <!-- footer_eof //-->
 345  <br>
 346  </body>
 347  </html>
 348  <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>


Généré le : Mon Nov 26 19:48:25 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics