Changeset 3841430
- Timestamp:
- 12/03/2026 01:27:43 AM (less than one hour ago)
- Location:
- clonemute
- Files:
-
- 8 added
- 14 edited
- 1 copied
-
tags/0.2.0 (copied) (copied from clonemute/trunk )
-
tags/0.2.0/clonemute.php (modified) (1 diff)
-
tags/0.2.0/languages/clonemute.pot (modified) (9 diffs)
-
tags/0.2.0/readme.txt (modified) (4 diffs)
-
tags/0.2.0/src/Admin/AdminActions.php (modified) (11 diffs)
-
tags/0.2.0/src/Admin/Messages.php (added)
-
tags/0.2.0/src/Admin/Notices.php (modified) (1 diff)
-
tags/0.2.0/src/Cli (added)
-
tags/0.2.0/src/Cli/Commands.php (added)
-
tags/0.2.0/src/Cli/Status.php (added)
-
tags/0.2.0/src/Env/EnvCapture.php (modified) (1 diff)
-
tags/0.2.0/src/Plugin.php (modified) (3 diffs)
-
trunk/clonemute.php (modified) (1 diff)
-
trunk/languages/clonemute.pot (modified) (9 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/src/Admin/AdminActions.php (modified) (11 diffs)
-
trunk/src/Admin/Messages.php (added)
-
trunk/src/Admin/Notices.php (modified) (1 diff)
-
trunk/src/Cli (added)
-
trunk/src/Cli/Commands.php (added)
-
trunk/src/Cli/Status.php (added)
-
trunk/src/Env/EnvCapture.php (modified) (1 diff)
-
trunk/src/Plugin.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
clonemute/tags/0.2.0/clonemute.php
r3828539 r3841430 4 4 * Plugin URI: https://wordpress.org/plugins/clonemute/ 5 5 * Description: Makes cloned WooCommerce sites safe: after you confirm a copy is a staging site, CloneMute blocks outgoing mail, payment gateways, scheduled tasks and known external services, and hides the site from search engines. 6 * Version: 0. 1.06 * Version: 0.2.0 7 7 * Requires at least: 7.0 8 8 * Requires PHP: 7.4 -
clonemute/tags/0.2.0/languages/clonemute.pot
r3828539 r3841430 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: CloneMute Staging Safety for WooCommerce 0. 1.0\n"5 "Project-Id-Version: CloneMute Staging Safety for WooCommerce 0.2.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/clonemute\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2026-1 1-26T01:23:54+00:00\n"12 "POT-Creation-Date: 2026-12-02T09:24:48+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.12.0\n" … … 40 40 msgstr "" 41 41 42 #: src/Admin/AdminActions.php:4 1042 #: src/Admin/AdminActions.php:464 43 43 msgid "CloneMute test mail" 44 44 msgstr "" 45 45 46 #: src/Admin/AdminActions.php:4 1146 #: src/Admin/AdminActions.php:465 47 47 msgid "If you can read this, mail is leaving this site. On a staging site that means the mail guard is not active." 48 48 msgstr "" … … 72 72 msgstr "" 73 73 74 #: src/Admin/ Notices.php:8874 #: src/Admin/Messages.php:23 75 75 msgid "Protection is on. This site is now treated as a staging site." 76 76 msgstr "" 77 77 78 #: src/Admin/ Notices.php:8978 #: src/Admin/Messages.php:24 79 79 msgid "Saved as a staging site, but CLONEMUTE_DISABLE_ALL in wp-config.php keeps every protection off. Remove that line to turn the protections on." 80 80 msgstr "" 81 81 82 #: src/Admin/ Notices.php:9082 #: src/Admin/Messages.php:25 83 83 msgid "The host name does not match. Nothing was changed." 84 84 msgstr "" 85 85 86 #: src/Admin/ Notices.php:9186 #: src/Admin/Messages.php:26 87 87 msgid "Protection cannot be enabled on this site (see the reasons below). Nothing was changed." 88 88 msgstr "" 89 89 90 #: src/Admin/ Notices.php:9290 #: src/Admin/Messages.php:27 91 91 msgid "Recorded as a production site. No protection is enabled." 92 92 msgstr "" 93 93 94 #: src/Admin/ Notices.php:9394 #: src/Admin/Messages.php:28 95 95 msgid "This site is protected as a staging site (or CLONEMUTE_ENV arms it). Remove the protection first if this really is the production site. Nothing was changed." 96 96 msgstr "" 97 97 98 #: src/Admin/ Notices.php:9498 #: src/Admin/Messages.php:29 99 99 msgid "The production confirmation of this site was removed. CloneMute treats it as unconfirmed again." 100 100 msgstr "" 101 101 102 #: src/Admin/Notices.php:95 102 #: src/Admin/Messages.php:30 103 msgid "This site has no production confirmation to remove. Nothing was changed." 104 msgstr "" 105 106 #: src/Admin/Messages.php:31 107 msgid "The address of this site cannot be read (its home URL has no host). Nothing was changed. With WP-CLI, pass --url=<site address>." 108 msgstr "" 109 110 #: src/Admin/Messages.php:32 103 111 msgid "OK, CloneMute will ask again the next time you log in." 104 112 msgstr "" 105 113 106 #: src/Admin/ Notices.php:96114 #: src/Admin/Messages.php:33 107 115 msgid "All protections were removed. Scheduled tasks that were paused will run again and may run in a burst." 108 116 msgstr "" 109 117 110 #: src/Admin/ Notices.php:97118 #: src/Admin/Messages.php:34 111 119 msgid "CLONEMUTE_ENV is set to \"staging\" in wp-config.php, so protection would come back on the next page load. Remove that line first. Nothing was changed." 112 120 msgstr "" 113 121 114 #: src/Admin/ Notices.php:98122 #: src/Admin/Messages.php:35 115 123 msgid "Test mail handed to the mail system. Check your inbox: if it arrives, mail is leaving this site." 116 124 msgstr "" 117 125 118 #: src/Admin/ Notices.php:99126 #: src/Admin/Messages.php:36 119 127 msgid "CloneMute stopped the test mail: mail protection works. It is listed under the blocked events." 120 128 msgstr "" 121 129 122 #: src/Admin/ Notices.php:100130 #: src/Admin/Messages.php:37 123 131 msgid "The test mail was not sent: the server could not send it." 124 132 msgstr "" 125 133 126 #: src/Admin/ Notices.php:101134 #: src/Admin/Messages.php:38 127 135 msgid "Added to the allow list." 128 136 msgstr "" 129 137 130 #: src/Admin/ Notices.php:102138 #: src/Admin/Messages.php:39 131 139 msgid "That value cannot be added to an allow list." 132 140 msgstr "" 133 141 142 #: src/Admin/Messages.php:40 143 msgid "The error message was dismissed. No protection was changed." 144 msgstr "" 145 146 #: src/Admin/Messages.php:41 147 msgid "Something went wrong. Nothing was changed." 148 msgstr "" 149 134 150 #: src/Admin/Notices.php:103 135 msgid " The error message was dismissed. No protection was changed."151 msgid "CloneMute: the recorded staging host does not match this site. Protection is OFF." 136 152 msgstr "" 137 153 138 154 #: src/Admin/Notices.php:104 139 msgid "Something went wrong. Nothing was changed."140 msgstr ""141 142 #: src/Admin/Notices.php:121143 msgid "CloneMute: the recorded staging host does not match this site. Protection is OFF."144 msgstr ""145 146 #: src/Admin/Notices.php:122147 155 msgid "This site was protected as a staging site under another address or on another installation, and has been moved or copied. Nothing is blocked here. If this is your production site, check that real mail and payments work again. If it is a copy of the staging site, protect it again on the CloneMute status page." 148 156 msgstr "" 149 157 150 #: src/Admin/Notices.php:1 23151 #: src/Admin/Notices.php:1 35158 #: src/Admin/Notices.php:105 159 #: src/Admin/Notices.php:117 152 160 #: src/Admin/Wizard.php:121 153 161 #: src/Admin/Wizard.php:136 … … 155 163 msgstr "" 156 164 157 #: src/Admin/Notices.php:1 26165 #: src/Admin/Notices.php:108 158 166 #: src/Admin/Pages.php:136 159 167 msgid "Send a test mail to me" 160 168 msgstr "" 161 169 162 #: src/Admin/Notices.php:1 29170 #: src/Admin/Notices.php:111 163 171 msgid "CloneMute: this site is armed but matches a production safeguard. Protection is OFF." 164 172 msgstr "" 165 173 174 #: src/Admin/Notices.php:115 175 msgid "CloneMute: the saved settings are unreadable. Nothing is blocked." 176 msgstr "" 177 178 #: src/Admin/Notices.php:116 179 msgid "Reset the saved state on the CloneMute status page, then check the environment and the settings." 180 msgstr "" 181 182 #: src/Admin/Notices.php:119 183 msgid "CloneMute: an internal error occurred. Nothing is blocked." 184 msgstr "" 185 166 186 #: src/Admin/Notices.php:133 167 msgid "CloneMute: the saved settings are unreadable. Nothing is blocked." 168 msgstr "" 169 170 #: src/Admin/Notices.php:134 171 msgid "Reset the saved state on the CloneMute status page, then check the environment and the settings." 172 msgstr "" 173 187 msgid "CloneMute: STAGING protection is active." 188 msgstr "" 189 190 #. translators: %d: number of active protections 174 191 #: src/Admin/Notices.php:137 175 msgid "CloneMute: an internal error occurred. Nothing is blocked."176 msgstr ""177 178 #: src/Admin/Notices.php:151179 msgid "CloneMute: STAGING protection is active."180 msgstr ""181 182 #. translators: %d: number of active protections183 #: src/Admin/Notices.php:155184 192 #, php-format 185 193 msgid "%d protection is on." … … 188 196 msgstr[1] "" 189 197 190 #: src/Admin/Notices.php:1 59198 #: src/Admin/Notices.php:141 191 199 #: vendor-prefixed/rotosix-core/src/Log/LogPage.php:67 192 200 msgid "Details" 193 201 msgstr "" 194 202 195 #: src/Admin/Notices.php:1 62203 #: src/Admin/Notices.php:144 196 204 #: src/Admin/Pages.php:133 197 205 msgid "Remove all protections" 198 206 msgstr "" 199 207 200 #: src/Admin/Notices.php:1 78208 #: src/Admin/Notices.php:160 201 209 msgid "CloneMute: CLONEMUTE_ENV is set to \"staging\" in wp-config.php, but protection cannot be enabled on this site. Nothing is blocked." 202 210 msgstr "" 203 211 204 212 #. translators: 1: protection name, 2: error class, 3: date and time (UTC) 205 #: src/Admin/Notices.php:1 99213 #: src/Admin/Notices.php:181 206 214 #, php-format 207 215 msgid "CloneMute: the \"%1$s\" protection hit an error (%2$s, %3$s UTC) and let a request through." 208 216 msgstr "" 209 217 218 #: src/Admin/Notices.php:188 219 msgid "Dismiss this message" 220 msgstr "" 221 222 #: src/Admin/Notices.php:189 223 msgid "Dismissing changes no protection. The message comes back if the error happens again." 224 msgstr "" 225 226 #. translators: %s: list of constants 210 227 #: src/Admin/Notices.php:206 211 msgid "Dismiss this message"212 msgstr ""213 214 #: src/Admin/Notices.php:207215 msgid "Dismissing changes no protection. The message comes back if the error happens again."216 msgstr ""217 218 #. translators: %s: list of constants219 #: src/Admin/Notices.php:224220 228 #, php-format 221 229 msgid "CloneMute: overridden by constant in wp-config: %s" … … 223 231 224 232 #. translators: %s: file name 225 #: src/Admin/Notices.php:2 43233 #: src/Admin/Notices.php:225 226 234 #, php-format 227 235 msgid "The wp_mail() function is replaced by %s. CloneMute may not be able to see or change mail sent through it; mail services that use the WordPress HTTP API are still covered by the outbound request block." … … 813 821 msgstr "" 814 822 823 #: src/Cli/Commands.php:170 824 msgid "The stored CloneMute settings cannot be read. Nothing is blocked until the state is set again." 825 msgstr "" 826 827 #: src/Cli/Commands.php:200 828 msgid "Saved as a staging site, but the protection is not active on this site." 829 msgstr "" 830 831 #: src/Cli/Commands.php:281 832 msgid "Pass --host=<host>: this site's address as `wp clonemute status` shows it." 833 msgstr "" 834 835 #. translators: %s: the reasons, joined 836 #: src/Cli/Commands.php:306 837 #, php-format 838 msgid "Protection cannot be enabled on this site: %s Nothing was changed." 839 msgstr "" 840 841 #. translators: %s: this site's host key 842 #: src/Cli/Commands.php:310 843 #, php-format 844 msgid "This site is %s (on a network, choose the site with --url)." 845 msgstr "" 846 847 #: src/Cli/Commands.php:340 848 msgid "The stored settings could not be read and were replaced by the defaults. Check the production domains and the other settings." 849 msgstr "" 850 851 #: src/Cli/Commands.php:342 852 msgid "The stored state was invalid and has been replaced; the other settings were kept." 853 msgstr "" 854 855 #: src/Cli/Commands.php:355 856 msgid "WP_ENVIRONMENT_TYPE is not set for WP-CLI. If only the web server sets it (fastcgi_param, SetEnv, PHP-FPM env), WP-CLI cannot check it: when it is \"production\" there, web requests stay unprotected. Check the CloneMute page in the admin." 857 msgstr "" 858 859 #: src/Cli/Commands.php:369 860 msgid "Nothing was changed: the site was already in that state." 861 msgstr "" 862 863 #: src/Cli/Commands.php:398 864 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:217 865 msgid "Unknown --format; use table or json." 866 msgstr "" 867 868 #: src/Cli/Commands.php:436 869 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:250 870 msgid "Write commands are disabled in this environment." 871 msgstr "" 872 873 #: src/Cli/Commands.php:440 874 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:253 875 #: vendor-prefixed/rotosix-core/src/Api/RestRegistrar.php:63 876 msgid "Sorry, you are not allowed to do that." 877 msgstr "" 878 815 879 #: src/Guard/HttpGuard.php:148 816 880 msgid "Request blocked by CloneMute (test site)." … … 992 1056 msgstr "" 993 1057 994 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:217995 msgid "Unknown --format; use table or json."996 msgstr ""997 998 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:250999 msgid "Write commands are disabled in this environment."1000 msgstr ""1001 1002 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:2531003 #: vendor-prefixed/rotosix-core/src/Api/RestRegistrar.php:631004 msgid "Sorry, you are not allowed to do that."1005 msgstr ""1006 1007 1058 #: vendor-prefixed/rotosix-core/src/Api/ErrorFactory.php:102 1008 1059 msgid "This batch has no rollback point." -
clonemute/tags/0.2.0/readme.txt
r3828539 r3841430 5 5 Tested up to: 7.2 6 6 Requires PHP: 7.4 7 Stable tag: 0. 1.07 Stable tag: 0.2.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 51 51 3. On a live site open the CloneMute page and choose "This is the new production site". CloneMute blocks nothing either way, but other Rotosix plugins (for example the scheduled imports of CatalogRelay) pause their scheduled work until the site is confirmed as production. 52 52 53 To pre-confirm a clone in a script, define `define( 'CLONEMUTE_ENV', 'staging' );` in `wp-config.php` of the copy. Safeguards still apply: the constant is refused on hosts you listed or confirmed as production and when `WP_ENVIRONMENT_TYPE` is explicitly `production`, and the admin says so. 53 = WP-CLI = 54 55 Confirm a copy from your clone script right after the copy is made: 56 57 `wp clonemute arm --host=stg.example.com` 58 59 This is the same confirmation as in the admin, with the same safeguards: it is refused on hosts you listed or confirmed as production and when `WP_ENVIRONMENT_TYPE` is explicitly `production`. WP-CLI only sees a `WP_ENVIRONMENT_TYPE` defined in `wp-config.php` or set in its own environment: a value set only in the web server configuration (fastcgi_param, SetEnv, PHP-FPM env) cannot be checked, so `arm` warns when it sees none, and you should check the CloneMute page in the admin. `--host` is this site's address without the scheme, with the port and the sub-directory if there is one, exactly as `wp clonemute status` shows it. On a multisite network choose the site with `--url=<site address>`. 60 61 * `wp clonemute status [--format=json]` shows the state, why the site is or is not protected and the state of every protection. 62 * `wp clonemute disarm` removes every protection. 63 * `wp clonemute production confirm` records the site as the production site; `wp clonemute production forget --host=<host>` removes that record. 64 65 Exit codes: 0 success (also when nothing had to change), 1 refused or failed, 2 saved as a staging site but no protection is active (for example because of `CLONEMUTE_DISABLE_ALL`). With `--format=json` the result or the error is one JSON document on standard output; messages go to standard error. Changes made with WP-CLI are marked "(WP-CLI)" in the event log. 66 67 Without WP-CLI you can pre-confirm a clone with `define( 'CLONEMUTE_ENV', 'staging' );` in `wp-config.php` of the copy. The same safeguards apply, the admin says when the constant is refused, and the protection cannot be removed while the constant is set. 54 68 55 69 Emergency switches for `wp-config.php`: `CLONEMUTE_DISABLE_ALL`, `CLONEMUTE_DISABLE_MAIL`, `CLONEMUTE_DISABLE_PAYMENTS`, `CLONEMUTE_DISABLE_CRON`, `CLONEMUTE_DISABLE_HTTP`, `CLONEMUTE_DISABLE_GATE` (login gate and REST limit). … … 79 93 == Changelog == 80 94 95 = 0.2.0 = 96 * New: WP-CLI commands `wp clonemute status`, `arm --host=<host>`, `disarm`, `production confirm` and `production forget --host=<host>`, with `--format=json`. They make the same checks as the admin screens. 97 * State changes made with WP-CLI are marked in the event log. 98 81 99 = 0.1.0 = 82 100 * First release: environment suggestions with explicit confirmation, mail, payment, scheduled task, outbound request, search engine and REST protections, read-only report, event log with privacy tools. … … 84 102 == Upgrade Notice == 85 103 104 = 0.2.0 = 105 Adds WP-CLI commands to confirm a copy from a clone script. No setting changes. 106 86 107 = 0.1.0 = 87 108 First release. -
clonemute/tags/0.2.0/src/Admin/AdminActions.php
r3828539 r3841430 27 27 */ 28 28 final class AdminActions { 29 30 /** 31 * Origins of a state change (written to the state_change log). 32 */ 33 const ORIGIN_ADMIN = 'admin'; 34 const ORIGIN_CLI = 'cli'; 29 35 30 36 const STATE_ACTIONS = array( 'arm', 'production', 'forget_production', 'later', 'disarm' ); … … 159 165 * "This is staging": recompute the hard blocks, compare the typed host, then arm. 160 166 * 161 * @param array $post Submitted fields. 162 * @return array 163 */ 164 public static function arm( array $post ): array { 167 * @param array $post Submitted fields. 168 * @param string $origin Where the request came from (ORIGIN_ADMIN or ORIGIN_CLI). 169 * @return array {ok, code, changed, blocks?} 170 */ 171 public static function arm( array $post, string $origin = self::ORIGIN_ADMIN ): array { 165 172 $s = SettingsRepo::load(); 166 173 $snap = EnvCapture::capture( $s, true ); 167 $t = StateMachine::arm( $snap, isset( $post['host'] ) ? (string) $post['host'] : '', time() ); 174 if ( self::ORIGIN_CLI === $origin ) { 175 // WP-CLI sets the Host header from --url or wp-cli.yml (operator configuration copied with the files, not a 176 // client header): judge it like any later request, without the request host. 177 $snap->request_host = ''; 178 } 179 $t = StateMachine::arm( $snap, isset( $post['host'] ) ? (string) $post['host'] : '', time() ); 168 180 if ( ! $t->ok ) { 169 181 $codes = array( 170 182 'hard_block' => 'arm_blocked', 171 183 'host_mismatch' => 'arm_host', 172 'no_host' => 'arm_blocked', 173 ); 174 return array( 175 'ok' => false, 176 'code' => $codes[ $t->error ] ?? 'error', 177 ); 184 'no_host' => 'no_host', 185 ); 186 $out = array( 187 'ok' => false, 188 'code' => $codes[ $t->error ] ?? 'error', 189 'changed' => false, 190 ); 191 if ( 'hard_block' === $t->error ) { 192 $out['blocks'] = $t->blocks; 193 } 194 return $out; 178 195 } 179 196 $code = Constants::disableAll() ? 'armed_off' : 'armed'; // Saved, but CLONEMUTE_DISABLE_ALL keeps every guard off. … … 181 198 // Already armed for this site (a second submit of the form): keep "since" and log nothing. 182 199 return array( 183 'ok' => true, 184 'code' => $code, 200 'ok' => true, 201 'code' => $code, 202 'changed' => false, 185 203 ); 186 204 } 187 205 if ( ! self::write( $t->changes ) ) { 188 return array( 189 'ok' => false, 190 'code' => 'error', 191 ); 206 return self::failed(); 192 207 } 193 208 Runtime::clearError(); 194 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> armed', array( 'to' => 'armed' ) ); 195 return array( 196 'ok' => true, 197 'code' => $code, 209 self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> armed', 'armed', $origin ); 210 return array( 211 'ok' => true, 212 'code' => $code, 213 'changed' => true, 198 214 ); 199 215 } … … 202 218 * "This is the new production site": record the fingerprint, enable nothing. 203 219 * 204 * @return array 205 */ 206 public static function production(): array { 220 * @param string $origin Where the request came from. 221 * @return array {ok, code, changed} 222 */ 223 public static function production( string $origin = self::ORIGIN_ADMIN ): array { 207 224 $s = SettingsRepo::load(); 208 225 $snap = EnvCapture::capture( $s, false ); … … 211 228 // lock the host as production. Removing the protection is a separate, explicit step. 212 229 return array( 213 'ok' => false, 214 'code' => 'production_armed', 230 'ok' => false, 231 'code' => 'production_armed', 232 'changed' => false, 215 233 ); 216 234 } … … 218 236 if ( ! $t->ok ) { 219 237 return array( 220 'ok' => false, 221 'code' => 'error', 238 'ok' => false, 239 'code' => 'no_host', 240 'changed' => false, 222 241 ); 223 242 } … … 227 246 if ( ! $again ) { 228 247 if ( ! self::write( $t->changes ) ) { 229 return array( 230 'ok' => false, 231 'code' => 'error', 232 ); 248 return self::failed(); 233 249 } 234 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> production', array( 'to' => 'production' ));250 self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> production', 'production', $origin ); 235 251 } 236 252 Runtime::clearError(); // No guard runs on a production site: an earlier guard error no longer applies. 237 253 return array( 238 'ok' => true, 239 'code' => 'production', 254 'ok' => true, 255 'code' => 'production', 256 'changed' => ! $again, 240 257 ); 241 258 } … … 244 261 * Forget the production confirmation of this host after the host name was typed (the way back from "production"). 245 262 * 246 * @param array $post Submitted fields. 247 * @return array 248 */ 249 public static function forgetProduction( array $post ): array { 263 * @param array $post Submitted fields. 264 * @param string $origin Where the request came from. 265 * @return array {ok, code, changed} 266 */ 267 public static function forgetProduction( array $post, string $origin = self::ORIGIN_ADMIN ): array { 250 268 $s = SettingsRepo::load(); 251 269 $snap = EnvCapture::capture( $s, false ); … … 255 273 // No confirmation for this host (any more): a second submit of the form. Nothing to remove, nothing to log. 256 274 return array( 257 'ok' => true, 258 'code' => 'prod_forgotten', 275 'ok' => true, 276 'code' => 'prod_forgotten', 277 'changed' => false, 259 278 ); 260 279 } 261 280 if ( ! $t->ok ) { 262 return array( 263 'ok' => false, 264 'code' => 'host_mismatch' === $t->error ? 'arm_host' : 'error', 281 $codes = array( 282 'host_mismatch' => 'arm_host', 283 'not_production' => 'prod_none', 284 'no_host' => 'no_host', 285 ); 286 return array( 287 'ok' => false, 288 'code' => $codes[ $t->error ] ?? 'error', 289 'changed' => false, 265 290 ); 266 291 } 267 292 if ( ! self::write( $t->changes ) ) { 268 return array( 269 'ok' => false, 270 'code' => 'error', 271 ); 293 return self::failed(); 272 294 } 273 295 Runtime::clearError(); 274 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> ' . ( $t->changes['state'] ?? $s->state ) . ' (production confirmation removed)', array( 'to' => $t->changes['state'] ?? $s->state ) ); 275 return array( 276 'ok' => true, 277 'code' => 'prod_forgotten', 296 $to = $t->changes['state'] ?? $s->state; 297 self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> ' . $to . ' (production confirmation removed)', $to, $origin ); 298 return array( 299 'ok' => true, 300 'code' => 'prod_forgotten', 301 'changed' => true, 278 302 ); 279 303 } … … 295 319 * Remove every guard at once. 296 320 * 297 * @return array 298 */ 299 public static function disarm(): array { 321 * @param string $origin Where the request came from. 322 * @return array {ok, code, changed} 323 */ 324 public static function disarm( string $origin = self::ORIGIN_ADMIN ): array { 300 325 $s = SettingsRepo::load(); 301 326 $t = StateMachine::disarm( $s, time() ); … … 303 328 // CLONEMUTE_ENV would arm the site again on the next request: report that instead of a success that does not stick. 304 329 return array( 305 'ok' => false, 306 'code' => 'disarm_const', 330 'ok' => false, 331 'code' => 'disarm_const', 332 'changed' => false, 307 333 ); 308 334 } 309 335 if ( $t->changes ) { 310 336 if ( ! self::write( $t->changes ) ) { 311 return array( 312 'ok' => false, 313 'code' => 'error', 314 ); 337 return self::failed(); 315 338 } 316 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, EnvCapture::capture( $s, false ) ) . ' -> unconfirmed', array( 'to' => 'unconfirmed' ));339 self::logState( StateMachine::fromLabel( $s, EnvCapture::capture( $s, false ) ) . ' -> unconfirmed', 'unconfirmed', $origin ); 317 340 } 318 341 Runtime::clearError(); 319 342 return array( 320 'ok' => true, 321 'code' => 'disarmed', 322 ); 343 'ok' => true, 344 'code' => 'disarmed', 345 'changed' => (bool) $t->changes, 346 ); 347 } 348 349 /** 350 * Result of a write that did not stick. 351 * 352 * @return array 353 */ 354 private static function failed(): array { 355 return array( 356 'ok' => false, 357 'code' => 'error', 358 'changed' => false, 359 ); 360 } 361 362 /** 363 * Log a state change with where it came from (changes made with WP-CLI say so in the summary). 364 * 365 * @param string $summary Summary ("from -> to"). 366 * @param string $to New state. 367 * @param string $origin ORIGIN_ADMIN or ORIGIN_CLI. 368 * @return void 369 */ 370 private static function logState( string $summary, string $to, string $origin ): void { 371 $context = array( 'to' => $to ); 372 if ( self::ORIGIN_CLI === $origin ) { 373 $summary .= ' (WP-CLI)'; 374 $context['via'] = 'cli'; 375 } 376 LogWriter::event( 'state_change', 'state', $summary, $context ); 323 377 } 324 378 -
clonemute/tags/0.2.0/src/Admin/Notices.php
r3828539 r3841430 85 85 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only code mapped through a whitelist. 86 86 $code = isset( $_GET['clonemute_msg'] ) ? sanitize_key( wp_unslash( $_GET['clonemute_msg'] ) ) : ''; 87 $map = array( 88 'armed' => array( 'success', __( 'Protection is on. This site is now treated as a staging site.', 'clonemute' ) ), 89 'armed_off' => array( 'warning', __( 'Saved as a staging site, but CLONEMUTE_DISABLE_ALL in wp-config.php keeps every protection off. Remove that line to turn the protections on.', 'clonemute' ) ), 90 'arm_host' => array( 'error', __( 'The host name does not match. Nothing was changed.', 'clonemute' ) ), 91 'arm_blocked' => array( 'error', __( 'Protection cannot be enabled on this site (see the reasons below). Nothing was changed.', 'clonemute' ) ), 92 'production' => array( 'success', __( 'Recorded as a production site. No protection is enabled.', 'clonemute' ) ), 93 'production_armed' => array( 'error', __( 'This site is protected as a staging site (or CLONEMUTE_ENV arms it). Remove the protection first if this really is the production site. Nothing was changed.', 'clonemute' ) ), 94 'prod_forgotten' => array( 'success', __( 'The production confirmation of this site was removed. CloneMute treats it as unconfirmed again.', 'clonemute' ) ), 95 'later' => array( 'info', __( 'OK, CloneMute will ask again the next time you log in.', 'clonemute' ) ), 96 'disarmed' => array( 'success', __( 'All protections were removed. Scheduled tasks that were paused will run again and may run in a burst.', 'clonemute' ) ), 97 'disarm_const' => array( 'error', __( 'CLONEMUTE_ENV is set to "staging" in wp-config.php, so protection would come back on the next page load. Remove that line first. Nothing was changed.', 'clonemute' ) ), 98 'test_mail_sent' => array( 'success', __( 'Test mail handed to the mail system. Check your inbox: if it arrives, mail is leaving this site.', 'clonemute' ) ), 99 'test_mail_caught' => array( 'success', __( 'CloneMute stopped the test mail: mail protection works. It is listed under the blocked events.', 'clonemute' ) ), 100 'test_mail_failed' => array( 'warning', __( 'The test mail was not sent: the server could not send it.', 'clonemute' ) ), 101 'allow_added' => array( 'success', __( 'Added to the allow list.', 'clonemute' ) ), 102 'allow_invalid' => array( 'error', __( 'That value cannot be added to an allow list.', 'clonemute' ) ), 103 'error_dismissed' => array( 'info', __( 'The error message was dismissed. No protection was changed.', 'clonemute' ) ), 104 'error' => array( 'error', __( 'Something went wrong. Nothing was changed.', 'clonemute' ) ), 105 ); 106 if ( isset( $map[ $code ] ) ) { 107 echo '<div class="notice notice-' . esc_attr( $map[ $code ][0] ) . ' is-dismissible" role="status"><p>' . esc_html( $map[ $code ][1] ) . '</p></div>'; 87 $msg = Messages::result( $code ); 88 if ( null !== $msg ) { 89 echo '<div class="notice notice-' . esc_attr( $msg[0] ) . ' is-dismissible" role="status"><p>' . esc_html( $msg[1] ) . '</p></div>'; 108 90 } 109 91 } -
clonemute/tags/0.2.0/src/Env/EnvCapture.php
r3828539 r3841430 107 107 return EnvSnapshot::fromArray( 108 108 array( 109 'home_key' => HostNormalizer::homeKey( (string) ( $src['home'] ?? '' ) ),110 'stored_home_key' => HostNormalizer::homeKey( (string) ( $src['stored_home'] ?? '' ) ),111 'request_host' => HostNormalizer::requestHost( (string) ( $src['request_host'] ?? '' ) ),112 'abspath_h' => Fingerprint::abspath( (string) ( $src['abspath'] ?? '' ) ),113 'db_h' => Fingerprint::db( (string) ( $src['db'] ?? '' ) ),114 'wpdb_prefix' => (string) ( $src['wpdb_prefix'] ?? '' ),115 'env_effective' => $types['effective'],116 'env_explicit' => $types['explicit'],117 'wpstg_const' => ! empty( $src['wpstg_const'] ),118 'wpstg_option' => ! empty( $src['wpstg_option'] ),109 'home_key' => HostNormalizer::homeKey( (string) ( $src['home'] ?? '' ) ), 110 'stored_home_key' => HostNormalizer::homeKey( (string) ( $src['stored_home'] ?? '' ) ), 111 'request_host' => HostNormalizer::requestHost( (string) ( $src['request_host'] ?? '' ) ), 112 'abspath_h' => Fingerprint::abspath( (string) ( $src['abspath'] ?? '' ) ), 113 'db_h' => Fingerprint::db( (string) ( $src['db'] ?? '' ) ), 114 'wpdb_prefix' => (string) ( $src['wpdb_prefix'] ?? '' ), 115 'env_effective' => $types['effective'], 116 'env_explicit' => $types['explicit'], 117 'wpstg_const' => ! empty( $src['wpstg_const'] ), 118 'wpstg_option' => ! empty( $src['wpstg_option'] ), 119 119 'clonemute_env_const' => array_key_exists( 'clonemute_env', $src ) ? $src['clonemute_env'] : Constants::env(), 120 'baseline' => $s->baseline,121 'production' => $s->production,122 'whitelist' => $s->prod_whitelist,123 'patterns' => $patterns,120 'baseline' => $s->baseline, 121 'production' => $s->production, 122 'whitelist' => $s->prod_whitelist, 123 'patterns' => $patterns, 124 124 ) 125 125 ); -
clonemute/tags/0.2.0/src/Plugin.php
r3828539 r3841430 14 14 use Rotosix\CloneMute\Admin\Pages; 15 15 use Rotosix\CloneMute\Admin\SettingsPage; 16 use Rotosix\CloneMute\Cli\Commands; 16 17 use Rotosix\CloneMute\Env\EnvCapture; 17 18 use Rotosix\CloneMute\Guard\Guard; … … 33 34 final class Plugin { 34 35 35 const VERSION = '0. 1.0';36 const VERSION = '0.2.0'; 36 37 37 38 /** … … 163 164 self::registerAdmin(); 164 165 } 166 if ( defined( 'WP_CLI' ) && WP_CLI ) { 167 Commands::register(); 168 } 165 169 if ( 'armed' !== $s->state && ! Constants::armRequested() ) { 166 170 return; -
clonemute/trunk/clonemute.php
r3828539 r3841430 4 4 * Plugin URI: https://wordpress.org/plugins/clonemute/ 5 5 * Description: Makes cloned WooCommerce sites safe: after you confirm a copy is a staging site, CloneMute blocks outgoing mail, payment gateways, scheduled tasks and known external services, and hides the site from search engines. 6 * Version: 0. 1.06 * Version: 0.2.0 7 7 * Requires at least: 7.0 8 8 * Requires PHP: 7.4 -
clonemute/trunk/languages/clonemute.pot
r3828539 r3841430 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: CloneMute Staging Safety for WooCommerce 0. 1.0\n"5 "Project-Id-Version: CloneMute Staging Safety for WooCommerce 0.2.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/clonemute\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2026-1 1-26T01:23:54+00:00\n"12 "POT-Creation-Date: 2026-12-02T09:24:48+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.12.0\n" … … 40 40 msgstr "" 41 41 42 #: src/Admin/AdminActions.php:4 1042 #: src/Admin/AdminActions.php:464 43 43 msgid "CloneMute test mail" 44 44 msgstr "" 45 45 46 #: src/Admin/AdminActions.php:4 1146 #: src/Admin/AdminActions.php:465 47 47 msgid "If you can read this, mail is leaving this site. On a staging site that means the mail guard is not active." 48 48 msgstr "" … … 72 72 msgstr "" 73 73 74 #: src/Admin/ Notices.php:8874 #: src/Admin/Messages.php:23 75 75 msgid "Protection is on. This site is now treated as a staging site." 76 76 msgstr "" 77 77 78 #: src/Admin/ Notices.php:8978 #: src/Admin/Messages.php:24 79 79 msgid "Saved as a staging site, but CLONEMUTE_DISABLE_ALL in wp-config.php keeps every protection off. Remove that line to turn the protections on." 80 80 msgstr "" 81 81 82 #: src/Admin/ Notices.php:9082 #: src/Admin/Messages.php:25 83 83 msgid "The host name does not match. Nothing was changed." 84 84 msgstr "" 85 85 86 #: src/Admin/ Notices.php:9186 #: src/Admin/Messages.php:26 87 87 msgid "Protection cannot be enabled on this site (see the reasons below). Nothing was changed." 88 88 msgstr "" 89 89 90 #: src/Admin/ Notices.php:9290 #: src/Admin/Messages.php:27 91 91 msgid "Recorded as a production site. No protection is enabled." 92 92 msgstr "" 93 93 94 #: src/Admin/ Notices.php:9394 #: src/Admin/Messages.php:28 95 95 msgid "This site is protected as a staging site (or CLONEMUTE_ENV arms it). Remove the protection first if this really is the production site. Nothing was changed." 96 96 msgstr "" 97 97 98 #: src/Admin/ Notices.php:9498 #: src/Admin/Messages.php:29 99 99 msgid "The production confirmation of this site was removed. CloneMute treats it as unconfirmed again." 100 100 msgstr "" 101 101 102 #: src/Admin/Notices.php:95 102 #: src/Admin/Messages.php:30 103 msgid "This site has no production confirmation to remove. Nothing was changed." 104 msgstr "" 105 106 #: src/Admin/Messages.php:31 107 msgid "The address of this site cannot be read (its home URL has no host). Nothing was changed. With WP-CLI, pass --url=<site address>." 108 msgstr "" 109 110 #: src/Admin/Messages.php:32 103 111 msgid "OK, CloneMute will ask again the next time you log in." 104 112 msgstr "" 105 113 106 #: src/Admin/ Notices.php:96114 #: src/Admin/Messages.php:33 107 115 msgid "All protections were removed. Scheduled tasks that were paused will run again and may run in a burst." 108 116 msgstr "" 109 117 110 #: src/Admin/ Notices.php:97118 #: src/Admin/Messages.php:34 111 119 msgid "CLONEMUTE_ENV is set to \"staging\" in wp-config.php, so protection would come back on the next page load. Remove that line first. Nothing was changed." 112 120 msgstr "" 113 121 114 #: src/Admin/ Notices.php:98122 #: src/Admin/Messages.php:35 115 123 msgid "Test mail handed to the mail system. Check your inbox: if it arrives, mail is leaving this site." 116 124 msgstr "" 117 125 118 #: src/Admin/ Notices.php:99126 #: src/Admin/Messages.php:36 119 127 msgid "CloneMute stopped the test mail: mail protection works. It is listed under the blocked events." 120 128 msgstr "" 121 129 122 #: src/Admin/ Notices.php:100130 #: src/Admin/Messages.php:37 123 131 msgid "The test mail was not sent: the server could not send it." 124 132 msgstr "" 125 133 126 #: src/Admin/ Notices.php:101134 #: src/Admin/Messages.php:38 127 135 msgid "Added to the allow list." 128 136 msgstr "" 129 137 130 #: src/Admin/ Notices.php:102138 #: src/Admin/Messages.php:39 131 139 msgid "That value cannot be added to an allow list." 132 140 msgstr "" 133 141 142 #: src/Admin/Messages.php:40 143 msgid "The error message was dismissed. No protection was changed." 144 msgstr "" 145 146 #: src/Admin/Messages.php:41 147 msgid "Something went wrong. Nothing was changed." 148 msgstr "" 149 134 150 #: src/Admin/Notices.php:103 135 msgid " The error message was dismissed. No protection was changed."151 msgid "CloneMute: the recorded staging host does not match this site. Protection is OFF." 136 152 msgstr "" 137 153 138 154 #: src/Admin/Notices.php:104 139 msgid "Something went wrong. Nothing was changed."140 msgstr ""141 142 #: src/Admin/Notices.php:121143 msgid "CloneMute: the recorded staging host does not match this site. Protection is OFF."144 msgstr ""145 146 #: src/Admin/Notices.php:122147 155 msgid "This site was protected as a staging site under another address or on another installation, and has been moved or copied. Nothing is blocked here. If this is your production site, check that real mail and payments work again. If it is a copy of the staging site, protect it again on the CloneMute status page." 148 156 msgstr "" 149 157 150 #: src/Admin/Notices.php:1 23151 #: src/Admin/Notices.php:1 35158 #: src/Admin/Notices.php:105 159 #: src/Admin/Notices.php:117 152 160 #: src/Admin/Wizard.php:121 153 161 #: src/Admin/Wizard.php:136 … … 155 163 msgstr "" 156 164 157 #: src/Admin/Notices.php:1 26165 #: src/Admin/Notices.php:108 158 166 #: src/Admin/Pages.php:136 159 167 msgid "Send a test mail to me" 160 168 msgstr "" 161 169 162 #: src/Admin/Notices.php:1 29170 #: src/Admin/Notices.php:111 163 171 msgid "CloneMute: this site is armed but matches a production safeguard. Protection is OFF." 164 172 msgstr "" 165 173 174 #: src/Admin/Notices.php:115 175 msgid "CloneMute: the saved settings are unreadable. Nothing is blocked." 176 msgstr "" 177 178 #: src/Admin/Notices.php:116 179 msgid "Reset the saved state on the CloneMute status page, then check the environment and the settings." 180 msgstr "" 181 182 #: src/Admin/Notices.php:119 183 msgid "CloneMute: an internal error occurred. Nothing is blocked." 184 msgstr "" 185 166 186 #: src/Admin/Notices.php:133 167 msgid "CloneMute: the saved settings are unreadable. Nothing is blocked." 168 msgstr "" 169 170 #: src/Admin/Notices.php:134 171 msgid "Reset the saved state on the CloneMute status page, then check the environment and the settings." 172 msgstr "" 173 187 msgid "CloneMute: STAGING protection is active." 188 msgstr "" 189 190 #. translators: %d: number of active protections 174 191 #: src/Admin/Notices.php:137 175 msgid "CloneMute: an internal error occurred. Nothing is blocked."176 msgstr ""177 178 #: src/Admin/Notices.php:151179 msgid "CloneMute: STAGING protection is active."180 msgstr ""181 182 #. translators: %d: number of active protections183 #: src/Admin/Notices.php:155184 192 #, php-format 185 193 msgid "%d protection is on." … … 188 196 msgstr[1] "" 189 197 190 #: src/Admin/Notices.php:1 59198 #: src/Admin/Notices.php:141 191 199 #: vendor-prefixed/rotosix-core/src/Log/LogPage.php:67 192 200 msgid "Details" 193 201 msgstr "" 194 202 195 #: src/Admin/Notices.php:1 62203 #: src/Admin/Notices.php:144 196 204 #: src/Admin/Pages.php:133 197 205 msgid "Remove all protections" 198 206 msgstr "" 199 207 200 #: src/Admin/Notices.php:1 78208 #: src/Admin/Notices.php:160 201 209 msgid "CloneMute: CLONEMUTE_ENV is set to \"staging\" in wp-config.php, but protection cannot be enabled on this site. Nothing is blocked." 202 210 msgstr "" 203 211 204 212 #. translators: 1: protection name, 2: error class, 3: date and time (UTC) 205 #: src/Admin/Notices.php:1 99213 #: src/Admin/Notices.php:181 206 214 #, php-format 207 215 msgid "CloneMute: the \"%1$s\" protection hit an error (%2$s, %3$s UTC) and let a request through." 208 216 msgstr "" 209 217 218 #: src/Admin/Notices.php:188 219 msgid "Dismiss this message" 220 msgstr "" 221 222 #: src/Admin/Notices.php:189 223 msgid "Dismissing changes no protection. The message comes back if the error happens again." 224 msgstr "" 225 226 #. translators: %s: list of constants 210 227 #: src/Admin/Notices.php:206 211 msgid "Dismiss this message"212 msgstr ""213 214 #: src/Admin/Notices.php:207215 msgid "Dismissing changes no protection. The message comes back if the error happens again."216 msgstr ""217 218 #. translators: %s: list of constants219 #: src/Admin/Notices.php:224220 228 #, php-format 221 229 msgid "CloneMute: overridden by constant in wp-config: %s" … … 223 231 224 232 #. translators: %s: file name 225 #: src/Admin/Notices.php:2 43233 #: src/Admin/Notices.php:225 226 234 #, php-format 227 235 msgid "The wp_mail() function is replaced by %s. CloneMute may not be able to see or change mail sent through it; mail services that use the WordPress HTTP API are still covered by the outbound request block." … … 813 821 msgstr "" 814 822 823 #: src/Cli/Commands.php:170 824 msgid "The stored CloneMute settings cannot be read. Nothing is blocked until the state is set again." 825 msgstr "" 826 827 #: src/Cli/Commands.php:200 828 msgid "Saved as a staging site, but the protection is not active on this site." 829 msgstr "" 830 831 #: src/Cli/Commands.php:281 832 msgid "Pass --host=<host>: this site's address as `wp clonemute status` shows it." 833 msgstr "" 834 835 #. translators: %s: the reasons, joined 836 #: src/Cli/Commands.php:306 837 #, php-format 838 msgid "Protection cannot be enabled on this site: %s Nothing was changed." 839 msgstr "" 840 841 #. translators: %s: this site's host key 842 #: src/Cli/Commands.php:310 843 #, php-format 844 msgid "This site is %s (on a network, choose the site with --url)." 845 msgstr "" 846 847 #: src/Cli/Commands.php:340 848 msgid "The stored settings could not be read and were replaced by the defaults. Check the production domains and the other settings." 849 msgstr "" 850 851 #: src/Cli/Commands.php:342 852 msgid "The stored state was invalid and has been replaced; the other settings were kept." 853 msgstr "" 854 855 #: src/Cli/Commands.php:355 856 msgid "WP_ENVIRONMENT_TYPE is not set for WP-CLI. If only the web server sets it (fastcgi_param, SetEnv, PHP-FPM env), WP-CLI cannot check it: when it is \"production\" there, web requests stay unprotected. Check the CloneMute page in the admin." 857 msgstr "" 858 859 #: src/Cli/Commands.php:369 860 msgid "Nothing was changed: the site was already in that state." 861 msgstr "" 862 863 #: src/Cli/Commands.php:398 864 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:217 865 msgid "Unknown --format; use table or json." 866 msgstr "" 867 868 #: src/Cli/Commands.php:436 869 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:250 870 msgid "Write commands are disabled in this environment." 871 msgstr "" 872 873 #: src/Cli/Commands.php:440 874 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:253 875 #: vendor-prefixed/rotosix-core/src/Api/RestRegistrar.php:63 876 msgid "Sorry, you are not allowed to do that." 877 msgstr "" 878 815 879 #: src/Guard/HttpGuard.php:148 816 880 msgid "Request blocked by CloneMute (test site)." … … 992 1056 msgstr "" 993 1057 994 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:217995 msgid "Unknown --format; use table or json."996 msgstr ""997 998 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:250999 msgid "Write commands are disabled in this environment."1000 msgstr ""1001 1002 #: vendor-prefixed/rotosix-core/src/Api/CliCommands.php:2531003 #: vendor-prefixed/rotosix-core/src/Api/RestRegistrar.php:631004 msgid "Sorry, you are not allowed to do that."1005 msgstr ""1006 1007 1058 #: vendor-prefixed/rotosix-core/src/Api/ErrorFactory.php:102 1008 1059 msgid "This batch has no rollback point." -
clonemute/trunk/readme.txt
r3828539 r3841430 5 5 Tested up to: 7.2 6 6 Requires PHP: 7.4 7 Stable tag: 0. 1.07 Stable tag: 0.2.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 51 51 3. On a live site open the CloneMute page and choose "This is the new production site". CloneMute blocks nothing either way, but other Rotosix plugins (for example the scheduled imports of CatalogRelay) pause their scheduled work until the site is confirmed as production. 52 52 53 To pre-confirm a clone in a script, define `define( 'CLONEMUTE_ENV', 'staging' );` in `wp-config.php` of the copy. Safeguards still apply: the constant is refused on hosts you listed or confirmed as production and when `WP_ENVIRONMENT_TYPE` is explicitly `production`, and the admin says so. 53 = WP-CLI = 54 55 Confirm a copy from your clone script right after the copy is made: 56 57 `wp clonemute arm --host=stg.example.com` 58 59 This is the same confirmation as in the admin, with the same safeguards: it is refused on hosts you listed or confirmed as production and when `WP_ENVIRONMENT_TYPE` is explicitly `production`. WP-CLI only sees a `WP_ENVIRONMENT_TYPE` defined in `wp-config.php` or set in its own environment: a value set only in the web server configuration (fastcgi_param, SetEnv, PHP-FPM env) cannot be checked, so `arm` warns when it sees none, and you should check the CloneMute page in the admin. `--host` is this site's address without the scheme, with the port and the sub-directory if there is one, exactly as `wp clonemute status` shows it. On a multisite network choose the site with `--url=<site address>`. 60 61 * `wp clonemute status [--format=json]` shows the state, why the site is or is not protected and the state of every protection. 62 * `wp clonemute disarm` removes every protection. 63 * `wp clonemute production confirm` records the site as the production site; `wp clonemute production forget --host=<host>` removes that record. 64 65 Exit codes: 0 success (also when nothing had to change), 1 refused or failed, 2 saved as a staging site but no protection is active (for example because of `CLONEMUTE_DISABLE_ALL`). With `--format=json` the result or the error is one JSON document on standard output; messages go to standard error. Changes made with WP-CLI are marked "(WP-CLI)" in the event log. 66 67 Without WP-CLI you can pre-confirm a clone with `define( 'CLONEMUTE_ENV', 'staging' );` in `wp-config.php` of the copy. The same safeguards apply, the admin says when the constant is refused, and the protection cannot be removed while the constant is set. 54 68 55 69 Emergency switches for `wp-config.php`: `CLONEMUTE_DISABLE_ALL`, `CLONEMUTE_DISABLE_MAIL`, `CLONEMUTE_DISABLE_PAYMENTS`, `CLONEMUTE_DISABLE_CRON`, `CLONEMUTE_DISABLE_HTTP`, `CLONEMUTE_DISABLE_GATE` (login gate and REST limit). … … 79 93 == Changelog == 80 94 95 = 0.2.0 = 96 * New: WP-CLI commands `wp clonemute status`, `arm --host=<host>`, `disarm`, `production confirm` and `production forget --host=<host>`, with `--format=json`. They make the same checks as the admin screens. 97 * State changes made with WP-CLI are marked in the event log. 98 81 99 = 0.1.0 = 82 100 * First release: environment suggestions with explicit confirmation, mail, payment, scheduled task, outbound request, search engine and REST protections, read-only report, event log with privacy tools. … … 84 102 == Upgrade Notice == 85 103 104 = 0.2.0 = 105 Adds WP-CLI commands to confirm a copy from a clone script. No setting changes. 106 86 107 = 0.1.0 = 87 108 First release. -
clonemute/trunk/src/Admin/AdminActions.php
r3828539 r3841430 27 27 */ 28 28 final class AdminActions { 29 30 /** 31 * Origins of a state change (written to the state_change log). 32 */ 33 const ORIGIN_ADMIN = 'admin'; 34 const ORIGIN_CLI = 'cli'; 29 35 30 36 const STATE_ACTIONS = array( 'arm', 'production', 'forget_production', 'later', 'disarm' ); … … 159 165 * "This is staging": recompute the hard blocks, compare the typed host, then arm. 160 166 * 161 * @param array $post Submitted fields. 162 * @return array 163 */ 164 public static function arm( array $post ): array { 167 * @param array $post Submitted fields. 168 * @param string $origin Where the request came from (ORIGIN_ADMIN or ORIGIN_CLI). 169 * @return array {ok, code, changed, blocks?} 170 */ 171 public static function arm( array $post, string $origin = self::ORIGIN_ADMIN ): array { 165 172 $s = SettingsRepo::load(); 166 173 $snap = EnvCapture::capture( $s, true ); 167 $t = StateMachine::arm( $snap, isset( $post['host'] ) ? (string) $post['host'] : '', time() ); 174 if ( self::ORIGIN_CLI === $origin ) { 175 // WP-CLI sets the Host header from --url or wp-cli.yml (operator configuration copied with the files, not a 176 // client header): judge it like any later request, without the request host. 177 $snap->request_host = ''; 178 } 179 $t = StateMachine::arm( $snap, isset( $post['host'] ) ? (string) $post['host'] : '', time() ); 168 180 if ( ! $t->ok ) { 169 181 $codes = array( 170 182 'hard_block' => 'arm_blocked', 171 183 'host_mismatch' => 'arm_host', 172 'no_host' => 'arm_blocked', 173 ); 174 return array( 175 'ok' => false, 176 'code' => $codes[ $t->error ] ?? 'error', 177 ); 184 'no_host' => 'no_host', 185 ); 186 $out = array( 187 'ok' => false, 188 'code' => $codes[ $t->error ] ?? 'error', 189 'changed' => false, 190 ); 191 if ( 'hard_block' === $t->error ) { 192 $out['blocks'] = $t->blocks; 193 } 194 return $out; 178 195 } 179 196 $code = Constants::disableAll() ? 'armed_off' : 'armed'; // Saved, but CLONEMUTE_DISABLE_ALL keeps every guard off. … … 181 198 // Already armed for this site (a second submit of the form): keep "since" and log nothing. 182 199 return array( 183 'ok' => true, 184 'code' => $code, 200 'ok' => true, 201 'code' => $code, 202 'changed' => false, 185 203 ); 186 204 } 187 205 if ( ! self::write( $t->changes ) ) { 188 return array( 189 'ok' => false, 190 'code' => 'error', 191 ); 206 return self::failed(); 192 207 } 193 208 Runtime::clearError(); 194 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> armed', array( 'to' => 'armed' ) ); 195 return array( 196 'ok' => true, 197 'code' => $code, 209 self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> armed', 'armed', $origin ); 210 return array( 211 'ok' => true, 212 'code' => $code, 213 'changed' => true, 198 214 ); 199 215 } … … 202 218 * "This is the new production site": record the fingerprint, enable nothing. 203 219 * 204 * @return array 205 */ 206 public static function production(): array { 220 * @param string $origin Where the request came from. 221 * @return array {ok, code, changed} 222 */ 223 public static function production( string $origin = self::ORIGIN_ADMIN ): array { 207 224 $s = SettingsRepo::load(); 208 225 $snap = EnvCapture::capture( $s, false ); … … 211 228 // lock the host as production. Removing the protection is a separate, explicit step. 212 229 return array( 213 'ok' => false, 214 'code' => 'production_armed', 230 'ok' => false, 231 'code' => 'production_armed', 232 'changed' => false, 215 233 ); 216 234 } … … 218 236 if ( ! $t->ok ) { 219 237 return array( 220 'ok' => false, 221 'code' => 'error', 238 'ok' => false, 239 'code' => 'no_host', 240 'changed' => false, 222 241 ); 223 242 } … … 227 246 if ( ! $again ) { 228 247 if ( ! self::write( $t->changes ) ) { 229 return array( 230 'ok' => false, 231 'code' => 'error', 232 ); 248 return self::failed(); 233 249 } 234 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> production', array( 'to' => 'production' ));250 self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> production', 'production', $origin ); 235 251 } 236 252 Runtime::clearError(); // No guard runs on a production site: an earlier guard error no longer applies. 237 253 return array( 238 'ok' => true, 239 'code' => 'production', 254 'ok' => true, 255 'code' => 'production', 256 'changed' => ! $again, 240 257 ); 241 258 } … … 244 261 * Forget the production confirmation of this host after the host name was typed (the way back from "production"). 245 262 * 246 * @param array $post Submitted fields. 247 * @return array 248 */ 249 public static function forgetProduction( array $post ): array { 263 * @param array $post Submitted fields. 264 * @param string $origin Where the request came from. 265 * @return array {ok, code, changed} 266 */ 267 public static function forgetProduction( array $post, string $origin = self::ORIGIN_ADMIN ): array { 250 268 $s = SettingsRepo::load(); 251 269 $snap = EnvCapture::capture( $s, false ); … … 255 273 // No confirmation for this host (any more): a second submit of the form. Nothing to remove, nothing to log. 256 274 return array( 257 'ok' => true, 258 'code' => 'prod_forgotten', 275 'ok' => true, 276 'code' => 'prod_forgotten', 277 'changed' => false, 259 278 ); 260 279 } 261 280 if ( ! $t->ok ) { 262 return array( 263 'ok' => false, 264 'code' => 'host_mismatch' === $t->error ? 'arm_host' : 'error', 281 $codes = array( 282 'host_mismatch' => 'arm_host', 283 'not_production' => 'prod_none', 284 'no_host' => 'no_host', 285 ); 286 return array( 287 'ok' => false, 288 'code' => $codes[ $t->error ] ?? 'error', 289 'changed' => false, 265 290 ); 266 291 } 267 292 if ( ! self::write( $t->changes ) ) { 268 return array( 269 'ok' => false, 270 'code' => 'error', 271 ); 293 return self::failed(); 272 294 } 273 295 Runtime::clearError(); 274 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, $snap ) . ' -> ' . ( $t->changes['state'] ?? $s->state ) . ' (production confirmation removed)', array( 'to' => $t->changes['state'] ?? $s->state ) ); 275 return array( 276 'ok' => true, 277 'code' => 'prod_forgotten', 296 $to = $t->changes['state'] ?? $s->state; 297 self::logState( StateMachine::fromLabel( $s, $snap ) . ' -> ' . $to . ' (production confirmation removed)', $to, $origin ); 298 return array( 299 'ok' => true, 300 'code' => 'prod_forgotten', 301 'changed' => true, 278 302 ); 279 303 } … … 295 319 * Remove every guard at once. 296 320 * 297 * @return array 298 */ 299 public static function disarm(): array { 321 * @param string $origin Where the request came from. 322 * @return array {ok, code, changed} 323 */ 324 public static function disarm( string $origin = self::ORIGIN_ADMIN ): array { 300 325 $s = SettingsRepo::load(); 301 326 $t = StateMachine::disarm( $s, time() ); … … 303 328 // CLONEMUTE_ENV would arm the site again on the next request: report that instead of a success that does not stick. 304 329 return array( 305 'ok' => false, 306 'code' => 'disarm_const', 330 'ok' => false, 331 'code' => 'disarm_const', 332 'changed' => false, 307 333 ); 308 334 } 309 335 if ( $t->changes ) { 310 336 if ( ! self::write( $t->changes ) ) { 311 return array( 312 'ok' => false, 313 'code' => 'error', 314 ); 337 return self::failed(); 315 338 } 316 LogWriter::event( 'state_change', 'state', StateMachine::fromLabel( $s, EnvCapture::capture( $s, false ) ) . ' -> unconfirmed', array( 'to' => 'unconfirmed' ));339 self::logState( StateMachine::fromLabel( $s, EnvCapture::capture( $s, false ) ) . ' -> unconfirmed', 'unconfirmed', $origin ); 317 340 } 318 341 Runtime::clearError(); 319 342 return array( 320 'ok' => true, 321 'code' => 'disarmed', 322 ); 343 'ok' => true, 344 'code' => 'disarmed', 345 'changed' => (bool) $t->changes, 346 ); 347 } 348 349 /** 350 * Result of a write that did not stick. 351 * 352 * @return array 353 */ 354 private static function failed(): array { 355 return array( 356 'ok' => false, 357 'code' => 'error', 358 'changed' => false, 359 ); 360 } 361 362 /** 363 * Log a state change with where it came from (changes made with WP-CLI say so in the summary). 364 * 365 * @param string $summary Summary ("from -> to"). 366 * @param string $to New state. 367 * @param string $origin ORIGIN_ADMIN or ORIGIN_CLI. 368 * @return void 369 */ 370 private static function logState( string $summary, string $to, string $origin ): void { 371 $context = array( 'to' => $to ); 372 if ( self::ORIGIN_CLI === $origin ) { 373 $summary .= ' (WP-CLI)'; 374 $context['via'] = 'cli'; 375 } 376 LogWriter::event( 'state_change', 'state', $summary, $context ); 323 377 } 324 378 -
clonemute/trunk/src/Admin/Notices.php
r3828539 r3841430 85 85 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only code mapped through a whitelist. 86 86 $code = isset( $_GET['clonemute_msg'] ) ? sanitize_key( wp_unslash( $_GET['clonemute_msg'] ) ) : ''; 87 $map = array( 88 'armed' => array( 'success', __( 'Protection is on. This site is now treated as a staging site.', 'clonemute' ) ), 89 'armed_off' => array( 'warning', __( 'Saved as a staging site, but CLONEMUTE_DISABLE_ALL in wp-config.php keeps every protection off. Remove that line to turn the protections on.', 'clonemute' ) ), 90 'arm_host' => array( 'error', __( 'The host name does not match. Nothing was changed.', 'clonemute' ) ), 91 'arm_blocked' => array( 'error', __( 'Protection cannot be enabled on this site (see the reasons below). Nothing was changed.', 'clonemute' ) ), 92 'production' => array( 'success', __( 'Recorded as a production site. No protection is enabled.', 'clonemute' ) ), 93 'production_armed' => array( 'error', __( 'This site is protected as a staging site (or CLONEMUTE_ENV arms it). Remove the protection first if this really is the production site. Nothing was changed.', 'clonemute' ) ), 94 'prod_forgotten' => array( 'success', __( 'The production confirmation of this site was removed. CloneMute treats it as unconfirmed again.', 'clonemute' ) ), 95 'later' => array( 'info', __( 'OK, CloneMute will ask again the next time you log in.', 'clonemute' ) ), 96 'disarmed' => array( 'success', __( 'All protections were removed. Scheduled tasks that were paused will run again and may run in a burst.', 'clonemute' ) ), 97 'disarm_const' => array( 'error', __( 'CLONEMUTE_ENV is set to "staging" in wp-config.php, so protection would come back on the next page load. Remove that line first. Nothing was changed.', 'clonemute' ) ), 98 'test_mail_sent' => array( 'success', __( 'Test mail handed to the mail system. Check your inbox: if it arrives, mail is leaving this site.', 'clonemute' ) ), 99 'test_mail_caught' => array( 'success', __( 'CloneMute stopped the test mail: mail protection works. It is listed under the blocked events.', 'clonemute' ) ), 100 'test_mail_failed' => array( 'warning', __( 'The test mail was not sent: the server could not send it.', 'clonemute' ) ), 101 'allow_added' => array( 'success', __( 'Added to the allow list.', 'clonemute' ) ), 102 'allow_invalid' => array( 'error', __( 'That value cannot be added to an allow list.', 'clonemute' ) ), 103 'error_dismissed' => array( 'info', __( 'The error message was dismissed. No protection was changed.', 'clonemute' ) ), 104 'error' => array( 'error', __( 'Something went wrong. Nothing was changed.', 'clonemute' ) ), 105 ); 106 if ( isset( $map[ $code ] ) ) { 107 echo '<div class="notice notice-' . esc_attr( $map[ $code ][0] ) . ' is-dismissible" role="status"><p>' . esc_html( $map[ $code ][1] ) . '</p></div>'; 87 $msg = Messages::result( $code ); 88 if ( null !== $msg ) { 89 echo '<div class="notice notice-' . esc_attr( $msg[0] ) . ' is-dismissible" role="status"><p>' . esc_html( $msg[1] ) . '</p></div>'; 108 90 } 109 91 } -
clonemute/trunk/src/Env/EnvCapture.php
r3828539 r3841430 107 107 return EnvSnapshot::fromArray( 108 108 array( 109 'home_key' => HostNormalizer::homeKey( (string) ( $src['home'] ?? '' ) ),110 'stored_home_key' => HostNormalizer::homeKey( (string) ( $src['stored_home'] ?? '' ) ),111 'request_host' => HostNormalizer::requestHost( (string) ( $src['request_host'] ?? '' ) ),112 'abspath_h' => Fingerprint::abspath( (string) ( $src['abspath'] ?? '' ) ),113 'db_h' => Fingerprint::db( (string) ( $src['db'] ?? '' ) ),114 'wpdb_prefix' => (string) ( $src['wpdb_prefix'] ?? '' ),115 'env_effective' => $types['effective'],116 'env_explicit' => $types['explicit'],117 'wpstg_const' => ! empty( $src['wpstg_const'] ),118 'wpstg_option' => ! empty( $src['wpstg_option'] ),109 'home_key' => HostNormalizer::homeKey( (string) ( $src['home'] ?? '' ) ), 110 'stored_home_key' => HostNormalizer::homeKey( (string) ( $src['stored_home'] ?? '' ) ), 111 'request_host' => HostNormalizer::requestHost( (string) ( $src['request_host'] ?? '' ) ), 112 'abspath_h' => Fingerprint::abspath( (string) ( $src['abspath'] ?? '' ) ), 113 'db_h' => Fingerprint::db( (string) ( $src['db'] ?? '' ) ), 114 'wpdb_prefix' => (string) ( $src['wpdb_prefix'] ?? '' ), 115 'env_effective' => $types['effective'], 116 'env_explicit' => $types['explicit'], 117 'wpstg_const' => ! empty( $src['wpstg_const'] ), 118 'wpstg_option' => ! empty( $src['wpstg_option'] ), 119 119 'clonemute_env_const' => array_key_exists( 'clonemute_env', $src ) ? $src['clonemute_env'] : Constants::env(), 120 'baseline' => $s->baseline,121 'production' => $s->production,122 'whitelist' => $s->prod_whitelist,123 'patterns' => $patterns,120 'baseline' => $s->baseline, 121 'production' => $s->production, 122 'whitelist' => $s->prod_whitelist, 123 'patterns' => $patterns, 124 124 ) 125 125 ); -
clonemute/trunk/src/Plugin.php
r3828539 r3841430 14 14 use Rotosix\CloneMute\Admin\Pages; 15 15 use Rotosix\CloneMute\Admin\SettingsPage; 16 use Rotosix\CloneMute\Cli\Commands; 16 17 use Rotosix\CloneMute\Env\EnvCapture; 17 18 use Rotosix\CloneMute\Guard\Guard; … … 33 34 final class Plugin { 34 35 35 const VERSION = '0. 1.0';36 const VERSION = '0.2.0'; 36 37 37 38 /** … … 163 164 self::registerAdmin(); 164 165 } 166 if ( defined( 'WP_CLI' ) && WP_CLI ) { 167 Commands::register(); 168 } 165 169 if ( 'armed' !== $s->state && ! Constants::armRequested() ) { 166 170 return;
Note:
See TracChangeset
for help on using the changeset viewer.