PHP code example of spkm / clear-pass

1. Go to this page and download the library: Download spkm/clear-pass library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spkm / clear-pass example snippets


use spkm\ClearPass\Facades\ClearPass;

$guest = ClearPass::identities()->guestUsers()->create([
    'username' => '[email protected]',
    'password' => 'a-strong-password',
    'role_id' => ClearPass::policyElements()->roles()->findByName('[Guest]')->id,   // roles are your server's own
    'expire_time' => now()->addDays(2),
    'sponsor_name' => 'Reception',
]);

$expiring = ClearPass::identities()->guestUsers()
    ->where('sponsor_profile', 'API')
    ->where('expire_time', '<', now()->addDay())
    ->orderBy('expire_time')
    ->get();

foreach (ClearPass::sessionControl()->activeSessions()->where('ssid', 'Guest')->lazy() as $session) {
    // one page of 100 at a time
}

$role = ClearPass::policyElements()->roles()->findByName('[Guest]');           // Role or null
$count = ClearPass::identities()->guestUsers()->where('enabled', true)->count();
$devices = ClearPass::policyElements()->networkDevices()->orderBy('name')->all(); // Collection of NetworkDevice

use spkm\ClearPass\Query\Query;
use spkm\ClearPass\Requests\Identities\GuestUser\GetGuestUsersRequest;

$response = ClearPass::send(new GetGuestUsersRequest(Query::make()->where('role_id', '=', 2)->limit(50)));
$response->status();
$response->json();
$response->dto();   // the same models the resource gives; throws ClearPassApiException for an error status

ClearPass::identities()->guestUsers()->find(12);                       // by id, null when there is none
ClearPass::identities()->guestUsers()->findByUsername('[email protected]');
ClearPass::identities()->guestUsers()->update(12, ['expire_time' => now()->addWeek()]);
ClearPass::identities()->guestUsers()->updateByUsername('[email protected]', ['enabled' => false], ['change_of_authorization' => 'true']);
ClearPass::identities()->guestUsers()->replace(12, $guest);            // PUT: the whole record
ClearPass::identities()->guestUsers()->delete(12);
ClearPass::insight()->alerts()->enable(3);                             // the actions a service documents
ClearPass::enforcementProfile()->natPools('ArubaOS-CX')->get();        // a service scoped by a path parameter
ClearPass::guestConfiguration()->guestManager()->update(['...' => '...']);

ClearPass::identities()->guestUsers()
    ->where('role_id', 2)                             // {"role_id": 2}
    ->where('expire_time', '>', now())                // {"expire_time": {"$gt": 1767225600}}
    ->whereIn('sponsor_profile', ['API', 'Reception'])
    ->whereBetween('simultaneous_use', [1, 3])
    ->whereContains('notes', 'parent')
    ->whereRegex('username', '^visitor', caseInsensitive: true)
    ->whereNull('mac')
    ->orderByDesc('expire_time')                      // sort=-expire_time
    ->limit(50)
    ->get();

$guest = ClearPass::identities()->guestUsers()->findByUsername('[email protected]');
$guest->expire_time?->diffForHumans();
$guest->current_state;          // active, disabled, expired or pending
$guest->extra;                  // the custom fields the account carries beyond the documented ones

$guest = ClearPass::identities()->guestUsers()->create(['username' => '[email protected]', 'password' => '…', 'role_id' => 2]);
ClearPass::identities()->guestUsers()->update($guest->id, ['notes' => 'Half day']);
ClearPass::identities()->guestUsers()->replace($guest->id, new GuestUser(username: '[email protected]', password: '…', role_id: 2));
ClearPass::identities()->guestUsers()->delete($guest->id, ['change_of_authorization' => 'true']);
bash
composer clearpass:install