示例#1
0
 /**
  * Updates files from git repository
  * Make sure user have access to repository and command is run as this user
  *
  * @param string $branch
  * @return $this
  */
 public function updateSourceCode($branch = CFG_GIT_BRANCH)
 {
     // Check that name is not any other command
     if (!FileSystem::checkFileName($branch)) {
         return $this;
     }
     // To use this command owner of folder and git repository must be the same as web user
     exec('git reset --hard origin/' . $branch . ' 2>&1; git pull -v origin ' . $branch . ' 2>&1', $out);
     if ($out) {
         $this->result_message[] = $out;
     }
     // Clear all caches - may be required to show fresh data
     @Cacher::getInstance()->clearAllCaches();
     return $this;
 }
示例#2
0
<?php

use TMCms\Config\Configuration;
use TMCms\Config\Settings;
use TMCms\Files\FileSystem;
use TMCms\Files\Image;
if (!preg_match('/\\.(?:jpg|png|jpeg|gif)&[a-z0-9&=\\_]+$/', QUERY)) {
    return;
}
$sep_pos = strpos(QUERY, '&');
$path = explode('/', substr(QUERY, 0, $sep_pos));
foreach ($path as &$dir) {
    if (!FileSystem::checkFileName($dir)) {
        return;
    }
}
$file = array_pop($path);
$path = implode('/', $path);
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$src_actions = substr(QUERY, $sep_pos + 1);
parse_str($src_actions, $actions);
$src_path = ($path ? $path . '/' : NULL) . $file;
if (!is_file(DIR_BASE . $src_path)) {
    return;
}
// Rotate before EXIF data
if ($ext == 'jpg' || $ext == 'jpeg') {
    $exif = @exif_read_data(DIR_BASE . $src_path);
    // file may be not a .jpg and this will raise an error
    $img = @imageCreateFromJpeg(DIR_BASE . $src_path);
    if ($img && $exif && isset($exif['Orientation'])) {
示例#3
0
 /**
  * Action for Edit file or folder
  */
 public function _edit()
 {
     $dir =& $_GET['path'];
     if (isset($dir[0]) && $dir[0] == '/') {
         $dir = substr($dir, 1);
     }
     $type = isset($_POST['type_of_1']) ? $_POST['type_of_1'] : (isset($_POST['type_of_2']) ? $_POST['type_of_2'] : (isset($_POST['type_of_3']) ? $_POST['type_of_3'] : false));
     if ($type == 'file') {
         // Files
         switch ($_GET['action']) {
             case 'rename':
                 if ($_POST['current_path'][0] == '/') {
                     $_POST['current_path'] = substr($_POST['current_path'], 1);
                 }
                 $new_path = DIR_BASE . $dir . $_POST['new_name'];
                 if (file_exists($new_path)) {
                     error('File "' . htmlspecialchars($_POST['new_name'], ENT_QUOTES) . '" already exists');
                 }
                 rename(DIR_BASE . $_POST['current_path'], $new_path);
                 App::add('File "' . $_POST['current_path'] . '" renamed to "' . $new_path . '"');
                 Messages::sendGreenAlert('File "' . $_POST['current_path'] . '" renamed to "' . $new_path . '"');
                 break;
             case 'delete':
                 if ($_POST['remove_path'][0] == '/') {
                     $_POST['remove_path'] = substr($_POST['remove_path'], 1);
                 }
                 if (is_file(DIR_BASE . $_POST['remove_path'])) {
                     unlink(DIR_BASE . $_POST['remove_path']);
                 }
                 App::add('File "' . $_POST['remove_path'] . '" deleted');
                 Messages::sendGreenAlert('File "' . $_POST['remove_path'] . '" deleted');
                 break;
             case 'content':
                 if ($_POST['file_name'][0] == '/') {
                     $_POST['file_name'] = substr($_POST['file_name'], 1);
                 }
                 file_put_contents(DIR_BASE . $_POST['file_name'], $_POST['content']);
                 App::add('Content of file "' . $_POST['file_name'] . '" edited');
                 Messages::sendGreenAlert('Content of file "' . $_POST['file_name'] . '" edited');
                 break;
         }
     } elseif ($type == 'folder') {
         // folders
         switch ($_GET['action']) {
             case 'rename':
                 if ($_POST['current_path'][0] == '/') {
                     $_POST['current_path'] = substr($_POST['current_path'], 1);
                 }
                 $new_path = DIR_BASE . $dir . $_POST['new_name'];
                 if (file_exists($new_path)) {
                     error('Folder "' . htmlspecialchars($_POST['new_name'], ENT_QUOTES) . '" already exists');
                 }
                 rename(DIR_BASE . $_POST['current_path'], $new_path);
                 App::add('Folder "' . $_POST['current_path'] . '" renamed to "' . $new_path . '"');
                 Messages::sendGreenAlert('Folder "' . $_POST['current_path'] . '" renamed to "' . $new_path);
                 break;
             case 'delete':
                 if ($_POST['remove_path'][0] == '/') {
                     $_POST['remove_path'] = substr($_POST['remove_path'], 1);
                 }
                 FileSystem::remDir(DIR_BASE . $_POST['remove_path'], $_POST['leave_folder']);
                 App::add('Folder "' . $_POST['remove_path'] . '" deleted');
                 Messages::sendGreenAlert('Folder "' . $_POST['remove_path'] . '" deleted');
                 break;
         }
     } elseif (!$type) {
         // New file or folder
         switch ($_GET['action']) {
             case 'dircreate':
                 if (!isset($_POST['dirname']) || !FileSystem::checkFileName($_POST['dirname'])) {
                     return;
                 }
                 $new_path = DIR_BASE . $dir . $_POST['dirname'];
                 if (file_exists($new_path)) {
                     error('Folder "' . htmlspecialchars($_POST['dirname'], ENT_QUOTES) . '" already exists');
                 }
                 FileSystem::mkDir($new_path);
                 App::add('Folder "' . DIR_BASE_URL . $dir . $_POST['dirname'] . '" created');
                 Messages::sendGreenAlert('Folder "' . DIR_BASE_URL . $dir . $_POST['dirname'] . '" created');
                 break;
             case 'filecreate':
                 if (!isset($_POST['file_name'], $_POST['content']) || !FileSystem::checkFileName($_POST['file_name'])) {
                     return;
                 }
                 $new_path = DIR_BASE . $dir . $_POST['file_name'];
                 if (file_exists($new_path)) {
                     error('File "' . htmlspecialchars($_POST['file_name'], ENT_QUOTES) . '" already exists');
                 }
                 FileSystem::mkDir(DIR_BASE . $dir);
                 file_put_contents($new_path, $_POST['content']);
                 App::add('File "' . $new_path . '" created');
                 Messages::sendGreenAlert('File "' . $new_path . '" created');
                 break;
         }
     }
     back();
 }
示例#4
0
 /**
  * @param string $key
  * @return bool
  */
 public function delete($key)
 {
     if (!FileSystem::checkFileName($key)) {
         return false;
     }
     $path = $this->getPathToFile($key);
     if (!$path) {
         return false;
     }
     $file = $path . $key;
     if (!is_file($file)) {
         return false;
     }
     unlink($file);
     // Delete file
     // If no more files in folder with same hash - remove all folder
     if (!count(FileSystem::scanDirs($path))) {
         FileSystem::remdir($path);
     }
     return true;
 }