Ejemplo n.º 1
0
 /**
  * Get the current instance
  *
  * @access public
  * @static
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new HMBKP_Services();
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
                    $error_message = ' - ' . $error_message;
                }
                $subject = sprintf(__('Backup of %s Failed', 'hmbkp'), $domain);
                $message = sprintf(__('BackUpWordPress was unable to backup your site %1$s.', 'hmbkp') . "\n\n" . __('Here are the errors that we\'re encountered:', 'hmbkp') . "\n\n" . '%2$s' . "\n\n" . __('If the errors above look like Martian, forward this email to %3$s and we\'ll take a look', 'hmbkp') . "\n\n" . __("Kind Regards,\nThe Apologetic BackUpWordPress Backup Emailing Robot", 'hmbkp'), home_url(), $error_message, '*****@*****.**');
                wp_mail($this->get_email_address_array(), $subject, $message, $headers);
                return;
            }
            $subject = sprintf(__('Backup of %s', 'hmbkp'), $domain);
            // If it's larger than the max attachment size limit assume it's not going to be able to send the backup
            if (@filesize($file) < hmbkp_get_max_attachment_size()) {
                $message = sprintf(__('BackUpWordPress has completed a backup of your site %1$s.', 'hmbkp') . "\n\n" . __('The backup file should be attached to this email.', 'hmbkp') . "\n\n" . __('You can download the backup file by clicking the link below:', 'hmbkp') . "\n\n" . '%2$s' . "\n\n" . __("Kind Regards,\nThe Happy BackUpWordPress Backup Emailing Robot", 'hmbkp'), home_url(), $download);
                $sent = wp_mail($this->get_email_address_array(), $subject, $message, $headers, $file);
            }
            // If we didn't send the email above then send just the notification
            if (!$sent) {
                $message = sprintf(__('BackUpWordPress has completed a backup of your site %1$s.', 'hmbkp') . "\n\n" . __('Unfortunately the backup file was too large to attach to this email.', 'hmbkp') . "\n\n" . __('You can download the backup file by clicking the link below:', 'hmbkp') . "\n\n" . '%2$s' . "\n\n" . __("Kind Regards,\nThe Happy BackUpWordPress Backup Emailing Robot", 'hmbkp'), home_url(), $download);
                wp_mail($this->get_email_address_array(), $subject, $message, $headers);
            }
        }
    }
    public static function intercom_data()
    {
        return array();
    }
    public static function intercom_data_html()
    {
    }
}
// Register the service
HMBKP_Services::register(__FILE__, 'HMBKP_Email_Service');
Ejemplo n.º 3
0
?>

						<?php 
if ($schedule->is_site_size_cached()) {
    printf(__('This schedule will store a maximum of %s of backups.', 'backupwordpress'), '<code>' . size_format($schedule->get_site_size() * $schedule->get_max_backups()) . '</code>');
}
?>

					</p>

				</td>

			</tr>

			<?php 
foreach (HMBKP_Services::get_services($schedule) as $service) {
    $service->field();
}
?>

		</tbody>

	</table>

	<p class="submit">
		<button type="submit" class="button-primary"><?php 
_e('Done', 'backupwordpress');
?>
</button>
	</p>
Ejemplo n.º 4
0
if (defined('HMBKP_SCHEDULE_TIME') && HMBKP_SCHEDULE_TIME !== '11pm') {
    ?>
					<p><?php 
    printf(__('You\'ve set it to: %s', 'hmbkp'), '<code>' . HMBKP_SCHEDULE_TIME . '</code>');
    ?>
</p>
				<?php 
}
?>

				<p><?php 
printf(__('The time that your schedules should run. Defaults to %s.', 'hmbkp'), '<code>23:00</code>');
?>
 <?php 
_e('e.g.', 'hmbkp');
?>
 <code>define( 'HMBKP_SCHEDULE_TIME', '07:30' );</code></p>

			</td>

		</tr>

		<?php 
foreach (HMBKP_Services::get_services() as $file => $service) {
    echo wp_kses_post(call_user_func(array($service, 'constant')));
}
?>

	</table>

</div>
Ejemplo n.º 5
0
 /**
  * Hook into the actions fired in HM Backup and set the status
  *
  * @param $action
  */
 protected function do_action($action)
 {
     // Pass the actions to all the services
     foreach (HMBKP_Services::get_services($this) as $service) {
         $service->action($action);
     }
     // Fire the parent function as well
     parent::do_action($action);
     switch ($action) {
         case 'hmbkp_mysqldump_started':
             $this->set_status(sprintf(__('Dumping Database %s', 'backupwordpress'), '(<code>' . $this->get_mysqldump_method() . '</code>)'));
             break;
         case 'hmbkp_mysqldump_verify_started':
             $this->set_status(sprintf(__('Verifying Database Dump %s', 'backupwordpress'), '(<code>' . $this->get_mysqldump_method() . '</code>)'));
             break;
         case 'hmbkp_archive_started':
             $this->set_status(sprintf(__('Creating zip archive %s', 'backupwordpress'), '(<code>' . $this->get_archive_method() . '</code>)'));
             break;
         case 'hmbkp_archive_verify_started':
             $this->set_status(sprintf(__('Verifying Zip Archive %s', 'backupwordpress'), '(<code>' . $this->get_archive_method() . '</code>)'));
             break;
         case 'hmbkp_backup_complete':
             $this->set_status(__('Finishing Backup', 'backupwordpress'));
             $this->update_average_schedule_run_time($this->get_schedule_running_start_time(), time());
             break;
         case 'hmbkp_error':
             if ($this->get_errors()) {
                 $file = $this->get_path() . '/.backup_errors';
                 if (file_exists($file)) {
                     @unlink($file);
                 }
                 if (!($handle = @fopen($file, 'w'))) {
                     return;
                 }
                 fwrite($handle, json_encode($this->get_errors()));
                 fclose($handle);
             }
             break;
         case 'hmbkp_warning':
             if ($this->get_warnings()) {
                 $file = $this->get_path() . '/.backup_warnings';
                 if (file_exists($file)) {
                     @unlink($file);
                 }
                 if (!($handle = @fopen($file, 'w'))) {
                     return;
                 }
                 fwrite($handle, json_encode($this->get_warnings()));
                 fclose($handle);
             }
             break;
     }
     do_action('hmbkp_action_complete', $action, $this);
 }
Ejemplo n.º 6
0
/**
 * Catch the schedule settings form submission
 *
 * Validate and either return errors or update the schedule
 */
function hmbkp_edit_schedule_submit()
{
    check_admin_referer('hmbkp-edit-schedule', 'hmbkp-edit-schedule-nonce');
    if (empty($_POST['hmbkp_schedule_id'])) {
        die;
    }
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_POST['hmbkp_schedule_id']));
    hmbkp_clear_settings_errors();
    $errors = array();
    $settings = array();
    if (isset($_POST['hmbkp_schedule_type'])) {
        $schedule_type = sanitize_text_field($_POST['hmbkp_schedule_type']);
        if (!trim($schedule_type)) {
            $errors['hmbkp_schedule_type'] = __('Backup type cannot be empty', 'backupwordpress');
        } elseif (!in_array($schedule_type, array('complete', 'file', 'database'))) {
            $errors['hmbkp_schedule_type'] = __('Invalid backup type', 'backupwordpress');
        } else {
            $settings['type'] = $schedule_type;
        }
    }
    if (isset($_POST['hmbkp_schedule_recurrence']['hmbkp_type'])) {
        $schedule_recurrence_type = sanitize_text_field($_POST['hmbkp_schedule_recurrence']['hmbkp_type']);
        if (empty($schedule_recurrence_type)) {
            $errors['hmbkp_schedule_recurrence']['hmbkp_type'] = __('Schedule cannot be empty', 'backupwordpress');
        } elseif (!in_array($schedule_recurrence_type, array_keys(hmbkp_get_cron_schedules())) && 'manually' !== $schedule_recurrence_type) {
            $errors['hmbkp_schedule_recurrence']['hmbkp_type'] = __('Invalid schedule', 'backupwordpress');
        } else {
            $settings['recurrence'] = $schedule_recurrence_type;
        }
    }
    if (isset($_POST['hmbkp_schedule_recurrence']['hmbkp_schedule_start_day_of_week'])) {
        $day_of_week = sanitize_text_field($_POST['hmbkp_schedule_recurrence']['hmbkp_schedule_start_day_of_week']);
        if (!in_array($day_of_week, array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'))) {
            $errors['hmbkp_schedule_start_day_of_week'] = __('Day of the week must be a valid lowercase day name', 'backupwordpress');
        } else {
            $settings['start_time']['day_of_week'] = $day_of_week;
        }
    }
    if (isset($_POST['hmbkp_schedule_recurrence']['hmbkp_schedule_start_day_of_month'])) {
        $day_of_month = absint($_POST['hmbkp_schedule_recurrence']['hmbkp_schedule_start_day_of_month']);
        $options = array('min_range' => 1, 'max_range' => 31);
        if (false === filter_var($day_of_month, FILTER_VALIDATE_INT, array('options' => $options))) {
            $errors['hmbkp_schedule_start_day_of_month'] = __('Day of month must be between 1 and 31', 'backupwordpress');
        } else {
            $settings['start_time']['day_of_month'] = $day_of_month;
        }
    }
    if (isset($_POST['hmbkp_schedule_recurrence']['hmbkp_schedule_start_hours'])) {
        $hours = absint($_POST['hmbkp_schedule_recurrence']['hmbkp_schedule_start_hours']);
        $options = array('min_range' => 0, 'max_range' => 23);
        if (false === filter_var($hours, FILTER_VALIDATE_INT, array('options' => $options))) {
            $errors['hmbkp_schedule_start_hours'] = __('Hours must be between 0 and 23', 'backupwordpress');
        } else {
            $settings['start_time']['hours'] = $hours;
        }
    }
    if (isset($_POST['hmbkp_schedule_recurrence']['hmbkp_schedule_start_minutes'])) {
        $minutes = absint($_POST['hmbkp_schedule_recurrence']['hmbkp_schedule_start_minutes']);
        $options = array('min_range' => 0, 'max_range' => 59);
        if (false === filter_var($minutes, FILTER_VALIDATE_INT, array('options' => $options))) {
            $errors['hmbkp_schedule_start_minutes'] = __('Minutes must be between 0 and 59', 'backupwordpress');
        } else {
            $settings['start_time']['minutes'] = $minutes;
        }
    }
    if (isset($_POST['hmbkp_schedule_max_backups'])) {
        $max_backups = sanitize_text_field($_POST['hmbkp_schedule_max_backups']);
        if (empty($max_backups)) {
            $errors['hmbkp_schedule_max_backups'] = __('Max backups can\'t be empty', 'backupwordpress');
        } elseif (!is_numeric($max_backups)) {
            $errors['hmbkp_schedule_max_backups'] = __('Max backups must be a number', 'backupwordpress');
        } elseif (!($max_backups >= 1)) {
            $errors['hmbkp_schedule_max_backups'] = __('Max backups must be greater than 0', 'backupwordpress');
        } else {
            $settings['max_backups'] = absint($max_backups);
        }
    }
    // Save the service options
    foreach (HMBKP_Services::get_services($schedule) as $service) {
        $errors = array_merge($errors, $service->save());
    }
    if (!empty($settings['recurrence']) && !empty($settings['start_time'])) {
        // Calculate the start time depending on the recurrence
        $start_time = hmbkp_determine_start_time($settings['recurrence'], $settings['start_time']);
        if ($start_time) {
            $schedule->set_schedule_start_time($start_time);
        }
    }
    if (!empty($settings['recurrence'])) {
        $schedule->set_reoccurrence($settings['recurrence']);
    }
    if (!empty($settings['type'])) {
        $schedule->set_type($settings['type']);
    }
    if (!empty($settings['max_backups'])) {
        $schedule->set_max_backups($settings['max_backups']);
    }
    // Save the new settings
    $schedule->save();
    // Remove any old backups in-case max backups was reduced
    $schedule->delete_old_backups();
    if ($errors) {
        foreach ($errors as $error) {
            hmbkp_add_settings_error($error);
        }
    }
    $redirect = remove_query_arg(array('hmbkp_panel', 'action'), wp_get_referer());
    if ($errors) {
        $redirect = wp_get_referer();
    }
    wp_safe_redirect($redirect, '303');
    die;
}
Ejemplo n.º 7
0
/**
 * Load Intercom and send across user information and server info
 *
 * Only loaded if the user has opted in.
 *
 * @return void
 */
function hmbkp_load_intercom_script()
{
    if (!get_option('hmbkp_enable_support')) {
        return;
    }
    require_once HMBKP_PLUGIN_PATH . 'classes/class-requirements.php';
    foreach (HMBKP_Requirements::get_requirement_groups() as $group) {
        foreach (HMBKP_Requirements::get_requirements($group) as $requirement) {
            $info[$requirement->name()] = $requirement->result();
        }
    }
    foreach (HMBKP_Services::get_services() as $file => $service) {
        array_merge($info, call_user_func(array($service, 'intercom_data')));
    }
    $current_user = wp_get_current_user();
    $info['user_hash'] = hash_hmac("sha256", $current_user->user_email, "fcUEt7Vi4ym5PXdcr2UNpGdgZTEvxX9NJl8YBTxK");
    $info['email'] = $current_user->user_email;
    $info['created_at'] = strtotime($current_user->user_registered);
    $info['app_id'] = "7f1l4qyq";
    $info['name'] = $current_user->display_name;
    $info['widget'] = array('activator' => '#intercom');
    ?>

	<script id="IntercomSettingsScriptTag">
		window.intercomSettings = <?php 
    echo json_encode($info);
    ?>
;
	</script>
	<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://static.intercomcdn.com/intercom.v1.js';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}};})()</script>

<?php 
}
Ejemplo n.º 8
0
/**
 * Catch the edit schedule form
 *
 * Validate and either return errors or update the schedule
 */
function hmnkp_edit_schedule_submit()
{
    if (empty($_GET['hmbkp_schedule_id'])) {
        die;
    }
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id']));
    $errors = array();
    if (isset($_GET['hmbkp_schedule_type'])) {
        $schedule_type = sanitize_text_field($_GET['hmbkp_schedule_type']);
        if (!trim($schedule_type)) {
            $errors['hmbkp_schedule_type'] = __('Backup type cannot be empty', 'hmbkp');
        } elseif (!in_array($schedule_type, array('complete', 'file', 'database'))) {
            $errors['hmbkp_schedule_type'] = __('Invalid backup type', 'hmbkp');
        } else {
            $schedule->set_type($schedule_type);
        }
    }
    if (isset($_GET['hmbkp_schedule_reoccurrence'])) {
        $schedule_reoccurrence = sanitize_text_field($_GET['hmbkp_schedule_reoccurrence']);
        if (empty($schedule_reoccurrence)) {
            $errors['hmbkp_schedule_reoccurrence'] = __('Schedule cannot be empty', 'hmbkp');
        } elseif (!in_array($schedule_reoccurrence, array_keys($schedule->get_cron_schedules())) && $schedule_reoccurrence !== 'manually') {
            $errors['hmbkp_schedule_reoccurrence'] = __('Invalid schedule', 'hmbkp');
        } else {
            $schedule->set_reoccurrence($schedule_reoccurrence);
        }
    }
    if (isset($_GET['hmbkp_schedule_max_backups'])) {
        $schedule_max_backups = sanitize_text_field($_GET['hmbkp_schedule_max_backups']);
        if (empty($schedule_max_backups)) {
            $errors['hmbkp_schedule_max_backups'] = __('Max backups can\'t be empty', 'hmbkp');
        } elseif (!is_numeric($schedule_max_backups)) {
            $errors['hmbkp_schedule_max_backups'] = __('Max backups must be a number', 'hmbkp');
        } elseif (!($schedule_max_backups >= 1)) {
            $errors['hmbkp_schedule_max_backups'] = __('Max backups must be greater than 0', 'hmbkp');
        } else {
            $schedule->set_max_backups((int) $schedule_max_backups);
        }
        // Remove any old backups in-case max backups was reduced
        $schedule->delete_old_backups();
    }
    // Save the service options
    foreach (HMBKP_Services::get_services($schedule) as $service) {
        $errors = array_merge($errors, $service->save());
    }
    $schedule->save();
    if ($errors) {
        echo json_encode($errors);
    }
    die;
}
     * Not in use
     * $return null
     */
    public function update(&$new_data, $old_data)
    {
    }
    /**
     * Used to determine if the service is in use or not
     */
    public function is_service_active()
    {
        return strlen($this->get_url()) > 0;
    }
    /**
     * @return string
     */
    protected function get_url()
    {
        return defined('WPRP_PLUGIN_SLUG') && get_option('wpr_api_key') ? $this->wpremote_webhook_url : false;
    }
    /**
     * @return string
     */
    protected function get_secret_key()
    {
        return get_option('wpr_api_key');
    }
}
// Register the service
HMBKP_Services::register(__FILE__, 'HMBKP_Webhook_WPRemote_Service');
Ejemplo n.º 10
0
    /**
     * Load Intercom and send across user information and server info. Only loaded if the user has opted in.
     *
     * @param $hook
     */
    public function load_intercom_script()
    {
        if (!get_option('hmbkp_enable_support')) {
            return;
        }
        foreach (HMBKP_Requirements::get_requirement_groups() as $group) {
            foreach (HMBKP_Requirements::get_requirements($group) as $requirement) {
                $info[$requirement->name()] = $requirement->result();
            }
        }
        foreach (HMBKP_Services::get_services() as $file => $service) {
            array_merge($info, call_user_func(array($service, 'intercom_data')));
        }
        $current_user = wp_get_current_user();
        $info['user_hash'] = hash_hmac('sha256', $current_user->user_email, 'fcUEt7Vi4ym5PXdcr2UNpGdgZTEvxX9NJl8YBTxK');
        $info['email'] = $current_user->user_email;
        $info['created_at'] = strtotime($current_user->user_registered);
        $info['app_id'] = '7f1l4qyq';
        $info['name'] = $current_user->display_name;
        $info['widget'] = array('activator' => '#intercom');
        ?>

		<script id="IntercomSettingsScriptTag">
			window.intercomSettings = <?php 
        echo json_encode($info);
        ?>
;
		</script>
		<script>!function(){function e(){var a=c.createElement("script");a.type="text/javascript",a.async=!0,a.src="https://static.intercomcdn.com/intercom.v1.js";var b=c.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)}var a=window,b=a.Intercom;if("function"==typeof b)b("reattach_activator"),b("update",intercomSettings);else{var c=document,d=function(){d.c(arguments)};d.q=[],d.c=function(a){d.q.push(a)},a.Intercom=d,a.attachEvent?a.attachEvent("onload",e):a.addEventListener("load",e,!1)}}();</script>

	<?php 
    }