Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
WIP #14 Fixed some things, web-artisan loads now again though there'r…
Browse files Browse the repository at this point in the history
…e still some minor things
  • Loading branch information
JN-Jones committed Feb 9, 2015
1 parent 29569d3 commit 1eb5ce9
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 206 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
composer.phar
composer.lock
.DS_Store
/vendor
composer.phar
composer.lock
.DS_Store
phpunit.phar
41 changes: 19 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
{
"name": "jones/web-artisan",
"description": "Adds a Webinterface for Laravel to your project",
"authors": [
{
"name": "Jones",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x"
},
"autoload": {
"classmap": [
"src/migrations"
],
"psr-0": {
"Jones\\WebArtisan": "src/"
}
},
"minimum-stability": "dev"
{
"name": "jones/web-artisan",
"description": "Adds a Webinterface for Laravel to your project",
"authors": [
{
"name": "Jones",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4.0",
"laravel/framework": "5.0.*"
},
"autoload": {
"psr-4": {
"Jones\\WebArtisan": "src/"
}
},
"minimum-stability": "dev"
}
269 changes: 135 additions & 134 deletions src/Jones/WebArtisan/Controllers/Cmd.php
Original file line number Diff line number Diff line change
@@ -1,135 +1,136 @@
<?php namespace Jones\WebArtisan\Controllers;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Lang;
use \Jones\WebArtisan\Cli\Output;
use Illuminate\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Input\ArrayInput;

class Cmd extends \BaseController
{
private $password = null;

public function __construct()
{
if (!Config::get('web-artisan::enable'))
{
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

if (Session::has('password'))
{
$this->password = Session::get('password');
}
}

public function index()
{
return View::make('web-artisan::webartisan');
}

public function password()
{
$this->password = trim(Input::get('password'));
Session::put('password', $this->password);
if ($this->checkUser())
{
echo Lang::get('web-artisan::webartisan.terminal.loggedin');
return;
}
echo Lang::get('web-artisan::webartisan.terminal.wrongpw');
}

public function run()
{
if (!$this->checkUser())
{
echo '<p>'.Lang::get('web-artisan::webartisan.terminal.needlogin').'</p>';
return;
}

$parts = explode(" ", Input::get('cmd'));

if(count($parts) < 2) // We need at least 2 entries: "artisan cmd"
{
echo '<p>'.Lang::get('web-artisan::webartisan.terminal.invalidcmd').'</p>';
return;
}

//first is "artisan" so remove it
unset($parts[0]);

//second is the command
$cmd = $parts[1];
unset($parts[1]);

$app = app();
$app->loadDeferredProviders();
$artisan = ConsoleApplication::start($app);

$command = $artisan->find($cmd);

$def = $command->getDefinition();
$arguments = $def->getArguments();
$fix = array();
foreach($arguments as $argument)
{
$fix[] = $argument->getName();
}
$arguments = $fix;

$params = array();
//the rest should be the parameter list
$i = 0; //The counter for our argument list
foreach($parts as $param)
{
// foo=bar, we don't need to work more
if(strpos($param, "=") !== false)
{
$param = explode("=", $param, 2);
$params[$param[0]] = $param[1];
}
else
{
//Do we have an argument or an option?
if(substr($param, 0, 1) == "-")
{
$params[$param] = true; //Option, simply set it to true
}
else
{
//Argument, we need a bit work
$params[$arguments[$i]] = $param;
++$i;
}
}
}
$params['command'] = $cmd;

$input = new ArrayInput($params);
$command->run($input, new Output());
}

private function checkUser() {
if (!in_array(@$_SERVER['REMOTE_ADDR'], Config::get('web-artisan::ips')))
{
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
else
{
$password = Config::get('web-artisan::password');

if ($password == $this->password)
{
return true;
}
else
{
return false;
}
}
}
<?php namespace Jones\WebArtisan\Controllers;

use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Lang;
use \Jones\WebArtisan\Cli\Output;
use Illuminate\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Input\ArrayInput;
use Illuminate\Routing\Controller;

class Cmd extends Controller
{
private $password = null;

public function __construct()
{
if (!config('web-artisan.enable'))
{
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

if (Session::has('password'))
{
$this->password = Session::get('password');
}
}

public function index()
{
return view('web-artisan::webartisan');
}

public function password()
{
$this->password = trim(Input::get('password'));
Session::put('password', $this->password);
if ($this->checkUser())
{
echo Lang::get('web-artisan::webartisan.terminal.loggedin');
return;
}
echo Lang::get('web-artisan::webartisan.terminal.wrongpw');
}

public function run()
{
if (!$this->checkUser())
{
echo '<p>'.Lang::get('web-artisan::webartisan.terminal.needlogin').'</p>';
return;
}

$parts = explode(" ", Input::get('cmd'));

if(count($parts) < 2) // We need at least 2 entries: "artisan cmd"
{
echo '<p>'.Lang::get('web-artisan::webartisan.terminal.invalidcmd').'</p>';
return;
}

//first is "artisan" so remove it
unset($parts[0]);

//second is the command
$cmd = $parts[1];
unset($parts[1]);

$app = app();
$app->loadDeferredProviders();
// $artisan = ConsoleApplication::start($app);
$artisan = new ConsoleApplication($app, $app['events']);

$command = $artisan->find($cmd);

$def = $command->getDefinition();
$arguments = $def->getArguments();
$fix = array();
foreach($arguments as $argument)
{
$fix[] = $argument->getName();
}
$arguments = $fix;

$params = array();
//the rest should be the parameter list
$i = 0; //The counter for our argument list
foreach($parts as $param)
{
// foo=bar, we don't need to work more
if(strpos($param, "=") !== false)
{
$param = explode("=", $param, 2);
$params[$param[0]] = $param[1];
}
else
{
//Do we have an argument or an option?
if(substr($param, 0, 1) == "-")
{
$params[$param] = true; //Option, simply set it to true
}
else
{
//Argument, we need a bit work
$params[$arguments[$i]] = $param;
++$i;
}
}
}
$params['command'] = $cmd;

$input = new ArrayInput($params);
$command->run($input, new Output());
}

private function checkUser()
{
if (!in_array(@$_SERVER['REMOTE_ADDR'], config('web-artisan.ips')))
{
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
else
{
$password = config('web-artisan.password');

if ($password == $this->password)
{
return true;
}
else
{
return false;
}
}
}
}
Loading

0 comments on commit 1eb5ce9

Please sign in to comment.