Skip to content

Commit

Permalink
Merge pull request #2675 from HB9HIL/check-folder-permissions
Browse files Browse the repository at this point in the history
Debug View - Check File Permissions recursive
  • Loading branch information
magicbug authored Nov 12, 2023
2 parents ba171a5 + 77c83ad commit 8380514
Showing 1 changed file with 43 additions and 51 deletions.
94 changes: 43 additions & 51 deletions application/controllers/Debug.php
Original file line number Diff line number Diff line change
@@ -1,69 +1,61 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Debug extends CI_Controller {
function __construct()
{
parent::__construct();
function __construct()
{
parent::__construct();

$this->load->model('user_model');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
}
/* User Facing Links to Backup URLs */
public function index()
{
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
}

/* User Facing Links to Backup URLs */
public function index()
{
$this->load->helper('file');

// Test writing to backup folder
if ( ! write_file('backup/myfile.txt', "dummydata"))
{
$data['backup_folder'] = false;
}
else
{
if(unlink(realpath('backup/myfile.txt'))) {
$data['backup_folder'] = true;
} else {
$data['backup_folder'] = false;
}
}
$backup_folder = $this->is_really_writable('backup');
$data['backup_folder'] = $backup_folder;

// Test writing to updates folder
if ( ! write_file('updates/myfile.txt', "dummydata"))
{
$data['updates_folder'] = false;
}
else
{
if(unlink(realpath('updates/myfile.txt'))) {
$data['updates_folder'] = true;
} else {
$data['updates_folder'] = false;
}
}
$updates_folder = $this->is_really_writable('updates');
$data['updates_folder'] = $updates_folder;

// Test writing to uploads folder
if ( ! write_file('uploads/myfile.txt', "dummydata"))
{
$data['uploads_folder'] = false;
}
else
{
if(unlink(realpath('uploads/myfile.txt'))) {
$data['uploads_folder'] = true;
} else {
$data['uploads_folder'] = false;
}
}
$uploads_folder = $this->is_really_writable('uploads');
$data['uploads_folder'] = $uploads_folder;

$data['page_title'] = "Debug";

$this->load->view('interface_assets/header', $data);
$this->load->view('debug/main');
$this->load->view('interface_assets/footer');
}

$data['page_title'] = "Debug";
private function is_really_writable($folder)
{
// Get the absolute path to the folder
$path = FCPATH . $folder;

$this->load->view('interface_assets/header', $data);
$this->load->view('debug/main');
$this->load->view('interface_assets/footer');
}
// Check if the folder exists
if (!file_exists($path)) {
return false;
}

// Check if the folder is writable
if (is_writable($path)) {
// Check if the subdirectories are writable (recursive check)
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
foreach ($iterator as $item) {
if (!is_writable($item->getPathname())) {
return false;
}
}

return true;
}

}
return false;
}
}

0 comments on commit 8380514

Please sign in to comment.