|mails * * Gleiche Regeln wie die Oberflaeche. Kein Befehl gibt den Text einer Mail * aus; Empfaengeradressen nur mit --with-recipients. Die Betreffzeilen stehen * in der Liste und koennen Namen oder Bestellnummern enthalten. */ if ( ! defined( 'ABSPATH' ) ) { exit; } class Wp360_Staging_Guard_Cli { /** * Zeigt den Zustand und stellt den Schutz ein. * * ## OPTIONS * * [] * : status (Standard), on, off, auto, hosts, allow oder mails. * * [] * : Host fuer "allow", z. B. api.example.com oder *.cdn.example.net. * * [--with-recipients] * : Bei "mails" auch die Empfaenger ausgeben. * * ## EXAMPLES * * wp 360-staging status * wp 360-staging on * wp 360-staging allow api.example.com * wp 360-staging hosts * wp 360-staging mails * * @param string[] $args Positionsargumente. * @param array $assoc_args Optionen. */ public function __invoke( $args, $assoc_args ) { $action = isset( $args[0] ) ? $args[0] : 'status'; switch ( $action ) { case 'status': $this->status(); break; case 'on': case 'off': case 'auto': $settings = Wp360_Staging_Guard_Settings::get(); $settings['mode'] = $action; Wp360_Staging_Guard_Settings::save( $settings ); WP_CLI::success( 'Mode set to "' . $action . '".' ); $this->status(); break; case 'hosts': $this->hosts(); break; case 'allow': if ( empty( $args[1] ) ) { WP_CLI::error( 'Please give a host: wp 360-staging allow api.example.com' ); } if ( ! Wp360_Staging_Guard_Admin_Page::apply_allow_host( $args[1] ) ) { WP_CLI::error( 'That is not a valid host name.' ); } WP_CLI::success( 'Host added to the allow list.' ); break; case 'mails': $this->mails( ! empty( $assoc_args['with-recipients'] ) ); break; default: WP_CLI::error( 'Unknown action. Use status, on, off, auto, hosts, allow or mails.' ); } } private function status() { $settings = Wp360_Staging_Guard_Settings::get(); $state = Wp360_Staging_Guard_Environment::state(); $counts = Wp360_Staging_Guard_Cron_Guard::counts(); WP_CLI::line( 'Protection: ' . ( $state['active'] ? 'active' : 'inactive' ) . ' (' . $state['reason'] . ')' ); WP_CLI::line( 'Mode: ' . $settings['mode'] ); WP_CLI::line( 'Environment: ' . $state['environment'] ); WP_CLI::line( 'This address: ' . home_url() ); WP_CLI::line( 'Live address: ' . ( '' !== $settings['live_url'] ? $settings['live_url'] : '-' ) ); WP_CLI::line( 'Notice: ' . ( $state['notice'] ? 'address differs from the live site, not protected' : 'none' ) ); WP_CLI::line( 'Mails: ' . $settings['mail_mode'] . ', ' . Wp360_Staging_Guard_Mail_Store::count() . ' caught' ); WP_CLI::line( 'Cron: ' . ( $settings['pause_cron'] ? 'paused' : 'running' ) . ', ' . $counts['due'] . ' due, ' . $counts['scheduled'] . ' scheduled' ); WP_CLI::line( 'WordPress.org: ' . ( $settings['allow_wporg'] ? 'allowed' : 'blocked' ) ); WP_CLI::line( 'noindex: ' . ( $settings['noindex'] ? 'on' : 'off' ) ); WP_CLI::line( 'Visitor lock: ' . ( $settings['lock_visitors'] ? 'on' : 'off' ) ); if ( Wp360_Staging_Guard_Plugin::is_disabled() ) { WP_CLI::warning( 'WP360_SG_DISABLE is set in wp-config.php: everything is switched off.' ); } } private function hosts() { $settings = Wp360_Staging_Guard_Settings::get(); $allowed = '' === $settings['allowed_hosts'] ? array() : explode( "\n", $settings['allowed_hosts'] ); WP_CLI::line( 'Allow list (' . count( $allowed ) . '):' ); foreach ( $allowed as $host ) { WP_CLI::line( ' ' . $host ); } $rows = Wp360_Staging_Guard_Http_Guard::log_rows(); WP_CLI::line( 'Seen (' . count( $rows ) . '):' ); foreach ( $rows as $row ) { WP_CLI::line( sprintf( ' %-40s blocked %d, allowed %d%s', $row['host'], $row['blocked'], $row['allowed'], $row['live'] ? ' [live site]' : '' ) ); } } /** * @param bool $with_recipients Auch die Empfaenger zeigen. */ private function mails( $with_recipients ) { $rows = Wp360_Staging_Guard_Mail_Store::recent( Wp360_Staging_Guard_Mail_Store::limit() ); WP_CLI::line( count( $rows ) . ' caught emails:' ); foreach ( $rows as $row ) { $line = sprintf( ' #%d %s %s', $row['id'], $row['created_at'], $row['subject'] ); if ( $with_recipients ) { $emails = array(); foreach ( $row['recipients'] as $recipient ) { if ( is_array( $recipient ) ) { $emails[] = (string) ( $recipient['email'] ?? '' ); } } $line .= ' -> ' . implode( ', ', $emails ); } WP_CLI::line( $line ); } } }