function cpanelextender_addFtpAccount($serviceId, $ftpUsername, $ftpPassword) { try { $service = Service::findOrFail($serviceId); } catch (Exception $e) { logActivity('Exception caught when trying to load the Service Model:' . $e->getMessage()); return json_encode(array('message' => 'Unable to load service model for: ' . $serviceId, 'success' => 0)); } $cPServer = cpanelextender_getCpanelAPIFromService($service); $cPServer->set_output('json'); $args = array('user' => $ftpUsername, 'pass' => $ftpPassword); $result = $cPServer->api2_query($service->username, 'Ftp', 'addftp', $args); $result = json_decode($result, true); $result = $result['cpanelresult']; if (array_key_exists('error', $result)) { $result['return']['reason'] = $result['error']; } $result['return']['result'] = $result['data'][0]['result']; return json_encode($result['return']); }
/** * Add load information to the Products/Services homepage panel * * @param Item $basePanel collection of homepage panels */ function populateLoadAverageInHomepagePanels(Item $basePanel) { $servicesPanel = $basePanel->getChild('Active Products/Services'); // If this is not populated at all we need to skip adding items. if (is_null($servicesPanel)) { return; } foreach ($servicesPanel->getChildren() as $serviceLink) { parse_str(parse_url($serviceLink->getUri(), PHP_URL_QUERY)); /** @var int $id Created by parse_str() */ /** @var Service $service */ // See http://docs.whmcs.com/classes/classes/WHMCS.Service.Service.html for details on this model $service = Service::findOrFail($id); $loadAverage = getLoadAverageFromService($service); if ($loadAverage) { $label = $serviceLink->getLabel(); $label .= "<br>Load average - One: {$loadAverage->one} "; $label .= "Five: {$loadAverage->five} "; $label .= "Fifteen: {$loadAverage->fifteen}"; $serviceLink->setLabel($label); } } }