Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F25244480
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Console/Commands/AccountReset.php b/app/Console/Commands/AccountReset.php
index 245e95a..1abe4f4 100644
--- a/app/Console/Commands/AccountReset.php
+++ b/app/Console/Commands/AccountReset.php
@@ -1,130 +1,130 @@
<?php
namespace AuthGrove\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Support\Facades\Password;
use AuthGrove\User;
use AuthGrove\Console\Services\AccountHelpers;
class AccountReset extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'account:reset {user} {--subject=} {--format=human}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send a mail with a reset password link for an account';
/**
* The user e-mail
*
* @var string
*/
private $email;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Gets e-mail subject from command line option or default l10n
*
* @return string the e-mail subject
*/
public function getEmailSubject () {
$subject = $this->option('subject');
if ($subject === null) {
return trans('emails.reset-password-subject');
}
return $subject;
}
/**
* Sends a reset passsword e-mail
*
* @return bool true if a mail has been sent, false if the user is invalid
*/
public function sendResetMail () {
//Information we need for this mail
$subject = $this->getEmailSubject();
$credentials = [
'email' => $this->email
];
//Tries to send the mail
$response = Password::sendResetLink($credentials, function($m) use ($subject)
{
$m->subject($subject);
});
//Handles password broker response, returning true on success
switch ($response) {
case PasswordBroker::RESET_LINK_SENT:
return true;
case PasswordBroker::INVALID_USER:
return false;
default:
- throw new Exception("Unhandled password broker response: " . $response);
+ throw new \Exception("Unhandled password broker response: " . $response);
}
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Gets the information
$user = AccountHelpers::findUser($this->argument('user'));
if ($user === null) {
$this->error("User not found.");
return;
}
$this->email = $user->getInformation()['email'];
//Operation
$success = $this->sendResetMail();
if (!$success) {
$this->error("The user has been found, but the password broker considers this user is invalid.");
exit;
}
//Regular output
$format = $this->option('format');
switch ($format) {
case "human":
$this->info("A reset link mail has been sent to $this->email.");
break;
case "json":
echo json_encode([
"result" => "ok",
"email" => $this->email
]);
echo PHP_EOL;
break;
default:
$this->error("Unknown format: $format");
}
}
}
diff --git a/app/Console/Commands/DatabaseShell.php b/app/Console/Commands/DatabaseShell.php
index a1b0ba1..e28c4e9 100644
--- a/app/Console/Commands/DatabaseShell.php
+++ b/app/Console/Commands/DatabaseShell.php
@@ -1,189 +1,189 @@
<?php
namespace AuthGrove\Console\Commands;
use Illuminate\Console\Command;
use Config;
class DatabaseShell extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:shell';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Launch an interactive shell for your database';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Executes the console command.
*/
public function handle() {
$this->runInteractiveShell();
}
/**
* Runs an interactive database shell
*
* Shell to run depends of the engine set in configuration.
*/
protected function runInteractiveShell () {
$engine = Config::get('database.default');
$command = $this->getCommand($engine);
$env = $this->getEnvironment($engine);
$this->runCommand($command, $env);
}
///
/// Helper methods to build commands
///
/**
* Gets the command to run an interactive shell for the specified db engine
*
* @param string $engine The database engine
*/
protected function getCommand ($engine) {
$method = 'getCommandFor' . ucfirst($engine);
if (method_exists($this, $method)) {
return call_user_func([$this, $method]);
}
throw new \LogicException("No interactive shell command available for $engine engine.");
}
/**
* Gets environment to run the command
*
* @param string $engine The database engine
*
* @return array|null
*/
private function getEnvironment ($engine) {
$method = 'getEnvironmentFor' . ucfirst($engine);
if (method_exists($this, $method)) {
return call_user_func([$this, $method]);
}
// If no custom environment is set, we're happy with the current one
return null;
}
/**
* Gets escaped database.connections option
*/
private function getOption ($option) {
$key = 'database.connections.' . $option;
$parameter = Config::get($key);
return escapeshellarg($parameter);
}
/**
* Gets command to run for a MySQL command line tool
*/
protected function getCommandForMysql () {
return
'mysql -h ' . $this->getOption('mysql.host')
. ' -u ' . $this->getOption('mysql.username')
. ' --password=' . $this->getOption('mysql.password')
. ' --default-character-set=' . $this->getOption('mysql.charset')
. ' ' . $this->getOption('mysql.database');
}
/**
* Gets command to run for a PostgreSQL interactive terminal
*/
protected function getCommandForPgsql () {
return
'psql -h ' . $this->getOption('pgsql.host')
. ' -d ' . $this->getOption('pgsql.database')
. ' -U ' . $this->getOption('pgsql.username');
}
/**
* Gets command to run for a SQL server client
*/
protected function getCommandForSqlsrv () {
'Sqlcmd -S ' . $this->getOption('sqlsrv.host')
. ' -U ' . $this->getOption('sqlsrv.username')
. ' -P ' . $this->getOption('sqlsrv.password')
. ' -d ' . $this->getOption('sqlsrv.database');
}
/**
* Gets command to run for a SQLite command line interaface
*/
protected function getCommandForSqlite () {
return 'sqlite3 ' . $this->getOption('sqlite.database');
}
/**
* Gets an array with the current environment variables
*
* @return array
*/
protected function getCurrentEnvironment() {
return $_SERVER;
}
/**
* Gets environment for a PostgreSQL interactive terminal
*
* The psql terminal doesn't provide arguments for the password
* or for the charset, but they can be provided in environment.
*
* @return array
*/
protected function getEnvironmentForPgsql () {
return [
// To store the password in the environment is deprecated,
// but no alternative solution is given.
'PGPASSWORD' => Config::get('database.connections.pgsql.password'),
'PGCLIENTENCODING' => Config::get('database.connections.pgsql.charset'),
] + $this->getCurrentEnvironment();
}
///
/// Helper method to run a process interactively
///
/**
* Runs a command interactively
*
* @param string $command The command to run
* @param array|null $env The environment to pass, or null if current environment should be kept intact.
*/
protected function runCommand ($command, $env = null) {
$spec = [STDIN, STDOUT, STDERR];
$proc = proc_open(
$command,
$spec,
$pipes,
null,
$env
);
if (!is_resource($proc)) {
- throw new Exception('Failed to passthru a command');
+ throw new \Exception('Failed to passthru a command');
}
proc_close($proc);
}
}
diff --git a/app/Http/Middleware/TrustProxy.php b/app/Http/Middleware/TrustProxy.php
index c27f44b..0512b7d 100644
--- a/app/Http/Middleware/TrustProxy.php
+++ b/app/Http/Middleware/TrustProxy.php
@@ -1,58 +1,58 @@
<?php namespace AuthGrove\Http\Middleware;
use AuthGrove\Enums\TrustProxyConfigurationMode;
use Config;
use Closure;
/**
* Allow the application to work behind a load balancer or a reverse proxy
*
* See http://symfony.com/doc/current/cookbook/request/load_balancer_reverse_proxy.html
*/
class TrustProxy {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$proxy = Config::get('app.proxy');
switch ($mode = self::getConfigurationMode($proxy)) {
case TrustProxyConfigurationMode::TrustNone:
break;
case TrustProxyConfigurationMode::TrustSome:
$request->setTrustedProxies($proxy);
break;
case TrustProxyConfigurationMode::TrustAll:
$remoteAddr = $request->server->get('REMOTE_ADDR');
$request->setTrustedProxies([ '127.0.0.1', $remoteAddr ]);
break;
default:
- throw new ArgumentException("Unhandled configuration mode: $mode");
+ throw new \ArgumentException("Unhandled configuration mode: $mode");
}
return $next($request);
}
/**
* Gets trust proxies configuration mode
*/
public static function getConfigurationMode ($configValue) {
if (!is_array($configValue) || !count($configValue)) {
return TrustProxyConfigurationMode::TrustNone;
}
if (in_array('*', $configValue)) {
return TrustProxyConfigurationMode::TrustAll;
}
return TrustProxyConfigurationMode::TrustSome;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Apr 9, 02:45 (8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3603866
Default Alt Text
(10 KB)
Attached To
Mode
rGROVE Auth Grove
Attached
Detach File
Event Timeline
Log In to Comment