Ejemplo n.º 1
0
    $p = json_decode(json_encode($event), True);
    // Reading options from POST/PUT
    $cookie = genUuid();
    $output = apiLogin($db, $p, $cookie);
    if ($output['code'] == 200) {
        // User is authenticated, need to set the cookie
        $app->setCookie('unetlab_session', $cookie, SESSION, '/api/', $_SERVER['SERVER_NAME'], False, False);
    }
    $app->response->setStatus($output['code']);
    $app->response->setBody(json_encode($output));
});
$app->get('/api/auth/logout', function () use($app, $db) {
    // Logout (DELETE request does not work with cookies)
    $cookie = $app->getCookie('unetlab_session');
    $app->deleteCookie('unetlab_session');
    $output = apiLogout($db, $cookie);
    $app->response->setStatus($output['code']);
    $app->response->setBody(json_encode($output));
});
$app->get('/api/auth', function () use($app, $db) {
    list($user, $tenant, $output) = apiAuthorization($db, $app->getCookie('unetlab_session'));
    if ($user === False) {
        // Set 401 not 412 for this page only -> used to refresh after a logout
        $output['code'] = 401;
        $app->response->setStatus($output['code']);
        $app->response->setBody(json_encode($output));
        return;
    }
    if (checkFolder(BASE_LAB . $user['folder']) !== 0) {
        // User has an invalid last viewed folder
        $user['folder'] = '/';
Ejemplo n.º 2
0
// Logging granularity: 0 = No logging, 1 = Errors only, 2 = Debug, 3 = cURL debug
$filename = "TestLeadList.csv";
// Default CSV lead list file to be loaded
// Parse the command line, looking for the filename of the ini file containing the operational parameters
if ($argc < 2) {
    echo "Syntax is: " . $argv[1] . " <INI file name> [<Lead List CSV filename>]\n";
    exit;
} else {
    // Attempt to open the ini file, and extract the operational parameters
    $params = parse_ini_file($argv[1]);
    if (!$params) {
        // Failed to parse the INI file, so force an exit
        if ($logLevel >= 1) {
            echo "LoadList: ERROR - Failed to parse INI file: " . $argv[1] . "\n";
        }
    } else {
        // If it has been provided, pick up the name of the CSV file containing the leads to be imported
        if ($argc > 2) {
            $filename = $argv[2];
        }
        // Attempt to log in to the API
        $response = apiLogin($params['baseURL'], $params['userId'], $params['password'], $params['apiKey'], $logLevel);
        if ($response != '') {
            // Logged in successfully, so go to work
            // Load the list, picking all of the details out of the CSV file
            loadLeadList($params['baseURL'], $params['userId'], $params['password'], $filename, $logLevel);
            // Now log out of the API
            apiLogout($params['baseURL'], $params['userId'], $params['password'], $logLevel);
        }
    }
}