100 lines
2.6 KiB
PHP
Executable File
100 lines
2.6 KiB
PHP
Executable File
|
|
<?php
|
|
header('Content-Type: application/json');
|
|
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
|
|
|
|
class PMTAInstaller {
|
|
private $sshKey = '/root/.ssh/id_rsa';
|
|
|
|
public function install($ip, $rootPass, $domain, $config = []) {
|
|
$script = $this->generateScript($domain, $config);
|
|
$tempFile = "/tmp/pmta_install_" . uniqid() . ".sh";
|
|
file_put_contents($tempFile, $script);
|
|
|
|
// SSH and run
|
|
$cmd = "sshpass -p '$rootPass' ssh -o StrictHostKeyChecking=no root@$ip 'bash -s' < $tempFile 2>&1";
|
|
$output = shell_exec($cmd);
|
|
unlink($tempFile);
|
|
|
|
return ['success' => strpos($output, 'PMTA INSTALLED') !== false, 'output' => $output];
|
|
}
|
|
|
|
private function generateScript($domain, $config) {
|
|
$license = $config['license'] ?? '';
|
|
return <<<BASH
|
|
#!/bin/bash
|
|
set -e
|
|
|
|
# Update system
|
|
apt-get update && apt-get upgrade -y
|
|
|
|
# Install dependencies
|
|
apt-get install -y wget curl nano net-tools
|
|
|
|
# Download PMTA
|
|
cd /tmp
|
|
wget -q https://download.port25.com/files/pmta-5.0-1.x86_64.rpm 2>/dev/null || echo "Using local PMTA"
|
|
|
|
# Install PMTA (if available)
|
|
if [ -f pmta-5.0-1.x86_64.rpm ]; then
|
|
apt-get install -y alien
|
|
alien -i pmta-5.0-1.x86_64.rpm
|
|
fi
|
|
|
|
# Create config directory
|
|
mkdir -p /etc/pmta
|
|
mkdir -p /var/log/pmta
|
|
mkdir -p /var/spool/pmta
|
|
|
|
# Generate config
|
|
cat > /etc/pmta/config << 'PMTACONFIG'
|
|
postmaster postmaster@$domain
|
|
|
|
smtp-listener 0.0.0.0:25
|
|
smtp-listener 0.0.0.0:587
|
|
|
|
<source 0/0>
|
|
always-allow-relaying yes
|
|
process-x-virtual-mta yes
|
|
</source>
|
|
|
|
<domain *>
|
|
max-smtp-out 20
|
|
smtp-pattern-lifetime 1h
|
|
</domain>
|
|
|
|
http-mgmt-port 8080
|
|
http-access 0.0.0.0 monitor
|
|
PMTACONFIG
|
|
|
|
# Start PMTA
|
|
systemctl enable pmta 2>/dev/null || true
|
|
systemctl start pmta 2>/dev/null || true
|
|
|
|
echo "PMTA INSTALLED"
|
|
BASH;
|
|
}
|
|
}
|
|
|
|
$action = $_POST['action'] ?? $_GET['action'] ?? '';
|
|
|
|
switch ($action) {
|
|
case 'install':
|
|
$installer = new PMTAInstaller();
|
|
$result = $installer->install($_POST['ip'], $_POST['password'], $_POST['domain'], $_POST);
|
|
echo json_encode($result);
|
|
break;
|
|
case 'check':
|
|
$ip = $_POST['ip'];
|
|
$ch = curl_init("http://$ip:8080/");
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5]);
|
|
$response = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
echo json_encode(['online' => $code == 200 || $code == 401, 'code' => $code]);
|
|
break;
|
|
default:
|
|
echo json_encode(['actions' => ['install', 'check']]);
|
|
}
|
|
|