Ejemplo n.º 1
0
 public static function login()
 {
     $username = null;
     $password = null;
     $valid = false;
     if (isset($_SESSION['username']) && isset($_SESSION['password'])) {
         // a session is active
         $username = $_SESSION['username'];
         $password = $_SESSION['password'];
         $valid = true;
     } else {
         if (isset($_POST['username']) && isset($_POST['password'])) {
             // a login is requested via HTTP POST
             $username = $_POST['username'];
             $password = $_POST['password'];
         } else {
             if (isset($_GET['username']) && isset($_GET['password'])) {
                 // a login is requested via HTTP GET
                 $username = $_GET['username'];
                 $password = $_GET['password'];
             }
         }
     }
     // validate the credentials
     if (!$valid) {
         $user_id = UserC::login($username, $password);
     } else {
         return true;
     }
     if ($user_id == -1) {
         // invalid credentials
         return false;
     }
     // valid credentials
     // so store everything as part of the session
     $_SESSION['username'] = strtolower($username);
     $_SESSION['password'] = $password;
     $_SESSION['userid'] = $user_id;
     $_SESSION['userconf'] = getConfiguration();
     $_SESSION['feed_new'] = '00.00';
     $_SESSION['feed_old'] = microtime(true);
     return true;
 }
Ejemplo n.º 2
0
     }
 } else {
     if ($what == 'file') {
         $name = joinPaths(CHRIS_USERS, $parameters);
         // enable cross origin requests
         header("Access-Control-Allow-Origin: *");
         // if the file does not exist, just die
         if (!is_file($name)) {
             die;
         }
         $fp = fopen($name, 'rb');
         fpassthru($fp);
         die;
     } else {
         if ($what == 'users') {
             $result['result'] = UserC::get();
         } else {
             if ($what == 'tag') {
                 $result['result'] = TagC::get($_SESSION['userid']);
             } else {
                 if ($what == 'directory_content') {
                     // user connects
                     // $ssh_connection = new Net_SSH2(CLUSTER_HOST);
                     // if (!$ssh_connection->login($_SESSION['username'], $_SESSION['password'])) {
                     //   die('Login Failed');
                     // }
                     //$result['result'] = $ssh_connection->exec('/usr/bin/php5 '.CHRIS_CONTROLLER_FOLDER.'/feed.browser.connector.php -d '.$_POST['dir']);
                     //echo $_POST["dir"];
                     $output = array();
                     exec('/usr/bin/php5 ' . CHRIS_CONTROLLER_FOLDER . '/feed.browser.connector.php -d ' . $_POST['dir'], $output);
                     $result['result'] = implode($output);
Ejemplo n.º 3
0
// $password
// $feedname
// $feed_id
// $jobid
// $memory
// $status
// $status_step
// *****************
// get the name of the executable as plugin name
$plugin_command_array = explode(' ', $command);
$plugin_name_array = explode('/', $plugin_command_array[0]);
$plugin_name = end($plugin_name_array);
array_shift($plugin_command_array);
$parameters = implode(' ', $plugin_command_array);
// get user if from username
$user_id = UserC::getID($username);
// create the feed if first batch job
if ($feed_id == -1) {
    $feed_id = FeedC::create($user_id, $plugin_name, $feedname, $status);
}
// create the feed directory
$user_path = joinPaths(CHRIS_USERS, $username);
$plugin_path = joinPaths($user_path, $plugin_name);
$feed_path = joinPaths($plugin_path, $feedname . '-' . $feed_id);
// create job directory
$job_path = $feed_path;
if ($jobid != '') {
    $job_path .= '/' . $jobid;
}
// Setup directories (including ssh/host vars)
// do we force this plugin to run locally as chris?
Ejemplo n.º 4
0
    // quick (and dirty) hack to ensure that there is always a '?' in the URL
    // we add it to ensure that a user is always logged in at chris/? or chris/experimental/?
    // if not, in collaboration mode it can happend that
    // user 1 is at: chris/
    // user 2 is at: chris/?
    // then the collaboration is buggy
    if ($_SERVER["REQUEST_URI"][strlen($_SERVER["REQUEST_URI"]) - 1] !== '?') {
        header("Location: ?");
        exit;
    }
    // update user-specific configuration
    // BACKGROUND
    if (isset($_SESSION['userconf']['general']) && isset($_SESSION['userconf']['general']['background'])) {
        $prefix = '';
        if (dirname($_SESSION['userconf']['general']['background']) == '.') {
            $prefix .= 'users/' . $_SESSION['username'] . '/' . CHRIS_USERS_CONFIG_DIR . '/';
        }
        $_SESSION['userconf']['general']['background'] = $prefix . $_SESSION['userconf']['general']['background'];
    } else {
        $_SESSION['userconf']['general']['background'] = "view/gfx/fnndsc_1920x1200.jpg";
    }
    // EMAIL ADDRESS
    if (isset($_SESSION['userconf']['general']) && isset($_SESSION['userconf']['general']['email'])) {
        UserC::setEmail($_SESSION['userid'], $_SESSION['userconf']['general']['email']);
    }
    // show the homepage
    echo homePage();
    exit;
}
// otherwise show the login screen
echo loginPage();
Ejemplo n.º 5
0
 /**
  * Try to login a user using a username and a cleartext password.
  *
  * @param string $username The username.
  * @param string $password The password in cleartext.
  * @return number The user ID of the user or -1 on failure.
  */
 public static function login($username, $password)
 {
     if (!isset($username) || !isset($password)) {
         return -1;
     }
     $ssh = new Net_SSH2(CLUSTER_HOST);
     if ($ssh->login($username, $password)) {
         // the user credentials are valid!
         // make sure this user is also allowed to access chris by checking the user table and grabbing the user id
         $userMapper = new Mapper('User');
         $userMapper->filter('username=(?)', $username);
         $userResults = $userMapper->get();
         // if user exist, return its id
         if (isset($userResults['User'][0])) {
             // setup directory if needed
             UserC::setupDir($username, $ssh);
             // valid user
             return $userResults['User'][0]->id;
         } else {
             $uid = $ssh->exec('id -u ' . $username);
             $report = "=========================================" . PHP_EOL;
             $report .= date('Y-m-d h:i:s') . ' ---> New user logging in...' . PHP_EOL;
             $report .= $username . PHP_EOL;
             $report .= $uid . PHP_EOL;
             // log logging information
             $logFile = joinPaths(CHRIS_LOG, 'new_user.log');
             $fh = fopen($logFile, 'a') or die("can't open file");
             fwrite($fh, $report);
             fclose($fh);
             // returns 0 since the user table doesnt have auto increment
             UserC::create($uid, $username);
             // setup directory if needed
             UserC::setupDir($username, $ssh);
             return $uid;
         }
     }
     // invalid credentials
     return -1;
 }