Beispiel #1
0
 public static function initCapsule()
 {
     $credentials = Tool::getConfig()['db_settings'];
     self::$capsule = new Capsule();
     self::$capsule->addConnection($credentials);
     self::$capsule->setEventDispatcher(new Dispatcher(new Container()));
     self::$capsule->setAsGlobal();
     self::$capsule->bootEloquent();
     if (Tool::getConfig()['log_queries']) {
         self::$capsule->getEventDispatcher()->listen('illuminate.query', function ($query, $params) {
             $log = fopen(__DIR__ . '/../../../misc/illuminate_queries.log', 'a+');
             fwrite($log, date('Y/m/d H:i:s') . ' [QUERY] : ' . $query);
             fwrite($log, ' [with params ');
             $afterFirst = false;
             foreach ($params as $param) {
                 if ($afterFirst) {
                     fwrite($log, ', ');
                 }
                 fwrite($log, $param);
                 if (!$afterFirst) {
                     $afterFirst = true;
                 }
             }
             fwrite($log, "]\n");
             fclose($log);
         });
     }
 }
Beispiel #2
0
 public function sendMail($template, $to, $subject, $values, $replyTo = null)
 {
     $template = $this->renderer->loadTemplate($template);
     $values['client_url'] = Tool::getConfig()['client_url'];
     $values['subject'] = $subject;
     $mailBody = $template->render($values);
     $message = \Swift_Message::newInstance(Tool::getConfig()['msg_alerts']['subject_prefix'] . " " . $subject)->setFrom(Tool::getConfig()['msg_alerts']['from'])->setTo($to)->setBody($mailBody, 'text/html');
     if ($replyTo) {
         $message->setReplyTo($replyTo);
     }
     $this->mailer->send($message);
 }
Beispiel #3
0
 /**
  * This is used in endpoints to ask recaptcha
  * to validate a specific recaptcha response
  */
 public static function assertRecaptchaValid($recaptcha_response)
 {
     $recaptcha = new ReCaptcha(Tool::getConfig()['recaptcha_secret']);
     if (!$recaptcha->verify($recaptcha_response)->isSuccess()) {
         throw new InvalidRecaptcha();
     }
 }
Beispiel #4
0
                case 'subject':
                    if (gettype($body->contact->subject) != 'string' || strlen($body->contact->subject) > 280) {
                        throw new InvalidField('subject');
                    }
                    break;
                case 'message':
                    if (gettype($body->contact->message) != 'string' || strlen($body->contact->message) > 16000) {
                        throw new InvalidField('message');
                    }
                    break;
            }
        }
    }
    // Sending mail
    $mailer = new Mailer();
    $mailer->sendMail('user_message.html', Tool::getConfig()['msg_alerts']['local_admins'], '[MSG] ' . $body->contact->subject, ['firstname' => $body->contact->firstname, 'lastname' => $body->contact->lastname, 'email' => $body->contact->email, 'message' => $body->contact->message], [$body->contact->email => $body->contact->firstname . ' ' . $body->contact->lastname]);
    // also saving message in database
    $message = new Message();
    $message->first_name = $body->contact->firstname;
    $message->last_name = $body->contact->lastname;
    $message->email = $body->contact->email;
    $message->subject = $body->contact->subject;
    $message->message = $body->contact->message;
    $message->sent = DB::raw('NOW()');
    $message->save();
    Tool::endWithJson(["success" => true]);
});
// HTTP REST Map
$app->post('/message', $send);
$app->options('/message', function () {
});
 private function alertWatchers($plugin)
 {
     $client_url = Tool::getConfig()['client_url'];
     foreach ($plugin->watchers()->get() as $watch) {
         $user = $watch->user;
         $mailer = new Mailer();
         $mailer->sendMail('plugin_updated.html', [$user->email => $user->username], 'Plugin update "' . $plugin->name . '"', ['plugin' => $plugin, 'user' => $user, 'client_url' => Tool::getConfig()['client_url']]);
     }
 }
Beispiel #6
0
<?php

require __DIR__ . '/../api/vendor/autoload.php';
/**
 * This is the crontab script.
 */
\API\Core\DB::initCapsule();
$taskDispatcher = new \API\Core\BackgroundTasks(["plugin_max_consecutive_xml_fetch_fails" => \API\Core\Tool::getConfig()['plugin_max_consecutive_xml_fetch_fails']]);
$options = getopt('i:k:t:');
// If the user at the command line specify
// no known options, there is the default
// set of tasks that runs.
if (sizeof($options) == 0) {
    $taskDispatcher->foreachPlugin(['update', 'alert_watchers', 'alert_plugin_team_on_xml_state_change']);
    $taskDispatcher->foreachAccessToken(['delete_AT_if_expired']);
    $taskDispatcher->foreachRefreshToken(['delete_lonely_RT']);
    $taskDispatcher->foreachSession(['delete_lonely_session']);
} else {
    $key = null;
    $tasks = [];
    if (isset($options['t']) && in_array(gettype($options['t']), ['string', 'array'])) {
        $tasks = gettype($options['t']) == 'array' ? $options['t'] : [$options['t']];
    }
    if (isset($options['k']) && gettype($options['k']) == 'string') {
        $taskDispatcher->wherePluginKeyIs($options['k'], $tasks);
    } elseif (isset($options['i']) && gettype($options['i'] == 'string')) {
        $taskDispatcher->wherePluginIdIs($options['i'], $tasks);
    }
}
Beispiel #7
0
 *
 * /plugin
 * /plugin/popular
 * /plugin/trending
 * /plugin/star
 */
use API\Core\Tool;
use Illuminate\Database\Capsule\Manager as DB;
use API\Model\Message;
use ReCaptcha\ReCaptcha;
require dirname(__FILE__) . '/../../config.php';
$send = function () use($app) {
    $msg_alerts_settings = Tool::getConfig()['msg_alerts'];
    $body = Tool::getBody();
    $fields = ['firstname', 'lastname', 'email', 'subject', 'message'];
    $recaptcha = new ReCaptcha(Tool::getConfig()['recaptcha_secret']);
    $resp = $recaptcha->verify($body->recaptcha_response);
    if (!$resp->isSuccess()) {
        return Tool::endWithJson(["error" => "Recaptcha not validated"]);
    }
    foreach ($fields as $prop) {
        if (!property_exists($body->contact, $prop)) {
            return Tool::endWithJson(["error" => "Missing " . $prop]);
        }
    }
    // Preparing to send mail, making recipients string
    $recipients = '';
    $i = 0;
    foreach ($msg_alerts_settings['recipients'] as $recipient) {
        if ($i > 0) {
            $recipients .= ', ';
Beispiel #8
0
        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;
    foreach ($msg_alerts_settings['recipients'] as $recipient) {
        if ($i > 0) {
            $recipients .= ', ';
        }
        $recipients .= $recipient;
        $i++;
    }
    mail($recipients, $msg_alerts_settings['subject_prefix'] . '[PLUGIN SUBMISSION] ' . $xml->name . ' (' . $xml->key . ')', 'A new plugin "' . $xml->name . '" with key "' . $xml->key . '" has been submitted and is awaiting to be verified. It has db id #' . $plugin->id, "From: GLPI Plugins <*****@*****.**>");
    return Tool::endWithJson(["success" => true]);
};
// HTTP REST Map
$app->get('/plugin', $all);
$app->post('/plugin', $submit);
Beispiel #9
0
    $user = User::where('id', '=', $user_id)->first();
    // We ensure the recatpcha_response
    // is provided as a string
    if (!isset($body->recaptcha_response) || gettype($body->recaptcha_response) != 'string') {
        throw new InvalidRecaptcha();
    }
    // and we verify it with recaptcha
    Tool::assertRecaptchaValid($body->recaptcha_response);
    if (!isset($body->author) || gettype($body->author) != 'string' || strlen($body->author) > 90) {
        throw new InvalidField('author');
    }
    if (!($author = Author::where('name', '=', $body->author)->first())) {
        throw new ResourceNotFound('Author', $body->author);
    }
    $mailer = new Mailer();
    $mailer->sendMail('authorship_claim.html', Tool::getConfig()['msg_alerts']['local_admins'], 'User ' . $user->username . ' claim authorship', ['user' => $user->toArray(), 'author' => $author->toArray()]);
    $app->halt(200);
});
// HTTP REST Map
$app->get('/author', $all);
$app->get('/author/top', $top);
$app->get('/author/:id', $single);
$app->get('/author/:id/plugin', $author_plugins);
$app->post('/claimauthorship', $claim_authorship);
$app->options('/author', function () {
});
$app->options('/author/top', function () {
});
$app->options('/author/:id', function ($id) {
});
$app->options('/author/:id/plugin', function ($id) {
Beispiel #10
0
    $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();
    $mailer = new Mailer();
    $mailer->sendMail('plugin_submission.html', Tool::getConfig()['msg_alerts']['local_admins'], '[PLUGIN SUBMISSION] ' . $xml->name . ' (' . $xml->key . ')', ['plugin_xml' => (array) $xml]);
    Tool::endWithJson(["success" => true]);
});
// HTTP REST Map
$app->get('/plugin', $all);
$app->post('/plugin', $submit);
$app->get('/plugin/new', $new);
$app->get('/plugin/popular', $popular);
$app->get('/plugin/trending', $trending);
$app->get('/plugin/updated', $updated);
$app->get('/plugin/rss_new', $rss_new);
$app->get('/plugin/rss_updated', $rss_updated);
$app->post('/plugin/star', $star);
$app->get('/plugin/:key', $single);
$app->get('/panel/plugin/:key', $single_authormode_view);
$app->post('/panel/plugin/:key', $single_authormode_edit);