Initial Commit

This commit is contained in:
2018-10-15 00:37:28 -05:00
commit b0bd5569c0
7508 changed files with 849336 additions and 0 deletions

42
app/Console/Kernel.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}

15
app/EsiToken.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class EsiToken extends Model
{
// Table Name
protected $table = 'EsiTokens';
//Primary Key
public $primaryKey = 'CharacterId';
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/dashboard';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function logout(Request $request) {
Auth::logout();
return redirect('/');
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/dashboard';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'characterid' => 'required|string',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'character_id' => $data['characterid'],
]);
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = '/dashboard';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;
class VerificationController extends Controller
{
/*
|--------------------------------------------------------------------------
| Email Verification Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling email verification for any
| user that recently registered with the application. Emails may also
| be resent if the user did not receive the original email message.
|
*/
use VerifiesEmails;
/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = '/dashboard';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Http\Controllers;
//use Laravel\Socialite\Contracts\Factory as Socialite;
//use Laravel\Socialite\Two\User as SocialiteUser;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Socialite;
//use SocialiteUser;
class AuthController extends Controller
{
use AuthenticatesUsers;
/**
* Redirect the user to the Eve Online authentication page.
*
* @return Response
*/
public function redirectToProvider() {
return Socialite::driver('eveonline')->redirect();
}
/**
* Obtain the user information from Eve Online
*
* @return Response
*/
public function handleProviderCallback(Socialite $social) {
$user = $social->driver('eveonline')->user();
Auth::login($user);
dd($user);
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View File

@@ -0,0 +1,88 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Library;
//use Illuminate\Foundation\Validation\ValidatesRequests;
//use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class DashboardController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('dashboard');
}
public function addMoon() {
return view('dashboard.addmoon');
}
public function profile() {
/**
* Check to see if the user has a valid esi token
*/
$user = Auth::user();
//Try to find the user's ESI token.
$token = DB::table('esitokens')->where('CharacterId', $user['character_id'])->first();
if($token != null) {
$html = '<h3>ESI Token Already Stored</h3>';
} else {
//Setup the display button if the user doesn't have an ESI registered
$state = uniqid();
session(['state' => $state]);
$esiLogin = new \App\Library\EsiLogin();
$html = $esiLogin->DisplayLoginButton($state);
}
return view('dashboard.profile')->with('html', $html);
}
public function callback(Request $request) {
$esiLogin = new \App\Library\EsiLogin();
//Pull the old session state from the session, and delete the key
$oldState = $request->session()->pull('state');
//Check the state to make sure it matches
if($oldState == $request->input('state')) {
$esiLogin->RetrieveAccessToken();
$esiLogin->RetrieveCharacterId();
//Store the token in the database
$token = new \App\EsiToken;
$token->CharacterId = $esiLogin->GetCharacterId();
$token->AccessToken = $esiLogin->GetAccessToken();
$token->RefreshToken = $esiLogin->GetRefreshToken();
$token->ExpiresIn = $esiLogin->GetRefreskTokenExpiry();
$token->save();
//Return view back to profile with success message
return view('dashboard')->with('message', 'Success!');
} else {
//Return view with error message back to the dashboard
return view('dashboard')->with('message', 'Error!');
}
}
public function displayMoons() {
$moons = DB::table('moons')->get();
return 'Moons Display Table';
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Moon;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
class MoonsController extends Controller
{
/**
* Add a new moon into the database
*
* @return \Illuminate\Http\Reponse
*/
public function addMoon(Request $request) {
$this->validate($request, [
'region' => 'required',
'system' => 'required',
'structure' => 'required',
]);
// Add new moon
$moon = new Moon;
$moon->Region = $request->input('region');
$moon->System = $request->input('system');
$moon->StructureName = $request->input('structure');
$moon->FirstOre = $request->input('firstore');
$moon->FirstQuantity = $request->input('firstquan');
$moon->SecondOre = $request->input('secondore');
$moon->SecondQuantity = $request->input('secondquan');
$moon->ThirdOre = $request->input('thirdore');
$moon->ThirdQuantity = $request->input('thirdquan');
$moon->FourthOre = $request->input('fourthore');
$moon->FourthQuantity = $request->input('fourthquan');
$moon->save();
return redirect('/dashboard')->with('success', 'Moon Added');
}
/**
* Returns a view with a table select for all of the structures in the corp owned by the player
*/
public function moonminedisplay() {
// Disable all caching by setting the NullCache as the
// preferred cache handler. By default, Eseye will use the
// FileCache.
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
/**
* Create the auth user space.
* Get the character Id.
* Check the character id against the esi token table
* If the refresh token is available then request an ESI pull
* If the refresh token is not available, display an error message
*/
$user = Auth::user();
$characterId = $user->getCharacterId();
// Prepare an authentication container for ESI
$authentication = new EsiAuthentication([
'client_id' => env('ESI_CLIENT_ID'),
'secret' => env('ESI_SECRET_KEY'),
'refresh_token' => null,
]);
// Instantiate a new ESI instance.
$esi = new Eseye($authentication);
}
}

64
app/Http/Kernel.php Normal file
View File

@@ -0,0 +1,64 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function redirectTo($request)
{
return route('login');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
class CheckForMaintenanceMode extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/dashboard');
}
return $next($request);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
'password',
'password_confirmation',
];
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
}

306
app/Library/EsiLogin.php Normal file
View File

@@ -0,0 +1,306 @@
<?php
/*
* W4RP Services
* GNU Public License
*/
namespace App\Library;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Session;
class EsiLogin {
private $characterId;
private $characterName;
private $tokenType;
private $corporationId;
private $corporationName;
private $allianceId;
private $allianceName;
private $logged;
private $refreshToken;
private $refreshTokenExpiry;
private $accessToken;
private $clientId;
private $secretKey;
private $useragent;
private $scope;
public function __construct($client = null, $secret = null, $useragent = null) {
if($client == null || $secret == null || $useragent == null) {
//Parse the data for the ESI Configuration file
$this->clientId = env('ESI_CLIENT_ID');
$this->secretKey = env('ESI_SECRET_KEY');
$this->useragent = env('ESI_USERAGENT');
$this->scope = env('ESI_SCOPES');
//$this->clientId = $fileEsi['client_id'];
//$this->secretKey = $fileEsi['secret'];
//$this->useragent = $fileEsi['useragent'];
} else {
$this->clientId = $client;
$this->secretKey = $secret;
$this->userAgent = $useragent;
}
}
public function GetCharacterId() {
return $this->characterId;
}
public function GetCharacterName() {
return $this->characterName;
}
public function GetCorporationId() {
return $this->corporationId;
}
public function GetCorporationName() {
return $this->corporationName;
}
public function GetAllianceId() {
return $this->allianceId;
}
public function GetAllianceName() {
return $this->allianceName;
}
public function GetAccessToken() {
return $this->accessToken;
}
public function GetRefreshToken() {
return $this->refreshToken;
}
public function GetRefreskTokenExpiry() {
return $this->refreshTokenExpiry;
}
public function SetAccessToken($access) {
$this->accessToken = $access;
}
public function SetRefreshtoken($refresh) {
$this->refreshToken = $refresh;
}
public function SetRefreshTokenExpiry($expire) {
$this->refreshTokenExpiry = $expire;
}
public function ESIStateMachine($state) {
switch($state) {
case 'new':
return $this->DisplayLoginButton();
break;
case 'eveonlinecallback':
$this->VerifyCallback();
if($this->logged == true) {
return 'logged';
} else {
return 'notlogged';
}
break;
default:
$this->UnsetState();
break;
}
}
public function VerifyCallback() {
if($this->CheckState() == 'okay') {
$this->RetrieveAccessToken();
$this->RetrieveCharacterId();
//Get all the information we might need, and store it
$char = $this->GetESIInfo($this->characterId, 'Character', $this->useragent);
$this->characterName = $char['name'];
$corp = $this->GetESIInfo($char['corporation_id'], 'Corporation', $this->useragent);
$this->corporationId = $char['corporation_id'];
$this->corporationName = $corp['name'];
if(isset($corp['alliance_id'])) {
$ally = $this->GetESIInfo($corp['alliance_id'], 'Alliance', $this->useragent);
$this->allianceId = $corp['alliance_id'];
$this->allianceName = $ally['name'];
}
} else {
$this->logged = false;
}
if($this->characterId != null) {
$this->logged = true;
} else {
$this->logged = false;
}
}
public function DisplayLoginButton($state) {
$html = "";
$html .= "<div class=\"container\">";
$html .= "<br><br><br>";
$html .= "<div class=\"jumbotron\">";
//$html .= "<h1><p align=\"center\">Warped Intentions Services Login</p></h1>";
//$html .= "<br>";
//$html .= "<p align=\"center\">One stop shop for the alliance services.</p>";
//$html .= "<br>";
$html .= "<p align=\"center\">";
$html .= "<a href=\"https://login.eveonline.com/oauth/authorize/?response_type=code&redirect_uri=";
$html .= env('ESI_CALLBACK_URI');
$html .= "&client_id=" . $this->clientId;
$html .= "&scope=" . urlencode($this->scope);
$html .= "&state=";
$html .= $state . "\">";
$html .= "<img src=\"images/EVE_SSO_Login_Buttons_Large_Black.png\">";
$html .= "</a>";
$html .= "</p>";
$html .= "</div>";
$html .= "</div>";
return $html;
}
public function CheckState($newState) {
if($newState != session('state')) {
$this->UnsetState();
return false;
} else {
return true;
}
}
public function UnsetState() {
Session::forget('state');
}
public function RetrieveCharacterId() {
$url = 'https://login.eveonline.com/oauth/verify';
$header = 'Authorization: Bearer ' . $this->accessToken;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
$data = json_decode($result, true);
$this->characterId = $data['CharacterID'];
$this->characterName = $data['CharacterName'];
$this->tokenType = $data['TokenType'];
}
public function RetrieveAccessToken() {
Session::forget('key');
$url = 'https://login.eveonline.com/oauth/token';
$header = 'Authorization: Basic ' . base64_encode($this->clientId . ':' . $this->secretKey);
$fields_string='';
$fields = array(
'grant_type' => 'authorization_code',
'code' => $_GET['code']
);
foreach($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string . '&');
//Initialize the curl channel
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result, true);
$this->accessToken = $data['access_token'];
$this->refreshToken = $data['refresh_token'];
$this->refreshTokenExpiry = time() + $data['expires_in'];
}
public function RefreshAccess() {
$url = 'https://login.eveonline.com/oauth/token';
$header = 'Authorization: Basic ' . base64_encode($this->clientId . ':' . $this->secretKey);
$fields_string = '';
$fields = array(
'grant_type' => 'refresh_token',
'refresh_token' => $this->refreshToken
);
foreach($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
//Initialize the cURL connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
//Get the resultant data from the curl call in an array format
$data = json_decode($result, true);
//Modify the variables of the class
$this->refreshToken = $data['refresh_token'];
$this->refreshTokenExpiry = now() + $data['expires_in'];
$this->accessToken = $data['access_token'];
}
public function GetESIInfo($id, $type, $useragent = null) {
if($useragent == null) {
$useragent = $this->useragent;
}
$url = $this->BuildSingleUrl($type, $id);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
//Check for a curl error
if(curl_error($ch)) {
return null;
} else {
curl_close($ch);
$data = json_decode($result, true);
return $data;
}
}
private function BuildSingleUrl($type, $id) {
$firstPart = 'https://esi.tech.ccp.is/latest/';
$lastPart = '/?datasource=tranquility';
if($type == 'Character') {
$url = $firstPart . 'characters/' . $id . $lastPart;
} else if ($type == 'Corporation') {
$url = $firstPart . 'corporations/' . $id . $lastPart;
} else if ($type == 'Alliance') {
$url = $firstPart . 'alliances/' . $id . $lastPart;
}
return $url;
}
}

285
app/Library/MoonCalc.php Normal file
View File

@@ -0,0 +1,285 @@
<?php
/*
* W4RP Services
* GNU Public License
*/
namespace App\Library;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Session;
class MoonCalc {
public function __construct() {
}
public function SpatialMoons($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan, \Simplon\Mysql\Mysql $db){
//Always assume a 1 month pull which equates to 5.55m3 per second or 2,592,000 seconds
//Total pull size is 14,385,600 m3
$totalPull = 5.55 * (3600.00 * 24.00 * 30.00);
//Get the configuration for pricing calculations
$config = $db->fetchRow('SELECT * FROM Config');
if($firstQuan >= 1.00) {
$firstPerc = $firstQuan / 100.00;
} else {
$firstPerc = $firstQuan;
}
if($secondQuan >= 1.00) {
$secondPerc = $secondQuan / 100.00;
} else {
$secondPerc = $secondQuan;
}
if($thirdQuan >= 1.00) {
$thirdPerc = $thirdQuan / 100.00;
} else {
$thirdPerc = $thirdQuan;
}
if($fourthQuan >= 1.00) {
$fourthPerc = $fourthQuan / 100.00;
} else {
$fourthPerc = $fourthQuan;
}
if($firstOre != "None") {
$m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $firstOre));
//Find the m3 value of the first ore
$firstActualm3 = floor($firstPerc * $totalPull);
//Calculate the units of the first ore
$firstUnits = floor($firstActualm3 / $m3Size);
//Get the unit price from the database
$firstUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name'=> $firstOre));
//Calculate the total price for the first ore
$firstTotal = $firstUnits * $firstUnitPrice;
} else {
$firstTotal = 0.00;
}
if($secondOre != "None") {
$m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $secondOre));
//find the m3 value of the second ore
$secondActualm3 = floor($secondPerc * $totalPull);
//Calculate the units of the second ore
$secondUnits = floor($secondActualm3 / $m3Size);
//Get the unit price from the database
$secondUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name' => $secondOre));
//calculate the total price for the second ore
$secondTotal = $secondUnits * $secondUnitPrice;
} else {
$secondTotal = 0.00;
}
if($thirdOre != "None") {
$m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $thirdOre));
//find the m3 value of the third ore
$thirdActualm3 = floor($thirdPerc * $totalPull);
//calculate the units of the third ore
$thirdUnits = floor($thirdActualm3 / $m3Size);
//Get the unit price from the database
$thirdUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name' => $thirdOre));
//calculate the total price for the third ore
$thirdTotal = $thirdUnits * $thirdUnitPrice;
} else {
$thirdTotal = 0.00;
}
if($fourthOre != "None") {
$m3Size = $db->fetchColumn('SELECT m3Size FROM ItemComposition WHERE Name= :name', array('name' => $fourthOre));
//Find the m3 value of the fourth ore
$fourthActualm3 = floor($fourthPerc * $totalPull);
//Calculate the units of the fourth ore
$fourthUnits = floor($fourthActualm3 / $m3Size);
//Get the unit price from the database
$fourthUnitPrice = $db->fetchColumn('SELECT UnitPrice FROM OrePrices WHERE Name= :name', array('name' => $fourthOre));
//calculate the total price for the fourth ore
$fourthTotal = $fourthUnits * $fourthUnitPrice;
} else {
$fourthTotal = 0.00;
}
//Calculate the total to price to be mined in one month
$totalPriceMined = $firstTotal + $secondTotal + $thirdTotal + $fourthTotal;
//Calculate the rental price. Refined rate is already included in the price from rental composition
$rentalPrice = $totalPriceMined * ($config['RentalTax'] / 100.00);
//Format the rental price to the appropriate number
$rentalPrice = number_format($rentalPrice, "2", ".", ",");
//Return the rental price to the caller
return $rentalPrice;
}
public function UpdateItemPricing() {
if(php_sapi_name() != 'cli') {
$browser = true;
printf("Running price update from browser.<br>");
} else {
$browser = false;
printf("Running price update from command line.\n");
}
$db = DBOpen();
//Get the configuration from the config table
$config = $db->fetchRow('SELECT * FROM Config');
//Calculate refine rate
$refineRate = $config['RefineRate'] / 100.00;
//Calculate the current time
$time = time();
//Get the max time from the database
$maxTime = $db->fetchColumn('SELECT MAX(Time) FROM Prices WHERE ItemId= :id', array('id' => 34));
//Get the price of the basic minerals
$tritaniumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 34, 'time' => $maxTime));
$pyeritePrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 35, 'time' => $maxTime));
$mexallonPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 36, 'time' => $maxTime));
$isogenPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 37, 'time' => $maxTime));
$nocxiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 38, 'time' => $maxTime));
$zydrinePrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 39, 'time' => $maxTime));
$megacytePrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 40, 'time' => $maxTime));
$morphitePrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 11399, 'time' => $maxTime));
$heliumIsotopesPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16274, 'time' => $maxTime));
$nitrogenIsotopesPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 17888, 'time' => $maxTime));
$oxygenIsotopesPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 17887, 'time' => $maxTime));
$hydrogenIsotopesPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 17889, 'time' => $maxTime));
$liquidOzonePrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16273, 'time' => $maxTime));
$heavyWaterPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16272, 'time' => $maxTime));
$strontiumClathratesPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16275, 'time' => $maxTime));
//Get the price of the moongoo
$atmosphericGasesPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16634, 'time' => $maxTime));
$evaporiteDepositsPirce = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16635, 'time' => $maxTime));
$hydrocarbonsPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16633, 'time' => $maxTime));
$silicatesPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16636, 'time' => $maxTime));
$cobaltPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16640, 'time' => $maxTime));
$scandiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16639, 'time' => $maxTime));
$titaniumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16638, 'time' => $maxTime));
$tungstenPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16637, 'time' => $maxTime));
$cadmiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16643, 'time' => $maxTime));
$platinumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16644, 'time' => $maxTime));
$vanadiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16642, 'time' => $maxTime));
$chromiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16641, 'time' => $maxTime));
$technetiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16649, 'time' => $maxTime));
$hafniumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16648, 'time' => $maxTime));
$caesiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16647, 'time' => $maxTime));
$mercuryPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16646, 'time' => $maxTime));
$dysprosiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16650, 'time' => $maxTime));
$neodymiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16651, 'time' => $maxTime));
$promethiumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16652, 'time' => $maxTime));
$thuliumPrice = $db->fetchColumn('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time', array('id' => 16653, 'time' => $maxTime));
//Get the item compositions
$items = $db->fetchRowMany('SELECT Name,ItemId FROM ItemComposition');
//Go through each of the items and update the price
foreach($items as $item) {
//Get the item composition
$composition = $db->fetchRow('SELECT * FROM ItemComposition WHERE ItemId= :id', array('id' => $item['ItemId']));
//Calculate the Batch Price
$batchPrice = ( ($composition['Tritanium'] * $tritaniumPrice) +
($composition['Pyerite'] * $pyeritePrice) +
($composition['Mexallon'] * $mexallonPrice) +
($composition['Isogen'] * $isogenPrice) +
($composition['Nocxium'] * $nocxiumPrice) +
($composition['Zydrine'] * $zydrinePrice) +
($composition['Megacyte'] * $megacytePrice) +
($composition['Morphite'] * $morphitePrice) +
($composition['HeavyWater'] * $heavyWaterPrice) +
($composition['LiquidOzone'] * $liquidOzonePrice) +
($composition['NitrogenIsotopes'] * $nitrogenIsotopesPrice) +
($composition['HeliumIsotopes'] * $heliumIsotopesPrice) +
($composition['HydrogenIsotopes'] * $hydrogenIsotopesPrice) +
($composition['OxygenIsotopes'] * $oxygenIsotopesPrice) +
($composition['StrontiumClathrates'] * $strontiumClathratesPrice) +
($composition['AtmosphericGases'] * $atmosphericGasesPrice) +
($composition['EvaporiteDeposits'] * $evaporiteDepositsPirce) +
($composition['Hydrocarbons'] * $hydrocarbonsPrice) +
($composition['Silicates'] * $silicatesPrice) +
($composition['Cobalt'] * $cobaltPrice) +
($composition['Scandium'] * $scandiumPrice) +
($composition['Titanium'] * $titaniumPrice) +
($composition['Tungsten'] * $tungstenPrice) +
($composition['Cadmium'] * $cadmiumPrice) +
($composition['Platinum'] * $platinumPrice) +
($composition['Vanadium'] * $vanadiumPrice) +
($composition['Chromium'] * $chromiumPrice)+
($composition['Technetium'] * $technetiumPrice) +
($composition['Hafnium'] * $hafniumPrice) +
($composition['Caesium'] * $caesiumPrice) +
($composition['Mercury'] * $mercuryPrice) +
($composition['Dysprosium'] * $dysprosiumPrice) +
($composition['Neodymium'] * $neodymiumPrice) +
($composition['Promethium'] * $promethiumPrice) +
($composition['Thulium'] * $thuliumPrice));
//Calculate the batch price with the refine rate included
//Batch Price is base price for everything
$batchPrice = $batchPrice * $refineRate;
//Calculate the unit price
$price = $batchPrice / $composition['BatchSize'];
//Calculate the m3 price
$m3Price = $price / $composition['m3Size'];
//Insert the prices into the Pricees table
$db->insert('OrePrices', array(
'Name' => $composition['Name'],
'ItemId' => $composition['ItemId'],
'BatchPrice' => $batchPrice,
'UnitPrice' => $price,
'm3Price' => $m3Price,
'Time' => $time
));
}
DBClose($db);
}
public function FetchNewPrices() {
//Open a database connection
$db = DBOpen();
$ItemIDs = array(
"Tritanium" => 34,
"Pyerite" => 35,
"Mexallon" => 36,
"Isogen" => 37,
"Nocxium" => 38,
"Zydrine" => 39,
"Megacyte" => 40,
"Morphite" => 11399,
"HeliumIsotopes" => 16274,
"NitrogenIsotopes" => 17888,
"OxygenIsotopes" => 17887,
"HydrogenIsotopes" => 17889,
"LiquidOzone" => 16273,
"HeavyWater" => 16272,
"StrontiumClathrates" => 16275,
"AtmosphericGases" => 16634,
"EvaporiteDeposits" => 16635,
"Hydrocarbons" => 16633,
"Silicates" => 16636,
"Cobalt" => 16640,
"Scandium" => 16639,
"Titanium" => 16638,
"Tungsten" => 16637,
"Cadmium" => 16643,
"Platinum" => 16644,
"Vanadium" => 16642,
"Chromium" => 16641,
"Technetium" => 16649,
"Hafnium" => 16648,
"Caesium" => 16647,
"Mercury" => 16646,
"Dysprosium" => 16650,
"Neodymium" => 16651,
"Promethium" => 16652,
"Thulium" => 16653,
);
$time = time();
$item = array();
//Get the json data for each ItemId from https://market.fuzzwork.co.uk/api/
//Base url is https://market.fuzzwork.co.uk/aggregates/?region=10000002&types=34
//Going to use curl for these requests
foreach($ItemIDs as $key => $value) {
$url = 'https://market.fuzzwork.co.uk/aggregates/?region=10000002&types=' . $value;
$item = FuzzworkPrice($url);
$db->insert('Prices', array(
'Name' => $key,
'ItemId' => $value,
'Price' => $item[$value]['sell']['median'],
'Time' => $time
));
}
UpdateItemPricing();
//Close the database connection
DBClose($db);
}
}

17
app/Moon.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Moon extends Model
{
// Table Name
protected $table = 'moons';
//Primary Key
public $primaryKey = 'id';
// Timestamps
public $timestamps = 'true';
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
$gate->define('isAdmin', function($user) {
return $user->user_type == 'Admin';
});
$gate->define('isW4RP', function($user) {
return $user->user_type == 'W4RP';
});
$gate->define('isLegacy', function($user) {
return $user->user_type == 'Legacy';
});
$gate->define('isGuest', function($user) {
return $user->user_type == 'Guest';
});
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
}

34
app/User.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'character_id'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function getCharacterId() {
return $this->character_id;
}
}