Exemple #1
0
 public function __call($name, $args)
 {
     if (!in_array($name, array('execute', 'select'))) {
         return call_user_func_array(array($this->_rdb, $name), $args);
     }
     Pluf_Log::stime('timer');
     $res = call_user_func_array(array($this->_rdb, $name), $args);
     Pluf_Log::perf(array('Pluf_DB_Stats', $this->_rdb->lastquery, Pluf_Log::etime('timer', 'total_sql')));
     Pluf_Log::inc('sql_query');
     return $res;
 }
Exemple #2
0
 function testAssertLog()
 {
     Pluf_Log::activeAssert();
     $GLOBALS['_PX_config']['log_delayed'] = true;
     assert('Pluf_Log::alog("hello")');
     $this->assertEqual(count(Pluf_Log::$stack), 1);
     $GLOBALS['_PX_config']['log_delayed'] = false;
     assert('Pluf_Log::alog("hello")');
     $this->assertEqual(count(Pluf_Log::$stack), 0);
     $this->assertEqual(2, count(file($this->logfile)));
 }
Exemple #3
0
 function testAssertLog()
 {
     if (Pluf::f('test_log_testremote', false) == false) {
         return;
     }
     Pluf_Log::activeAssert();
     $GLOBALS['_PX_config']['log_delayed'] = true;
     assert('Pluf_Log::alog("hello")');
     $this->assertEqual(count(Pluf_Log::$stack), 1);
     $GLOBALS['_PX_config']['log_delayed'] = false;
     assert('Pluf_Log::alog("hello")');
     $this->assertEqual(count(Pluf_Log::$stack), 0);
 }
Exemple #4
0
 /**
  * Entry point for the post-update signal.
  *
  * It tries to find the name of the project, when found it runs an
  * update of the timeline.
  */
 public static function postUpdate($signal, &$params)
 {
     // Chop the ".git" and get what is left
     $pname = basename($params['git_dir'], '.git');
     try {
         $project = IDF_Project::getOr404($pname);
     } catch (Pluf_HTTP_Error404 $e) {
         Pluf_Log::event(array('IDF_Plugin_SyncGit::postUpdate', 'Project not found.', array($pname, $params)));
         return false;
         // Project not found
     }
     // Now we have the project and can update the timeline
     Pluf_Log::debug(array('IDF_Plugin_SyncGit::postUpdate', 'Project found', $pname, $project->id));
     IDF_Scm::syncTimeline($project, true);
     Pluf_Log::event(array('IDF_Plugin_SyncGit::postUpdate', 'sync', array($pname, $project->id)));
 }
Exemple #5
0
 /**
  * Update the timeline in post commit.
  *
  */
 public function processSyncTimeline($params)
 {
     $pname = basename($params['rel_dir']);
     try {
         $project = IDF_Project::getOr404($pname);
     } catch (Pluf_HTTP_Error404 $e) {
         Pluf_Log::event(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'Project not found.', array($pname, $params)));
         return false;
         // Project not found
     }
     // Now we have the project and can update the timeline
     Pluf_Log::debug(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'Project found', $pname, $project->id));
     IDF_Scm::syncTimeline($project, true);
     Pluf_Log::event(array('IDF_Plugin_SyncMercurial::processSyncTimeline', 'sync', array($pname, $project->id)));
 }
Exemple #6
0
/**
 * This script process the queue of items.
 *
 * At the moment the queue is only used for the webhooks, but it would
 * be good in the future to use it for indexing and email
 * notifications.
 *
 */
require dirname(__FILE__) . '/../src/IDF/conf/path.php';
require 'Pluf.php';
Pluf::start(dirname(__FILE__) . '/../src/IDF/conf/idf.php');
Pluf_Dispatcher::loadControllers(Pluf::f('idf_views'));
#;*/ ::
$lock_file = Pluf::f('idf_queuecron_lock', Pluf::f('tmp_folder', '/tmp') . '/queuecron.lock');
if (file_exists($lock_file)) {
    Pluf_Log::event(array('queuecron.php', 'skip'));
    return;
}
file_put_contents($lock_file, time(), LOCK_EX);
/**
 * [signal]
 *
 * queuecron.php::run
 *
 * [sender]
 *
 * queuecron.php
 *
 * [description]
 *
 * This signal allows an application to perform a set of tasks when
Exemple #7
0
 /**
  * End the time to track.
  *
  * @param $key Tracker
  * @param $total Tracker to store the total (null)
  * @return float Time for this track
  */
 public static function etime($key, $total = null)
 {
     $t = microtime(true) - Pluf_Log::$store['time_tracker_' . $key];
     if ($total) {
         Pluf_Log::inc('time_tracker_' . $total, $t);
     }
     return $t;
 }
Exemple #8
0
 /**
  * Update the timeline after a push
  *
  */
 public function processSyncTimeline($project_name)
 {
     try {
         $project = IDF_Project::getOr404($project_name);
     } catch (Pluf_HTTP_Error404 $e) {
         Pluf_Log::event(array('IDF_Plugin_SyncMonotone::processSyncTimeline', 'Project not found.', array($project_name, $params)));
         return false;
         // Project not found
     }
     Pluf_Log::debug(array('IDF_Plugin_SyncMonotone::processSyncTimeline', 'Project found', $project_name, $project->id));
     IDF_Scm::syncTimeline($project, true);
     Pluf_Log::event(array('IDF_Plugin_SyncMonotone::processSyncTimeline', 'sync', array($project_name, $project->id)));
 }
Exemple #9
0
 /** 
  * Parse the queue.
  *
  * It is a signal handler to just hook itself at the right time in
  * the cron job performing the maintainance work.
  *
  * The processing relies on the fact that no other processing jobs
  * must run at the same time. That is, your cron job must use a
  * lock file or something like to not run in parallel.
  *
  * The processing is simple, first get 500 queue items, mark them
  * as being processed and for each of them call the processItem()
  * method which will trigger another event for processing.
  *
  * If you are processing more than 500 items per batch, you need
  * to switch to a different solution.
  *
  */
 public static function process($sender, &$params)
 {
     $where = 'status=0 OR status=2';
     $items = Pluf::factory('IDF_Queue')->getList(array('filter' => $where, 'nb' => 500));
     Pluf_Log::event(array('IDF_Queue::process', $items->count()));
     foreach ($items as $item) {
         $item->status = 1;
         $item->update();
     }
     foreach ($items as $item) {
         $item->status = 1;
         $item->processItem();
     }
 }
Exemple #10
0
 /**
  * Given an array with the authentication data, auth the user and return it.
  */
 public static function authenticate($auth_data)
 {
     $password = $auth_data['password'];
     $login = $auth_data['login'];
     // Small security check against the login
     if (preg_match('/[^A-Za-z0-9\\-\\_]/', $login)) {
         return false;
     }
     // We check the user against the LDAP server, if it works we
     // are happy, if not return false.
     $ldap_dn = Pluf::f('auth_ldap_dn', 'ou=users,dc=example,dc=com');
     $ldap_user = Pluf::f('auth_ldap_user', null);
     $ldap_password = Pluf::f('auth_ldap_password', null);
     $ldap_version = Pluf::f('auth_ldap_version', 3);
     $ldap_user_key = Pluf::f('auth_ldap_user_key', 'uid');
     // If auth_ldap_password_key, it will use crypt hash control
     // to test the login password, else it will bind.
     $ldap_password_key = Pluf::f('auth_ldap_password_key', null);
     $ldap_surname_key = Pluf::f('auth_ldap_surname_key', 'sn');
     $ldap_givenname_key = Pluf::f('auth_ldap_givenname_key', 'cn');
     $ldap_email_key = Pluf::f('auth_ldap_email_key', 'mail');
     $ldap = ldap_connect(Pluf::f('auth_ldap_host', 'localhost'));
     ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, Pluf::f('auth_ldap_version', 3));
     if (!ldap_bind($ldap, $ldap_user, $ldap_password)) {
         Pluf_Log::warn(sprintf('Cannot bind to the ldap server, user:%s, password:***', $ldap_user));
         ldap_close($ldap);
         return false;
     }
     // Go for a search
     $search = ldap_search($ldap, $ldap_dn, '(' . $ldap_user_key . '=' . $login . ')', array($ldap_user_key, $ldap_surname_key, $ldap_givenname_key, $ldap_email_key));
     $n = ldap_get_entries($ldap, $search);
     if ($n['count'] != 1) {
         ldap_close($ldap);
         return false;
     }
     $entry = ldap_first_entry($ldap, $search);
     // We get all the data first, the bind or hash control is done
     // later. If we control with bind now, we need to search again
     // to have an $entry resource to get the values.
     list($family_name, ) = @ldap_get_values($ldap, $entry, $ldap_surname_key);
     list($first_name, ) = @ldap_get_values($ldap, $entry, $ldap_givenname_key);
     list($email, ) = @ldap_get_values($ldap, $entry, $ldap_email_key);
     $user_dn = ldap_get_dn($ldap, $entry);
     if ($ldap_password_key) {
         // Password authentication.
         list($ldap_hash, ) = ldap_get_values($ldap, $entry, $ldap_password_key);
         $ldap_hash = substr($ldap_hash, 7);
         $salt = substr($ldap_hash, 0, 12);
         $hash = crypt($password, $salt);
         if ($ldap_hash != $hash) {
             ldap_close($ldap);
             return false;
         }
     } else {
         // Bind authentication
         if (!@ldap_bind($ldap, $user_dn, $password)) {
             ldap_close($ldap);
             return false;
         }
     }
     // We get the user values as the
     // Now we get the user and we create it if not available
     $user = self::getUser($login);
     if ($user) {
         ldap_close($ldap);
         return $user;
     }
     // Need to create it
     ldap_close($ldap);
     $user_model = Pluf::f('pluf_custom_user', 'Pluf_User');
     $user = new $user_model();
     $user->active = true;
     $user->login = $login;
     $user->password = $password;
     $user->last_name = $family_name;
     $user->first_name = $first_name;
     $user->email = $email;
     $user->create();
     return $user;
 }
Exemple #11
0
 /**
  * Init a new empty bare repository.
  *
  * @param string Full path to the repository
  */
 public function initRepository($fullpath)
 {
     if (!file_exists($fullpath)) {
         mkdir($fullpath, 0750, true);
     }
     $out = array();
     $res = 0;
     exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '') . Pluf::f('git_path', 'git') . ' --git-dir=%s init', escapeshellarg($fullpath)), $out, $res);
     if ($res != 0) {
         Pluf_Log::error(array('IDF_Plugin_Git_Serve::initRepository', $res, $fullpath));
         throw new Exception(sprintf('Init repository error, exit status %d.', $res));
     }
     Pluf_Log::event(array('IDF_Plugin_Git_Serve::initRepository', 'success', $fullpath));
     // Add the post-update hook by removing the original one and add the
     // Indefero's one.
     $p = realpath(dirname(__FILE__) . '/../../../../scripts/git-post-update');
     $p = Pluf::f('idf_plugin_syncgit_post_update', $p);
     if (!@unlink($fullpath . '/hooks/post-update')) {
         Pluf_Log::warn(array('IDF_Plugin_Git_Serve::initRepository', 'post-update hook removal error.', $fullpath . '/hooks/post-update'));
         return;
     }
     $out = array();
     $res = 0;
     exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '') . 'ln -s %s %s', escapeshellarg($p), escapeshellarg($fullpath . '/hooks/post-update')), $out, $res);
     if ($res != 0) {
         Pluf_Log::warn(array('IDF_Plugin_Git_Serve::initRepository', 'post-update hook creation error.', $fullpath . '/hooks/post-update'));
         return;
     }
     Pluf_Log::debug(array('IDF_Plugin_Git_Serve::initRepository', 'Added post-update hook.', $fullpath));
     // Configure the core.quotepath option
     $quotepath = Pluf::f('git_core_quotepath', true) == true ? 'true' : 'false';
     $out = array();
     $res = 0;
     exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '') . Pluf::f('git_path', 'git') . ' config -f %s/config --add core.quotepath %s', escapeshellarg($fullpath), escapeshellarg($quotepath)), $out, $res);
     if ($res != 0) {
         Pluf_Log::warn(array('IDF_Plugin_Git_Serve::initRepository', 'core.quotepath configuration error.', $quotepath));
         return;
     }
     Pluf_Log::debug(array('IDF_Plugin_Git_Serve::initRepository', 'core.quotepath configured.', $quotepath));
 }
Exemple #12
0
/**
 * This script will send the notifications after a push in your 
 * repository.
 */
require dirname(__FILE__) . '/../src/IDF/conf/path.php';
require 'Pluf.php';
Pluf::start(dirname(__FILE__) . '/../src/IDF/conf/idf.php');
Pluf_Dispatcher::loadControllers(Pluf::f('idf_views'));
/**
 * [signal]
 *
 * gitpostupdate.php::run
 *
 * [sender]
 *
 * gitpostupdate.php
 *
 * [description]
 *
 * This signal allows an application to perform a set of tasks on a
 * post update of a git repository.
 *
 * [parameters]
 *
 * array('git_dir' => '/path/to/git/repository.git',
 *       'env' => array_merge($_ENV, $_SERVER));
 *
 */
$params = array('git_dir' => $argv[1], 'env' => array_merge($_ENV, $_SERVER));
Pluf_Log::event(array('gitpostupdate.php', 'Send run signal.', $params));
Pluf_Signal::send('gitpostupdate.php::run', 'gitpostupdate.php', $params);
Exemple #13
0
 * This script will send the notifications after a push in your 
 * repository.
 */
require dirname(__FILE__) . '/../src/IDF/conf/path.php';
require 'Pluf.php';
Pluf::start(dirname(__FILE__) . '/../src/IDF/conf/idf.php');
Pluf_Dispatcher::loadControllers(Pluf::f('idf_views'));
/**
 * [signal]
 *
 * svnpostcommit.php::run
 *
 * [sender]
 *
 * svnpostcommit.php
 *
 * [description]
 *
 * This signal allows an application to perform a set of tasks on a
 * post commit of a subversion repository.
 *
 * [parameters]
 *
 * array('repo_dir' => '/path/to/subversion/repository',
 *       'revision' => 1234,
 *       'env' => array_merge($_ENV, $_SERVER));
 *
 */
$params = array('repo_dir' => $argv[1], 'revision' => $argv[2], 'env' => array_merge($_ENV, $_SERVER));
Pluf_Log::event(array('svnpostcommit.php', 'Send run signal.', $params));
Pluf_Signal::send('svnpostcommit.php::run', 'svnpostcommit.php', $params);
Exemple #14
0
 /**
  * Run shell_exec and log some information.
  *
  * @param $caller Calling method
  * @param $cmd Command to run
  * @return string The output
  */
 public static function shell_exec($caller, $cmd)
 {
     Pluf_Log::stime('timer');
     $ret = shell_exec($cmd);
     Pluf_Log::perf(array($caller, $cmd, Pluf_Log::etime('timer', 'total_exec')));
     Pluf_Log::debug(array($caller, $cmd, $ret));
     Pluf_Log::inc('exec_calls');
     return $ret;
 }