<commit_before><?php
    

    require 'lib/Slim/Slim.php';
    \Slim\Slim::registerAutoloader();

    $app = new \Slim\Slim();

    //if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler");
    //else ob_start();

    require_once('OracleSession.php');
    $handler = new OracleSessionHandler();
    session_set_save_handler(
                             array($handler, '_open'),
                             array($handler, '_close'),
                             array($handler, '_read'),
                             array($handler, '_write'),
                             array($handler, '_destroy'),
                             array($handler, '_gc')
                             );
    
    // the following prevents unexpected effects when using objects as save handlers
    register_shutdown_function('session_write_close');
    
    require_once('config.php');


    $parts = explode('/', $app->request->getResourceUri()); 
    if (sizeof($parts)) array_shift($parts);
      
    $need_auth = true;
    # Work around to allow beamline sample registration without CAS authentication
    # For use on the touchscreen computers in the hutch
    if (sizeof($parts) >= 2) {
        if (
            (($parts[0] == 'assign') && in_array($_SERVER["REMOTE_ADDR"], $blsr)) ||
            (($parts[0] == 'shipment' && $parts[1] == 'containers') && in_array($_SERVER["REMOTE_ADDR"], $blsr)) ||
            ($parts[0] == 'cal' && $parts[1] == 'ics' && $parts[2] == 'h')
            ) {
            $need_auth = false;
        }
        
    # Allow barcode reader unauthorised access, same as above, certain IPs only
    } else if (sizeof($parts) == 1) {
        if ($parts[0] == 'tracking' && in_array($_SERVER["REMOTE_ADDR"], $bcr)) {
            $need_auth = false;
        }
    }
    
    if ($need_auth) {
        require_once 'lib/CAS/CAS.php';
        phpCAS::client(CAS_VERSION_2_0, 'liveauth.diamond.ac.uk', 443, '/cas');
        //phpCAS::setCasServerCACert($cacert);
        phpCAS::setNoCasServerValidation();
        phpCAS::forceAuthentication();
    }

    $user = class_exists('phpCAS') ? phpCAS::getUser() : null;

    date_default_timezone_set('Europe/London');
    
    include_once('includes/class.page.php');
    include_once('includes/class.db.php');
    
    $db = new Oracle($isb['user'], $isb['pass'], $isb['db'], $app);
    register_shutdown_function(array(&$db, '__destruct'));
    
    if ($parts[0] == 'logout') {
        $db->pq("INSERT INTO log4stat (id,priority,log4jtimestamp,msg,detail) 
            VALUES (s_log4stat.nextval, 'ISPYB2_STAT', SYSDATE, 'LOGOFF', :1)", 
            array($user));
        phpCAS::logout();
    }
    
    include_once('includes/class.type.php');
    $type = new ProposalType($app, $db, $user);
    $type->get_type();
    
?><commit_msg>fix authentication for barcode scanners<commit_after><?php
    

    require 'lib/Slim/Slim.php';
    \Slim\Slim::registerAutoloader();

    $app = new \Slim\Slim();

    //if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler");
    //else ob_start();

    require_once('OracleSession.php');
    $handler = new OracleSessionHandler();
    session_set_save_handler(
                             array($handler, '_open'),
                             array($handler, '_close'),
                             array($handler, '_read'),
                             array($handler, '_write'),
                             array($handler, '_destroy'),
                             array($handler, '_gc')
                             );
    
    // the following prevents unexpected effects when using objects as save handlers
    register_shutdown_function('session_write_close');
    
    require_once('config.php');


    $parts = explode('/', $app->request->getResourceUri()); 
    if (sizeof($parts)) array_shift($parts);
      
    $need_auth = true;
    # Work around to allow beamline sample registration without CAS authentication
    if (sizeof($parts) >= 2) {
        if (
            # For use on the touchscreen computers in the hutch
            (($parts[0] == 'assign') && in_array($_SERVER["REMOTE_ADDR"], $blsr)) ||
            (($parts[0] == 'shipment' && $parts[1] == 'containers') && in_array($_SERVER["REMOTE_ADDR"], $blsr)) ||
            ($parts[0] == 'cal' && $parts[1] == 'ics' && $parts[2] == 'h') || 

            # Allow barcode reader unauthorised access, same as above, certain IPs only
            ($parts[0] == 'shipment' && $parts[1] == 'dewars' && in_array($_SERVER["REMOTE_ADDR"], $bcr))
            ) {
            $need_auth = false;
        }
    }
    
    
    if ($need_auth) {
        require_once 'lib/CAS/CAS.php';
        phpCAS::client(CAS_VERSION_2_0, 'liveauth.diamond.ac.uk', 443, '/cas');
        //phpCAS::setCasServerCACert($cacert);
        phpCAS::setNoCasServerValidation();
        phpCAS::forceAuthentication();
    }

    $user = class_exists('phpCAS') ? phpCAS::getUser() : null;

    date_default_timezone_set('Europe/London');
    
    include_once('includes/class.page.php');
    include_once('includes/class.db.php');
    
    $db = new Oracle($isb['user'], $isb['pass'], $isb['db'], $app);
    register_shutdown_function(array(&$db, '__destruct'));
    
    if ($parts[0] == 'logout') {
        $db->pq("INSERT INTO log4stat (id,priority,log4jtimestamp,msg,detail) 
            VALUES (s_log4stat.nextval, 'ISPYB2_STAT', SYSDATE, 'LOGOFF', :1)", 
            array($user));
        phpCAS::logout();
    }
    
    include_once('includes/class.type.php');
    $type = new ProposalType($app, $db, $user);
    $type->get_type();
    
?>
{'fraction_non_alphanumeric': 0.1657526976826464, 'fraction_numerical': 0.0070758889085441356, 'mean_word_length': 2.379557680812911, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7505179', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1720, 'n_words': 323}