Orderadmin/index.php 0000644 00000000032 14757772277 0007500 0 ustar 00 plugin_name = $plugin_name;
$this->version = $version;
}
public function get_plugin_name()
{
return $this->plugin_name;
}
public function add_submenu_page()
{
add_submenu_page('upload.php', $this->plugin_name, 'Protect Uploads ', 'manage_options', $this->plugin_name . '-settings-page', array($this, 'render_settings_page'));
}
public function verify_settings_page() {
if(!isset($_POST['protect-uploads_nonce'])) {
return;
}
if(!wp_verify_nonce($_POST['protect-uploads_nonce'], 'submit_form')) {
return;
}
if(!current_user_can('manage_options')) {
return;
}
if(!check_admin_referer('submit_form', 'protect-uploads_nonce')) {
return;
}
if (isset($_POST['submit']) && isset($_POST['protection'])) {
$this->save_form(sanitize_text_field($_POST['protection']));
}
}
public function render_settings_page()
{
?>
display_messages();
?>
Protect Uploads
plugin_name . '-settings-page">' . __('Settings') . '';
array_unshift($links, $settings_link);
return $links;
}
public function get_uploads_dir()
{
$uploads_dir = wp_upload_dir();
return $uploads_dir['basedir'];
}
public function get_uploads_url()
{
$uploads_dir = wp_upload_dir();
return $uploads_dir['baseurl'];
}
public function get_uploads_subdirectories()
{
return [self::get_uploads_dir()];
}
public function save_form($protection)
{
if ($protection == 'index_php') {
$this->create_index();
}
if ($protection == 'htaccess') {
$this->create_htaccess();
}
if ($protection == 'remove') {
$this->remove_index();
$this->remove_htaccess();
}
}
// used to check if the current htaccess has been generated by the plugin
public function get_htaccess_identifier()
{
return "[plugin_name=" . $this->plugin_name . "]";
}
public function create_index()
{
// check if index php does not exists
if (self::check_protective_file('index.php') === false) {
$indexContent = "get_plugin_name() . " Plugin\n";
$htaccessContent .= "\tOptions -Indexes\n";
$htaccessContent .= "# [date={$date}] [php={$phpv}] " . self::get_htaccess_identifier() . " [version={$this->version}]\n";
$htaccessContent .= "# END " . $this->get_plugin_name() . " Plugin\n";
// if htaccess does NOT exist yet
if (self::check_protective_file('.htaccess') === false) {
// try to create and save the new htaccess file
if (!file_put_contents(self::get_uploads_dir() . '/' . '.htaccess', $htaccessContent)) {
self::register_message('Impossible to create or modified the htaccess file.', 'error');
} else {
self::register_message('The htaccess file has been created.');
}
}
else {
// if content added to existing htaccess
if (file_put_contents(self::get_uploads_dir() . '/.htaccess', $htaccessContent, FILE_APPEND | LOCK_EX)) {
self::register_message('The htaccess file has been updated.');
} else {
self::register_message('The existing htaccess file couldn\'t be updated. Please check file permissions.', 'error');
}
}
}
public function remove_index()
{
$i = 0;
foreach (self::get_uploads_subdirectories() as $subDirectory) {
if (file_exists($subDirectory . '/index.php')) {
unlink($subDirectory . '/index.php');
$i++;
}
}
if ($i == count(self::get_uploads_subdirectories())) {
self::register_message('The index.php file(s) have(has) been deleted.');
}
}
public function remove_htaccess()
{
if (file_exists(self::get_uploads_dir() . '/.htaccess')) {
$htaccessContent = file_get_contents(self::get_uploads_dir() . '/.htaccess');
$htaccessContent = preg_replace('/(# BEGIN protect-uploads Plugin)(.*?)(# END protect-uploads Plugin)/is', '', $htaccessContent);
file_put_contents(self::get_uploads_dir() . '/.htaccess', $htaccessContent, LOCK_EX);
// if htaccess is empty, we remove it.
if (strlen(preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", file_get_contents(self::get_uploads_dir() . '/.htaccess'))) == 0) {
unlink(self::get_uploads_dir() . '/.htaccess');
}
//
self::register_message('The htaccess file has been updated.');
}
}
public function get_protective_files_array()
{
$uploads_files = ['index.php', 'index.html', '.htaccess'];
$response = [];
foreach ($uploads_files as $file) {
if (file_exists(self::get_uploads_dir() . '/' . $file)) {
$response[] = $file;
}
}
return $response;
}
public function check_protective_file($file)
{
if (in_array($file, self::get_protective_files_array())) {
return true;
} else {
return false;
}
}
public function get_uploads_root_response_code()
{
$response = wp_remote_get( self::get_uploads_url() );
$code = wp_remote_retrieve_response_code($response);
return $code;
}
public function get_htaccess_content()
{
return file_get_contents(self::get_uploads_dir() . '/.htaccess');
}
public function check_htaccess_is_self_generated()
{
if (self::check_protective_file('.htaccess') && preg_match('/' . self::get_htaccess_identifier() . '/', self::get_htaccess_content())) {
return true;
} else {
return false;
}
}
// heart? <3
public function check_uploads_is_protected()
{
foreach (self::get_protective_files_array() as $file) {
if ($file === 'index.html') {
return true;
break;
}
if ($file === 'index.php') {
return true;
break;
}
if ($file === '.htaccess' && self::get_uploads_root_response_code() === 200) {
return false;
break;
}
}
if (self::get_uploads_root_response_code() === 403) {
return true;
}
else {
return false;
}
}
public function check_protective_file_removable() {
if( self::check_protective_file('index.html') ) {
return false;
}
elseif( self::check_protective_file('.htaccess') === false && self::get_uploads_root_response_code() === 403 ) {
return false;
}
else {
return true;
}
}
public function get_uploads_protection_message_array()
{
$response = [];
foreach (self::get_protective_files_array() as $file) {
if ($file === '.htaccess' && self::get_uploads_root_response_code() === 403) {
$response[] = ' ' . __('.htaccess file is present and access to uploads directory returns 403 code.', $this->plugin_name);
}
if ($file === 'index.php') {
$response[] = ' ' . __('index.php file is present.', $this->plugin_name);
}
if ($file === 'index.html') {
$response[] = ' ' . __('index.html file is present.', $this->plugin_name);
}
}
if (self::check_protective_file('.htaccess') === true && self::get_uploads_root_response_code() === 200) {
$response[] = ' ' . __('.htaccess file is present but not protecting uploads directory.', $this->plugin_name);
}
if (self::check_protective_file('.htaccess') === false && self::get_uploads_root_response_code() === 403) {
$response[] = ' ' . __('Access to uploads directory is protected (403) with a global .htaccess or another global declaration.', $this->plugin_name);
}
return $response;
}
public function check_apache()
{
if (!function_exists('apache_get_modules')) {
self::register_message('The Protect Uploads plugin cannot work without Apache. Yourself or your web host has to activate this module.');
}
}
public function register_message($message, $type = 'updated', $id = 0)
{
$this->messages['apache'][] = array(
'message' => __($message, $this->plugin_name),
'type' => $type,
'id' => $id
);
}
public function display_messages()
{
foreach ($this->messages as $name => $messages) {
foreach ($messages as $message) {
return '' . $message['message'] . '
';
}
}
}
}
includes/index.php 0000644 00000000032 14757772277 0010216 0 ustar 00 version = '0.5.2';
$this->plugin_name = 'protect-uploads';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
}
private function load_dependencies()
{
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-protect-uploads-loader.php';
require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-protect-uploads-i18n.php';
require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-protect-uploads-admin.php';
$this->loader = new Alti_ProtectUploads_Loader();
}
/**
* set locale for translation ends.
*/
private function set_locale()
{
$plugin_i18n = new Alti_ProtectUploads_i18n();
$plugin_i18n->set_domain($this->get_plugin_name());
$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
}
/**
* action and filter for admin side
*/
private function define_admin_hooks()
{
$plugin_admin = new Alti_ProtectUploads_Admin($this->get_plugin_name(), $this->get_version());
$this->loader->add_action('admin_menu', $plugin_admin, 'add_submenu_page');
$this->loader->add_action('admin_init', $plugin_admin, 'verify_settings_page');
$this->loader->add_filter('plugin_action_links_' . $this->get_plugin_name() . '/' . $this->get_plugin_name() . '.php', $plugin_admin, 'add_settings_link');
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
}
public function run()
{
$this->loader->run();
}
public function get_plugin_name()
{
return $this->plugin_name;
}
public function get_loader()
{
return $this->loader;
}
public function get_version()
{
return $this->version;
}
}
includes/class-protect-uploads-loader.php 0000644 00000010522 14757772277 0014610 0 ustar 00 actions = array();
$this->filters = array();
}
/**
* Add a new action to the collection to be registered with WordPress.
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int Optional $priority The priority at which the function should be fired.
* @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int Optional $priority The priority at which the function should be fired.
* @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int Optional $priority The priority at which the function should be fired.
* @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
* @return type The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args
);
return $hooks;
}
/**
* Register the filters and actions with WordPress.
*/
public function run() {
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}
includes/class-protect-uploads-i18n.php 0000644 00000001254 14757772277 0014123 0 ustar 00 domain,
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}
/**
* Set the domain equal to that of the specified domain.
* @param string $domain The domain that represents the locale of this plugin.
*/
public function set_domain( $domain ) {
$this->domain = $domain;
}
}
includes/class-protect-uploads-deactivator.php 0000644 00000000471 14757772277 0015651 0 ustar 00 plugin_name, $this->version);
$plugin->remove_index();
$plugin->remove_htaccess();
delete_option( $this->get_plugin_name().'-protection' );
}
} includes/class-protect-uploads-activator.php 0000644 00000000160 14757772277 0015333 0 ustar 00 \n"
"Language-Team: Marko97 \n"
"Language: it_IT\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.7.7\n"
"X-Poedit-Basepath: ../\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-KeywordsList: _;__;_e\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: .\n"
#: admin/class-protect-uploads-admin.php:56
msgid "Settings"
msgstr "Impostazioni"
#: admin/class-protect-uploads-admin.php:122
msgid "Impossible to create or modified the index.php file in "
msgstr "Impossibile creare o modificare il file index.php in"
#: admin/class-protect-uploads-admin.php:136
msgid ""
"The index.php file has been created in main folder and subfolders (two "
"levels max)."
msgstr ""
"Il file index.php è stato creato nella cartella principale e nelle sotto "
"cartelle (massimo 2 livelli)"
#: admin/class-protect-uploads-admin.php:170
msgid "Impossible to create or modified the htaccess file."
msgstr "Impossibile creare o modificare il file .htaccess"
#: admin/class-protect-uploads-admin.php:179
msgid "The htaccess file has been created."
msgstr "Il file .htaccess è stato creato"
#: admin/class-protect-uploads-admin.php:191
msgid "Existing htaccess has been updated."
msgstr "Il file .htaccess è stato aggiornato"
#: admin/class-protect-uploads-admin.php:221
msgid "The index.php file(s) have(has) been deleted."
msgstr ""
"Il file index.php è stato eliminato / I file index.php sono stati eliminati"
#: admin/class-protect-uploads-admin.php:250
msgid "The htaccess file has been updated."
msgstr "Il file .htacess è stato aggiornato"
#: admin/class-protect-uploads-admin.php:294
msgid ""
"The Protect Uploads plugin cannot work without Apache. Yourself or your web "
"host has to activate this module."
msgstr ""
"Il plugin Protect Uploads non può funzionare senza Apache. Verifica il tuo "
"webserver e attiva questo modulo."
#: admin/views/includes/protect-uploads-admin-message.php:7
msgid "Error code"
msgstr "Codice errore"
#: admin/views/includes/protect-uploads-admin-message.php:7
msgid "Go to Protect Uploads documentation"
msgstr "Documentazione di Protect Uploads (in inglese)"
#: admin/views/protect-uploads-admin-settings-page.php:9
msgid "by"
msgstr "da"
#: admin/views/protect-uploads-admin-settings-page.php:10
msgid ""
"Prevent users to browse your uploads directory. You'll protect your uploads "
"directory to be accessed and content stolen too easily in one batch."
msgstr ""
"Inibisci la possibilità agli utenti di navigare nella directory upload. "
"Questo consente di proteggerti da eventuali furti e impedire l'esecuzione di "
"batch a questo scopo."
#: admin/views/protect-uploads-admin-settings-page.php:17
msgid "Status"
msgstr "Stato"
#: admin/views/protect-uploads-admin-settings-page.php:22
msgid "Uploads directory is protected."
msgstr "La directory upload è protetta"
#: admin/views/protect-uploads-admin-settings-page.php:24
msgid ""
"Your uploads directory is already protected by an htaccess "
"file or an Apache setting set for the whole website. You don't need extra "
"protection.
The «remove option» behind will have no effect on the current "
"protection."
msgstr ""
"La directory upload è già protetta da un file .htaccess o "
"una configurazione Apache. Non necessiti di ulteriore protezione."
"
L'opzione «rimuovi opzione» non avrà effetto sulla protezione attuale."
#: admin/views/protect-uploads-admin-settings-page.php:27
msgid "Uploads directory is not protected!"
msgstr "La directory upload non è protetta!"
#: admin/views/protect-uploads-admin-settings-page.php:34
#: admin/views/protect-uploads-admin-settings-page.php:39
msgid "Protection"
msgstr "Protezione"
#: admin/views/protect-uploads-admin-settings-page.php:44
msgid "add index file"
msgstr "Aggiungi file index"
#: admin/views/protect-uploads-admin-settings-page.php:45
msgid ""
"This will create an index.php file on the root of your uploads directory. "
"This simple trick will hide the content of your whole uploads directory."
msgstr ""
"Questa operazione creerà un file index.php vuoto nella directory upload. "
"Questo è un semplice trucchetto per nascondere il contenuto nella directory."
#: admin/views/protect-uploads-admin-settings-page.php:50
msgid "prevent directory listing with htaccess"
msgstr "Inserisci protezione tramite .htaccess"
#: admin/views/protect-uploads-admin-settings-page.php:51
msgid ""
"Through the htaccess file, it will prevent people to browse your uploads "
"directory and return a 403 code (Forbidden Access)."
msgstr ""
"Tramite il file .htaccess, questo bloccherà l'accesso alle risorse presenti "
"nella directory mostrando il codice errore 403 (accesso negato)."
#: admin/views/protect-uploads-admin-settings-page.php:56
msgid "remove protection or disabled protection"
msgstr "Disattiva protezione"
#: admin/views/protect-uploads-admin-settings-page.php:57
msgid "Your uploads directory is not protected."
msgstr ""
"Questa operazione disabiliterà la protezione. Eventuali altre protezioni non "
"verranno disabilitate."
#: admin/views/protect-uploads-admin-settings-page.php:65
msgid "Check"
msgstr "Verifica"
#: admin/views/protect-uploads-admin-settings-page.php:68
msgid "Visit your"
msgstr "Visita"
#: admin/views/protect-uploads-admin-settings-page.php:68
msgid "uploads directory"
msgstr "la directory upload"
#: admin/views/protect-uploads-admin-settings-page.php:68
msgid "to check the current protection"
msgstr "per verificare la protezione attuale"
#: admin/views/protect-uploads-admin-settings-page.php:73
msgid "Support"
msgstr "Supporto"
#: admin/views/protect-uploads-admin-settings-page.php:76
msgid ""
"Protect Uploads Plugin support page."
msgstr ""
"Vedi la nostra pagina di supporto del plugin. (in inglese)"
#: admin/views/protect-uploads-admin-settings-page.php:77
msgid ""
"This plugin is compatible with the Watermark Plugin."
msgstr ""
"Questo plugin è compatibile con "
"span> Watermark Plugin."
#: admin/views/protect-uploads-admin-settings-page.php:78
msgid ""
"To do so, you have to: 1. Install the Watermark Plugin 2. Then choose your "
"settings in this page and Update."
msgstr " "
#: admin/views/protect-uploads-admin-settings-page.php:85
msgid "Update"
msgstr "Salva le modifiche"
#: admin/views/protect-uploads-admin-settings-page.php:94
msgid "Protect Uploads plugin is developped by"
msgstr "Questo plugin è stato sviluppato da"
languages/protect-uploads-it_IT.mo 0000644 00000011615 14757772277 0013237 0 ustar 00 # 4 L L M
S # ^ # 3 7 r '
> I R Y m a # # S - k L | l \ #
( 9 H ' K ( s
% . 1 7 4 i J
$
m ! $ f L ; 9 _ a $ t d &