Exemplo n.º 1
0
 public function handle()
 {
     $token = Seat::get('slack_token');
     if ($token == null) {
         throw new SlackSettingException("missing slack_token in settings");
     }
     // get members list from slack team
     $api = new SlackApi($token);
     $members = $api->members();
     // iterate over each member, check if the user mail match with a seat account and update the relation table
     foreach ($members as $m) {
         if ($m['id'] != 'USLACKBOT' && $m['deleted'] == false && $m['is_bot'] == false && !key_exists('api_app_id', $m['profile'])) {
             $user = User::where('email', '=', $m['profile']['email'])->first();
             if ($user != null) {
                 $slackUser = SlackUser::find($user->id);
                 if ($slackUser == null) {
                     $slackUser = new SlackUser();
                     $slackUser->user_id = $user->id;
                     $slackUser->invited = true;
                 }
                 $slackUser->slack_id = $m['id'];
                 $slackUser->save();
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Checks if the administrative contact has been
  * configured
  *
  * @return bool
  */
 public function hasDefaultAdminContact()
 {
     if (Seat::get('admin_contact') === '*****@*****.**') {
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * @expectedException Seat\Slackbot\Exceptions\SlackSettingException
  */
 public function testTokenException()
 {
     // pre test
     Seat::set('slack_token', '');
     // test
     $job = new SlackChannelsUpdate();
     $job->handle();
 }
Exemplo n.º 4
0
 /**
  * Redirect the user to the Eve Online authentication page.
  *
  * @param \Laravel\Socialite\Contracts\Factory $social
  *
  * @return \Seat\Web\Http\Controllers\Auth\Response
  */
 public function redirectToProvider(Socialite $social)
 {
     // Prevent dropping into this route is SSO
     // is disabled.
     if (Seat::get('allow_sso') !== 'yes') {
         abort(404);
     }
     return $social->driver('eveonline')->redirect();
 }
Exemplo n.º 5
0
 /**
  * Set the Slack token API
  *
  * @throws \Seat\Slackbot\Exceptions\SlackSettingException
  */
 public function call()
 {
     // load token and team uri from settings
     $token = Seat::get('slack_token');
     if ($token == null) {
         throw new SlackSettingException("missing slack_token in settings");
     }
     $this->slackApi = new SlackApi($token);
 }
Exemplo n.º 6
0
 /**
  * @param \Seat\Web\Http\Validation\SeatSettings $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postUpdateSettings(SeatSettings $request)
 {
     Seat::set('registration', $request->registration);
     Seat::set('admin_contact', $request->admin_contact);
     Seat::set('force_min_mask', $request->force_min_mask);
     Seat::set('min_character_access_mask', $request->min_character_access_mask);
     Seat::set('min_corporation_access_mask', $request->min_corporation_access_mask);
     Seat::set('allow_sso', $request->allow_sso);
     Seat::set('allow_tracking', $request->allow_tracking);
     return redirect()->back()->with('success', 'SeAT settings updated!');
 }
Exemplo n.º 7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->line('SeAT Admin Email Set Tool');
     $this->info('The current admin email is: ' . Seat::get('admin_contact'));
     $this->question('Please enter the new administrator email address:');
     $email = $this->ask('Email: ');
     while (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         // invalid email address
         $this->error($email . ' is not a valid email. Please try again:');
         $email = $this->ask('Email: ');
     }
     $this->info('Setting the administrator email to: ' . $email);
     Seat::set('admin_contact', $email);
 }
Exemplo n.º 8
0
 public function handle()
 {
     $token = Seat::get('slack_token');
     if ($token == null) {
         throw new SlackSettingException("missing slack_token in settings");
     }
     // init Slack Api using token
     $api = new SlackApi($token);
     // make a call in order to fetch both public and private channels
     $channels = array_merge($api->channels(false), $api->channels(true));
     $slackChannelIds = [];
     // iterate over each slack channel and create or update information from SeAT
     foreach ($channels as $channel) {
         // init channels ids array which will be used later in order to remove outdate channels
         $slackChannelIds[] = $channel['id'];
         // init flags to default value
         $isGroup = true;
         $isGeneral = false;
         // try to get channel object from SeAT
         $slackChannel = SlackChannel::find($channel['id']);
         // Determine if this is a group (private channel) or a channel
         if (substr($channel['id'], 0, 1) === 'C') {
             $isGroup = false;
         }
         if ($isGroup == false) {
             $isGeneral = (bool) $channel['is_general'];
         }
         // create the channel if it doesn't exist
         if ($slackChannel == null) {
             SlackChannel::create(['id' => $channel['id'], 'name' => $channel['name'], 'is_group' => $isGroup, 'is_general' => $isGeneral]);
             continue;
         }
         // update the channel if it is already known by SeAT
         $slackChannel->update(['name' => $channel['name'], 'is_general' => $isGeneral]);
     }
     // get all known channels from SeAT
     SlackChannel::whereNotIn('id', $slackChannelIds)->delete();
     /*
     // iterate over each of them and check if they are still valid
     // if not, we will remove them from the database since they are no longer usable
     foreach ($seatChannels as $channel) {
         if (in_array($channel->id, $slackChannelIds) == false) {
             $channel->delete();
         }
     }
     */
 }
Exemplo n.º 9
0
 /**
  *
  * @return \Illuminate\View\View
  */
 public function getHome()
 {
     // Warn if the admin contact has not been set yet.
     if (auth()->user()->hasSuperUser()) {
         if (Seat::get('admin_contact') === '*****@*****.**') {
             session()->flash('warning', trans('web::seat.admin_contact_warning'));
         }
     }
     // Check for the default EVE SSO generated email.
     if (str_contains(auth()->user()->email, '@seat.local')) {
         session()->flash('warning', trans('web::seat.sso_email_warning'));
     }
     $server_status = $this->getEveLastServerStatus();
     $total_character_isk = $this->getTotalCharacterIsk();
     $total_character_skillpoints = $this->getTotalCharacterSkillpoints();
     $total_character_killmails = $this->getTotalCharacterKillmails();
     $newest_mail = $this->getAllCharacterNewestMail();
     return view('web::home', compact('server_status', 'total_character_isk', 'total_character_skillpoints', 'total_character_killmails', 'newest_mail'));
 }
Exemplo n.º 10
0
 /**
  * Set the configuration parameters for Pheal
  */
 public function __construct()
 {
     // Just return the instance if we have already
     // configured it
     if ($this->instance !== null) {
         return $this->instance;
     }
     // Get a Pheal 'instance'
     $config = Config::getInstance();
     // Configure Pheal
     $config->access = new EveApiAccess();
     $config->cache = new HashedNameFileStorage(config('eveapi.config.pheal.cache_path'));
     $config->log = new PsrLogger($this->getPhealLogger());
     $config->fetcher = app('Pheal\\Fetcher\\Guzzle');
     $config->api_customkeys = true;
     $config->http_timeout = 60;
     // Compile a user-agent string
     $config->http_user_agent = 'eveseat/' . config('eveapi.config.version') . ' ' . Seat::get('admin_contact');
     // Set the instance
     $this->instance = $config;
     return $this->instance;
 }
Exemplo n.º 11
0
 /**
  * @param \Seat\Web\Validation\SeatSettings $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postUpdateSettings(SeatSettings $request)
 {
     Seat::set('registration', $request->registration);
     Seat::set('admin_contact', $request->admin_contact);
     return redirect()->back()->with('success', 'SeAT settings updated!');
 }
Exemplo n.º 12
0
 private function restoreGroup($groupId)
 {
     // load token and team uri from settings
     $token = Seat::get('slack_token');
     if ($token == null) {
         throw new SlackSettingException("missing slack_token in settings");
     }
     $slackApi = new SlackApi($token);
     $apiGroup = $slackApi->info($groupId, true);
     SlackChannel::create(['id' => $apiGroup['id'], 'name' => $apiGroup['name'], 'is_group' => true]);
 }
Exemplo n.º 13
0
 /**
  * Handle the calling of the required function to
  * update the EVE SDE data.
  */
 public function handle()
 {
     // Start by warning the user about the command that will be run
     $this->comment('Warning! This Laravel command uses exec() to execute a ');
     $this->comment('mysql shell command to import an extracted dump. Due');
     $this->comment('to the way the command is constructed, should someone ');
     $this->comment('view the current running processes of your server, they ');
     $this->comment('will be able to see your SeAT database users password.');
     $this->line('');
     $this->line('Ensure that you understand this before continuing.');
     // Test that we have valid Database details. An exception
     // will be thrown if this fails.
     DB::connection()->getDatabaseName();
     if (!$this->confirm('Are you sure you want to update to the latest EVE SDE?', true)) {
         $this->warn('Exiting');
         return;
     }
     // Request the json from eveseat/resources
     $this->json = $this->getJsonResource();
     // Ensure we got a response, else fail.
     if (!$this->json) {
         $this->warn('Unable to reach the resources endpoint.');
         return;
     }
     // Check if we should attempt getting the
     // version string locally
     if ($this->option('local')) {
         $version_number = env('SDE_VERSION', null);
         if (!is_null($version_number)) {
             $this->comment('Using locally sourced version number of: ' . $version_number);
             $this->json->version = env('SDE_VERSION');
         } else {
             $this->warn('Unable to determine the version number override. ' . 'Using remote version: ' . $this->json->version);
         }
     }
     // Avoid an existing SDE to be accidentally installed again
     // except if the user explicitly ask for it
     if ($this->json->version == Seat::get('installed_sde') && $this->option('force') == false) {
         $this->warn('You are already running the latest SDE version.');
         $this->warn('If you want to install it again, run this command with --force argument.');
         return;
     }
     // Ask for a confirmation before installing an existing SDE version
     if ($this->option('force') == true) {
         $this->warn('You will re-download and install the current SDE version.');
         if (!$this->confirm('Are you sure ?', true)) {
             $this->info('Nothing has been updated.');
             return;
         }
     }
     //TODO: Allow for tables to be specified in config file
     // Show a final confirmation with some info on what
     // we are going to be doing.
     $this->info('The local SDE data will be updated to ' . $this->json->version);
     $this->info(count($this->json->tables) . ' tables will be updated: ' . implode(', ', $this->json->tables));
     $this->info('Download format will be: ' . $this->json->format);
     $this->line('');
     $this->info('The SDE will be imported to mysql://' . config('database.connections.mysql.username') . '@' . config('database.connections.mysql.host') . '/' . config('database.connections.mysql.database'));
     if (!$this->confirm('Does the above look OK?', true)) {
         $this->warn('Exiting');
         return;
     }
     if (!$this->isStorageOk()) {
         $this->error('Storage path is not OK. Please check permissions');
         return;
     }
     // Download the SDE's
     $this->getSde();
     $this->importSde();
     Seat::set('installed_sde', $this->json->version);
     $this->line('SDE Update Command Complete');
     // Analytics
     dispatch((new Analytics((new AnalyticsContainer())->set('type', 'event')->set('ec', 'queues')->set('ea', 'update_sde')->set('el', 'console')->set('ev', $this->json->version)))->onQueue('medium'));
     return;
 }
Exemplo n.º 14
0
 /**
  * Retreive a client-id from the cache. If none
  * exists, generate one.
  */
 private function getClientID()
 {
     $id = Seat::get('analytics_id');
     if (!$id) {
         // Generate a V4 random UUID
         //  https://gist.github.com/dahnielson/508447#file-uuid-php-L74
         $id = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
         // Set the generated UUID in the applications config
         Seat::set('analytics_id', $id);
     }
     return $id;
 }
Exemplo n.º 15
0
 public function postConfiguration(ValidateConfiguration $request)
 {
     Seat::set('slack_token', $request->input('slack-configuration-token'));
     return redirect()->back()->with('success', 'The Slack test token has been updated');
 }
Exemplo n.º 16
0
 /**
  * Work with settings.
  *
  * Providing a string argument will retreive a setting.
  * Providing an array arguement will set a setting.
  *
  * @param      $name
  * @param bool $global
  *
  * @return mixed
  * @throws \Seat\Services\Exceptions\SettingException
  */
 function setting($name, bool $global = false)
 {
     // If we received an array, it means we want to set.
     if (is_array($name)) {
         // Check that we have at least 2 keys.
         if (count($name) < 2) {
             throw new \Seat\Services\Exceptions\SettingException('Must provide a name and value when setting a setting.');
         }
         // If we have a third element in the array, set it.
         $for_id = $name[2] ?? null;
         if ($global) {
             return \Seat\Services\Settings\Seat::set($name[0], $name[1], $for_id);
         }
         return \Seat\Services\Settings\Profile::set($name[0], $name[1], $for_id);
     }
     // If we just got a string, it means we want to get.
     if ($global) {
         return \Seat\Services\Settings\Seat::get($name);
     }
     return \Seat\Services\Settings\Profile::get($name);
 }
Exemplo n.º 17
0
/**
 * Retrive a Setting value
 *
 * @param      $name
 * @param bool $global
 *
 * @return mixed
 */
function setting($name, $global = false)
{
    if ($global) {
        return \Seat\Services\Settings\Seat::get($name);
    }
    return \Seat\Services\Settings\Profile::get($name);
}