Esempio n. 1
0
 /**
  * get a combination of the configured destinations as well as the automated post
  * location, such as solarSystem and involved entities
  * @param array $kill
  * @return string[]
  */
 private static function getDestinations(array $kill)
 {
     $destinations = array();
     $destinations[] = '/topic/location.solarsystem.' . $kill['solarSystemID'];
     // victim
     if ($kill['victim']['characterID'] > 0) {
         $destinations[] = '/topic/involved.character.' . $kill['victim']['characterID'];
     }
     if ($kill['victim']['corporationID'] > 0) {
         $destinations[] = '/topic/involved.corporation.' . $kill['victim']['corporationID'];
     }
     if ($kill['victim']['factionID'] > 0) {
         $destinations[] = '/topic/involved.faction.' . $kill['victim']['factionID'];
     }
     if ($kill['victim']['allianceID'] > 0) {
         $destinations[] = '/topic/involved.alliance.' . $kill['victim']['allianceID'];
     }
     // attackers
     foreach ($kill['attackers'] as $attacker) {
         if ($attacker['characterID'] > 0) {
             $destinations[] = '/topic/involved.character.' . $attacker['characterID'];
         }
         if ($attacker['corporationID'] > 0) {
             $destinations[] = '/topic/involved.corporation.' . $attacker['corporationID'];
         }
         if ($attacker['factionID'] > 0) {
             $destinations[] = '/topic/involved.faction.' . $attacker['factionID'];
         }
         if ($attacker['allianceID'] > 0) {
             $destinations[] = '/topic/involved.alliance.' . $attacker['allianceID'];
         }
     }
     $destinations = array_merge($destinations, \King23\Core\Registry::getInstance()->stomp['destination_post']);
     return $destinations;
 }
Esempio n. 2
0
 public function registerForm($request)
 {
     if (isset($_POST['XSRF'])) {
         if (\Kingboard\Lib\Form::getXSRFToken() == $_POST['XSRF']) {
             if (!isset($_POST['passwd']) || !isset($_POST['passwd2']) || !isset($_POST['login'])) {
                 $this->_context['registration_failed'] = 'Please fill in all fields';
             } elseif ($_POST['passwd'] != $_POST['passwd2']) {
                 $this->_context['registration_failed'] = 'both Password fields need to have the same value';
             } elseif (!is_null(\Kingboard\Model\User::findOne(array('username' => $_POST['login'])))) {
                 $this->_context['registration_failed'] = 'email/login allready in use';
             } elseif (!\Kingboard\Lib\Form::isEmail($_POST['login'])) {
                 $this->_context['registration_failed'] = 'not a valid email adresse';
             } else {
                 $validationCode = sha1(time() . $_POST['login']);
                 $user = new \Kingboard\Model\User();
                 $user->username = $_POST['login'];
                 $user->password = hash('sha256', $_POST['passwd']);
                 $user->status = \Kingboard\Model\User::STATUS_NEW;
                 $user->validationCode = $validationCode;
                 $user->save();
                 $body = file_get_contents(APP_PATH . '/templates/mails/verify_email.html');
                 $body = strtr($body, array("{{username}}" => $_POST['login'], "{{hostname}}" => \King23\Core\Registry::getInstance()->baseHost, "{{activationkey}}" => $validationCode));
                 $headers = "From: " . \King23\Core\Registry::getInstance()->sendFromEmail . "\r\n";
                 $headers .= "Reply-To: " . \King23\Core\Registry::getInstance()->sendFromEmail . "\r\n";
                 $headers .= "X-Mailer: PHP/" . phpversion();
                 mail($_POST['login'], "Kingboard Activation", $body, $headers);
                 $this->redirect('/');
             }
         } else {
             $this->_context['registration_failed'] = 'XSRF Token Invalid.';
         }
     }
     return $this->render('user/registration.html', $_POST);
 }
Esempio n. 3
0
 /**
  * read the config and create stomp object according to config
  */
 public function __construct()
 {
     $reg = \King23\Core\Registry::getInstance();
     $this->user = $reg->stomp["user"];
     $this->password = $reg->stomp["passwd"];
     $this->url = $reg->stomp["url"];
     $this->stomp = new \Stomp($this->url, $this->user, $this->password);
 }
Esempio n. 4
0
 /**
  * Experimental task to enable kill processing from queue.
  * @param array $options
  */
 public function stomp_process_queue(array $options)
 {
     $this->cli->header("Starting Stomp Import");
     $reg = Registry::getInstance();
     $log = $reg->getLogger();
     $stompcfg = $reg->stomp;
     if (is_null($stompcfg) || !is_array($stompcfg)) {
         $this->cli->error("stomp is not configured, see config.php for details");
         $log->critical("stomp not configured, exiting");
         return;
     }
     $stomp = new \Stomp($stompcfg['url'], $stompcfg['user'], $stompcfg['passwd']);
     // destination has the destination topic (for example /topic/kills)
     $destination = $reg->stomp['destination_read'];
     // we subscribe with additional parameters
     $stomp->subscribe($destination, array("id" => $reg->stomp['dsub_id'], "persistent" => "true", "ack" => "client", "prefetch-count" => 1));
     while (true) {
         try {
             if (!$stomp->hasFrame()) {
                 continue;
             }
             $frame = $stomp->readFrame();
             if ($frame) {
                 $log->debug("received frame with message-id: " . $frame->headers['message-id']);
                 $killdata = json_decode($frame->body, true);
                 $existing = Kill::getByKillId($killdata["killID"]);
                 if (!is_null($existing)) {
                     $log->debug($frame->headers['message-id'] . '::' . $killdata["killID"] . " kill by killID exists");
                     $stomp->ack($frame);
                     continue;
                 }
                 try {
                     $apiParser = new EveAPI();
                     $apiParser->parseKill($killdata);
                     $log->debug($frame->headers['message-id'] . '::' . $killdata["killID"] . " saved");
                     $stomp->ack($frame);
                 } catch (\Exception $e) {
                     $log->error($frame->headers['message-id'] . "could not be saved, exception: " . $e->getMessage());
                 }
             }
         } catch (\StompException $e) {
             $log->error("there was some kind of error with stomp: " . $e->getMessage());
             $log->info("going to sleep for 10, retrying then");
             // we have a stomp exception here most likely that means that the server died.
             // so we are going to sleep for a bit and retry
             sleep(10);
             // replace stomp connection by new one
             // @todo: check if that might cause open connections not to close over time
             unset($stomp);
             $stomp = new \Stomp($stompcfg['url'], $stompcfg['user'], $stompcfg['passwd']);
             $stomp->subscribe($destination, array("id" => $reg->stomp['dsub_id'], "persistent" => "true", "ack" => "client", "prefetch-count" => 1));
             $log->info("stomp process retrying");
         }
     }
 }
Esempio n. 5
0
 public function background(array $params)
 {
     $backgrounds = Registry::getInstance()->assets['backgrounds'];
     $dt = new \DateTime();
     $dt->setTime(date("H"), 0, 0);
     srand($dt->getTimestamp());
     $asset = new \Assetic\Asset\FileAsset($backgrounds[rand(0, count($backgrounds) - 1)]);
     header('Content-Type: image/jpeg');
     header("Cache-Control: public, max-age=3600, s-max-age=1800");
     echo $asset->dump();
     return true;
 }
Esempio n. 6
0
 /**
  * this method is the one that should be called when the
  * user returns from the OAuth2 Provider, and will use the auth class set
  * in config to process the data
  * @param array $params should contain one key named key, identifying which key from the config to use for this provider
  * @return string
  */
 public function callback(array $params)
 {
     if ($_GET['state'] != \Kingboard\Lib\Form::getXSRFToken()) {
         return $this->error("XSRF Token mismatch");
     }
     try {
         $config = \King23\Core\Registry::getInstance()->oAuth2ProviderList[$params["key"]];
         $class = $config['auth_class'];
         $class::login($config);
         $this->redirect("/account/");
     } catch (\Exception $e) {
         $this->_context['login_failed'] = $e->getMessage();
         return $this->login($params);
     }
 }
Esempio n. 7
0
 /**
  * constructor, should be called by all derived views
  * will cause redirect if $loginrequired and not logged in
  * @param bool $loginrequired
  */
 public function __construct($loginrequired = false)
 {
     if (isset($_COOKIE['PHPSESSID'])) {
         session_start();
     }
     if ($loginrequired && !Auth::isLoggedIn()) {
         session_start();
         $this->redirect("/login");
     }
     parent::__construct();
     $reg = Registry::getInstance();
     $this->_context['images'] = $reg->imagePaths;
     $this->_context['baseHost'] = $reg->baseHost;
     $this->_context['disqus'] = $reg->disqus;
     // ownerID, if this is an owned board, this should be filled, for public boards this needs to be false
     $this->_context['ownerID'] = $reg->ownerID;
     // ownerType, if this is an owned board, this should be filled, for public boards this doesn't matter
     $this->_context['ownerType'] = $reg->ownerType;
     // when user is logged in we provide user object to all pages, false otherwise
     $this->_context['user'] = Auth::getUser();
     // make sure all views have the XSRF Token available
     $this->_context['XSRF'] = Form::getXSRFToken();
     // Global Kingboard information
     // pass version information
     $this->_context['Kingboard']['Version'] = Kingboard::VERSION;
     // ownerName, use Kingboard if not set
     if (!is_null($reg->ownerName) && $reg->ownerName) {
         $this->_context['Kingboard']['Name'] = $reg->ownerName;
     } else {
         $this->_context['Kingboard']['Name'] = Kingboard::NAME;
     }
     // release name
     $this->_context['Kingboard']['ReleaseName'] = Kingboard::RELEASE_NAME;
     // pick bootstrap theme path from public/css/themes folder
     $this->_context['theme'] = !is_null($reg->theme) ? $reg->theme : "default";
     // set header image, fall back to default if non configured
     $this->_context['header_image'] = !is_null($reg->headerImage) ? $reg->headerImage : "/images/banner/kingboard.png";
     $debugbar = $reg->debugbar;
     if (!is_null($debugbar)) {
         $jsrenderer = new JavascriptRenderer($debugbar, '/DebugBar');
         $this->_context['debugbar_header'] = $jsrenderer->renderhead();
         $this->_context['debugbar'] = $jsrenderer->render();
     }
     // ingame browser check
     $this->_context['igb'] = $this->isIGB();
 }
Esempio n. 8
0
 /**
  * Login the current user
  * @static
  * @param string $username
  * @param string $password
  * @return bool|\Kingboard\Model\User
  */
 public static function login($username, $password)
 {
     try {
         $reg = \King23\Core\Registry::getInstance();
         $host = $reg->authJabberHost;
         $port = $reg->authJabberPort;
         $domain = !is_null($reg->authJabberDomain) ? $reg->authJabberDomain : $reg->authJabberHost;
         $xmpphp = \Wrapper\XMPPHP\XMPPHPWrapper::getXMPPHP($host, $port, $username, $password, "Kingboard", $domain);
         $xmpphp->connect();
         $xmpphp->processUntil('session_start');
         $xmpphp->disconnect();
         if (!($user = \Kingboard\Model\User::findOne(array('username' => $username)))) {
             $user = new \Kingboard\Model\User();
             $user->username = $username;
             $user->save();
         }
         $_SESSION["Kingboard_Auth"] = array("User" => $user);
         return $_SESSION["Kingboard_Auth"]["User"];
     } catch (\Exception $e) {
         // just skip the error, we'll return false
     }
     return false;
 }
Esempio n. 9
0
<?php

/**
 * Kingboards King23 Routing configuration, usually you should not need to touch this.
 */
// basic router configuration
$router = \King23\Core\Router::getInstance();
$router->setBaseHost(\King23\Core\Registry::getInstance()->baseHost);
// home
$router->addRoute("/", 'Kingboard\\Views\\Homepage', "newIndex", array());
//$router->addRoute("/", 'Kingboard\Views\Date', 'index', array('date', 'page'));
$router->addRoute("/top/value", 'Kingboard\\Views\\Homepage', 'topValue');
$router->addRoute("/top/killer", 'Kingboard\\Views\\Homepage', 'topKiller');
$router->addRoute("/top/loser", 'Kingboard\\Views\\Homepage', 'topLoser');
// information
$router->addRoute("/information", 'Kingboard\\Views\\Information', "index");
// assetic
$router->addRoute("/assets/js/", 'Kingboard\\Views\\Assetic', "js");
$router->addRoute("/assets/css/", 'Kingboard\\Views\\Assetic', "css");
$router->addRoute("/assets/fonts/", 'Kingboard\\Views\\Assetic', 'fonts', array('font'));
$router->addRoute("/assets/background/", 'Kingboard\\Views\\Assetic', 'background');
// eve information
$router->addRoute("/eveinfo/", 'Kingboard\\Views\\EveInfo', "eveItem", array('itemid'));
$router->addRoute("/day/", 'Kingboard\\Views\\Date', 'index', array('date', 'page'));
// url search
$router->addRoute('/faction/name/', 'Kingboard\\Views\\Search', "nameFaction", array("factionname"));
$router->addRoute("/pilot/name/", 'Kingboard\\Views\\Search', "namePilot", array('pilotname'));
$router->addRoute('/corporation/name/', 'Kingboard\\Views\\Search', "nameCorporation", array("corpname"));
$router->addRoute('/alliance/name/', 'Kingboard\\Views\\Search', "nameAlliance", array("alliancename"));
// corp/alliance/faction/pilot statistics
$router->addRoute("/details/", 'Kingboard\\Views\\Homepage', "killlist", array("ownerType", "ownerID", "page"));
Esempio n. 10
0
 /**
  * ensure there is an ID placed
  * @param string $id
  * @param string $charname
  * @return int
  * @throws \Exception
  */
 public function ensureEveEntityID($id, $charname)
 {
     $id = (int) $id;
     if ($id == 0) {
         if ($id = NameSearch::getEveIdByName($charname)) {
             return $id;
         }
         if (!empty($charname)) {
             Registry::getInstance()->getLogger()->debug("{$charname} not found, trying to fetch from API");
             $pheal = new Pheal();
             $result = $pheal->eveScope->typeName(array('names' => $charname))->toArray();
             if ((int) $result[0]['characterID'] > 0) {
                 return (int) $result[0]['characterID'];
             }
         }
         Registry::getInstance()->getLogger()->warning("no id found for {$charname}");
         // with an empty charname we have to assume its 0
         return 0;
         //throw new \Exception("No such characterID");
     }
     return $id;
 }
Esempio n. 11
0
 public function battle_updates(array $options)
 {
     $log = Registry::getInstance()->getLogger();
     $hours = 168;
     if (isset($options[0]) && $options[0] > 0) {
         $hours = $options[0];
     }
     $log->info("updating battles for the last {$hours} hours");
     $settings = BattleSettings::getActiveSettings($hours);
     foreach ($settings as $battleSetting) {
         $log->info("Generating battle for " . $battleSetting->_id);
         Battle::generateForSettings($battleSetting);
     }
     $log->info("done updating battles");
 }
 /**
  * setup all indexes for Kingboard
  * @param array $options
  * @return void
  */
 public function setup_indexes(array $options)
 {
     if (count($options) != 0) {
         $this->cli->error('this task takes no arguments');
         return;
     }
     $reg = \King23\Core\Registry::getInstance();
     $this->cli->message("Setting Killmail_Kill indexes");
     // Kingboard_Kill indexes
     $col = $reg->mongo['db']->Kingboard_Kill;
     /* @var \MongoCollection $col */
     // victim Names
     $col->ensureIndex(array('victim.characterName' => 1), array("name" => "v_charname"));
     // attacker Names
     $col->ensureIndex(array('attackers.characterName' => 1), array("name" => "a_charname"));
     // victim ID
     $col->ensureIndex(array('victim.characterID' => 1), array("name" => "v_charid"));
     // attacker ID
     $col->ensureIndex(array('attackers.characterID' => 1), array("name" => "a_charid"));
     // corporation victim id
     $col->ensureIndex(array('victim.corporationID' => 1), array("name" => "v_corpid"));
     // corporation attacker id
     $col->ensureIndex(array('attackers.corporationID' => 1), array("name" => "a_corpid"));
     // corporation victim name
     $col->ensureIndex(array('victim.corporationName' => 1), array("name" => "v_corpname"));
     // corporation attacker name
     $col->ensureIndex(array('attackers.corporationName' => 1), array("name" => "a_corpname"));
     // alliance victim id
     $col->ensureIndex(array('victim.allianceID' => 1), array("name" => "v_alliid"));
     // alliance attacker id
     $col->ensureIndex(array('attackers.allianceID' => 1), array("name" => "a_alliid"));
     // alliance victim name
     $col->ensureIndex(array('victim.allianceName' => 1), array("name" => "v_alliname"));
     // alliance attacker name
     $col->ensureIndex(array('attackers.allianceName' => 1), array("name" => "a_alliname"));
     // faction victim id
     $col->ensureIndex(array('victim.factionID' => 1), array("name" => "v_factid"));
     // faction attacker id
     $col->ensureIndex(array('attackers.factionID' => 1), array("name" => "a_factid"));
     // faction victim name
     $col->ensureIndex(array('victim.factionName' => 1), array("name" => "v_factname"));
     // faction attacker name
     $col->ensureIndex(array('attackers.factionName' => 1), array("name" => "a_factname"));
     // indexes for the battle queries
     // battle kills
     $col->ensureIndex(array('killTime' => 1, 'location.solarSystem' => 1, 'attackers.corporationID' => 1, 'attackers.allianceID' => 1, 'victim.corporationID' => 1, 'victim.allianceID' => 1), array('name' => 'battlequeries'));
     // battle losses
     $col->ensureIndex(array('killTime' => 1, 'location.solarSystem' => 1, 'victim.corporationID' => 1, 'victim.allianceID' => 1), array('name' => 'battlelosses'));
     // kill datail indexes
     $col->ensureIndex(array('involvedCorporations' => 1, 'killTime' => -1), array('name' => "invcorps"));
     $col->ensureIndex(array('involvedCharacters' => 1, 'killTime' => -1), array('name' => "invchars"));
     $col->ensureIndex(array('involvedFactions' => 1, 'killTime' => -1), array('name' => "invfactions"));
     $col->ensureIndex(array('involvedAlliances' => 1, 'killTime' => -1), array('name' => "invalliances"));
     // killtime Index
     $col->ensureIndex(array('killTime' => 1), array("name" => "killtime"));
     // saved time index
     $col->ensureIndex(array('saved' => 1), array("name" => "savedi"));
     // location.solarSystem
     $col->ensureIndex(array('location.solarSystem' => 1), array("name" => "systemname"));
     $col->ensureIndex(array('killID' => 1), array("name" => "killid", "unique" => true));
     $col->ensureIndex(array('totalISKValue' => -1), array("name" => "iskvalue"));
     $this->cli->message("Setting Killmail_EveItem indexes");
     // Kingboard_EveItem
     $col = $reg->mongo['db']->Kingboard_EveItem;
     // typeID
     $col->ensureIndex(array('typeID' => 1), array('unique' => true));
     // typeName
     $col->ensureIndex(array('typeName' => 1));
     $this->cli->message("Setting Killmail_EveSolarSystem indexes");
     // Kingboard_EveSolarSystem
     $col = $reg->mongo['db']->Kingboard_EveSolarSystem;
     // itemID
     $col->ensureIndex(array('itemID' => 1), array('unique' => true));
     // itemName
     $col->ensureIndex(array('itemName' => 1));
     // top pilots
     $this->cli->message("Setting up KillsByShipByPilot indexes");
     $col = $reg->mongo['db']->Kingboard_Kill_MapReduce_KillsByShipByPilot;
     $col->ensureIndex(array('value.total' => -1));
     $this->cli->message("Setting up LossesByShipByPilot indexes");
     $col = $reg->mongo['db']->Kingboard_Kill_MapReduce_LossesByShipByPilot;
     $col->ensureIndex(array('value.total' => -1));
     $this->cli->message("Setting up NameSearch indexes");
     $col = $reg->mongo['db']->Kingboard_Kill_MapReduce_NameSearch;
     $col->ensureIndex(array('value.id' => 1));
 }
Esempio n. 13
0
<?php

$assets = array();
$assets['css'] = array();
$assets['js'] = array();
$assets['fonts'] = array();
// css files
$assets['css'][] = APP_PATH . "/vendor/twbs/bootstrap/dist/css/bootstrap.css";
$assets['css'][] = APP_PATH . "/public/css/bootstrap_theme.css";
$assets['css'][] = APP_PATH . "/public/css/main.css";
$assets['css'][] = APP_PATH . "/public/css/datetimepicker.css";
// js files
$assets['js'][] = APP_PATH . "/vendor/frameworks/jquery/jquery.js";
$assets['js'][] = APP_PATH . "/vendor/twbs/bootstrap/dist/js/bootstrap.min.js";
//$assets['js'][] = APP_PATH . "/vendor/twitter/typeahead.js/dist/typeahead.jquery.js";
$assets['js'][] = APP_PATH . "/public/typeahead.js-0.9.3/dist/typeahead.min.js";
$assets['js'][] = APP_PATH . "/public/js/common.js";
$assets['js'][] = APP_PATH . "/public/js/bootstrap-datetimepicker.js";
$assets['fonts']["glyphicons-halflings-regular.eot"] = APP_PATH . '/vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.eot';
$assets['fonts']["glyphicons-halflings-regular.svg"] = APP_PATH . '/vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.svg';
$assets['fonts']["glyphicons-halflings-regular.ttf"] = APP_PATH . '/vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf';
$assets['fonts']["glyphicons-halflings-regular.woff"] = APP_PATH . '/vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.woff';
$assets['backgrounds'] = [];
$assets['backgrounds'][] = APP_PATH . "/public/images/background/background1.jpg";
$assets['backgrounds'][] = APP_PATH . "/public/images/background/background2.jpg";
$assets['backgrounds'][] = APP_PATH . "/public/images/background/background3.jpg";
\King23\Core\Registry::getInstance()->assets = $assets;
Esempio n. 14
0
 /**
  * get the amount of kills per page to display from the configuration
  * @return mixed
  */
 public function getKillsPerPage()
 {
     return Registry::getInstance()->killListConfig["perPage"];
 }