Beispiel #1
0
 public function verifyAndUpdatePlugins()
 {
     $plugins = Plugin::where('active', '=', 1)->get();
     // Going to compare checksums
     // for each of these plugins
     $n = 0;
     foreach ($plugins as $num => $plugin) {
         $n++;
         // Defaults not to update
         $update = false;
         // fetching via http
         $xml = @file_get_contents($plugin->xml_url);
         if (!$xml) {
             echo 'Plugin (' . $n . '/' . sizeof($plugins) . "): \"" . $plugin->name . "\" Cannot get XML file via HTTP, Skipping.\n";
             continue;
         }
         $crc = md5($xml);
         // compute crc
         if ($plugin->xml_crc != $crc || $plugin->name == NULL) {
             $update = true;
             // if we got
             // missing name or changing
             // crc, then we're going to
             // update that one
         } else {
             echo 'Plugin (' . $n . '/' . sizeof($plugins) . "): \"" . $plugin->name . "\" Already updated, Skipping.\n";
             continue;
         }
         // loading XML OO-style with simplemxl
         $xml = new ValidableXMLPluginDescription($xml);
         if (!$xml->isValid()) {
             echo 'Plugin (' . $n . '/' . sizeof($plugins) . "): \"" . $plugin->name . "\" Unreadable/Non validable XML, Skipping.\n";
             echo "Errors: \n";
             foreach ($xml->errors as $error) {
                 echo " - " . $error . "\n";
             }
             continue;
         }
         $xml = $xml->contents;
         echo 'Plugin (' . $n . '/' . sizeof($plugins) . '): Updating ... ';
         $this->updatePlugin($plugin, $xml, $crc);
     }
 }
 private function alertAdminsOfXMLErrors($plugin)
 {
     $errors = [];
     if ($plugin->xml_state == 'bad_xml_url') {
         $errors[] = ['reason' => 'url', 'url' => $plugin->xml_url];
     } elseif ($plugin->xml_state == 'xml_error') {
         // Reevaluating Errors with previous plain-text xml,
         // using the collectMode of ValidableXMLPluginDescription
         $xml = new ValidableXMLPluginDescription($this->currentXml, true);
         $xml->validate();
         foreach ($xml->errors as $_error) {
             $error = [];
             $error['reason'] = $_error->getInfo('reason');
             switch ($error['reason']) {
                 case 'parse':
                     $error['line'] = $_error->getInfo('line');
                     $error['errstring'] = $_error->getInfo('errstring');
                 case 'field':
                     $error['field'] = $_error->getInfo('field');
                     $error['errstring'] = $_error->getInfo('errstring');
             }
             $errors[] = $error;
         }
     } else {
         return;
     }
     $permissions = $plugin->permissions;
     foreach ($permissions as $user) {
         if ($user->pivot->admin || $user->pivot->allowed_notifications) {
             $mailer = new Mailer();
             $mailer->sendMail('xml_error.html', [$user->email], '"' . $plugin->key . '"' . ' Plugin\'s XML has turned invalid', ['errors' => $errors, 'plugin' => $plugin, 'user' => $user]);
         }
     }
 }
Beispiel #3
0
     return Tool::endWithJson(["error" => "Recaptcha not validated"]);
 }
 foreach ($fields as $prop) {
     if (!property_exists($body, $prop)) {
         return Tool::endWithJson(["error" => "Missing " . $prop]);
     }
 }
 // Quickly validating
 if (Plugin::where('xml_url', '=', $body->plugin_url)->count() > 0) {
     return Tool::endWithJson(["error" => "That plugin XML URL has already been submitted."]);
 }
 $xml = @file_get_contents($body->plugin_url);
 if (!$xml) {
     return Tool::endWithJson(["error" => "We cannot fetch that URL."]);
 }
 $xml = new ValidableXMLPluginDescription($xml);
 if (!$xml->isValid()) {
     return Tool::endWithJson(["error" => "Unreadable/Non validable XML.", "details" => $xml->errors]);
 }
 $xml = $xml->contents;
 if (Plugin::where('key', '=', $xml->key)->count() > 0) {
     return Tool::endWithJson(["error" => "Your XML describe a plugin whose key already exists in our database."]);
 }
 $plugin = new Plugin();
 $plugin->xml_url = $body->plugin_url;
 $plugin->date_added = DB::raw('NOW()');
 $plugin->active = false;
 $plugin->save();
 $msg_alerts_settings = Tool::getConfig()['msg_alerts'];
 $recipients = '';
 $i = 0;
Beispiel #4
0
 $resp = $recaptcha->verify($body->recaptcha_response);
 if (!$resp->isSuccess()) {
     throw new InvalidRecaptcha();
 }
 if (!isset($body->plugin_url) || gettype($body->plugin_url) != 'string') {
     throw new InvalidField('plugin_url');
 }
 // Quickly validating
 if (Plugin::where('xml_url', '=', $body->plugin_url)->count() > 0) {
     throw new UnavailableName('XML_URL', $body->plugin_url);
 }
 $xml = @file_get_contents($body->plugin_url);
 if (!$xml) {
     throw new InvalidXML('url', $body->plugin_url);
 }
 $xml = new ValidableXMLPluginDescription($xml);
 $xml->validate();
 $xml = $xml->contents;
 if (Plugin::where('key', '=', $xml->key)->count() > 0) {
     throw new UnavailableName('Plugin', $xml->key);
 }
 $plugin = new Plugin();
 $plugin->xml_url = $body->plugin_url;
 $plugin->date_added = DB::raw('NOW()');
 $plugin->active = false;
 $plugin->download_count = 0;
 $plugin->save();
 $plugin->permissions()->attach($user);
 $user = $plugin->permissions()->where('user_id', '=', $user->id)->first();
 $user->pivot['admin'] = true;
 $user->pivot->save();