-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2675 from HB9HIL/check-folder-permissions
Debug View - Check File Permissions recursive
- Loading branch information
Showing
1 changed file
with
43 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |