function spImportDump( $fileName, $options ) {
	$store = new SecurePoll_XMLStore( $fileName );
	$success = $store->readFile();
	if ( !$success ) {
		echo "Error reading XML dump, possibly corrupt\n";
		return false;
	}
	$electionIds = $store->getAllElectionIds();
	if ( !count( $electionIds ) ) {
		echo "No elections found to import.\n";
		return true;
	}

	$xc = new SecurePoll_Context;
	$xc->setStore( $store );
	$dbw = wfGetDB( DB_MASTER );

	# Start the configuration transaction
	$dbw->begin();
	foreach ( $electionIds as $id ) {
		$elections = $store->getElectionInfo( array( $id ) );
		$electionInfo = reset( $elections );
		$existingId = $dbw->selectField( 
			'securepoll_elections', 
			'el_entity', 
			array( 'el_title' => $electionInfo['title'] ), 
			__METHOD__, 
			array( 'FOR UPDATE' ) );
		if ( $existingId !== false ) {
			if ( $options['replace'] ) {
				spDeleteElection( $existingId );
				$success = spImportConfiguration( $store, $electionInfo );
			} elseif ( $options['update-msgs'] ) {
				# Do the message update and move on to the next election
				$success = spUpdateMessages( $store, $electionInfo );
			} else {
				echo "Conflicting election title found \"{$electionInfo['title']}\"\n";
				echo "Use --replace to replace the existing election.\n";
				$success = false;
			}
		} elseif ( $options['update-msgs'] ) {
			echo "Cannot update messages: election \"{$electionInfo['title']}\" not found.\n";
			echo "Import the configuration first, without the --update-msgs switch.\n";
			$success = false;
		} else {
			$success = spImportConfiguration( $store, $electionInfo );
		}
		if ( !$success ) {
			$dbw->rollback();
			return false;
		}
	}
	$dbw->commit();
	return true;
}
	function convertFile( $fileName ) {
		$this->context = SecurePoll_Context::newFromXmlFile( $fileName );
		if ( !$this->context ) {
			spFatal( "Unable to parse XML file \"$fileName\"" );
		}
		$electionIds = $this->context->getStore()->getAllElectionIds();
		if ( !count( $electionIds ) ) {
			spFatal( "No elections found in XML file \"$fileName\"" );
		}
		$electionId = reset( $electionIds );
		$this->election = $this->context->getElection( reset( $electionIds ) );
		$this->convert( $electionId );
	}
EOT;

if ( !isset( $options['name'] ) && !isset( $args[0] ) ) {
	spFatal( $usage );
}

if ( !class_exists( 'SecurePoll_Context' ) ) {
	if ( isset( $options['name'] ) ) {
		spFatal( "Cannot load from database when SecurePoll is not installed" );
	}
	require( dirname( __FILE__ ) . '/../SecurePoll.php' );
}

$context = new SecurePoll_Context;
if ( !isset( $options['name'] ) ) {
	$context = SecurePoll_Context::newFromXmlFile( $args[0] );
	if ( !$context ) {
		spFatal( "Unable to parse XML file \"{$args[0]}\"" );
	}
	$electionIds = $context->getStore()->getAllElectionIds();
	if ( !count( $electionIds ) ) {
		spFatal( "No elections found in XML file \"{$args[0]}\"" );
	}
	$election = $context->getElection( reset( $electionIds ) );
} else {
	$election = $context->getElectionByTitle( $options['name'] );
	if ( !$election ) {
		spFatal( "The specified election does not exist." );
	}
}
	/**
	 * Show a tally of the results in the uploaded file
	 */
	function submitUpload() {
		global $wgOut;
		if ( !isset( $_FILES['tally_file'] )
			|| !is_uploaded_file( $_FILES['tally_file']['tmp_name'] ) 
			|| !$_FILES['tally_file']['size'] )
		{
			$wgOut->addWikiMsg( 'securepoll-no-upload' );
			return;
		}
		$context = SecurePoll_Context::newFromXmlFile( $_FILES['tally_file']['tmp_name'] );
		if ( !$context ) {
			$wgOut->addWikiMsg( 'securepoll-dump-corrupt' );
			return;
		}
		$electionIds = $context->getStore()->getAllElectionIds();
		$election = $context->getElection( reset( $electionIds ) );

		$status = $election->tally();
		if ( !$status->isOK() ) {
			$wgOut->addWikiText( $status->getWikiText( 'securepoll-tally-upload-error' ) );
			return;
		}
		$tallier = $status->value;
		$wgOut->addHTML( $tallier->getHtmlResult() );
	}
if ( !class_exists( 'SecurePoll_RemoteMWAuth' ) ) {
	header( 'HTTP/1.1 500 Internal Server Error' );
	echo "SecurePoll is disabled.\n";
	exit( 1 );
}

header( 'Content-Type: application/vnd.php.serialized; charset=utf-8' );

$token = $wgRequest->getVal( 'token' );
$id = $wgRequest->getInt( 'id' );
if ( is_null( $token ) || !$id ) {
	echo serialize( Status::newFatal( 'securepoll-api-invalid-params' ) );
	exit;
}

$user = User::newFromId( $id );
if ( !$user ) {
	echo serialize( Status::newFatal( 'securepoll-api-no-user' ) );
	exit;
}
$token2 = SecurePoll_RemoteMWAuth::encodeToken( $user->getToken() );
if ( $token2 !== $token ) {
	echo serialize( Status::newFatal( 'securepoll-api-token-mismatch' ) );
	exit;
}
$context = new SecurePoll_Context;
$auth = $context->newAuth( 'local' );
$status = Status::newGood( $auth->getUserParams( $user ) );
echo serialize( $status );

Beispiel #6
0
require( dirname(__FILE__).'/cli.inc' );

$usage = <<<EOT
Usage: php dump.php [options...] <election name>
Options:
    -o <outfile>                Output to the specified file
    --votes                     Include vote records
    --all-langs                 Include messages for all languages instead of just the primary
    --jump                      Produce a configuration dump suitable for setting up a jump wiki
EOT;

if ( !isset( $args[0] ) ) {
	spFatal( $usage );
}

$context = new SecurePoll_Context;
$election = $context->getElectionByTitle( $args[0] );
if ( !$election ) {
	spFatal( "There is no election called \"$args[0]\"" );
}

if ( !isset( $options['o'] ) ) {
	$fileName = '-';
} else {
	$fileName = $options['o'];
}
if ( $fileName === '-' ) {
	$outFile = STDOUT;
} else {
	$outFile = fopen( $fileName, 'w' );
}