Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove folder permissions notices #833

Merged
merged 33 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e9d99f8
Remove folder permissions notices
Jul 16, 2015
2b8de2b
Merge branch 'master' into remove-whoami
Jul 31, 2015
17f238f
Make notices dismissable
Jul 31, 2015
d4835f6
Display a form to get users connection credentials
Jul 31, 2015
428a939
Fix code formatting
Jul 31, 2015
fd95e12
Extract list of possible paths to own method
Jul 31, 2015
7e01802
Add a function comment
Jul 31, 2015
6092f59
Force FTP form
Sep 4, 2015
4982cb4
Merge remote-tracking branch 'origin/master' into remove-whoami
Oct 3, 2015
cdfe2e4
Show notice and hide backups list
Oct 3, 2015
5b174ac
Merge branch 'master' into remove-whoami
Oct 3, 2015
237aa4b
Merge branch 'master' into remove-whoami
willmot Mar 2, 2016
1d5a525
Refactor the request_credentials code so it actually works
willmot Mar 4, 2016
0915923
WPCS fixes
willmot Mar 4, 2016
0e0c946
Merge branch 'master' into remove-whoami
willmot Mar 6, 2016
b9173ef
Improved error messaging
willmot Mar 9, 2016
3267c87
s/sites/site's when used in a singulat possesive context
willmot Mar 10, 2016
7503fdb
Merge branch 'master' into remove-whoami
willmot Mar 18, 2016
611b878
Ensure Path is readable before calling `disk_free_space`
willmot Mar 18, 2016
1894726
Merge branch 'master' into remove-whoami
dashaluna Jun 15, 2016
1f4395a
Clean up - combine conditions in if statements for better readability…
dashaluna Jun 15, 2016
5231211
Merge branch 'master' into remove-whoami
dashaluna Jun 16, 2016
45492c0
Use whitelist_html for translated strings to allow some HTML
dashaluna Jun 16, 2016
cd957da
Clean up translatin strings - remove allowed HTML per string and add …
dashaluna Jun 17, 2016
6b507f8
Merge branch 'master' into remove-whoami
dashaluna Jul 27, 2016
00e6788
Merge branch 'master' into remove-whoami
willmot Aug 29, 2016
3f81248
Improve the ability to automatically create the backups directory
willmot Aug 29, 2016
badc2e4
Avoid a Warning when the backup path isn't readable
willmot Aug 29, 2016
7b9be93
Correct the order of error messages when both a custom path and the d…
willmot Aug 29, 2016
32f6791
Minor - simplify 'if' statements. Fix coding standards - full stop af…
dashaluna Sep 1, 2016
148377c
Merge branch 'master' into remove-whoami
dashaluna Sep 1, 2016
4d9791b
Merge branch 'master' into remove-whoami
sambulance Nov 22, 2016
a02d722
Check for correct server permission, else show site credentials form
sambulance Nov 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions admin/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,52 @@ function request_delete_schedule() {
}
add_action( 'admin_post_hmbkp_request_delete_schedule', 'HM\BackUpWordPress\request_delete_schedule' );

add_action( 'admin_post_hmbkp_request_credentials', function() {

global $wp_filesystem;

ob_start();
$creds = request_filesystem_credentials( '' );
ob_end_clean();

// Default to showing an error if we're not able to connect.
$url = add_query_arg( 'connection_error', 1, get_settings_url() );

/**
* If we have valid filesystem credentials then let's attempt
* to use them to create the backups directory. If we can't create it in
* WP_CONTENT_DIR then we fallback to trying in uploads.
*/
if ( WP_Filesystem( $creds ) ) {

// If we're able to connect then no need to redirect with an error.
$url = get_settings_url();

// If the backup path exists then let's just try to chmod it to the correct permissions.
if (
is_dir( Path::get_instance()->get_default_path() ) &&
! $wp_filesystem->chmod( Path::get_instance()->get_default_path(), FS_CHMOD_DIR )
) {
$url = add_query_arg( 'creation_error', 1, get_settings_url() );
} else {

// If the path doesn't exist then try to correct the permission for the parent directory and create it.
$wp_filesystem->chmod( dirname( Path::get_instance()->get_default_path() ), FS_CHMOD_DIR );

if (
! $wp_filesystem->mkdir( Path::get_instance()->get_default_path(), FS_CHMOD_DIR ) &&
! $wp_filesystem->mkdir( Path::get_instance()->get_fallback_path(), FS_CHMOD_DIR )
) {
$url = add_query_arg( 'creation_error', 1, get_settings_url() );
}
}
}

wp_safe_redirect( $url , 303 );
die;

} );

/**
* Perform a manual backup
*
Expand Down
8 changes: 8 additions & 0 deletions admin/filesystem-credentials.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$_POST['action'] = 'hmbkp_request_credentials';
$extra_fields = array( 'action' );

if ( ! isset( $_GET['creation_error'] ) ) {
request_filesystem_credentials( admin_url( 'admin-post.php' ), '', isset( $_GET['connection_error'] ), false, $extra_fields );
}
14 changes: 11 additions & 3 deletions admin/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@

</h1>

<?php include_once( HMBKP_PLUGIN_PATH . 'admin/backups.php' ); ?>
<?php if ( has_server_permissions() ) : ?>

<p class="howto"><?php printf( __( 'If you\'re finding BackUpWordPress useful, please %1$s rate it on the plugin directory%2$s.', 'backupwordpress' ), '<a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/backupwordpress">', '</a>' ); ?></p>
<?php include_once( HMBKP_PLUGIN_PATH . 'admin/backups.php' ); ?>

<?php include_once( HMBKP_PLUGIN_PATH . 'admin/upsell.php' ); ?>
<p class="howto"><?php printf( __( 'If you\'re finding BackUpWordPress useful, please %1$s rate it on the plugin directory%2$s.', 'backupwordpress' ), '<a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/backupwordpress">', '</a>' ); ?></p>

<?php include_once( HMBKP_PLUGIN_PATH . 'admin/upsell.php' ); ?>

<?php else : ?>

<?php include_once( HMBKP_PLUGIN_PATH . 'admin/filesystem-credentials.php' ); ?>

<?php endif; ?>

</div>
32 changes: 24 additions & 8 deletions classes/class-path.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ public function get_existing_path() {
*/
public function calculate_path() {

$paths = $this->get_possible_paths();

// Loop through possible paths, use the first one that exists/can be created and is writable.
foreach ( $paths as $path ) {
// Also handles fixing perms / directory already exists.
if ( wp_mkdir_p( $path ) && wp_is_writable( $path ) ) {
break;
}
}

/**
* If we managed to create a writable path then use that,
* otherwise just return the unwritable path.
*/
if ( file_exists( $path ) && wp_is_writable( $path ) ) {
$this->path = $path;
} else {
$this->path = reset( $paths );
}
}

public function get_possible_paths() {

$paths = array();

// If we have a custom path then try to use it.
Expand All @@ -293,13 +316,7 @@ public function calculate_path() {
// If that didn't work then fallback to a new directory in uploads.
$paths[] = $this->get_fallback_path();

// Loop through possible paths, use the first one that exists/can be created and is writable.
foreach ( $paths as $path ) {
if ( wp_mkdir_p( $path ) && file_exists( $path ) && wp_is_writable( $path ) ) { // Also handles fixing perms / directory already exists.
$this->path = $path;
break;
}
}
return $paths;
}

/**
Expand Down Expand Up @@ -410,7 +427,6 @@ public function move_old_backups( $from ) {
if ( false !== strpos( $from, WP_CONTENT_DIR ) && Path::get_path() !== $from ) {
rmdirtree( $from );
}

}

/**
Expand Down
5 changes: 4 additions & 1 deletion classes/class-requirement.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ class Requirement_Backup_Path_Permissions extends Requirement {
* @return string
*/
public static function test() {
return substr( sprintf( '%o', fileperms( Path::get_path() ) ), - 4 );
if ( is_readable( PATH::get_path() ) ) {
return substr( sprintf( '%o', fileperms( Path::get_path() ) ), - 4 );
}
return 'Unreadable';
}
}
Requirements::register( 'HM\BackUpWordPress\Requirement_Backup_Path_Permissions', 'Site' );
Expand Down
2 changes: 1 addition & 1 deletion classes/class-site-size.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Site Size class
*
* Use to calculate the total or partial size of the sites database and files.
* Use to calculate the total or partial size of the site's database and files.
*/
class Site_Size {

Expand Down
23 changes: 19 additions & 4 deletions functions/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,24 +393,39 @@ function rmdirtree( $dir ) {
@rmdir( $dir );

return true;

}

/**
* Check if a backup is possible with regards to file
* permissions etc.
* Check if we have read and write permission on the server
*
* @return bool
*/
function is_backup_possible() {
function has_server_permissions() {

if ( ! wp_is_writable( Path::get_path() ) || ! is_dir( Path::get_path() ) ) {
if ( ! wp_is_writable( Path::get_path() ) ) {
return false;
}

if ( ! is_readable( Path::get_root() ) ) {
return false;
}

return true;
}

/**
* Check if a backup is possible with regards to file
* permissions etc.
*
* @return bool
*/
function is_backup_possible() {

if ( ! has_server_permissions() || ! is_dir( Path::get_path() ) ) {
return false;
}

if ( ! Requirement_Mysqldump_Command_Path::test() && ! Requirement_PDO::test() ) {
return false;
}
Expand Down
Loading