Ignore:
Timestamp:
Feb 12, 2013, 11:19:57 AM (12 years ago)
Author:
plg
Message:

merge r20712 from branch 2.4 to trunk

bug 2844: increase security on LocalFiles Editor, filter on files to edit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/LocalFilesEditor/include/tpl.inc.php

    r11654 r20714  
    11<?php
    2 
    32if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    43
    5 $edited_file = isset($_POST['edited_file']) ? $_POST['edited_file'] : '';
     4$edited_file = '';
     5
     6if (isset($_POST['edit']))
     7{
     8  $_POST['template'] = $_POST['file_to_edit'];
     9}
     10
     11if (!empty($_POST['template']))
     12{
     13  if (preg_match('#\.\./#', $_POST['template']))
     14  {
     15    die('Hacking attempt! template extension must be in template-extension directory');
     16  }
     17
     18  if (!preg_match('#\.tpl$#', $_POST['template']))
     19  {
     20    die('Hacking attempt! template extension must be a *.tpl file');
     21  }
     22
     23  $template->assign('template', $_POST['template']);
     24 
     25  $edited_file = './template-extension/'.$_POST['template'];
     26}
     27
    628$content_file = '';
    7 
    8 if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit']))
     29if (file_exists($edited_file))
    930{
    10   $edited_file = $_POST['file_to_edit'];
    11   if (file_exists($edited_file))
    12   {
    13     $content_file = file_get_contents($edited_file);
    14   }
    15   else
    16   {
    17     $content_file = '';
    18   }
     31  $content_file = file_get_contents($edited_file);
    1932}
    2033
     
    5164  else
    5265  {
     66    $template->assign('template', $filename);
    5367    $edited_file = $_POST['tpl_parent'] . '/' . $filename;
    5468    $content_file = ($_POST['tpl_model'] == '0') ? '' : file_get_contents($_POST['tpl_model']);
     
    118132  foreach (get_extents() as $pwg_template)
    119133  {
    120     $value = './template-extension/' . $pwg_template;
     134    $value = $pwg_template;
    121135    $options[$value] =  str_replace('/', ' / ', $pwg_template);
    122136    if ($edited_file == $value) $selected = $value;
     
    127141    $selected = $edited_file;
    128142  }
    129   $template->assign('css_lang_tpl', array(
    130     'OPTIONS' => $options,
    131     'SELECTED' => $selected,
    132     'NEW_FILE_URL' => $my_base_url.'-tpl&amp;newfile',
    133     'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right'
    134     )
    135   );
     143  $template->assign(
     144    'css_lang_tpl',
     145    array(
     146      'SELECT_NAME' => 'file_to_edit',
     147      'OPTIONS' => $options,
     148      'SELECTED' => $selected,
     149      'NEW_FILE_URL' => $my_base_url.'-tpl&amp;newfile',
     150      'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right'
     151      )
     152    );
    136153}
    137154
Note: See TracChangeset for help on using the changeset viewer.