1) { $email = $argv[1]; $support_ticket = array_key_exists(2, $argv) ? $argv[2] : "none"; } else { $email = ""; $support_ticket = "none"; } if (empty($email)) { $email = getenv('EMAIL'); } if (empty($email)) { $email = $softnas_config['support']['useremail']; } if (empty($email)) { onFatalError('You must provide a valid email address that is registered with the SoftNAS Helpdesk'); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { onFatalError('The provided email address does not appear to be a valid email: ' . $email); } $softnas_id = $softnas_config['system']['platform'] . ":" . $softnas_config['system']['hwid']; if (empty($softnas_id)) { onFatalError('Unable to retrieve the system identification string'); } $request = array('email' => $email, 'instance_id' => $softnas_id . '_Support_Ticket=' . $support_ticket); $diag_script = tempnam('/tmp','sndiag'); if (FALSE == $diag_script) { onFatalError('Unable to create a temporary file. Perhaps the root file system is full or mounted read only?'); } $diag_log = tempnam('/var/www/softnas/logs/','diaglog-'); if (FALSE == $diag_log) { onFatalError('Unable to create a temporary file. Perhaps the root file system is full or mounted read only?'); } chmod($diag_log,0644); logit('Retrieving diagnostics module from SoftNAS'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $URL_SUPPORT_API . '/diagnostics.src'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); if (!$output) { $info = curl_getinfo($ch); onFatalError('Diagnostics module retrieval failure: ' . $info['http_code'] . ' ' . curl_error($ch)); } $info = curl_getinfo($ch); if ($info['http_code'] != 200) { onFatalError('Diagnostics module HTTP Failure: Response Code ' . $info['http_code'] . "\n" . $output); } curl_close($ch); if (FALSE == file_put_contents($diag_script,$output)) { onFatalError('Failed to write diagnostics module to ' . $diag_script); } logit('Requesting an upload URL from SoftNAS'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $URL_SUPPORT_API); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); $output = curl_exec($ch); if (!$output) { $info = curl_getinfo($ch); onFatalError('API Failure: ' . $info['http_code'] . ' ' . curl_error($ch)); } $info = curl_getinfo($ch); if ($info['http_code'] != 200) { onFatalError('HTTP Failure: Response Code ' . $info['http_code'] . "\n" . $output); } curl_close($ch); $response = json_decode($output,true); if (!$response) { onFatalError('Invalid Response: ' . $output); } if ($response['success'] != true) { onFatalError('Request Failed: ' . $response['msg']); } $upload_url = $response['url_put']; if (!$upload_url) { onFatalError('The API indicated the operation was successful but failed to provide an upload URL for the support report'); } $download_url = $response['url_get']; if (!$download_url) { onFatalError('The API indicated the operation was successful but failed to provide a download URL for the support report'); } logit("After this process is complete, your support report can be accessed\nfor 7 days at the following URL:\n\n" . $download_url . "\n\n"); logit('Starting diagnostics gathering process...'); if (FALSE == chmod($diag_script,0700)) { onFatalError('Unable to set executable'); } if (FALSE === system('nohup ' . $diag_script . " '$upload_url'" .' &> ' . $diag_log . '