diff --git a/iso_configs/server/scripts/configure_apache2.sh b/iso_configs/server/scripts/configure_apache2.sh new file mode 100755 index 00000000..a89e59b2 --- /dev/null +++ b/iso_configs/server/scripts/configure_apache2.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +# Function to check if Apache is installed +check_apache() { + if ! command -v apache2 &> /dev/null; then + dialog --msgbox "Apache is not installed. Installing now..." 10 50 + sudo apt update + sudo apt install -y apache2 + dialog --msgbox "Apache has been installed successfully." 10 50 + else + dialog --msgbox "Apache is already installed." 10 50 + fi +} + +# Function to start Apache service +start_apache() { + sudo systemctl start apache2 + dialog --msgbox "Apache service started." 10 30 +} + +# Function to stop Apache service +stop_apache() { + sudo systemctl stop apache2 + dialog --msgbox "Apache service stopped." 10 30 +} + +# Function to restart Apache service +restart_apache() { + sudo systemctl restart apache2 + dialog --msgbox "Apache service restarted." 10 30 +} + +# Function to enable Apache service +enable_apache() { + sudo systemctl enable apache2 + dialog --msgbox "Apache service enabled." 10 30 +} + +# Function to disable Apache service +disable_apache() { + sudo systemctl disable apache2 + dialog --msgbox "Apache service disabled." 10 30 +} + +# Function to configure Apache virtual host +configure_apache_virtual_host() { + DOMAIN=$(dialog --inputbox "Enter the domain name (e.g., example.com):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + sudo mkdir -p /var/www/$DOMAIN/html + sudo chown -R $USER:$USER /var/www/$DOMAIN/html + sudo chmod -R 755 /var/www/$DOMAIN + + cat < /dev/null + + ServerAdmin webmaster@localhost + ServerName $DOMAIN + ServerAlias www.$DOMAIN + DocumentRoot /var/www/$DOMAIN/html + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + +EOF + + sudo a2ensite $DOMAIN.conf + sudo systemctl reload apache2 + dialog --msgbox "Apache virtual host for $DOMAIN configured successfully." 10 50 +} + +# Main function to configure Apache +configure_apache() { + check_apache + + while true; do + local APACHE_CHOICE + APACHE_CHOICE=$(dialog --clear --backtitle "Apache Configuration" \ + --title "Apache Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Start Apache" \ + 2 "Stop Apache" \ + 3 "Restart Apache" \ + 4 "Enable Apache at Boot" \ + 5 "Disable Apache at Boot" \ + 6 "Configure Virtual Host" \ + 7 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then break; fi + + case "$APACHE_CHOICE" in + 1) start_apache ;; + 2) stop_apache ;; + 3) restart_apache ;; + 4) enable_apache ;; + 5) disable_apache ;; + 6) configure_apache_virtual_host ;; + 7) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;; + esac + done +} + +# Execute the main function to configure Apache +configure_apache diff --git a/iso_configs/server/scripts/configure_firewalld.sh b/iso_configs/server/scripts/configure_firewalld.sh new file mode 100755 index 00000000..e0e9ec43 --- /dev/null +++ b/iso_configs/server/scripts/configure_firewalld.sh @@ -0,0 +1,145 @@ +k#!/bin/bash + +# Function to enable firewalld +enable_firewalld() { + systemctl enable firewalld + systemctl start firewalld + dialog --msgbox "firewalld enabled and started." 10 30 +} + +# Function to disable firewalld +disable_firewalld() { + systemctl stop firewalld + systemctl disable firewalld + dialog --msgbox "firewalld disabled and stopped." 10 30 +} + +# Function to add service to firewalld +add_service() { + SERVICE=$(dialog --inputbox "Enter the service name to add (e.g., ssh, http, https):" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$SERVICE" ]; then + dialog --msgbox "Please enter a valid service name." 10 30 + else + firewall-cmd --permanent --add-service=$SERVICE + firewall-cmd --reload + dialog --msgbox "Service $SERVICE added to firewalld." 10 30 + fi +} + +# Function to remove service from firewalld +remove_service() { + SERVICE=$(dialog --inputbox "Enter the service name to remove:" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$SERVICE" ]; then + dialog --msgbox "Please enter a valid service name." 10 30 + else + firewall-cmd --permanent --remove-service=$SERVICE + firewall-cmd --reload + dialog --msgbox "Service $SERVICE removed from firewalld." 10 30 + fi +} + +# Function to add port to firewalld +add_port() { + PORT=$(dialog --inputbox "Enter the port to add (e.g., 8080/tcp):" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$PORT" ]; then + dialog --msgbox "Please enter a valid port." 10 30 + else + firewall-cmd --permanent --add-port=$PORT + firewall-cmd --reload + dialog --msgbox "Port $PORT added to firewalld." 10 30 + fi +} + +# Function to remove port from firewalld +remove_port() { + PORT=$(dialog --inputbox "Enter the port to remove (e.g., 8080/tcp):" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$PORT" ]; then + dialog --msgbox "Please enter a valid port." 10 30 + else + firewall-cmd --permanent --remove-port=$PORT + firewall-cmd --reload + dialog --msgbox "Port $PORT removed from firewalld." 10 30 + fi +} + +# Function to configure zones in firewalld +configure_zones() { + ZONE=$(dialog --inputbox "Enter the zone name (e.g., public, home, work):" 10 50 3>&1 1>&2 2>&3 3>&-) + INTERFACE=$(dialog --inputbox "Enter the interface name (e.g., eth0, wlan0):" 10 50 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + return 1 + fi + + if [ -z "$ZONE" ] || [ -z "$INTERFACE" ]; then + dialog --msgbox "Please enter valid zone and interface names." 10 30 + else + firewall-cmd --zone=$ZONE --add-interface=$INTERFACE --permanent + firewall-cmd --reload + dialog --msgbox "Interface $INTERFACE added to zone $ZONE." 10 30 + fi +} + +# Function to configure firewalld options +configure_firewalld() { + while true; do + FIREWALL_CHOICE=$(dialog --clear --backtitle "Firewalld Configuration" \ + --title "Firewalld Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Enable firewalld" \ + 2 "Disable firewalld" \ + 3 "Add Service" \ + 4 "Remove Service" \ + 5 "Add Port" \ + 6 "Remove Port" \ + 7 "Configure Zones" \ + 8 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then + break + fi + + case $FIREWALL_CHOICE in + 1) enable_firewalld ;; + 2) disable_firewalld ;; + 3) add_service ;; + 4) remove_service ;; + 5) add_port ;; + 6) remove_port ;; + 7) configure_zones ;; + 8) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;; + esac + done +} + +# Execute the main function to configure firewalld +configure_firewalld + diff --git a/iso_configs/server/scripts/configure_hostname.sh b/iso_configs/server/scripts/configure_hostname.sh new file mode 100755 index 00000000..f95ec262 --- /dev/null +++ b/iso_configs/server/scripts/configure_hostname.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +# Function to set hostname +set_hostname() { + NEW_HOSTNAME=$(dialog --inputbox "Enter the new hostname:" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [ -z "$NEW_HOSTNAME" ]; then + dialog --msgbox "Hostname cannot be empty. Please enter a valid hostname." 10 60 + else + hostnamectl set-hostname "$NEW_HOSTNAME" + dialog --msgbox "Hostname set to $NEW_HOSTNAME." 10 60 + fi +} + +# Function to display current hostname +show_hostname() { + CURRENT_HOSTNAME=$(hostnamectl --static) + dialog --msgbox "Current hostname is: $CURRENT_HOSTNAME" 10 60 +} + +# Function to display network interfaces +show_network_interfaces() { + dialog --msgbox "$(ip -o link show | awk '{print $2,$9}')" 20 60 +} + +# Function to display IP addresses +show_ip_addresses() { + dialog --msgbox "$(ip -4 addr show | grep inet)" 30 80 +} + +# Function to configure DNS settings +configure_dns() { + while true; do + DNS_CHOICE=$(dialog --clear --backtitle "DNS Configuration" \ + --title "DNS Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Set DNS Servers" \ + 2 "Show DNS Configuration" \ + 3 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $DNS_CHOICE in + 1) set_dns_servers ;; + 2) show_dns_configuration ;; + 3) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Function to set DNS servers +set_dns_servers() { + DNS_SERVERS=$(dialog --inputbox "Enter DNS servers separated by comma (e.g., 8.8.8.8,8.8.4.4):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [ -z "$DNS_SERVERS" ]; then + dialog --msgbox "DNS servers cannot be empty. Please enter valid DNS servers." 10 60 + else + echo "nameserver $DNS_SERVERS" | sudo tee /etc/resolv.conf >/dev/null + dialog --msgbox "DNS servers set to: $DNS_SERVERS" 10 60 + fi +} + +# Function to show current DNS configuration +show_dns_configuration() { + CURRENT_DNS=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}' | tr '\n' ' ') + dialog --msgbox "Current DNS configuration:\n$CURRENT_DNS" 10 60 +} + +# Function to configure host options +configure_host() { + while true; do + HOST_CHOICE=$(dialog --clear --backtitle "Host Configuration" \ + --title "Host Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Set Hostname" \ + 2 "Show Hostname" \ + 3 "Show Network Interfaces" \ + 4 "Show IP Addresses" \ + 5 "DNS Configuration" \ + 6 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $HOST_CHOICE in + 1) set_hostname ;; + 2) show_hostname ;; + 3) show_network_interfaces ;; + 4) show_ip_addresses ;; + 5) configure_dns ;; + 6) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Execute the main function to configure host settings +configure_host diff --git a/iso_configs/server/scripts/configure_mariadb.sh b/iso_configs/server/scripts/configure_mariadb.sh new file mode 100755 index 00000000..e504876b --- /dev/null +++ b/iso_configs/server/scripts/configure_mariadb.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# Function to check if MariaDB is installed +check_mariadb() { + if ! command -v mariadb &> /dev/null; then + dialog --msgbox "MariaDB is not installed. Installing now..." 10 50 + sudo apt update + sudo apt install -y mariadb-server + sudo mysql_secure_installation + dialog --msgbox "MariaDB has been installed and secured successfully." 10 50 + else + dialog --msgbox "MariaDB is already installed." 10 50 + fi +} + +# Function to start MariaDB service +start_mariadb() { + sudo systemctl start mariadb + dialog --msgbox "MariaDB service started." 10 30 +} + +# Function to stop MariaDB service +stop_mariadb() { + sudo systemctl stop mariadb + dialog --msgbox "MariaDB service stopped." 10 30 +} + +# Function to restart MariaDB service +restart_mariadb() { + sudo systemctl restart mariadb + dialog --msgbox "MariaDB service restarted." 10 30 +} + +# Function to enable MariaDB service +enable_mariadb() { + sudo systemctl enable mariadb + dialog --msgbox "MariaDB service enabled." 10 30 +} + +# Function to disable MariaDB service +disable_mariadb() { + sudo systemctl disable mariadb + dialog --msgbox "MariaDB service disabled." 10 30 +} + +# Function to configure MariaDB +configure_mariadb() { + check_mariadb + + while true; do + local MARIADB_CHOICE + MARIADB_CHOICE=$(dialog --clear --backtitle "MariaDB Configuration" \ + --title "MariaDB Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Start MariaDB" \ + 2 "Stop MariaDB" \ + 3 "Restart MariaDB" \ + 4 "Enable MariaDB at Boot" \ + 5 "Disable MariaDB at Boot" \ + 6 "Secure MariaDB Installation" \ + 7 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then break; fi + + case "$MARIADB_CHOICE" in + 1) start_mariadb ;; + 2) stop_mariadb ;; + 3) restart_mariadb ;; + 4) enable_mariadb ;; + 5) disable_mariadb ;; + 6) sudo mysql_secure_installation ;; + 7) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;; + esac + done +} + +# Execute the main function to configure MariaDB +configure_mariadb diff --git a/iso_configs/server/scripts/configure_nginx.sh b/iso_configs/server/scripts/configure_nginx.sh new file mode 100755 index 00000000..3d486235 --- /dev/null +++ b/iso_configs/server/scripts/configure_nginx.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +# Function to check if NGINX is installed +check_nginx() { + if ! command -v nginx &> /dev/null; then + dialog --msgbox "NGINX is not installed. Installing now..." 10 50 + sudo apt update + sudo apt install -y nginx + dialog --msgbox "NGINX has been installed successfully." 10 50 + else + dialog --msgbox "NGINX is already installed." 10 50 + fi +} + +# Function to start NGINX service +start_nginx() { + sudo systemctl start nginx + dialog --msgbox "NGINX service started." 10 30 +} + +# Function to stop NGINX service +stop_nginx() { + sudo systemctl stop nginx + dialog --msgbox "NGINX service stopped." 10 30 +} + +# Function to restart NGINX service +restart_nginx() { + sudo systemctl restart nginx + dialog --msgbox "NGINX service restarted." 10 30 +} + +# Function to enable NGINX service +enable_nginx() { + sudo systemctl enable nginx + dialog --msgbox "NGINX service enabled." 10 30 +} + +# Function to disable NGINX service +disable_nginx() { + sudo systemctl disable nginx + dialog --msgbox "NGINX service disabled." 10 30 +} + +# Function to configure NGINX virtual host +configure_nginx_virtual_host() { + DOMAIN=$(dialog --inputbox "Enter the domain name (e.g., example.com):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + sudo mkdir -p /var/www/$DOMAIN/html + sudo chown -R $USER:$USER /var/www/$DOMAIN/html + sudo chmod -R 755 /var/www/$DOMAIN + + cat < /dev/null +server { + listen 80; + server_name $DOMAIN www.$DOMAIN; + root /var/www/$DOMAIN/html; + index index.html index.htm; + location / { + try_files $uri $uri/ =404; + } +} +EOF + + sudo ln -s /etc/nginx/sites-available/$DOMAIN /etc/nginx/sites-enabled/ + sudo nginx -t && sudo systemctl reload nginx + dialog --msgbox "NGINX virtual host for $DOMAIN configured successfully." 10 50 +} + +# Main function to configure NGINX +configure_nginx() { + check_nginx + + while true; do + local NGINX_CHOICE + NGINX_CHOICE=$(dialog --clear --backtitle "NGINX Configuration" \ + --title "NGINX Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Start NGINX" \ + 2 "Stop NGINX" \ + 3 "Restart NGINX" \ + 4 "Enable NGINX at Boot" \ + 5 "Disable NGINX at Boot" \ + 6 "Configure Virtual Host" \ + 7 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then break; fi + + case "$NGINX_CHOICE" in + 1) start_nginx ;; + 2) stop_nginx ;; + 3) restart_nginx ;; + 4) enable_nginx ;; + 5) disable_nginx ;; + 6) configure_nginx_virtual_host ;; + 7) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;; + esac + done +} + +# Execute the main function to configure NGINX +configure_nginx diff --git a/iso_configs/server/scripts/configure_postgresql.sh b/iso_configs/server/scripts/configure_postgresql.sh new file mode 100755 index 00000000..10de2bc5 --- /dev/null +++ b/iso_configs/server/scripts/configure_postgresql.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# Function to check if PostgreSQL is installed +check_postgresql() { + if ! command -v psql &> /dev/null; then + dialog --msgbox "PostgreSQL is not installed. Installing now..." 10 50 + sudo apt update + sudo apt install -y postgresql postgresql-contrib + dialog --msgbox "PostgreSQL has been installed successfully." 10 50 + else + dialog --msgbox "PostgreSQL is already installed." 10 50 + fi +} + +# Function to start PostgreSQL service +start_postgresql() { + sudo systemctl start postgresql + dialog --msgbox "PostgreSQL service started." 10 30 +} + +# Function to stop PostgreSQL service +stop_postgresql() { + sudo systemctl stop postgresql + dialog --msgbox "PostgreSQL service stopped." 10 30 +} + +# Function to restart PostgreSQL service +restart_postgresql() { + sudo systemctl restart postgresql + dialog --msgbox "PostgreSQL service restarted." 10 30 +} + +# Function to enable PostgreSQL service +enable_postgresql() { + sudo systemctl enable postgresql + dialog --msgbox "PostgreSQL service enabled." 10 30 +} + +# Function to disable PostgreSQL service +disable_postgresql() { + sudo systemctl disable postgresql + dialog --msgbox "PostgreSQL service disabled." 10 30 +} + +# Function to configure PostgreSQL +configure_postgresql() { + check_postgresql + + while true; do + local POSTGRESQL_CHOICE + POSTGRESQL_CHOICE=$(dialog --clear --backtitle "PostgreSQL Configuration" \ + --title "PostgreSQL Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Start PostgreSQL" \ + 2 "Stop PostgreSQL" \ + 3 "Restart PostgreSQL" \ + 4 "Enable PostgreSQL at Boot" \ + 5 "Disable PostgreSQL at Boot" \ + 6 "Create PostgreSQL User" \ + 7 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then break; fi + + case "$POSTGRESQL_CHOICE" in + 1) start_postgresql ;; + 2) stop_postgresql ;; + 3) restart_postgresql ;; + 4) enable_postgresql ;; + 5) disable_postgresql ;; + 6) create_postgresql_user ;; + 7) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;; + esac + done +} + +# Execute the main function to configure PostgreSQL +configure_postgresql diff --git a/iso_configs/server/scripts/configure_sqlite.sh b/iso_configs/server/scripts/configure_sqlite.sh new file mode 100755 index 00000000..41076c9d --- /dev/null +++ b/iso_configs/server/scripts/configure_sqlite.sh @@ -0,0 +1,128 @@ +#!/bin/bash + +# Function to check if SQLite is installed +check_sqlite() { + if ! command -v sqlite3 &> /dev/null; then + dialog --msgbox "SQLite is not installed. Installing now..." 10 50 + sudo apt update + sudo apt install -y sqlite3 + dialog --msgbox "SQLite has been installed successfully." 10 50 + else + dialog --msgbox "SQLite is already installed." 10 50 + fi +} + +# Function to create a SQLite database +create_sqlite_database() { + DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database to create (e.g., /path/to/db.sqlite):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + sqlite3 $DB_PATH "VACUUM;" + dialog --msgbox "SQLite database $DB_PATH created successfully." 10 30 +} + +# Function to create a SQLite table +create_sqlite_table() { + DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database (to create table in):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + TABLE_NAME=$(dialog --inputbox "Enter the name of the table to create:" 10 40 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + COLUMNS=$(dialog --inputbox "Enter table columns (e.g., id INTEGER PRIMARY KEY, name TEXT):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + sqlite3 $DB_PATH "CREATE TABLE $TABLE_NAME ($COLUMNS);" + dialog --msgbox "Table $TABLE_NAME created successfully in SQLite database $DB_PATH." 10 30 +} + +# Function to insert data into a SQLite table +insert_sqlite_data() { + DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database (to insert data into table):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + TABLE_NAME=$(dialog --inputbox "Enter the name of the table to insert data into:" 10 40 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + COLUMNS=$(dialog --inputbox "Enter column names (e.g., name, age):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + VALUES=$(dialog --inputbox "Enter values to insert (e.g., 'John', 30):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + sqlite3 $DB_PATH "INSERT INTO $TABLE_NAME ($COLUMNS) VALUES ($VALUES);" + dialog --msgbox "Data inserted successfully into table $TABLE_NAME of SQLite database $DB_PATH." 10 30 +} + +# Function to query data from a SQLite table +query_sqlite_data() { + DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database (to query data from table):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + QUERY=$(dialog --inputbox "Enter SQL query (e.g., SELECT * FROM table_name):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + RESULT=$(sqlite3 -header -column $DB_PATH "$QUERY") + dialog --msgbox "Query result:\n\n$RESULT" 20 70 +} + +# Function to back up a SQLite database +backup_sqlite_database() { + DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database to backup:" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + BACKUP_FILE=$(dialog --inputbox "Enter the path and name of the backup file (e.g., /home/user/backup.sql):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + sqlite3 $DB_PATH ".backup $BACKUP_FILE" + dialog --msgbox "Backup of SQLite database $DB_PATH successfully saved to $BACKUP_FILE." 10 30 +} + +# Function to restore a SQLite database from backup +restore_sqlite_database() { + DB_PATH=$(dialog --inputbox "Enter the path and name of the SQLite database to restore to:" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + BACKUP_FILE=$(dialog --inputbox "Enter the path and name of the backup file (e.g., /home/user/backup.sql):" 10 50 3>&1 1>&2 2>&3 3>&-) + if [ $? -eq 1 ]; then return; fi + + sqlite3 $DB_PATH ".restore $BACKUP_FILE" + dialog --msgbox "SQLite database $DB_PATH successfully restored from $BACKUP_FILE." 10 30 +} + +# Main function to configure SQLite +configure_sqlite() { + check_sqlite + + while true; do + local SQLITE_CHOICE + SQLITE_CHOICE=$(dialog --clear --backtitle "SQLite Configuration" \ + --title "SQLite Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Create Database" \ + 2 "Create Table" \ + 3 "Insert Data into Table" \ + 4 "Query Data from Table" \ + 5 "Backup Database" \ + 6 "Restore Database" \ + 7 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -eq 1 ]; then break; fi + + case "$SQLITE_CHOICE" in + 1) create_sqlite_database ;; + 2) create_sqlite_table ;; + 3) insert_sqlite_data ;; + 4) query_sqlite_data ;; + 5) backup_sqlite_database ;; + 6) restore_sqlite_database ;; + 7) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 30 ;; + esac + done +} + +# Execute the main function to configure SQLite +configure_sqlite diff --git a/iso_configs/server/scripts/configure_ssh.sh b/iso_configs/server/scripts/configure_ssh.sh new file mode 100755 index 00000000..d9b32fe2 --- /dev/null +++ b/iso_configs/server/scripts/configure_ssh.sh @@ -0,0 +1,230 @@ +#!/bin/bash + +# Function to generate SSH keys +generate_ssh_keys() { + dialog --yesno "Do you want to generate SSH keys?" 10 60 + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + SSH_DIR=~/.ssh + mkdir -p $SSH_DIR + SSH_KEY_FILE=$SSH_DIR/id_rsa + ssh-keygen -t rsa -b 4096 -f $SSH_KEY_FILE -N "" + + dialog --msgbox "SSH keys generated in $SSH_KEY_FILE." 10 60 +} + +# Function to add SSH key to authorized_keys +add_ssh_key() { + KEY_FILE=$(dialog --inputbox "Enter the path to the SSH public key file:" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [ -z "$KEY_FILE" ]; then + dialog --msgbox "Please enter a valid path to the SSH public key file." 10 60 + else + mkdir -p ~/.ssh + cat "$KEY_FILE" >> ~/.ssh/authorized_keys + dialog --msgbox "SSH key added to authorized_keys." 10 60 + fi +} + +# Function to configure advanced SSH options +configure_advanced_ssh() { + while true; do + ADV_CHOICE=$(dialog --clear --backtitle "SSH Advanced Configuration" \ + --title "SSH Advanced Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Edit SSH Config File" \ + 2 "Restart SSH Service" \ + 3 "Check SSH Service Status" \ + 4 "Install OpenSSH Server" \ + 5 "Uninstall OpenSSH Server" \ + 6 "View SSH Logs" \ + 7 "Backup SSH Config" \ + 8 "Restore SSH Config" \ + 9 "Change SSH Port" \ + 10 "Enable/Disable Password Authentication" \ + 11 "List SSH Connections" \ + 12 "Back to SSH Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $ADV_CHOICE in + 1) ${EDITOR:-nano} /etc/ssh/sshd_config ;; + 2) systemctl restart ssh ;; + 3) systemctl status ssh ;; + 4) install_openssh_server ;; + 5) uninstall_openssh_server ;; + 6) view_ssh_logs ;; + 7) backup_ssh_config ;; + 8) restore_ssh_config ;; + 9) change_ssh_port ;; + 10) toggle_password_authentication ;; + 11) list_ssh_connections ;; + 12) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Function to install OpenSSH Server +install_openssh_server() { + dialog --yesno "Do you want to install OpenSSH Server?" 10 60 + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + apt update + apt install -y openssh-server + systemctl start ssh + systemctl enable ssh + dialog --msgbox "OpenSSH Server installed and enabled." 10 60 +} + +# Function to uninstall OpenSSH Server +uninstall_openssh_server() { + dialog --yesno "Do you want to uninstall OpenSSH Server?" 10 60 + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + systemctl stop ssh + systemctl disable ssh + apt remove -y openssh-server + dialog --msgbox "OpenSSH Server uninstalled." 10 60 +} + +# Function to view SSH logs +view_ssh_logs() { + dialog --msgbox "$(journalctl -u ssh --no-pager)" 30 80 +} + +# Function to backup SSH config +backup_ssh_config() { + BACKUP_DIR="/var/backups" + BACKUP_FILE="sshd_config_$(date +"%Y%m%d_%H%M%S").bak" + cp /etc/ssh/sshd_config $BACKUP_DIR/$BACKUP_FILE + dialog --msgbox "SSH config backed up to $BACKUP_DIR/$BACKUP_FILE." 10 60 +} + +# Function to restore SSH config +restore_ssh_config() { + BACKUP_FILE=$(dialog --inputbox "Enter the full path of the SSH config backup file:" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [ -z "$BACKUP_FILE" ]; then + dialog --msgbox "Please enter a valid path to the SSH config backup file." 10 60 + elif [ ! -f "$BACKUP_FILE" ]; then + dialog --msgbox "Backup file not found." 10 60 + else + cp "$BACKUP_FILE" /etc/ssh/sshd_config + systemctl restart ssh + dialog --msgbox "SSH config restored from $BACKUP_FILE." 10 60 + fi +} + +# Function to change SSH port +change_ssh_port() { + NEW_PORT=$(dialog --inputbox "Enter the new SSH port:" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + if [[ $NEW_PORT =~ ^[0-9]+$ ]]; then + sed -i "s/#Port 22/Port $NEW_PORT/" /etc/ssh/sshd_config + systemctl restart ssh + dialog --msgbox "SSH port changed to $NEW_PORT." 10 60 + else + dialog --msgbox "Invalid port number." 10 60 + fi +} + +# Function to enable/disable password authentication in SSH +toggle_password_authentication() { + STATUS=$(dialog --menu "Choose an option:" 10 60 2 \ + 1 "Enable Password Authentication" \ + 2 "Disable Password Authentication" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + case $STATUS in + 1) sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config ;; + 2) sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config ;; + esac + + systemctl restart ssh + dialog --msgbox "Password authentication $(echo $STATUS | tr '[:lower:]' '[:upper:]')." 10 60 +} + +# Function to list SSH connections +list_ssh_connections() { + netstat -tnpa | grep 'ESTABLISHED.*sshd' + dialog --msgbox "List of SSH connections displayed." 10 60 +} + +# Function to check if OpenSSH is installed +check_ssh_installation() { + dpkg -l openssh-server >/dev/null 2>&1 + if [ $? -eq 0 ]; then + dialog --msgbox "OpenSSH is installed." 10 60 + else + dialog --msgbox "OpenSSH is not installed." 10 60 + fi +} + +# Function to configure SSH options +configure_ssh() { + while true; do + SSH_CHOICE=$(dialog --clear --backtitle "SSH Configuration" \ + --title "SSH Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Generate SSH Keys" \ + 2 "Add SSH Key to authorized_keys" \ + 3 "Advanced Configuration" \ + 4 "Check SSH Installation" \ + 5 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $SSH_CHOICE in + 1) generate_ssh_keys ;; + 2) add_ssh_key ;; + 3) configure_advanced_ssh ;; + 4) check_ssh_installation ;; + 5) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Execute the main function to configure SSH +configure_ssh diff --git a/iso_configs/server/scripts/configure_static_ip.sh b/iso_configs/server/scripts/configure_static_ip.sh new file mode 100755 index 00000000..e33ae535 --- /dev/null +++ b/iso_configs/server/scripts/configure_static_ip.sh @@ -0,0 +1,158 @@ +#!/bin/bash + +# Function to configure static IP +configure_static_ip() { + while true; do + # Prompt for network interface + INTERFACE=$(dialog --inputbox "Enter physical network interface (e.g., eth0):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Prompt for IP address + IP_ADDRESS=$(dialog --inputbox "Enter static IP address (e.g., 192.168.1.100):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Validate IP address format + if ! valid_ip "$IP_ADDRESS"; then + dialog --msgbox "Invalid IP address format. Please enter a valid IP address." 10 60 + continue + fi + + # Prompt for netmask + NETMASK=$(dialog --inputbox "Enter netmask (e.g., 255.255.255.0):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Validate netmask format + if ! valid_netmask "$NETMASK"; then + dialog --msgbox "Invalid netmask format. Please enter a valid netmask." 10 60 + continue + fi + + # Prompt for gateway + GATEWAY=$(dialog --inputbox "Enter gateway (optional, leave blank if none):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Prompt for DNS server + DNS_SERVER=$(dialog --inputbox "Enter DNS server (optional, leave blank if none):" 10 60 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + return 1 + fi + + # Apply the static IP configuration + if [ -z "$INTERFACE" ] || [ -z "$IP_ADDRESS" ] || [ -z "$NETMASK" ]; then + dialog --msgbox "Network interface, IP address, and netmask cannot be empty. Please enter valid information." 10 60 + else + apply_static_ip "$INTERFACE" "$IP_ADDRESS" "$NETMASK" "$GATEWAY" "$DNS_SERVER" + return $? + fi + done +} + +# Function to validate IP address format +valid_ip() { + local ip=$1 + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + local IFS='.' + ip=($ip) + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + else + false + fi +} + +# Function to validate netmask format +valid_netmask() { + local netmask=$1 + if [[ $netmask =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + local IFS='.' + netmask=($netmask) + [[ ${netmask[0]} -le 255 && ${netmask[1]} -le 255 && ${netmask[2]} -le 255 && ${netmask[3]} -le 255 ]] + else + false + fi +} + +# Function to apply static IP configuration +apply_static_ip() { + local interface=$1 + local ip_address=$2 + local netmask=$3 + local gateway=$4 + local dns_server=$5 + + # Apply configuration to /etc/network/interfaces + cat </dev/null +auto lo +iface lo inet loopback + +auto $interface +iface $interface inet static + address $ip_address + netmask $netmask + gateway $gateway + dns-nameservers $dns_server +EOF + + # Restart networking service + sudo systemctl restart networking + + # Check if configuration applied successfully + if ifconfig $interface | grep -q "$ip_address"; then + dialog --msgbox "Static IP configuration applied successfully:\nInterface: $interface\nIP Address: $ip_address\nNetmask: $netmask\nGateway: $gateway\nDNS Server: $dns_server" 12 60 + return 0 + else + dialog --msgbox "Failed to apply static IP configuration. Please check your settings and try again." 10 60 + return 1 + fi +} + +# Main function to configure host settings +configure_host() { + while true; do + HOST_CHOICE=$(dialog --clear --backtitle "Host Configuration" \ + --title "Host Menu" \ + --menu "Choose an option:" 20 60 10 \ + 1 "Configure Static IP" \ + 2 "Show Current Network Settings" \ + 3 "Back to Main Menu" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled + if [ $? -ne 0 ]; then + break + fi + + case $HOST_CHOICE in + 1) configure_static_ip ;; + 2) show_current_network_settings ;; + 3) break ;; + *) dialog --msgbox "Invalid option. Please choose a valid option." 10 60 ;; + esac + done +} + +# Function to show current network settings +show_current_network_settings() { + CURRENT_SETTINGS=$(ip addr show) + dialog --msgbox "Current Network Settings:\n\n$CURRENT_SETTINGS" 20 80 +} + +# Execute the main function to configure host settings +configure_host diff --git a/iso_configs/server/scripts/create_user.sh b/iso_configs/server/scripts/create_user.sh new file mode 100755 index 00000000..b822776f --- /dev/null +++ b/iso_configs/server/scripts/create_user.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Function to create users +create_user() { + USERNAME=$(dialog --inputbox "Enter the username of the new user:" 10 40 3>&1 1>&2 2>&3 3>&-) + useradd -m $USERNAME + passwd $USERNAME + dialog --msgbox "User $USERNAME created successfully." 10 30 +} + +# Call the function to create users +create_user diff --git a/iso_configs/server/scripts/update_and_install.sh b/iso_configs/server/scripts/update_and_install.sh new file mode 100755 index 00000000..2d4ba9e0 --- /dev/null +++ b/iso_configs/server/scripts/update_and_install.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +# Function to update package list +update_package_list() { + echo "Updating package list..." + if ! sudo apt update; then + echo "Failed to update package list." + dialog --title "Error" --msgbox "Failed to update package list. Check your internet connection or repository settings." 10 60 + return 1 + fi + echo "Package list updated successfully." +} + +# Function to install selected packages +install_selected_packages() { + local selected_packages=("$@") + + echo "Installing selected packages..." + for package in "${selected_packages[@]}"; do + echo "Installing package: $package" + if sudo apt install -y "$package"; then + echo "Package $package installed successfully." + else + echo "Failed to install package: $package" + dialog --title "Error" --msgbox "Failed to install package: $package" 10 60 + fi + done + echo "All packages installed successfully." + dialog --title "Success" --msgbox "All packages installed successfully." 10 60 +} + +# List of packages available for installation +PACKAGES=("vim" + "nano" + "emacs" + "mcedit" + "joe" + "wget" + "curl" + "lynx" + "htop" + "iftop" + "iotop" + "net-tools" + "dnsutils") + +# Check if script is running as root +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root." + dialog --title "Error" --msgbox "This script must be run as root." 10 30 + exit 1 +fi + +# Update package list before installation +update_package_list + +# Prepare package list for dialog +DIALOG_PACKAGES=() +for idx in "${!PACKAGES[@]}"; do + DIALOG_PACKAGES+=("$((idx + 1))" "${PACKAGES[$idx]}" off) +done + +while true; do + # Show dialog box for package selection + echo "Starting package selection dialog..." + selections=$(dialog --stdout --checklist "Select packages to install (use space to select):" 20 60 ${#PACKAGES[@]} "${DIALOG_PACKAGES[@]}" 3>&1 1>&2 2>&3) + + # Check if cancel button is pressed or no selection was made + if [[ $? -ne 0 ]]; then + echo "Installation canceled." + dialog --title "Information" --msgbox "Installation canceled." 10 60 + exit 0 + fi + + # Check if no selection was made + if [[ -z "$selections" ]]; then + echo "No packages selected. Please select at least one package." + dialog --title "Error" --msgbox "No packages selected. Please select at least one package." 10 60 + else + break + fi +done + +# Convert selection into an array +IFS=" " read -r -a packages_to_install <<< "$selections" + +# Call function to install selected packages +install_selected_packages "${packages_to_install[@]}" + +echo "Script completed." + diff --git a/iso_configs/server/scripts/welcome.sh b/iso_configs/server/scripts/welcome.sh new file mode 100755 index 00000000..2d6a6cc5 --- /dev/null +++ b/iso_configs/server/scripts/welcome.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Function to display the main menu +main_menu() { + while true; do + CHOICE=$(dialog --clear --backtitle "PeppermintOS Server Configuration" \ + --title "Main Menu" \ + --menu "Choose an option:" 20 60 12 \ + 1 "Configure SSH" \ + 2 "Configure Static IP" \ + 3 "Update and Install Packages" \ + 4 "Configure firewalld" \ + 5 "Configure Hostname" \ + 6 "Create User" \ + 7 "Configure Nginx" \ + 8 "Configure Apache2" \ + 9 "Configure MariaDB" \ + 10 "Configure PostgreSQL" \ + 11 "Configure SQLite" \ + 12 "Exit" \ + 3>&1 1>&2 2>&3 3>&-) + + # Check if user canceled or exited + if [[ $? -ne 0 ]]; then + clear + echo "Menu closed or canceled. Exiting..." + exit 0 + fi + + clear + + case $CHOICE in + 1) sudo ./configure_ssh.sh ;; + 2) sudo ./configure_static_ip.sh ;; + 3) sudo ./update_and_install.sh ;; + 4) sudo ./configure_firewalld.sh ;; + 5) sudo ./configure_hostname.sh ;; + 6) sudo ./create_user.sh ;; + 7) sudo ./configure_nginx.sh ;; + 8) sudo ./configure_apache2.sh ;; + 9) sudo ./configure_mariadb.sh ;; + 10) sudo ./configure_postgresql.sh ;; + 11) sudo ./configure_sqlite.sh ;; + 12) clear; echo "Exiting..."; exit 0 ;; + *) dialog --msgbox "Invalid option." 10 30 ;; + esac + done +} + +# Show welcome message +dialog --msgbox "Welcome to PeppermintOS Server Friendly Configuration Tool! +This tool will help you configure various aspects of your server, including: + +1. SSH: Configure the SSH server and client for secure remote access. +2. Static IP: Set a static IP address for consistent network communication. +3. Update and Install Packages: Ensure your system is up-to-date and install essential packages. +4. firewalld: Set up firewall rules to secure your server. +5. Hostname: Change the hostname of your server. +6. Create User: Add new users to your system. +7. Nginx: Configure the Nginx web server. +8. Apache2: Configure the Apache2 web server. +9. MariaDB: Set up the MariaDB database server. +10. PostgreSQL: Set up the PostgreSQL database server. +11. SQLite: Configure the SQLite database. + +Please select an option from the menu to begin." 20 60 + +# Display main menu +main_menu +