Repository navigation
Expand file tree
/
Copy pathwp-ssh.php
More file actions
96 lines (75 loc) · 2.96 KB
/
Copy pathwp-ssh.php
File metadata and controls
96 lines (75 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Plugin Name: WP SSH (Remote Bridge)
* Description: A private, self-hosted remote management bridge for this site. Lets you (or a trusted assistant) manage options, content, media, plugins and theme files over an authenticated HTTPS endpoint instead of raw SSH. Not intended for public distribution — each install generates its own unique secret key and is scoped to safe, whitelisted actions only.
* Version: 1.3.0
* Author: MOHD SAMAR
* License: GPLv2 or later
* Text Domain: wp-ssh
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'WP_SSH_VERSION', '1.3.0' );
define( 'WP_SSH_DIR', plugin_dir_path( __FILE__ ) );
define( 'WP_SSH_OPTION', 'wp_ssh_settings' );
require_once WP_SSH_DIR . 'includes/class-wp-ssh-auth.php';
require_once WP_SSH_DIR . 'includes/class-wp-ssh-actions.php';
require_once WP_SSH_DIR . 'includes/class-wp-ssh-api.php';
require_once WP_SSH_DIR . 'includes/class-wp-ssh-admin.php';
/**
* Activation: generate a unique secret key for THIS install and set safe defaults.
* Nothing here is shared across sites — every activation gets its own random key.
*/
function wp_ssh_activate() {
$settings = get_option( WP_SSH_OPTION );
if ( ! is_array( $settings ) ) {
$settings = array();
}
if ( empty( $settings['secret_key'] ) ) {
$settings['secret_key'] = wp_ssh_generate_key();
}
if ( ! isset( $settings['enabled'] ) ) {
$settings['enabled'] = false; // Off by default. You must opt in from the admin screen.
}
if ( ! isset( $settings['allow_write_queries'] ) ) {
$settings['allow_write_queries'] = false;
}
if ( ! isset( $settings['allow_root_files'] ) ) {
$settings['allow_root_files'] = false; // Off by default — file actions stay scoped to wp-content unless explicitly enabled.
}
if ( ! isset( $settings['read_only_mode'] ) ) {
$settings['read_only_mode'] = false;
}
if ( ! isset( $settings['ip_allowlist'] ) ) {
$settings['ip_allowlist'] = '';
}
if ( ! isset( $settings['site_label'] ) ) {
$settings['site_label'] = '';
}
if ( ! isset( $settings['health_check_enabled'] ) ) {
$settings['health_check_enabled'] = false; // Off by default, opt in from the admin screen.
}
if ( ! isset( $settings['health_check_email'] ) ) {
$settings['health_check_email'] = '';
}
if ( ! isset( $settings['log'] ) ) {
$settings['log'] = array();
}
update_option( WP_SSH_OPTION, $settings );
if ( ! wp_next_scheduled( 'wp_ssh_health_check' ) ) {
wp_schedule_event( time(), 'hourly', 'wp_ssh_health_check' );
}
}
register_activation_hook( __FILE__, 'wp_ssh_activate' );
function wp_ssh_deactivate() {
wp_clear_scheduled_hook( 'wp_ssh_health_check' );
}
register_deactivation_hook( __FILE__, 'wp_ssh_deactivate' );
add_action( 'wp_ssh_health_check', array( 'WP_SSH_Actions', 'run_health_check' ) );
function wp_ssh_generate_key() {
return wp_generate_password( 64, false, false );
}
add_action( 'plugins_loaded', function () {
load_plugin_textdomain( 'wp-ssh', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
} );