Ejemplo n.º 1
0
 /**
  * @param array $formData
  * @param HtmlForm $form
  *
  * @return bool|string
  * @throws DBUnexpectedError
  * @throws Exception
  * @throws MWException
  */
 public static function processInput(array $formData, HtmlForm $form)
 {
     error_reporting(0);
     global $wgCreateWikiSQLfiles, $IP;
     $DBname = $formData['dbname'];
     $founderName = $formData['founder'];
     $dbw = wfGetDB(DB_MASTER);
     $dbTest = $dbw->query('SHOW DATABASES LIKE ' . $dbw->addQuotes($DBname) . ';');
     $rows = $dbTest->numRows();
     $dbTest->free();
     if ($rows !== 0) {
         return wfMessage('createwiki-error-dbexists')->plain();
     }
     $farmerLogEntry = new ManualLogEntry('farmer', 'createandpromote');
     $farmerLogEntry->setPerformer($form->getUser());
     $farmerLogEntry->setTarget($form->getTitle());
     $farmerLogEntry->setComment($formData['comment']);
     $farmerLogEntry->setParameters(array('4::wiki' => $DBname, '5::founder' => $founderName));
     $farmerLogID = $farmerLogEntry->insert();
     $farmerLogEntry->publish($farmerLogID);
     $dbw->query('SET storage_engine=InnoDB;');
     $dbw->query('CREATE DATABASE ' . $dbw->addIdentifierQuotes($DBname) . ';');
     $dbw->selectDB($DBname);
     foreach ($wgCreateWikiSQLfiles as $file) {
         $dbw->sourceFile($file);
     }
     $dbw->insert('site_stats', array('ss_row_id' => 1));
     $dbw->close();
     // Add DNS record to cloudflare
     global $wgCreateWikiUseCloudFlare, $wgCloudFlareUser, $wgCloudFlareKey;
     if ($wgCreateWikiUseCloudFlare) {
         $domainPrefix = substr($DBname, 0, -4);
         $cloudFlare = new cloudflare_api($wgCloudFlareUser, $wgCloudFlareKey);
         $cloudFlareResult = $cloudFlare->rec_new('orain.org', 'CNAME', $domainPrefix, 'lb.orain.org');
         if (!is_object($cloudFlareResult) || $cloudFlareResult->result !== 'success') {
             wfDebugLog('CreateWiki', 'CloudFlare FAILED to add CNAME for ' . $domainPrefix . '.orain.org');
         } else {
             wfDebugLog('CreateWiki', 'CloudFlare CNAME added for ' . $domainPrefix . '.orain.org');
         }
     }
     // Create local account for founder (hack)
     $out = exec("php5 {$IP}/extensions/CentralAuth/maintenance/createLocalAccount.php " . escapeshellarg($founderName) . ' --wiki ' . escapeshellarg($DBname));
     if (!strpos($out, 'created')) {
         return wfMessage('createwiki-error-usernotcreated')->plain();
     }
     require_once "{$IP}/includes/UserRightsProxy.php";
     // Grant founder sysop and bureaucrat rights
     $founderUser = UserRightsProxy::newFromName($DBname, $founderName);
     $newGroups = array('sysop', 'bureaucrat');
     array_map(array($founderUser, 'addGroup'), $newGroups);
     $founderUser->invalidateCache();
     $form->getOutput()->addWikiMsg('createwiki-success', $DBname);
     return true;
 }
Ejemplo n.º 2
0
 //create needed entries if $entries differs from $number_of_records (initial create of zone file)
 if ($number_of_records <= $entries) {
     $difference = $number_of_records - $entries;
 }
 if ($entries < $number_of_records) {
     $difference = $number_of_records - $entries;
 }
 if ($number_of_records > $ip_array_available) {
     $difference = $number_of_records - $entries - ($number_of_records - $ip_array_available);
 }
 while ($i4 < $difference) {
     $ip_new = $ip_array[$i5]["ip"];
     $good_new = $ip_array[$i5]["good"];
     if ($good_new == 1) {
         $content_new = $ip_new;
         $write_new = $cf->rec_new($domain, $type, $name, $content_new);
     }
     //error handling if IP is already in table
     $new_response_array = get_object_vars($write_new);
     $new_response_array_retry = $new_response_array;
     while ($new_response_array_retry["msg"] == "The record already exists." && $end == false) {
         $i5++;
         //move file pointer +1
         $ip_new_retry = $ip_array[$i5]["ip"];
         $good_new_retry = $ip_array[$i5]["good"];
         if ($good_new_retry == 1) {
             $content_new_retry = $ip_new_retry;
             $write_new_retry = $cf->rec_new($domain, $type, $name, $content_new_retry);
         } else {
             //seems like no more good ips are available
             $end = true;