ADding some docs

Esse commit está contido em:
Felipe
2010-11-01 17:44:02 -02:00
commit e06a267ac3
31 arquivos alterados com 244 adições e 149 exclusões
Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 98 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 98 KiB

Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 11 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 11 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 12 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 12 KiB

Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
+13 -5
Ver Arquivo
@@ -21,11 +21,19 @@ class En {
}
public function __construct()
{
$this->messages['passwordRequired'] = "I need a password for this user, please: ";
$this->messages['autenticated'] = Mind::message("\nMain: %s autenticated", "[OK]", false);//"\n[OK] %s autenticated\n";
$this->messages['not_allowed'] = Mind::message("\nMain: You have not autenticated your credentials yet", '[Fail]', false);
$this->messages['not_allowed_tip'] = "Try calling the command\n auth < login >\nA password will be required.\n";
$this->messages['no_such_file'] = Mind::message("\nMain: No such command '%s'", "[Fail]", false);
$this->messages['programRequired'] = Mind::message("API: You must send the program name, to execute", '[Fail]', false);
$this->messages['loginRequired'] = Mind::message("Auth: Both login and password are required", '[Fail]', false);
$this->messages['passwordRequired'] = "I need a password for this user, please: ";
$this->messages['autenticated'] = Mind::message("\nMain: %s autenticated", "[OK]", false);//"\n[OK] %s autenticated\n";
$this->messages['not_allowed'] = Mind::message("\nMain: You have not autenticated your credentials yet", '[Fail]', false);
$this->messages['not_allowed_tip'] = "Try calling the command\n auth < login >\nA password will be required.\n";
$this->messages['no_such_file'] = Mind::message("\nMain: No such command '%s'", "[Fail]", false);
$this->messages['auth_fail'] = Mind::message("\nAuth: Wrong user or password", "[Fail]", false);
$this->messages['bye'] = "Logging out...\n";
$this->messages['http_invalid_requisition'] = <<<MESSAGE
Invalid HTTP requisition.
You *must* send some POST data acoording your request, and also a variable "program" by post, with the name of the program you want to run.
MESSAGE;
}
}
?>
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
+29 -19
Ver Arquivo
@@ -1,24 +1,34 @@
<?php
echo "<b>Requisition data:</b><br/>";
print_r($_REQ);
echo "<br/><b>Return:</b><br/>";
if(isset($_REQ['data']) && sizeof($_REQ['data'])>0)
/**
* This is the server file which will receive the requisition
* All the HTTP requests are goning to reach this file, so,
* it will treat the POST data before routing the requisition
* With this, you can send by post, the program variable, saying
* the program you want to execute, and the parameters you want
* to pass
*/
if(!isset($_REQ))
{
$program= preg_replace("/['\"\\\.\/]/", '', $_REQ['data'][0]);
for($i=1; $i<sizeof($_REQ['data']); $i++)
{
$params[]= $_REQ['data'][$i];
}
Mind::write("http_invalid_requisition");
exit;
}
if(!isset($_REQ['data']))
$_REQ['data']= Array();
foreach($_POST as $k=>$value)
{
$_REQ['data'][$k]= preg_replace("/['\"\\\.\/]/", '', $value);
}
if(file_exists('mind3rd/API/programs/'.ucfirst($program).".php"))
if(isset($app))
{
include('mind3rd/API/programs/'.ucfirst($program).".php");
//$program= new $program($params);
$program= new $program($program);
echo "\n";
exit;
}else{
//echo "No such function!\nType mind -h or mind command -h for help\n";
$_MIND->write('no_such_file', true, $program);
}
if(!isset($_REQ['data']) || !isset($_REQ['data']['program']))
{
Mind::write('programRequired');
return false;
}
$program= $app->findCommand($_REQ['data']['program']);
$program= $program->getFileName();
$program = new $program();
$program->HTTPExecute();
}
Arquivo normal → Arquivo executável
+8 -1
Ver Arquivo
@@ -1,5 +1,12 @@
<?php
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
interface program
{
public function __construct($params=false);
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output);
public function HTTPExecute();
public function configure();
public function runAction();
}
Arquivo normal → Arquivo executável
Ver Arquivo
+76 -12
Ver Arquivo
@@ -2,35 +2,99 @@
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
class Auth extends Symfony\Component\Console\Command\Command
/**
* This class represents the program auth, receiving the user and
* may also receive the password. It will start your session
* allowing you to run the restricted programs
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
class Auth extends MindCommand implements program
{
public function configure()
{
$this->setName('auth')
->setDescription('Autenticate a user')
->setRestrict(false)
->setDefinition(Array(
new InputArgument('login', InputArgument::REQUIRED, 'Login to access')
new InputArgument('login', InputArgument::REQUIRED, 'Login to access'),
new InputArgument('pwd', InputArgument::OPTIONAL, 'The user password')
))
->setHelp(<<<EOT
Sets the user with a password.
It is required to run most of the commands
It is required to autenticate, to run most of the commands
EOT
);
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output)
{
Mind::write('passwordRequired', true);
$pw= $this->getPassword(true);
Mind::write('autenticated', true, $input->getArgument('login'));
Mind::write("xxxxxx");
//echo "\n[OK] ".$input->getArgument('login')." ".Mind::write('autenticated')."\n";
if(!$pw= $input->getArgument('pwd'))
{
Mind::write('passwordRequired', true);
$pw= $this->getPassword(true);
}
$this->login= $input->getArgument('login');
$this->pwd= $pw;
if($this->runAction())
Mind::write('autenticated', true, $input->getArgument('login'));
}
public function HTTPExecute()
{
GLOBAL $_REQ;
if(!isset($_REQ['data']))
{
Mind::write('loginRequired');
return false;
}elseif(!isset($_REQ['data']['pwd']) || !isset($_REQ['data']['login']))
{
Mind::write('loginRequired');
return false;
}
$this->pwd= $_REQ['data']['pwd'];
$this->login= $_REQ['data']['pwd'];
if($this->runAction())
Mind::write('autenticated', true, $_REQ['data']['login']);
}
private function action()
{
if($db = new SQLiteDatabase(_MINDSRC_.'/mind3rd/SQLite/mind'))
{
$result= $db->query("SELECT * FROM user where login='".$this->login.
"' AND pwd='".sha1($this->pwd)."' AND status= 'A'");
$row= false;
while ($result->valid())
{
$row = $result->current();
$_SESSION['auth']= JSON_encode($row);
$_SESSION['login']= $row['login'];
break;
}
if(!$row)
{
Mind::write('auth_fail', true);
return false;
}
}else{
die('Database not found!');
}
return $this;
}
public function runAction()
{
return $this->action();
}
/**
* function taken from: http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
* this method should read the user's password not showing any character of their password
* @param Booladn $stars if true, show an * for each typed char
* @param Boolan $stars if true, show an * for each typed char
* @return String password
*/
private function getPassword($stars = false)
+15 -1
Ver Arquivo
@@ -3,7 +3,7 @@
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
class Clear extends Symfony\Component\Console\Command\Command
class Clear extends MindCommand implements program
{
public function configure()
{
@@ -19,4 +19,18 @@ EOT
{
system('clear');
}
public function HTTPExecute()
{
}
private function action()
{
return $this;
}
public function runAction()
{
return $this->action();
}
}
+20 -2
Ver Arquivo
@@ -3,13 +3,14 @@
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
class Quit extends Symfony\Component\Console\Command\Command
class Quit extends MindCommand implements program
{
public function configure()
{
$this->setName('exit')
->setDescription('Finishes the application')
->setDefinition(Array())
->setFileName('Quit')
->setHelp(<<<EOT
Finishes the application, leaving the console;
EOT
@@ -17,7 +18,24 @@ EOT
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
echo "Logging out...\n";
$this->runAction();
exit;
}
public function HTTPExecute()
{
$this->runAction();
}
private function action()
{
session_destroy();
Mind::write('bye');
return $this;
}
public function runAction()
{
return $this->action();
}
}
+40 -8
Ver Arquivo
@@ -1,10 +1,12 @@
<?php
//use Mind\Command;
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
class RunTest extends Symfony\Component\Console\Command\Command
class RunTest extends MindCommand implements program
{
public function configure()
{
@@ -12,26 +14,56 @@
->setName('test')
->setDescription('Performs some tests on theWebMind')
->setDefinition(array())
->setRestrict(false)
->setFileName('RunTest')
->setHelp(<<<EOT
Executes specific tests and report their results, about the system itself
EOT
);
}
private function action()
{
$this->runStep1();
$this->runStep2();
}
public function runAction()
{
return $this->action();
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
if(!isset($_SESSION['auth']))
{
Mind::write('not_allowed');
Mind::write('not_allowed_tip');
if(!parent::execute($input, $output))
return false;
}
$this->runStep1();
return $this->runAction();
}
public function HTTPExecute()
{
if(!parent::HTTPExecute())
return false;
return $this->runAction();
}
private function runStep1()
{
// by this point, if it reached here, we know these steps are ok
Mind::message('Autoloader', '[OK]');
Mind::message('Includes', '[OK]');
Mind::message('Namespaces', '[OK]');
}
private function runStep2()
{
if(!$db = new SQLiteDatabase(_MINDSRC_.'/mind3rd/SQLite/mind'))
{
Mind::message('Database', '[Fail]');
return false;
}
Mind::message('Database', '[OK]');
return true;
}
public function __construct($name = null) {
parent::__construct($name);
}
}
+17 -1
Ver Arquivo
@@ -3,7 +3,7 @@
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
class CommandName extends Symfony\Component\Console\Command\Command
class CommandName extends MindCommand implements program
{
public function configure()
{
@@ -28,5 +28,21 @@ EOT
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$this->runAction();
}
public function HTTPExecute()
{
$this->runAction();
}
private function action()
{
return $this;
}
public function runAction()
{
return $this->action();
}
}
Arquivo normal → Arquivo executável
+1 -86
Ver Arquivo
@@ -1,88 +1,3 @@
<?php
require(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Shell.php');
require(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Application.php');
require(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Command/Command.php');
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
$app= new Symfony\Component\Console\Application('mind');
$app->addCommands(Array(
new RunTest(),
new Quit(),
new Auth(),
new Clear()
));
$helperSet= false;
$helperSet = ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
$app->setHelperSet($helperSet);
include_once('external/Symfony/Component/Console/Shell.php');
$sh= new Symfony\Component\Console\Shell($app);
$sh->run();
/**
* This file receives the shell call for a program,
* and parses its parameters, calling the program from the API
*
*/
/*
function shellExecute($command)
{
GLOBAL $_MIND;
readline_completion_function('mmindAutoComplete');
if(!is_array($command))
$command= explode(' ', $command);
$program= array_shift($command); // the first parameter is the program itself
try
{
$program= new $program($command);
//echo "\n";
}catch(Exception $e){
print_r($e->getMessage());
}
}
$fp = fopen("php://stdin", "r");
$in = '';
if(isset($params[0]))
{
if($params[0]== 'help' || $params[0]== '-h' || $params[0]== '--help')
{
new help();
exit;
}elseif($params[0]== '-u' && isset($params[1]))
{
new autenticate(Array($params[1]));
}
}else
new clear();
echo "Welcome to mind3rd:\nType help to see the help content\n";
while($in != "exit")
{
if(!isset($_SESSION['login']))
echo "mind > ";
else
echo $_SESSION['login'].'@mind > ';
$in=trim(fgets($fp));
if($in!='exit' && trim($in)!='')
{
shellExecute($in);
}
}
new clear();
exit;
*/
$sh->run();
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
+25 -2
Ver Arquivo
@@ -42,8 +42,31 @@
return false;
}
require('interfaces/program.php');
require('classes/Mind.php');
require(_MINDSRC_.'/mind3rd/API/interfaces/program.php');
require(_MINDSRC_.'/mind3rd/API/classes/Mind.php');
require(_MINDSRC_.'/mind3rd/API/classes/MindCommand.php');
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Shell.php');
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Application.php');
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Command/Command.php');
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
$app= new Symfony\Component\Console\Application('mind');
$app->addCommands(Array(
new RunTest(),
new Quit(),
new Auth(),
new Clear(),
new Info(),
new Create()
));
$helperSet= false;
$helperSet = ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
$app->setHelperSet($helperSet);
if(isset($_SERVER['argv']))
{
$params= $_SERVER['argv'];
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
externo Arquivo normal → Arquivo executável
Ver Arquivo
externo Arquivo normal → Arquivo executável
Ver Arquivo
externo Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
-12
Ver Arquivo
@@ -1,16 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
<file>file:/var/www/mind/mind3rd/API/L10N/En.php</file>
<file>file:/var/www/mind/mind3rd/API/classes/Mind.php</file>
<file>file:/var/www/mind/mind3rd/env/defaults.ini</file>
<file>file:/var/www/mind/mind3rd/API/programs/Auth.php</file>
<file>file:/var/www/mind/index.php</file>
<file>file:/var/www/mind/mind3rd/API/utils.php</file>
<file>file:/var/www/mind/mind3rd/API/http.php</file>
<file>file:/var/www/mind/mind3rd/API/programs/RunTest.php</file>
<file>file:/var/www/mind/mind3rd/API/external/Symfony/Component/Console/Command/Command.php</file>
<file>file:/var/www/mind/mind3rd/API/shell.php</file>
</open-files>
</project-private>
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo