mailserver-cli
Version:
72 lines (57 loc) • 1.91 kB
JavaScript
import inquirer from "inquirer";
import chalk from "chalk";
import figlet from "figlet";
import { getCloudflareDomains } from "../lib/cloudflare.js";
import { checkFQDN } from "../lib/utils.js";
import { setupMailServer } from "../lib/setup.js";
// Display a cool banner
console.log(chalk.blue(figlet.textSync("Mail Server CLI", { horizontalLayout: "full" })));
async function main() {
console.log(chalk.green("Welcome to the Mail Server Setup!"));
// Ask user what they want to do
const { action } = await inquirer.prompt([
{
type: "list",
name: "action",
message: "What would you like to do?",
choices: ["Start Installation", "Exit"],
},
]);
if (action === "Exit") {
console.log(chalk.red("Exiting CLI. Goodbye!"));
process.exit(0);
}
// Ask for Cloudflare API Token
const { apiToken } = await inquirer.prompt([
{
type: "password",
name: "apiToken",
message: "Enter your Cloudflare API Token (Read & Edit Access):",
mask: "*",
},
]);
// Fetch available domains from Cloudflare
const domains = await getCloudflareDomains(apiToken);
if (domains.length === 0) {
console.log(chalk.red("No domains found in your Cloudflare account!"));
process.exit(1);
}
// Let the user select a domain
const { selectedDomain } = await inquirer.prompt([
{
type: "list",
name: "selectedDomain",
message: "Select a domain for your mail server:",
choices: domains,
},
]);
console.log(chalk.cyan(`Selected domain: ${selectedDomain}`));
// Check if the hostname is FQDN compliant
await checkFQDN();
// Proceed with Mail Server Setup
await setupMailServer(selectedDomain);
console.log(chalk.green("Mail Server setup completed successfully!"));
}
// Run the CLI
main();