'ThurData SiteBuilder Provisioning', 'APIVersion' => '1.2', 'DefaultNonSSLPort' => '80', 'DefaultSSLPort' => '443', 'RequiresServer' => true, 'ServiceSingleSignOnLabel' => 'Login to siteBuilder', 'AdminSingleSignOnLabel' => 'Login to siteBuilder Admin' ); } function siteBuilder_ConfigOptions() { siteBuilderCreateTables(); return ["BuilderURL" => [ "FriendlyName" => "Builder URL", # Full Builder URL (prefix//hostname:port/) "Type" => "text", # Text Box "Size" => "25", # Defines the Field Width "Description" => "Full Builder URL (prefix//hostname:port/)", "Default" => "https://builder.thurdata.ch/", ], ]; } /** * Test connection to a siteBuilder server 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 siteBuilder_Testconnection($params) { $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']); $response = $siteBuilder->ping($params['serverusername'], $params['serverpassword']); if($response['response']['answer'] == 'pong') { return array( 'success' => true, 'error' => '', ); } return array( 'success' => false, 'error' => $response, ); } /** * Provision a new account of a siteBuilder server. * * Attempt to provision a new siteBuilder account. 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/supported-functions/ * * @return string 'success' or an error message */ function siteBuilder_CreateAccount($params) { $username = strtolower(substr($params['clientsdetails']['firstname'],0,2) . substr($params['clientsdetails']['lastname'],0,3)) . $params['serviceid']; $userdomain = $params['domain']; try { Capsule::table('tblhosting') ->where('id', '=', $params['serviceid']) ->update( array( 'username' => $username, 'domain' => $userdomain, ) ); } catch (\Exception $e) { logModuleCall( 'siteBuilder', __FUNCTION__, $params, 'Error: could save username & domain in database', $e->getMessage() ); return 'Error: could save username & password in database'; } try { Capsule::table('sitePro_acc') ->insert( array( 'account' => $username, 'pid' => $params['serviceid'], 'enabled' => true, ) ); } catch (\Exception $e) { logModuleCall( 'siteBuilder', __FUNCTION__, $params, 'Error: could save username & serviceid in database', $e->getMessage() ); return 'Error: could save username & serviceid in database'; } return 'success'; } /** * Removes a siteBuilder account. * * 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/supported-functions/ * * @return string 'success' or an error message */ function siteBuilder_TerminateAccount($params) { try { $active = Capsule::table('sitePro_acc') ->where('account',$params['username']) ->value('enabled'); } catch (\Exception $e) { logModuleCall( 'siteBuilder', __FUNCTION__, $params, 'Error: could remove account from database', $e->getMessage() ); return 'Error: could remove account from database'; } if($active == true) { return 'Error: Account is active, please suspend account first'; } try { Capsule::table('sitePro_site') ->where('relid',$params['serviceid']) ->delete(); } catch (\Exception $e) { logModuleCall( 'siteBuilder', __FUNCTION__, $params, 'Error: could remove domains from database', $e->getMessage() ); return 'Error: could remove domains from database'; } try { Capsule::table('sitePro_acc') ->where('account',$params['username']) ->delete(); } catch (\Exception $e) { logModuleCall( 'siteBuilder', __FUNCTION__, $params, 'Error: could remove account from database', $e->getMessage() ); return 'Error: could remove account from database'; } $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']); $response = $siteBuilder->terminate($params['domain'],$params['username']); if($response['status'] != '200') { return 'Error: ' . $response['response']; } return 'success'; } /** * Set a siteBuilder account to status inactive. * * 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/supported-functions/ * * @return string 'success' or an error message */ function siteBuilder_SuspendAccount($params) { $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']); $status = $siteBuilder->isprodenabled($params['domain'],$params['username']); if($status['status'] != '200') { return 'Error: ' . $status['error_msg']; } if($response['response']['isenabled'] == 'YES'){ $response = $siteBuilder->disableprod($params['domain'],$params['username']); if($response['status'] != '200') { return 'Error: ' . $response['error_msg']; } } try { Capsule::table('sitePro_acc') ->where('account',$params['username']) ->update(array( 'enabled' => false, )); } catch (\Exception $e) { logModuleCall( 'siteBuilder', __FUNCTION__, $params, 'Error: could remove account from database', $e->getMessage() ); return 'Error: could remove account from database'; } return 'success'; } /** * Set a siteBuilder account to status active. * * 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/supported-functions/ * * @return string 'success' or an error message */ function siteBuilder_UnsuspendAccount($params) { try { Capsule::table('sitePro_acc') ->where('account',$params['username']) ->update(array( 'enabled' => true, )); } catch (\Exception $e) { logModuleCall( 'siteBuilder', __FUNCTION__, $params, 'Error: could remove account from database', $e->getMessage() ); return 'Error: could remove account from database'; } return 'success'; } /** * 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. * * @param array $params common module parameters * * @see https://developers.whmcs.com/provisioning-modules/client-area-output/ * * @return array */ function siteBuilder_ClientArea($params) { $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']); $clientInfo = array('moduleclientarea' => '1'); $clientInfo['domain'] = $params['domain']; $accountObj = Capsule::table('sitePro_acc') ->where('pid', $params['serviceid']) ->get(); $sitesObj = Capsule::table('sitePro_site') ->where('relid', $params['serviceid']) ->get(); $clientInfo['sites'] = []; foreach($sitesObj as $site){ $response = $siteBuilder->getSSLDays($site->name, $params['username']); if($response['status'] != '200') { $sslDays = 0; } array_push($clientInfo['sites'],['name' => $site->name, 'ssldays' => $sslDays['ssl_remaining']]); } return array( 'tabOverviewReplacementTemplate' => 'clientarea', 'vars' => $clientInfo, ); } /** * Perform single sign-on for a siteBuilder account. * * 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/single-sign-on/ * * @return array */ function siteBuilder_ServiceSingleSignOn($params) { } /** * Upgrade or downgrade a siteBuilder account by package. * * 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/supported-functions/ * * @return string "success" or an error message */ function siteBuilder_ChangePackage($params) { return 'success'; } /** * Usage Update * * Important: Runs daily per server not per product * Run Manually: /admin/reports.php?report=disk_usage_summary&action=updatestats * @param array $params common module parameters * * @see https://developers.whmcs.com/provisioning-modules/usage-update/ */ function siteBuilder_UsageUpdate($params) { } /** * 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 siteBuilder_ClientAreaCustomButtonArray ($params) { return array( 'Neue Webseite' => 'newSite', ); } /** * Additional actions a client user can invoke. * * Define additional actions a client user is allowed to perform for an instance of a * product/service. * * @see https://developers.whmcs.com/provisioning-modules/supported-functions/ * * @return array */ function siteBuilder_ClientAreaAllowedFunctions() { return array( "Add Site" => "addSite", "new Site" => "newSite", "Confirm Delete Site" => "delSiteConfirm", "Delete Site" => "delSite", ); } /** * Opens a form to add a new domain. * * @param array $params common module parameters * * @see https://developers.whmcs.com/provisioning-modules/supported-functions/ * * @return array template information */ function siteBuilder_newSite($params) { return array( 'breadcrumb' => array( 'clientarea.php?action=productdetails&id=' . $params['serviceid'] . '&modop=custom&a=newSite' => 'Neue Webseite', ), 'templatefile' => 'siteBuilder_new_site', ); } /** * Adds a new domain to a siteBuilder account. * * @param array $params common module parameters * * @see https://developers.whmcs.com/provisioning-modules/supported-functions/ * * @return string "success" or an error message */ function siteBuilder_addSite($params) { if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){ return 'Error: invalid site name'; } $site = $_POST['d'] . '.' . $params['domain']; $siteBuilder = new ApiClient(getSiteBuilderApiURL($params), $params['serveraccesshash']); $response = $siteBuilder->deployDev($params['username'], $site, $params['serverusername'], $params['serverpassword']); if($response['status'] != '200') { return 'Error: ' . $response['response']; } try { Capsule::table('sitePro_site') ->insert( array( 'relid' => $params['serviceid'], 'name' => $site, 'enabled' => false, ) ); } catch (\Exception $e) { logModuleCall( 'siteBuilder', __FUNCTION__, $params, 'Error: could save site & serviceid in database', $e->getMessage() ); return 'Error: could save site & serviceid in database'; } return 'success'; } /** * Opens a form to delete a domain from a siteBuilder account. * * @param array $params common module parameters * * @see https://developers.whmcs.com/provisioning-modules/supported-functions/ * * @return array template information */ function siteBuilder_delDomainConfirm($params) { return array( 'templatefile' => 'siteBuilder_del_domain_confirm', 'vars' => array( 'deldomain' => $_POST['d'], ), ); } /** * Removes a domain from a siteBuilder account. * * @param array $params common module parameters * * @see https://developers.whmcs.com/provisioning-modules/supported-functions/ * * @return string "success" or an error message */ function siteBuilder_delDomain($params) { if(!filter_var($_POST['d'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)){ return 'Error: invalid domain name'; } return 'success'; } /** * Returns API Url . * * @param string $params common module parameters * @param string $user * @param string $params common module parameters * * @return string $apiUrl */ function getSiteBuilderApiURL($params) { $httpPrefix = $params['serversecure'] ? 'https://' : 'http://'; $serverPort = $params['serverport'] ? ':' . $params['serverport'] . '/' : '/'; return $httpPrefix . $params['serverhostname'] . $serverPort; } function siteBuilderCreateTables() { // Create a new table. if (!Capsule::schema()->hasTable('sitePro_acc')) { try { Capsule::schema()->create( 'sitePro_acc', function ($table) { /** @var \Illuminate\Database\Schema\Blueprint $table */ $table->increments('id'); $table->string('account'); $table->integer('pid'); $table->boolean('enabled'); } ); } catch (\Exception $e) { echo "Unable to create sitePro_acc: {$e->getMessage()}"; } } if (!Capsule::schema()->hasTable('sitePro_site')) { try { Capsule::schema()->create( 'sitePro_site', function ($table) { /** @var \Illuminate\Database\Schema\Blueprint $table */ $table->increments('id'); $table->integer('relid'); $table->string('name'); $table->boolean('enabled'); } ); } catch (\Exception $e) { echo "Unable to create sitePro_site: {$e->getMessage()}"; } } }