Example #1
0
 public function action()
 {
     $mode = $_POST['new_mode'];
     $rec_option = $_POST['is_recursive'];
     $valid_options = array('none', 'files', 'folders', 'both');
     $chmod_perm = is_dir($path) ? $chmod_dirs : $chmod_files;
     // check perm
     if ($chmod_perm === FALSE) {
         $fileORfolder = is_dir($path) ? 'folders' : 'files';
         $response = "Changing" . $fileORfolder . "permissions are not allowed.";
         $this->r = array($response, 403);
         return;
     }
     // check mode
     if (!preg_match("/^[0-7]{3}\$/", $mode)) {
         $this->r = array('The supplied permission mode is incorrect.', 400);
         return;
     }
     // check recursive option
     if (!in_array($rec_option, $valid_options)) {
         $this->r = array("wrong option", 400);
         return;
     }
     // check if server disabled chmod
     if (is_function_callable('chmod') === FALSE) {
         $this->r = array('The chmod function has been disabled by the server.', 'chmod', 403);
         return;
     }
     $mode = "0" . $mode;
     $mode = octdec($mode);
     rchmod($path, $mode, $rec_option);
 }
Example #2
0
function rchmod($source, $mode, $rec_option = "none", $is_rec = FALSE)
{
    if ($rec_option == "none") {
        chmod($source, $mode);
    } else {
        if ($is_rec === FALSE) {
            chmod($source, $mode);
        }
        $files = scandir($source);
        foreach ($files as $file) {
            if ($file != "." && $file != "..") {
                if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
                    if ($rec_option == "folders" || $rec_option == "both") {
                        chmod($source . DIRECTORY_SEPARATOR . $file, $mode);
                    }
                    rchmod($source . DIRECTORY_SEPARATOR . $file, $mode, $rec_option, TRUE);
                } else {
                    if ($rec_option == "files" || $rec_option == "both") {
                        chmod($source . DIRECTORY_SEPARATOR . $file, $mode);
                    }
                }
            }
        }
    }
}
Example #3
0
         response(trans('File_Permission_Wrong_Mode'), 400)->send();
         exit;
     }
     // check recursive option
     if (!in_array($rec_option, $valid_options)) {
         response("wrong option", 400)->send();
         exit;
     }
     // check if server disabled chmod
     if (is_function_callable('chmod') === FALSE) {
         response(sprintf(trans('Function_Disabled'), 'chmod'), 403)->send();
         exit;
     }
     $mode = "0" . $mode;
     $mode = octdec($mode);
     rchmod($path, $mode, $rec_option);
     break;
 case 'save_text_file':
     $content = $_POST['new_content'];
     // $content = htmlspecialchars($content); not needed
     // $content = stripslashes($content);
     // no file
     if (!file_exists($path)) {
         response(trans('File_Not_Found'), 404)->send();
         exit;
     }
     // not writable or edit not allowed
     if (!is_writable($path) || $edit_text_files === FALSE) {
         response(sprintf(trans('File_Open_Edit_Not_Allowed'), strtolower(trans('Edit'))), 403)->send();
         exit;
     }
Example #4
0
 public function changePermissions()
 {
     $this->log('<comment>~ Changing permissions</comment>');
     rchmod(storage_path(), 0777, 0777);
     rchmod(base_path('bootstrap/cache'), 0777, 0777);
     if ($this->post('db_type') == 'sqlite') {
         $db_name = $this->post('db_name', '');
         rchmod($this->baseDirectory . DIRECTORY_SEPARATOR . $db_name, 0777, 0777);
     }
     $this->log('<info>[ + ] Changing permissions [OK]</info>');
 }
Example #5
0
 /**
  * Recursive chmod.
  *
  * @param string $path
  * @param int    $filePerm
  * @param int    $dirPerm
  *
  * @return bool
  */
 function rchmod($path, $filePerm = 0644, $dirPerm = 0755)
 {
     if (!file_exists($path)) {
         return false;
     }
     if (is_file($path)) {
         chmod($path, $filePerm);
     } elseif (is_dir($path)) {
         $foldersAndFiles = scandir($path);
         $entries = array_slice($foldersAndFiles, 2);
         foreach ($entries as $entry) {
             rchmod($path . DIRECTORY_SEPARATOR . $entry, $filePerm, $dirPerm);
         }
         chmod($path, $dirPerm);
     }
     return true;
 }
Example #6
0
function rchmod($path, $filemode, $dirmode)
{
    if (is_dir($path)) {
        if (!chmod($path, $dirmode)) {
            return false;
        }
        $objects = scandir($path);
        if (is_array($objects)) {
            foreach ($objects as $file) {
                if ($file != '.' && $file != '..') {
                    if (!rchmod($path . '/' . $file, $filemode, $dirmode)) {
                        return false;
                    }
                }
            }
        }
        return true;
    } elseif (is_link($path)) {
        return true;
    } elseif (is_file($path)) {
        return chmod($path, $filemode);
    }
    return false;
}