Skip to content

Commit

Permalink
PHP version update 7.x into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
khuzamajutt committed Oct 5, 2024
1 parent a3f514a commit b986f8e
Show file tree
Hide file tree
Showing 127 changed files with 940 additions and 878 deletions.
2 changes: 2 additions & 0 deletions bin/freeswitch/application.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

--[[
application.lua
Disclaimer: Use at your own risk. No implied warranties or help if/when stuff blows up.
Expand Down Expand Up @@ -39,6 +40,7 @@ function application_Hangup(s, status, arg)
end

oFreeswitch.consoleLog("INFO", "Execution Done")
-- application_fetch()
end

-- Application Fetch
Expand Down
2 changes: 1 addition & 1 deletion bin/freeswitch/spool_failed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function application_fetch()

-- application_data = JSON:encode must be placed before application_id, And I don't know why ?
api_request['application_data'] = JSON:encode(app_result)
api_request['spool_id'] = spool_id
api_request['spool_id'] = tostring(env:getHeader("spool_id"))
api_request['application_id'] = app_id

-- disable any further execution, untill we have fresh application id
Expand Down
35 changes: 23 additions & 12 deletions core/Account.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,28 @@ public function __construct($account_id = NULL)
$this->_load();
}
}
//
public function set($data) {
foreach ($data as $field => $value) {
// Only set the property if it exists in the Contact object
if (property_exists($this, $field)) {
$this->$field = $value;
}

public static function construct_from_array($aAccount)
{
$oAccount = new Account();
foreach ($aAccount as $field => $value) {
$oAccount->$field = $value;
}
return $oAccount;
}
}

public static function locate($search_value, $contactField = 'phone')
{
// locate an existing account
$accountFilter = array($contactField => $search_value);
$listAccount = static::search($accountFilter);
if ($listAccount) {
$aAccount = array_shift($listAccount);
return Account::load($aAccount['account_id']);
}
return false; // no account found
}

public static function search($aFilter = array())
{
$aAccount = array();
Expand Down Expand Up @@ -207,18 +220,16 @@ public static function search($aFilter = array())

public static function getClass(&$account_id, $namespace = 'ICT\\Core\\Account')
{
$account_type = ''; // Initialize the variable here
if (ctype_digit(trim($account_id))) {
$query = "SELECT type FROM " . self::$table . " WHERE account_id='%account_id%' ";
$result = DB::query(self::$table, $query, array('account_id' => $account_id));
if (is_resource($result)) {
$account_type = mysqli_result($result, 0);
if($row = $result->fetch_row()) {
$account_type = $row[0];
}
} else {
$account_type = $account_id;
$account_id = null;
}
// The rest of the code remains unchanged
$class_name = ucfirst(strtolower(trim($account_type)));
if (!empty($namespace)) {
$class_name = $namespace . '\\' . $class_name;
Expand Down
Empty file modified core/Account/Did.php
100755 → 100644
Empty file.
File renamed without changes.
Empty file modified core/Account/Extension.php
100755 → 100644
Empty file.
Empty file modified core/Action.php
100755 → 100644
Empty file.
5 changes: 2 additions & 3 deletions core/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function authenticate($credentials, $auth_type)
{
try {
$oUser = User::authenticate($credentials, $auth_type);

if ($oUser instanceof User) {
do_login($oUser);
return true;
Expand All @@ -46,10 +45,9 @@ protected function _authorize($permission)
}
return true;
}

protected function set($oEntity, $data)
{
exit;
foreach ($data as $key => $value) {
try {
$oEntity->$key = $value;
Expand All @@ -58,6 +56,7 @@ protected function set($oEntity, $data)
}
}
}

public function create_interface($interface_type = null, $root_path = null)
{
global $path_cache;
Expand Down
5 changes: 3 additions & 2 deletions core/Api/Account/DidApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use ICT\Core\Api\AccountApi;

#[\AllowDynamicProperties]
class DidApi extends AccountApi
{

Expand All @@ -19,12 +20,12 @@ class DidApi extends AccountApi
*
* @url POST /dids
*/
public function create($data = array(), $account_id = null)
public function create($data = array())
{
$data['type'] = 'did';
return parent::create($data);
}

/**
* List all available accounts
*
Expand Down
5 changes: 3 additions & 2 deletions core/Api/Account/ExtensionApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use ICT\Core\Api\AccountApi;

#[\AllowDynamicProperties]
class ExtensionApi extends AccountApi
{

Expand All @@ -19,12 +20,12 @@ class ExtensionApi extends AccountApi
*
* @url POST /extensions
*/
public function create($data = array(), $account_id = null)
public function create($data = array())
{
$data['type'] = 'extension';
return parent::create($data);
}

/**
* List all available accounts
*
Expand Down
48 changes: 25 additions & 23 deletions core/Api/AccountApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ICT\Core\User;
use stdClass;

#[\AllowDynamicProperties]
class AccountApi extends Api
{

Expand All @@ -28,29 +29,29 @@ class AccountApi extends Api
*
* @url POST /accounts
*/
public function create($data = array(), $account_id = null)
public function create($data = array())
{
$this->_authorize('account_create');

if (isset($data['type']) && !empty($data['type'])) {
$oAccount = Account::load($data['type']);
} else {
$oAccount = new Account();
}
$aSetting = $oAccount->settings;
$this->_authorize('account_create');

if (isset($data['type']) && !empty($data['type'])) {
$oAccount = Account::load($data['type']);
} else {
$oAccount = new Account();
$oAccount->account_id = $account_id;
$oAccount->set($data);
if (isset($data['settings']) && !empty($data['settings'])) {
$oAccount->settings = array_merge($aSetting, $oAccount->settings);
}
if ($oAccount->save()) {
return $oAccount->account_id;
} else {
throw new CoreException(417, 'Account creation failed');
}
}
$aSetting = $oAccount->settings; // prepare a copy of default settings
$this->set($oAccount, $data);
if (isset($data['settings']) && !empty($data['settings'])) {
// override default settings but preserve the unchanged settings
$oAccount->settings = array_merge($aSetting, $oAccount->settings);
}

if ($oAccount->save()) {
return $oAccount->account_id;
} else {
throw new CoreException(417, 'Account creation failed');
}
}

/**
* List all available accounts
*
Expand Down Expand Up @@ -113,12 +114,13 @@ public function update($account_id, $data = array())
$this->_authorize('account_update');

$oAccount = Account::load($account_id);
$aSetting = $oAccount->settings;
$oAccount->account_id = $account_id;
$oAccount->set($data);
$aSetting = $oAccount->settings; // prepare a copy of old settings
$this->set($oAccount, $data);
if (isset($data['settings']) && !empty($data['settings'])) {
// override old settings but preserve the unchanged settings
$oAccount->settings = array_merge($aSetting, $oAccount->settings);
}

if ($oAccount->save()) {
return $oAccount;
} else {
Expand Down
13 changes: 13 additions & 0 deletions core/Api/Authenticate.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use ICT\Core\CoreException;
use ICT\Core\User;

#[\AllowDynamicProperties]
class AuthenticateApi extends Api
{

Expand All @@ -26,16 +27,25 @@ public function create($data = array())
{
$key_type = null;
$credentials = null;

if (isset($data['hash'])) {
$key_type = User::AUTH_TYPE_DIGEST;
$credentials = array('username' => null, 'password' => $data['hash']);
} else if (isset($data['SAMLResponse'])) { // Azure
$key_type = User::AUTH_TYPE_SAML;
$xml_data = base64_decode($data['SAMLResponse']);
$xmlObject = simplexml_load_string($xml_data);
$userAttribute = json_decode(json_encode($xmlObject->Assertion->AttributeStatement),true);
$user_email = $userAttribute['Attribute'][5]['AttributeValue']; // email
$credentials = array('email' => $data['email'], 'saml' => $xmlObject);
} else if (isset($data['password_hash'])) {
$key_type = User::AUTH_TYPE_DIGEST;
$credentials = array('username' => null, 'password' => $data['password_hash']);
} else {
$key_type = User::AUTH_TYPE_BASIC;
$credentials = array('username' => null, 'password' => $data['password']);
}

if (isset($data['email'])) {
$credentials['username'] = $data['email'];
} else if (isset($data['username'])) {
Expand All @@ -45,18 +55,21 @@ public function create($data = array())
} else {
throw new CoreException(401, 'No valid username found');
}

try {
$oUser = User::authenticate($credentials, $key_type);
$oUser->token = $oUser->generate_token();
$oUser->access_token = $oUser->token;
$oUser->expires_in = (60 * 60 * 24 * 30 * 12 * 1); // valid for one year
$oUser->token_type = 'Bearer';
$oUser->scope = 'All';

return $oUser;
} catch (CoreException $ex) {
throw new CoreException(401, 'Invalid user name and password: '.$ex->getMessage());
}
}

/**
* Cancel current authentication token
*
Expand Down
15 changes: 8 additions & 7 deletions core/Api/CampaignApi.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use ICT\Core\CoreException;
use ICT\Core\Schedule;

#[\AllowDynamicProperties]
class CampaignApi extends Api
{
/**
Expand All @@ -25,20 +26,15 @@ public function create($data = array())
{
$this->_authorize('campaign_create');
$oCampaign = new Campaign();
if (isset($data['program_id'])) {
$oCampaign->program_id = $data['program_id'];
}
if (isset($data['group_id'])) {
$oCampaign->group_id = $data['group_id'];
}
$this->set($oCampaign, $data);

if ($oCampaign->save()) {
return $oCampaign->campaign_id;
} else {
throw new CoreException(417, 'Campaign creation failed');
}
}


/**
* List all available contacts
*
Expand Down Expand Up @@ -72,6 +68,7 @@ public function update($campaign_id, $data = array())
$this->_authorize('campaign_update');
$oCampaign= new Campaign($campaign_id);
$this->set($oCampaign, $data);

if ($oCampaign->save()) {
if ($oCampaign->status == Campaign::STATUS_RUNNING) {
$oCampaign->reload();
Expand Down Expand Up @@ -136,16 +133,20 @@ public function stop_campaign($campaign_id)
public function schedule_create($campaign_id, $action, $data = array())
{
$this->_authorize('task_create');

$oCampaign = new Campaign($campaign_id);

$oSchedule = new Schedule();
$this->set($oSchedule, $data);
$oSchedule->type = 'campaign';
$oSchedule->action = $action ;
$oSchedule->data = $oCampaign->campaign_id;
$oSchedule->account_id = $oCampaign->account_id;
$oSchedule->save();

return $oSchedule->task_id;
}

/**
* Cancel campaign schedule
*
Expand Down
Loading

0 comments on commit b986f8e

Please sign in to comment.