Show hint about upload permissions on LotW page

This commit is contained in:
phl0
2024-01-31 09:53:56 +01:00
parent d0d563573d
commit 2973300b32
3 changed files with 39 additions and 0 deletions

View File

@@ -55,6 +55,10 @@ class Lotw extends CI_Controller {
// Set Page Title
$data['page_title'] = "Logbook of the World";
// Check folder permissions
$uploads_folder = $this->is_really_writable('uploads');
$data['uploads_folder'] = $uploads_folder;
// Load Views
$this->load->view('interface_assets/header', $data);
$this->load->view('lotw_views/index');
@@ -1123,4 +1127,31 @@ class Lotw extends CI_Controller {
endswitch;
}
private function is_really_writable($folder) {
// Get the absolute path to the folder
$path = FCPATH . $folder;
// 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 ($item->isDir() && basename($item->getPathName()) != '..') {
if (!is_writable($item->getRealPath())) {
return false;
}
}
}
return true;
}
return false;
}
} // end class

View File

@@ -61,3 +61,6 @@ $lang['lotw_cert_expired'] = 'At least one of your LoTW certificates is expired!
// Lotw User
$lang['lotw_user'] = 'This station uses LoTW.';
$lang['lotw_last_upload'] = 'Last upload';
// Upload folder permissions
$lang['lotw_upload_folder_permissions'] = 'Upload folder is not writable. Please contact your admin.';

View File

@@ -1,4 +1,9 @@
<div class="container lotw">
<?php if($uploads_folder != true) { ?>
<div class="alert alert-warning" role="alert" style="margin-top: 1rem;">
<span class="badge text-bg-info"><?php echo lang('general_word_important'); ?></span> <i class="fas fa-ban"></i> <?php echo lang('lotw_upload_folder_permissions'); ?>
</div>
<?php } ?>
<br>
<a class="btn btn-outline-primary btn-sm float-end" href="<?php echo site_url('/lotw/import'); ?>" role="button"><i class="fas fa-cloud-download-alt"></i> <?php echo lang('lotw_btn_lotw_import'); ?></a>
<h2><?php echo lang('lotw_title'); ?></h2>