fix install script11
This commit is contained in:
parent
8cf2b6c563
commit
a6b49aa3f9
|
|
@ -36,7 +36,7 @@ class EnrollmentManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main enrollment process
|
* Main enrollment process - calls the enrollment script
|
||||||
*/
|
*/
|
||||||
public function enrollRouter($hashKey, $apiEndpoint = null) {
|
public function enrollRouter($hashKey, $apiEndpoint = null) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -46,87 +46,47 @@ class EnrollmentManager {
|
||||||
|
|
||||||
$this->reportProgress('INIT', 'Starting router enrollment process...', 0);
|
$this->reportProgress('INIT', 'Starting router enrollment process...', 0);
|
||||||
|
|
||||||
// Step 1: Check system requirements
|
// Use the enrollment script with sudo
|
||||||
$this->reportProgress('REQUIREMENTS', 'Checking system requirements...', 10);
|
$command = "sudo /usr/local/bin/enroll-router.sh '$hashKey' '$apiEndpoint' 2>&1";
|
||||||
if (!$this->checkSystemRequirements()) {
|
$output = '';
|
||||||
throw new Exception('System requirements check failed');
|
$returnCode = 0;
|
||||||
|
|
||||||
|
$this->reportProgress('INIT', 'Executing enrollment script...', 10);
|
||||||
|
|
||||||
|
// Execute the enrollment script
|
||||||
|
$success = executeCommand($command, $output, $returnCode);
|
||||||
|
|
||||||
|
if ($success && $returnCode === 0) {
|
||||||
|
$this->reportProgress('COMPLETE', 'Router enrollment completed successfully!', 100);
|
||||||
|
|
||||||
|
// Parse output to get router information if available
|
||||||
|
$routerName = 'Unknown';
|
||||||
|
$routerId = 'Unknown';
|
||||||
|
|
||||||
|
// Try to extract router info from output
|
||||||
|
if (preg_match('/Router Name: (.+)/', $output, $matches)) {
|
||||||
|
$routerName = trim($matches[1]);
|
||||||
|
}
|
||||||
|
if (preg_match('/Router ID: (.+)/', $output, $matches)) {
|
||||||
|
$routerId = trim($matches[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'success' => true,
|
||||||
|
'routerName' => $routerName,
|
||||||
|
'routerId' => $routerId,
|
||||||
|
'message' => 'Router enrollment completed successfully',
|
||||||
|
'output' => $output
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
throw new Exception('Enrollment script failed: ' . $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: Install OpenZiti if needed
|
|
||||||
$this->reportProgress('INSTALL', 'Installing OpenZiti CLI...', 20);
|
|
||||||
if (!$this->installZiti()) {
|
|
||||||
throw new Exception('OpenZiti installation failed');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 3: Create directories
|
|
||||||
$this->reportProgress('DIRECTORIES', 'Creating necessary directories...', 30);
|
|
||||||
if (!$this->createDirectories()) {
|
|
||||||
throw new Exception('Failed to create directories');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 4: Register router with API
|
|
||||||
$this->reportProgress('REGISTER', 'Registering router with ZitiNexus Portal...', 40);
|
|
||||||
$result = $this->apiClient->registerRouter($hashKey);
|
|
||||||
if (!$result['success']) {
|
|
||||||
throw new Exception('Router registration failed: ' . $result['error']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->routerData = $result['data'];
|
|
||||||
$this->reportProgress('REGISTER', 'Router registered successfully: ' . $this->routerData['routerInfo']['name'], 50);
|
|
||||||
|
|
||||||
// Step 5: Save configuration files
|
|
||||||
$this->reportProgress('CONFIG', 'Saving configuration files...', 60);
|
|
||||||
if (!$this->saveConfiguration()) {
|
|
||||||
throw new Exception('Failed to save configuration files');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 6: Enroll router with OpenZiti
|
|
||||||
$this->reportProgress('ENROLL', 'Enrolling router with OpenZiti controller...', 70);
|
|
||||||
if (!$this->enrollWithZiti()) {
|
|
||||||
throw new Exception('Router enrollment with OpenZiti failed');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 7: Create systemd service
|
|
||||||
$this->reportProgress('SERVICE', 'Creating systemd service...', 80);
|
|
||||||
if (!$this->createSystemdService()) {
|
|
||||||
throw new Exception('Failed to create systemd service');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 8: Start router service
|
|
||||||
$this->reportProgress('START', 'Starting router service...', 90);
|
|
||||||
if (!$this->startRouter()) {
|
|
||||||
throw new Exception('Failed to start router service');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 9: Report success status
|
|
||||||
$this->reportProgress('REPORT', 'Reporting enrollment status...', 95);
|
|
||||||
$this->reportSuccessStatus($hashKey);
|
|
||||||
|
|
||||||
$this->reportProgress('COMPLETE', 'Router enrollment completed successfully!', 100);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'success' => true,
|
|
||||||
'routerName' => $this->routerData['routerInfo']['name'],
|
|
||||||
'routerId' => $this->routerData['routerInfo']['id'],
|
|
||||||
'message' => 'Router enrollment completed successfully'
|
|
||||||
];
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$errorMsg = $e->getMessage();
|
$errorMsg = $e->getMessage();
|
||||||
logMessage('ERROR', $errorMsg);
|
logMessage('ERROR', $errorMsg);
|
||||||
$this->reportProgress('ERROR', $errorMsg, null);
|
$this->reportProgress('ERROR', $errorMsg, null);
|
||||||
|
|
||||||
// Report failure status
|
|
||||||
if (!empty($hashKey) && !empty($this->routerData['callbackUrl'])) {
|
|
||||||
$this->apiClient->reportStatus(
|
|
||||||
$this->routerData['callbackUrl'],
|
|
||||||
$hashKey,
|
|
||||||
'failed',
|
|
||||||
null,
|
|
||||||
$errorMsg
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'error' => $errorMsg
|
'error' => $errorMsg
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,15 @@ deploy_ui() {
|
||||||
# Copy main UI files (assets are now inside public)
|
# Copy main UI files (assets are now inside public)
|
||||||
cp -r public includes "$WEB_DIR/" || error_exit "Failed to copy UI files"
|
cp -r public includes "$WEB_DIR/" || error_exit "Failed to copy UI files"
|
||||||
|
|
||||||
|
# Copy the enrollment script to a system location
|
||||||
|
if [[ -f "../Router-enrollment-script/enroll-router.sh" ]]; then
|
||||||
|
cp "../Router-enrollment-script/enroll-router.sh" "/usr/local/bin/" || error_exit "Failed to copy enrollment script"
|
||||||
|
chmod +x "/usr/local/bin/enroll-router.sh" || error_exit "Failed to make enrollment script executable"
|
||||||
|
log "SUCCESS" "Copied enrollment script to /usr/local/bin/enroll-router.sh"
|
||||||
|
else
|
||||||
|
log "WARNING" "Enrollment script not found at ../Router-enrollment-script/enroll-router.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
# Copy root-level PHP files for direct access (when document root is main directory)
|
# Copy root-level PHP files for direct access (when document root is main directory)
|
||||||
if [[ -f "index.php" ]]; then
|
if [[ -f "index.php" ]]; then
|
||||||
cp index.php "$WEB_DIR/" || log "WARNING" "Failed to copy root index.php"
|
cp index.php "$WEB_DIR/" || log "WARNING" "Failed to copy root index.php"
|
||||||
|
|
@ -356,6 +365,7 @@ www-data ALL=(ALL) NOPASSWD: /usr/bin/which
|
||||||
www-data ALL=(ALL) NOPASSWD: /usr/bin/hostname
|
www-data ALL=(ALL) NOPASSWD: /usr/bin/hostname
|
||||||
www-data ALL=(ALL) NOPASSWD: /usr/bin/uname
|
www-data ALL=(ALL) NOPASSWD: /usr/bin/uname
|
||||||
www-data ALL=(ALL) NOPASSWD: /usr/bin/lsb_release
|
www-data ALL=(ALL) NOPASSWD: /usr/bin/lsb_release
|
||||||
|
www-data ALL=(ALL) NOPASSWD: /usr/local/bin/enroll-router.sh
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Validate sudoers file
|
# Validate sudoers file
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue