*Added log manager

*Added some constants
Added the 'who am i' program
Esse commit está contido em:
Felipe N. Moura
2012-04-07 16:41:09 -03:00
commit 79bebb1de7
17 arquivos alterados com 134 adições e 66 exclusões
+1
Ver Arquivo
@@ -18,6 +18,7 @@ mind3rd/SQLite/mind
## Temporary files
##
mind3rd/API/temp/*
mind3rd/API/logs/*
##
## Development meta files
-1
Ver Arquivo
@@ -1809,7 +1809,6 @@ var Expr = Sizzle.selectors = {
match[3] = test[3] - 0;
}
// TODO: Move to normal caching system
match[0] = done++;
return match;
-1
Ver Arquivo
@@ -1809,7 +1809,6 @@ var Expr = Sizzle.selectors = {
match[3] = test[3] - 0;
}
// TODO: Move to normal caching system
match[0] = done++;
return match;
+1 -1
Ver Arquivo
@@ -19,7 +19,7 @@
case 'PUT' : parse_str(file_get_contents('php://input'), $put_vars);
$_REQ['data'] = $put_vars;
break;
default:
default :
$_REQ['data']= null;
}
include('mind3rd/API/utils/utils.php');
+1
Ver Arquivo
@@ -29,6 +29,7 @@ class En implements l10n{
}
public function __construct()
{
$this->messages['welcome'] = "Welcome to mind3rd.\nPlease, type 'help' to see the basic help content.\nType 'list' to see the complete list of commands.\n";
$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: ";
+1
Ver Arquivo
@@ -36,6 +36,7 @@ class pt implements l10n{
public function __construct()
{
//header('Content-type: text/html; charset=iso-8859-1');
$this->messages['welcome'] = "Bem vindo ao mind3rd.\nDigite 'help' para ver o conteúdo básico da ajuda.\nDigite 'list' para ver a lista completa de comandos.\n";
$this->messages['programRequired'] = Mind::message("API: Você precisa passar o nome do programa a ser executado.", '[Fail]', false);
$this->messages['loginRequired'] = Mind::message("Auth: Tanto login quanto senha são obrigatórios.", '[Fail]', false);
$this->messages['passwordRequired'] = "Precisarei do password para este usuário, por favor: ";
+3
Ver Arquivo
@@ -481,9 +481,12 @@ class MindCommand extends Symfony\Component\Console\Command\Command
}
/**
* Reads from keyboard in hiddenn mode.
*
* 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 passwords from console, not showing any character
* or replacing them by stars(asterisks)
*
* @method readPassword
* @param Boolan $stars if true, show an * for each typed char
* @return String password
+63
Ver Arquivo
@@ -0,0 +1,63 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Logs different types of messages.
*
* This class logs different types of messages innto files.
* The available types are the following:
* user User interactions, like login or login failure
* project Interactions with projects, like creating a project, add a user to it or commiting it.
* sys System logs, like errors or warnings(lines starting with E represent errors, while W represents warnings)
*
* @author felipenmoura
*/
class MindLog {
const LOG_TYPE_USER = 'user';
const LOG_TYPE_PROJECT= 'project';
const LOG_TYPE_SYS = 'sys';
public static function log($type, $msg, Array $details= null){
GLOBAL $_MIND;
if($details)
$msg." - Details: ".json_encode($details);
$msg.= ' - '.date('m/d/Y - H:i:s') . ' ip: '.(isset ($_SERVER['HTTP_X_FORWARDED_FOR'])?
$_SERVER['HTTP_X_FORWARDED_FOR']:
key_exists('REMOTE_ADDR', $_SERVER)?
$_SERVER['REMOTE_ADDR']:
'local');
switch($type){
case self::LOG_TYPE_USER:{
if(strtolower($_MIND->conf['log_user_interaction'])){
if(!@file_put_contents(_MINDSRC_.\LOGS_DIR.'user.log', $msg."\n", FILE_APPEND)){
echo "ERROR: failed trying to create log! please, check the writting permissions for "._MINDSRC_.\LOGS_DIR."!";
}
}
break;
}
case self::LOG_TYPE_PROJECT:{
if(strtolower($_MIND->conf['log_project_interaction'])){
if(@file_put_contents(_MINDSRC_.\LOGS_DIR.'project.log', $msg."\n", FILE_APPEND)){
echo "ERROR: failed trying to create log! please, check the writting permissions for "._MINDSRC_.\LOGS_DIR."!";
}
}
break;
}
default:{
if(!@file_put_contents(_MINDSRC_.\LOGS_DIR.'sys.log', $msg."\n", FILE_APPEND)){
echo "ERROR: failed trying to create log! please, check the writting permissions for "._MINDSRC_.\LOGS_DIR."!";
}
break;
}
}
}
}
+1 -1
Ver Arquivo
@@ -141,7 +141,7 @@ class MindProject extends VersionManager{
";
$data= $db->query($hasProject);
if(sizeof($data)>0)
return true;
return $data;
return false;
}
+1 -2
Ver Arquivo
@@ -25,7 +25,6 @@
public function executableFunction()
{
//echo "AAAAAAAAA";
if(!\API\User::userExists($this->user))
{
echo "user does not exist";
@@ -36,7 +35,7 @@
echo "project does not exist";
return false; // TODO: put it into L10N
}
$pF= new DAO\ProjectFactory($this->project);
$pF= new DAO\ProjectFactory(Array('name'=>$this->project));
//print_r($pF);
echo $this->project."\n\n";
echo "BBBBBBBBB";
+3
Ver Arquivo
@@ -43,12 +43,15 @@
if(!$row)
{
Mind::write('auth_fail', true);
\MindLog::log(\MindLog::LOG_TYPE_USER, 'FAIL - Tried login with user \''.$this->login.'\' and failed');
return false;
}
}else{
die('Database not found!');
}
Mind::write('autenticated', true, $this->login);
\MindLog::log(\MindLog::LOG_TYPE_USER, ' OK - \''.$this->login.'\' logged in');
return $this;
}
+2
Ver Arquivo
@@ -159,6 +159,7 @@ EOT
Mind::openProject(Array('pk_project'=>$key,
'name'=>$this->argName));
\MindLog::log(\MindLog::LOG_TYPE_PROJECT, " OK - Project '".$this->argName."' create by ".$_SESSION['login']);
break;
case 'user':
$db= new MindDB();
@@ -195,6 +196,7 @@ EOT
)";
$db->execute($qr_newUser);
Mind::write('userCreated', true, $this->argName);
\MindLog::log(\MindLog::LOG_TYPE_USER, " OK - User '".$this->argName."' create by ".$_SESSION['login']);
echo "\n";
break;
default:
-54
Ver Arquivo
@@ -1,54 +0,0 @@
<?php
/**
* This file is part of TheWebMind 3rd generation.
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
* @license licenses/mind3rd.license
*/
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
/**
* This class represents a model for programs
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
class helpContent extends MindCommand implements program
{
public function executableFunction()
{
echo "theWebMind(or just mind):\n website: http://thewebmind.org\n Twitter: @thewebmind\n Docs: http://docs.thewebmind.org\n\n";
"The list of startup commands:\n".
" install : installs the application itself\n".
" uninstall: uninstalls the application, but do NOT remove projects,\n".
" users or history\n".
" remove : installs the application AND REMOVE every data it may\n".
" have created, including ALL projects, history and users.\n".
" --help :\n";
" -h :\n";
" help :\n";
" ? :\n";
" Shows this help content.\n\n";
echo "After installing, you can open the application by calling the 'mind' command anywhere.\n".
"You will also be able to send POST requisition to mind's server address sending the command you want to execute and its parameters.\n";
}
public function __construct()
{
$this->setCommandName('helps')
->setFileName('helpContent')
->setDescription("Shows the help content")
->setRestrict(false)
->setHelp("Shows the help content")
->setAction(function($class){
$class->executableFunction();
});
/*$this->addRequiredArgument('firstArgument',
'first, and required argument',
Array('X', 'Y', 'Z'));*/
$this->init();
}
}
Arquivo executável
+47
Ver Arquivo
@@ -0,0 +1,47 @@
<?php
/**
* This file is part of TheWebMind 3rd generation.
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
* @license licenses/mind3rd.license
*/
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
/**
* This class represents a model for programs
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
class Who extends MindCommand implements program
{
public function executableFunction()
{
$name= JSON_decode($_SESSION['auth']);
$name= $name->name;
echo 'You are '.$_SESSION['login'].", also known as ".$name."\n";
}
public function __construct()
{
$this->setCommandName('who')
->setDescription("Show information about the currently logged used")
->setRestrict(true)
->setHelp("Show information about the currently logged used")
->setAction(function($class){
$class->executableFunction();
});
/*$this->addOption('am', 'am');
$this->addOption('i', 'i');*/
$this->addRequiredArgument('am',
'am',
Array('am'));
$this->addRequiredArgument('i',
'I',
Array('i', 'I', 'i?', 'I?'));
$this->init();
}
}
+4 -5
Ver Arquivo
@@ -7,8 +7,8 @@
*/
// setting the general helperSet
$helperSet= true;
/*$helperSet= ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
$helperSet= true;
/*$helperSet= ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
$app->setHelperSet($helperSet);*/
if(isset($_SERVER['argv']))
@@ -20,11 +20,10 @@
/* let's load the plugins, if they are allowed */
Mind::$triggers= array_keys($app->getCommands());
//var_dump($app);
try {
$sh= new Symfony\Component\Console\Shell($app);
\Mind::write('welcome');
$sh->run();
}catch(Exception $exc) {
+1
Ver Arquivo
@@ -34,6 +34,7 @@
define('KNOWLEDGE_BASE', 'mind3rd/SQLite/mind');
define('KNOWLEDGE_DDL', 'mind3rd/SQLite/ddl.sql');
define('MODELS_DIR', '/mind3rd/API/models/');
define('LOGS_DIR', '/mind3rd/API/logs/');
define('ABOUT_INI', '/mind3rd/env/about.ini');
define('DEFAULTS_INI', '/mind3rd/env/defaults.ini');
define('MIND_CONF', '/mind3rd/env/mind.ini');
+5 -1
Ver Arquivo
@@ -23,4 +23,8 @@ use_prefix_on_merged_entities= true
; how many points should consider an entity worth of mergin or not
merging_amount_pts=2
; should admin users be able to install components to the structure?
allow_installation=true
allow_installation=true
; should log user interactions(like login or login failures)
log_user_interaction=yes
; shouold log project interactions(like creation, commit or permissions)
log_project_interaction=yes