Example #1
0
        $app->response->setBody(json_encode($output));
    })->via('DELETE', 'GET', 'POST');
    $app->run();
}
// Define output for unprivileged requests
$forbidden = array('code' => 401, 'status' => 'forbidden', 'message' => $GLOBALS['messages']['90032']);
/***************************************************************************
 * Authentication
 **************************************************************************/
$app->post('/api/auth/login', function () use($app, $db) {
    // Login
    $event = json_decode($app->request()->getBody());
    $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));
});
Example #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);
        }
    }
}