diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/azuracast/azuracast.php b/azuracast/azuracast.php new file mode 100644 index 0000000..df5b21b --- /dev/null +++ b/azuracast/azuracast.php @@ -0,0 +1,1069 @@ + 'AzuraCast', + 'APIVersion' => '1.1', // Use API Version 1.1 + 'RequiresServer' => true, // Set true if module requires a server to work + 'DefaultNonSSLPort' => '', // Default Non-SSL Connection Port + 'DefaultSSLPort' => '', // Default SSL Connection Port + 'ServiceSingleSignOnLabel' => 'Login to AzuraCast', + 'AdminSingleSignOnLabel' => 'Login to AzuraCast', + ); +} + +/** + * Define product configuration options. + * + * The values you return here define the configuration options that are + * presented to a user when configuring a product for use with the module. These + * values are then made available in all module function calls with the key name + * configoptionX - with X being the index number of the field from 1 to 24. + * + * You can specify up to 24 parameters, with field types: + * * text + * * password + * * yesno + * * dropdown + * * radio + * * textarea + * + * Examples of each and their possible configuration parameters are provided in + * this sample function. + * + * @see https://developers.whmcs.com/provisioning-modules/config-options/ + * + * @return array + */ +function azuracast_ConfigOptions() +{ + return array( + // a text field type allows for single line text input + 'Max Listenrs' => array( + 'Type' => 'text', + 'Size' => '25', + 'Default' => '50', + 'Description' => 'Enter the max amount of listeners that this package can have', + ), + // the dropdown field type renders a select menu of options + 'AutoDJ Enabled' => array( + 'Type' => 'dropdown', + 'Options' => array( + 'yes' => 'Yes', + 'no' => 'No', + ), + 'Description' => 'Is AutoDJ enabled for this package', + ), + 'Streamer DJs Enabled' => array( + 'Type' => 'dropdown', + 'Options' => array( + 'yes' => 'Yes', + 'no' => 'No', + ), + 'Description' => 'Is Streamer DJs enabled for this package', + ), + ); +} + +/** + * Provision a new instance of a product/service. + * + * Attempt to provision a new instance of a given product/service. This is + * called any time provisioning is requested inside of WHMCS. Depending upon the + * configuration, this can be any of: + * * When a new order is placed + * * When an invoice for a new order is paid + * * Upon manual request by an admin user + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return string "success" or an error message + */ +function azuracast_CreateAccount(array $params) +{ + try { + // Call the service's provisioning function, using the values provided + // by WHMCS in `$params`. + // + // A sample `$params` array may be defined as: + // + // ``` + // array( + // 'domain' => 'The domain of the service to provision', + // 'username' => 'The username to access the new service', + // 'password' => 'The password to access the new service', + // 'configoption1' => 'The amount of disk space to provision', + // 'configoption2' => 'The new services secret key', + // 'configoption3' => 'Whether or not to enable FTP', + // ... + // ) + // ``` + // Gather together all the config stuff we need. + $station_name = $params['customfields']['Station Name']; + $station_url = $params['customfields']['Station URL']; + $station_genre = $params['customfields']['Station Genre']; + $station_desc = $params['customfields']['Station Description']; + $listeners = $params['configoption1']; + $ac_name = $params['clientsdetails']['firstname'].' '.$params['clientsdetails']['lastname']; + $sc_email = rand(10000,99999).'@'.$params['serverhostname']; + $ac_pass = $params['password']; + $ac_now = time(); + $api_key = $params['serverpassword']; + if($params['serversecure']=='on'){ + $secure = 'https://'; + } else { + $secure = 'http://'; + } + if($params['configoption2']=='yes'){ + $autodj = 'liquidsoap'; + } else { + $autodj = 'none'; + } + if($params['configoption3']=='yes'){ + $streamers = 'true'; + } else { + $streamers = 'false'; + } + $api_url = $secure.$params['serverhostname']; + // DEBUG ME + //die($autodj); + + // Let's create the station + $short = str_replace(' ', '_', $station_name); + $short_name = strtolower($short); + $create_url = $api_url.'/api/admin/stations'; + $create_ch = curl_init(); + $create_headers = array( + 'Accept: application/json', + 'Content-Type: application/json', + 'X-API-Key: '.$api_key, + ); + curl_setopt($create_ch, CURLOPT_URL, $create_url); + curl_setopt($create_ch, CURLOPT_HTTPHEADER, $create_headers); + curl_setopt($create_ch, CURLOPT_HEADER, 0); + $create_body = '{ + "id": 0, + "name": "'.$station_name.'", + "short_name": "'.$short_name.'", + "is_enabled": true, + "frontend_type": "shoutcast2", + "frontend_config":{"max_listeners":'.$listeners.'}, + "backend_type": "'.$autodj.'", + "backend_config": [ + "string" + ], + "description": "'.$station_desc.'", + "url": "'.$station_url.'", + "genre": "'.$station_genre.'", + "radio_base_dir": "/var/azuracast/stations/'.$short_name.'", + "enable_requests": false, + "request_delay": 5, + "request_threshold": 15, + "disconnect_deactivate_streamer": 0, + "enable_streamers": '.$streamers.', + "is_streamer_live": false, + "enable_public_page": false, + "enable_on_demand": false, + "enable_on_demand_download": false, + "enable_hls": false, + "api_history_items": 5, + "timezone": "UTC", + "branding_config": [ + "string" + ] + }'; + curl_setopt($create_ch, CURLOPT_POSTFIELDS,$create_body); + curl_setopt($create_ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($create_ch, CURLOPT_TIMEOUT, 30); + $create_json_return = curl_exec($create_ch); + $create_return = json_decode($create_json_return); + if($create_return->{'code'}=='500'||$create_return->{'code'}=='403'||$create_return->{'code'}=='404'){ + die($create_return->{'formatted_message'}); + } else { + $station_id = $create_return->{'id'}; + $params['model']->serviceProperties->save(['Station ID' => $station_id]); + + // Create Permissions + $perm_url = $api_url.'/api/admin/roles'; + $perm_ch = curl_init(); + $perm_headers = array( + 'Accept: application/json', + 'Content-Type: application/json', + 'X-API-Key: '.$api_key, + ); + curl_setopt($perm_ch, CURLOPT_URL, $perm_url); + curl_setopt($perm_ch, CURLOPT_HTTPHEADER, $perm_headers); + curl_setopt($perm_ch, CURLOPT_HEADER, 0); + $perm_body = '{ + "id": 0, + "name": "'.$short_name.'", + "permissions": { + "global": [], + "station": { + "'.$station_id.'": [ + "manage station automation", + "manage station broadcasting", + "manage station media", + "manage station mounts", + "manage station podcasts", + "manage station remotes", + "manage station streamers", + "manage station web hooks", + "view station logs", + "view station management", + "view station reports" + ] + } + } +}'; + curl_setopt($perm_ch, CURLOPT_POSTFIELDS,$perm_body); + curl_setopt($perm_ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($perm_ch, CURLOPT_TIMEOUT, 30); + $perm_json_return = curl_exec($perm_ch); + $perm_return = json_decode($perm_json_return); + if($perm_return->{'code'}=='500'||$perm_return->{'code'}=='403'||$perm_return->{'code'}=='404'){ + die($perm_return->{'formatted_message'}); + } else { + $perm_id = $perm_return->{'id'}; + $perm_name = $perm_return->{'name'}; + // create user now + $user_url = $api_url.'/api/admin/users'; + $user_ch = curl_init(); + $user_headers = array( + 'Accept: application/json', + 'Content-Type: application/json', + 'X-API-Key: '.$api_key, + ); + curl_setopt($user_ch, CURLOPT_URL, $user_url); + curl_setopt($user_ch, CURLOPT_HTTPHEADER, $user_headers); + curl_setopt($user_ch, CURLOPT_HEADER, 0); + $user_body = '{ + "id": 0, + "email": "'.$sc_email.'", + "new_password": "'.$ac_pass.'", + "name": "'.$ac_name.'", + "locale": "en_US", + "show_24_hour_time": true, + "created_at": '.$ac_now.', + "updated_at": '.$ac_now.', + "roles": [ + { +"id": '.$perm_id.' + } + ] +}'; + curl_setopt($user_ch, CURLOPT_POSTFIELDS,$user_body); + curl_setopt($user_ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($user_ch, CURLOPT_TIMEOUT, 30); + $user_json_return = curl_exec($user_ch); + $user_return = json_decode($user_json_return); + if($user_return->{'code'}=='500'||$user_return->{'code'}=='403'||$user_return->{'code'}=='404'){ + die($user_return->{'formatted_message'}); + } else { + $user_id = $user_return->{'id'}; + $params['model']->serviceProperties->save(['Permission ID' => $perm_id]); + $params['model']->serviceProperties->save(['AzuraCast ID' => $user_id]); + $params['model']->serviceProperties->save(['Username' => $sc_email]); + return 'success'; + } + } + } + + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Suspend an instance of a product/service. + * + * Called when a suspension is requested. This is invoked automatically by WHMCS + * when a product becomes overdue on payment or can be called manually by admin + * user. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return string "success" or an error message + */ +function azuracast_SuspendAccount(array $params) +{ + try { + // Call the service's suspend function, using the values provided by + // WHMCS in `$params`. + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Un-suspend instance of a product/service. + * + * Called when an un-suspension is requested. This is invoked + * automatically upon payment of an overdue invoice for a product, or + * can be called manually by admin user. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return string "success" or an error message + */ +function azuracast_UnsuspendAccount(array $params) +{ + try { + // Call the service's unsuspend function, using the values provided by + // WHMCS in `$params`. + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Terminate instance of a product/service. + * + * Called when a termination is requested. This can be invoked automatically for + * overdue products if enabled, or requested manually by an admin user. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return string "success" or an error message + */ +function azuracast_TerminateAccount(array $params) +{ + try { + // Call the service's terminate function, using the values provided by + // WHMCS in `$params`. + $station_id = $params['customfields']['Station ID']; + $azuracast_id = $params['customfields']['AzuraCast ID']; + $perm_id = $params['customfields']['Permission ID']; + $api_key = $params['serverpassword']; + if($params['serversecure']=='on'){ + $secure = 'https://'; + } else { + $secure = 'http://'; + } + $api_url = $secure.$params['serverhostname']; + $st_url = $api_url.'/api/admin/station/'.$station_id; + $st_ch = curl_init(); + $st_headers = array( + 'Accept: application/json', + 'Content-Type: application/json', + 'X-API-Key: '.$api_key, + ); + curl_setopt($st_ch, CURLOPT_URL, $st_url); + curl_setopt($st_ch, CURLOPT_HTTPHEADER, $st_headers); + curl_setopt($st_ch, CURLOPT_HEADER, 0); + $st_body = '{}'; + + curl_setopt($st_ch, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($st_ch, CURLOPT_POSTFIELDS,$st_body); + curl_setopt($st_ch, CURLOPT_RETURNTRANSFER, true); + + // Timeout in seconds + curl_setopt($st_ch, CURLOPT_TIMEOUT, 30); + + $st_json_return = curl_exec($st_ch); + $st_return = json_decode($st_json_return); + if($st_return->{'code'}=='500'||$st_return->{'code'}=='403'||$st_return->{'code'}=='404'){ + die($st_return->{'type'}); + } else { + $p_url = $api_url.'/api/admin/role/'.$perm_id; + $p_ch = curl_init(); + $p_headers = array( + 'Accept: application/json', + 'Content-Type: application/json', + 'X-API-Key: '.$api_key, + ); + curl_setopt($p_ch, CURLOPT_URL, $p_url); + curl_setopt($p_ch, CURLOPT_HTTPHEADER, $p_headers); + curl_setopt($p_ch, CURLOPT_HEADER, 0); + $p_body = '{}'; + + curl_setopt($p_ch, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($p_ch, CURLOPT_POSTFIELDS,$p_body); + curl_setopt($p_ch, CURLOPT_RETURNTRANSFER, true); + + // Timeout in seconds + curl_setopt($p_ch, CURLOPT_TIMEOUT, 30); + + $p_json_return = curl_exec($p_ch); + $p_return = json_decode($p_json_return); + if($p_return->{'code'}=='500'||$p_return->{'code'}=='403'||$p_return->{'code'}=='404'){ + die($p_return->{'type'}); + } else { + $u_url = $api_url.'/api/admin/user/'.$azuracast_id; + $u_ch = curl_init(); + $u_headers = array( + 'Accept: application/json', + 'Content-Type: application/json', + 'X-API-Key: '.$api_key, + ); + curl_setopt($u_ch, CURLOPT_URL, $u_url); + curl_setopt($u_ch, CURLOPT_HTTPHEADER, $u_headers); + curl_setopt($u_ch, CURLOPT_HEADER, 0); + $u_body = '{}'; + + curl_setopt($u_ch, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($u_ch, CURLOPT_POSTFIELDS,$u_body); + curl_setopt($u_ch, CURLOPT_RETURNTRANSFER, true); + + // Timeout in seconds + curl_setopt($u_ch, CURLOPT_TIMEOUT, 30); + + $u_json_return = curl_exec($u_ch); + $u_return = json_decode($u_json_return); + if($u_return->{'code'}=='500'||$u_return->{'code'}=='403'||$u_return->{'code'}=='404'){ + die($u_return->{'type'}); + } else { + return 'success'; + } + } + } + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Change the password for an instance of a product/service. + * + * Called when a password change is requested. This can occur either due to a + * client requesting it via the client area or an admin requesting it from the + * admin side. + * + * This option is only available to client end users when the product is in an + * active status. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return string "success" or an error message + */ +function azuracast_ChangePassword(array $params) +{ + try { + // Call the service's change password function, using the values + // provided by WHMCS in `$params`. + // + // A sample `$params` array may be defined as: + // + // ``` + // array( + // 'username' => 'The service username', + // 'password' => 'The new service password', + // ) + // ``` + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Upgrade or downgrade an instance of a product/service. + * + * Called to apply any change in product assignment or parameters. It + * is called to provision upgrade or downgrade orders, as well as being + * able to be invoked manually by an admin user. + * + * This same function is called for upgrades and downgrades of both + * products and configurable options. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return string "success" or an error message + */ +function azuracast_ChangePackage(array $params) +{ + try { + // Call the service's change password function, using the values + // provided by WHMCS in `$params`. + // + // A sample `$params` array may be defined as: + // + // ``` + // array( + // 'username' => 'The service username', + // 'configoption1' => 'The new service disk space', + // 'configoption3' => 'Whether or not to enable FTP', + // ) + // ``` + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Renew an instance of a product/service. + * + * Attempt to renew an existing instance of a given product/service. This is + * called any time a product/service invoice has been paid. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return string "success" or an error message + */ +function azuracast_Renew(array $params) +{ + try { + // Call the service's provisioning function, using the values provided + // by WHMCS in `$params`. + // + // A sample `$params` array may be defined as: + // + // ``` + // array( + // 'domain' => 'The domain of the service to provision', + // 'username' => 'The username to access the new service', + // 'password' => 'The password to access the new service', + // 'configoption1' => 'The amount of disk space to provision', + // 'configoption2' => 'The new services secret key', + // 'configoption3' => 'Whether or not to enable FTP', + // ... + // ) + // ``` + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Test connection with the given server parameters. + * + * Allows an admin user to verify that an API connection can be + * successfully made with the given configuration parameters for a + * server. + * + * When defined in a module, a Test Connection button will appear + * alongside the Server Type dropdown when adding or editing an + * existing server. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return array + */ +function azuracast_TestConnection(array $params) +{ + try { + // Call the service's connection test function. + + $success = true; + $errorMsg = ''; + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + $success = false; + $errorMsg = $e->getMessage(); + } + + return array( + 'success' => $success, + 'error' => $errorMsg, + ); +} + +/** + * Additional actions an admin user can invoke. + * + * Define additional actions that an admin user can perform for an + * instance of a product/service. + * + * @see azuracast_buttonOneFunction() + * + * @return array + */ +function azuracast_AdminCustomButtonArray() +{ + return array( + + ); +} + +/** + * Additional actions a client user can invoke. + * + * Define additional actions a client user can perform for an instance of a + * product/service. + * + * Any actions you define here will be automatically displayed in the available + * list of actions within the client area. + * + * @return array + */ +function azuracast_ClientAreaCustomButtonArray() +{ + return array( + + ); +} + +/** + * Custom function for performing an additional action. + * + * You can define an unlimited number of custom functions in this way. + * + * Similar to all other module call functions, they should either return + * 'success' or an error message to be displayed. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * @see azuracast_AdminCustomButtonArray() + * + * @return string "success" or an error message + */ +function azuracast_buttonOneFunction(array $params) +{ + try { + // Call the service's function, using the values provided by WHMCS in + // `$params`. + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Custom function for performing an additional action. + * + * You can define an unlimited number of custom functions in this way. + * + * Similar to all other module call functions, they should either return + * 'success' or an error message to be displayed. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * @see azuracast_ClientAreaCustomButtonArray() + * + * @return string "success" or an error message + */ +function azuracast_actionOneFunction(array $params) +{ + try { + // Call the service's function, using the values provided by WHMCS in + // `$params`. + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return $e->getMessage(); + } + + return 'success'; +} + +/** + * Admin services tab additional fields. + * + * Define additional rows and fields to be displayed in the admin area service + * information and management page within the clients profile. + * + * Supports an unlimited number of additional field labels and content of any + * type to output. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * @see azuracast_AdminServicesTabFieldsSave() + * + * @return array + */ +function azuracast_AdminServicesTabFields(array $params) +{ + try { + // Call the service's function, using the values provided by WHMCS in + // `$params`. + $response = array(); + + // Return an array based on the function's response. + return array( + + ); + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + // In an error condition, simply return no additional fields to display. + } + + return array(); +} + +/** + * Execute actions upon save of an instance of a product/service. + * + * Use to perform any required actions upon the submission of the admin area + * product management form. + * + * It can also be used in conjunction with the AdminServicesTabFields function + * to handle values submitted in any custom fields which is demonstrated here. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * @see azuracast_AdminServicesTabFields() + */ +function azuracast_AdminServicesTabFieldsSave(array $params) +{ + // Fetch form submission variables. + $originalFieldValue = isset($_REQUEST['azuracast_original_uniquefieldname']) + ? $_REQUEST['azuracast_original_uniquefieldname'] + : ''; + + $newFieldValue = isset($_REQUEST['azuracast_uniquefieldname']) + ? $_REQUEST['azuracast_uniquefieldname'] + : ''; + + // Look for a change in value to avoid making unnecessary service calls. + if ($originalFieldValue != $newFieldValue) { + try { + // Call the service's function, using the values provided by WHMCS + // in `$params`. + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + // Otherwise, error conditions are not supported in this operation. + } + } +} + +/** + * Perform single sign-on for a given instance of a product/service. + * + * Called when single sign-on is requested for an instance of a product/service. + * + * When successful, returns a URL to which the user should be redirected. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return array + */ +function azuracast_ServiceSingleSignOn(array $params) +{ + try { + // Call the service's single sign-on token retrieval function, using the + // values provided by WHMCS in `$params`. + $response = array(); + + return array( + 'success' => true, + 'redirectTo' => 'http://'.$params['serverhostname'], + ); + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return array( + 'success' => false, + 'errorMsg' => $e->getMessage(), + ); + } +} + +/** + * Perform single sign-on for a server. + * + * Called when single sign-on is requested for a server assigned to the module. + * + * This differs from ServiceSingleSignOn in that it relates to a server + * instance within the admin area, as opposed to a single client instance of a + * product/service. + * + * When successful, returns a URL to which the user should be redirected to. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return array + */ +function azuracast_AdminSingleSignOn(array $params) +{ + try { + // Call the service's single sign-on admin token retrieval function, + // using the values provided by WHMCS in `$params`. + $response = array(); + + return array( + 'success' => true, + 'redirectTo' => 'http://'.$params['serverhostname'], + ); + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + return array( + 'success' => false, + 'errorMsg' => $e->getMessage(), + ); + } +} + +/** + * Client area output logic handling. + * + * This function is used to define module specific client area output. It should + * return an array consisting of a template file and optional additional + * template variables to make available to that template. + * + * The template file you return can be one of two types: + * + * * tabOverviewModuleOutputTemplate - The output of the template provided here + * will be displayed as part of the default product/service client area + * product overview page. + * + * * tabOverviewReplacementTemplate - Alternatively using this option allows you + * to entirely take control of the product/service overview page within the + * client area. + * + * Whichever option you choose, extra template variables are defined in the same + * way. This demonstrates the use of the full replacement. + * + * Please Note: Using tabOverviewReplacementTemplate means you should display + * the standard information such as pricing and billing details in your custom + * template or they will not be visible to the end user. + * + * @param array $params common module parameters + * + * @see https://developers.whmcs.com/provisioning-modules/module-parameters/ + * + * @return array + */ +function azuracast_ClientArea(array $params) +{ + // Determine the requested action and set service call parameters based on + // the action. + $requestedAction = isset($_REQUEST['customAction']) ? $_REQUEST['customAction'] : ''; + + if ($requestedAction == 'manage') { + $serviceAction = 'get_usage'; + $templateFile = 'templates/manage.tpl'; + } else { + $serviceAction = 'get_stats'; + $templateFile = 'templates/overview.tpl'; + } + + try { + // Call the service's function based on the request action, using the + // values provided by WHMCS in `$params`. + $response = array(); + + $extraVariable1 = 'abc'; + $extraVariable2 = '123'; + + return array( + 'tabOverviewReplacementTemplate' => $templateFile, + 'templateVariables' => array( + 'extraVariable1' => $extraVariable1, + 'extraVariable2' => $extraVariable2, + ), + ); + } catch (Exception $e) { + // Record the error in WHMCS's module log. + logModuleCall( + 'azuracast', + __FUNCTION__, + $params, + $e->getMessage(), + $e->getTraceAsString() + ); + + // In an error condition, display an error page. + return array( + 'tabOverviewReplacementTemplate' => 'error.tpl', + 'templateVariables' => array( + 'usefulErrorHelper' => $e->getMessage(), + ), + ); + } +} diff --git a/azuracast/hooks.php b/azuracast/hooks.php new file mode 100644 index 0000000..0ed7067 --- /dev/null +++ b/azuracast/hooks.php @@ -0,0 +1,110 @@ +getChild('My Services Actions'))) { + + // define new sidebar panel + $customPanel = $secondarySidebar->addChild('AzuraCast Panel'); + + // set panel attributes + $customPanel->moveToFront() + ->setIcon('fa-user') + ->setBodyHtml( + 'Your HTML output goes here...' + ) + ->setFooterHtml( + 'Footer HTML can go here...' + ); + + // define link + $customPanel->addChild( + 'Sample Link Menu Item', + array( + 'uri' => 'clientarea.php?action=services&module=azuracast', + 'icon' => 'fa-list-alt', + 'order' => 2, + ) + ); + + } +}); diff --git a/azuracast/lib/README.md b/azuracast/lib/README.md new file mode 100644 index 0000000..7e59801 --- /dev/null +++ b/azuracast/lib/README.md @@ -0,0 +1 @@ +Include libraries and third party modules here. diff --git a/azuracast/logo.png b/azuracast/logo.png new file mode 100644 index 0000000..314fffc Binary files /dev/null and b/azuracast/logo.png differ diff --git a/azuracast/templates/error.tpl b/azuracast/templates/error.tpl new file mode 100644 index 0000000..7934fd1 --- /dev/null +++ b/azuracast/templates/error.tpl @@ -0,0 +1,9 @@ +
Extra template variables work here too: {$usefulErrorHelper}
+Please go back and try again.
+ +If the problem persists, please contact support.
diff --git a/azuracast/templates/manage.tpl b/azuracast/templates/manage.tpl new file mode 100644 index 0000000..c84b8c4 --- /dev/null +++ b/azuracast/templates/manage.tpl @@ -0,0 +1,48 @@ +This is an example of an additional custom page within a module's client area product management pages.
+ +Everything that is available in the overview is also available in this template file along with any custom defined template variables.
+ +Overview output goes here...
+ +Please Remember: When overriding the default product overview output, it is important to provide the product details and information that are normally displayed on this page. These are provided below.
+ +