Skip to content

Instantly share code, notes, and snippets.

@Inquisitor-Sasha
Last active December 27, 2015 20:09
Show Gist options
  • Save Inquisitor-Sasha/7381941 to your computer and use it in GitHub Desktop.
Save Inquisitor-Sasha/7381941 to your computer and use it in GitHub Desktop.
Script concepts for creating a new wiki using Simple Farm.
<?php
# Inquisitor Ehrenstein
# [email protected]
# GNU General Public License
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
die( -1 );
}
// This is the prefix used for database names for the wiki farm
$dbprefix = ''; // This prefix is for the name of the database, not for the tables!
// Database user that can create databases
$dbcreateUser = ''; // For security, this is all that this user should be able to do; do not use root!
$dbcreateUserPassword = ''; // Password of this user
// Get the information about the new wiki from the form
$wikiName = $_POST['wikiName'];
$userName = $_POST['userName'];
$userPass = $_POST['userPass'];
$wikiDomain = $_POST['wikiDomain'];
// Convert the wiki domain string to lowercase with first capital letter for use as the database name
$wikiDomain = ucfirst(strtolower($wikiDomain));
$wikiName = escapeshellcmd($wikiName);
$userName = escapeshellcmd($userName);
$userPass = escapeshellcmd($userPass);
rename('LocalSettings.php','LocalSettings1.php');
shell_exec('WIKI='.$dbprefix,$wikiName.' php maintenance/install.php '.$wikiName.' '.$userName.' --pass='.$userPass.' --dbname='.$dbprefix,$wikiName.' --dbprefix='.$wgDBprefix.' --dbuser='.$wgDBuser.' --dbpass='.$wgDBpassword.'');
unlink('LocalSettings.php');
rename('LocalSettings1.php','LocalSettings.php');
?>
@Southparkfan
Copy link

POSSIBLE SECURITY FLAW ALERT:

Per http://php.net/manual/en/function.escapeshellcmd.php it seems escapeshellarg should be used, or:

$escapedshellcmd = escapeshellcmd('WIKI='.$dbprefix,$wikiName.' php maintenance/install.php '.$wikiName.' '.$userName.' --pass='.$userPass.' --dbname='.$dbprefix,$wikiName.' --dbprefix='.$wgDBprefix.'  --dbuser='.$wgDBuser.' --dbpass='.$wgDBpassword.'');

shell_exec($escapedshellcmd);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment