Создание пользователей в Elastix на php

В этой заметке я покажу как с помощью PHP создать группу в Elastix, добавить в нее пользователя, и назначить права. Собственно сам скрипт:

#!/usr/bin/php -q
<?
include_once("/var/www/html/libs/paloSantoACL.class.php");
include_once("/var/www/html/libs/paloSantoDB.class.php");
include_once("/var/www/html/modules/group_permission/libs/paloSantoGroupPermission.class.php");

$pDB = new paloDB("sqlite3:////var/www/db/acl.db");
$pACL = new paloACL($pDB);

echo "================= CREATING GROUPS=================\n";
$pACL->createGroup('PBXAdmin','NEOPbx Administrator',1);
$idGroupA=$pACL->getIdGroup("PBXAdmin");
echo "ID PBXAdmin:".$idGroupA."\n";

echo "============ SET GROUP PERMISSIONS ============\n";
$pACLGP = new paloSantoGroupPermission();
$arrResources=$pACLGP->loadGroupPermissionsACL($pACL->getIdGroup("administrator"));
$listaPermisosNuevosGrupo = array();
foreach($arrResources as $resource) {
    $listaPermisosNuevosGrupo[]   = $resource["resource_id"];
}
echo "Set permissions for group PBXAdmin: ";
$pACLGP -> saveGroupPermissions("access",$idGroupA,$listaPermisosNuevosGrupo);
echo "OK\n";

echo "============ ADD USERS ============\n";
echo "Creating user 'adminvirt': ";
$pwd=randomPassword();
$pACL->createUser("adminvirt","adminvirt",md5($pwd),"","","");
$pACL->addToGroup($pACL->getIdUser("adminvirt"),$idGroupA);
echo "OK\n";
echo "Password user 'adminvirt': $pwd\n";

echo "============ INSTALLATION COMPLETE ============\n";

function randomPassword() {
    $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
    $pass = '';                           //password is a string
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 20; $i++) {
	$n = mt_rand(0, $alphaLength);    
        $pass = $pass.$alphabet[$n];      //append a random character
    }
    return ($pass); 
}

?>