#!/usr/env python3

import subprocess
import os 

RED = '\033[91m'
GREEN = '\033[92m'
BLUE = '\033[94m'
RESET = '\033[0m'

service_configs = {
    "openvpn" : [],
    "samba": [],
    "ftp":[],
    "php":[],
    "ssh":["/etc/ssh/ssh_config"],
    "postfix":[],
    "apache2":[],
    "nginx":[],
    "mongodb":[],
    "mariadb":[],
    "mysql":[],
    "sqlite":[],
    "sftpd": [],
    "vsftpd":[],
    "proftpd":[],
    "ncftp":[],
    "tnftp":[],
    "tftp":[],
    "citadel":[],
    "squid":[],
    "opensmtpd": [],
    "apt": [],
    "ufw": [],
    "gdm": [],
    "lightdm": [],
    "snapd": [],
    "wordpress": [],
    "firefox": [],
    "chromium": []
    

}

# find current
print("\n\nHere are critical services currently FOUND in the system:")
for key in service_configs:
    current_pkgs = subprocess.getoutput("dpkg -l | awk '{print $2}'")
    for pkg in current_pkgs.split("\n"):
        if (key in pkg):
            print(RED + "" + key + RESET)
            break 


            

# display service options 
print("EXAMPLE HOW TO RUN: -1 -2 ")
print("\n\nChoose to configure service configs and REMBER to choose ufw, apt, snapd, ssh: ")
count = 0
for serv in service_configs.keys():
    if key not in ["ufw", "apt", "snapd", "ssh"]:
        print(f"{count} = {serv}")
    count += 1


# choose option 
options = input("Choose service configs: ")
options = [int(i.strip(' ')) for i in options.split("-")[1:]]
print(options)

# copy service & replace config 
for option in options:
    config_files = list(service_configs.values())
    config_files = config_files[option]
    cname = list(service_configs.keys())[option]
    for cfile in config_files:
        # check for file existing 
        
        os.system("sudo cp " + cfile + " root/birch/output_files/copy"+cfile.replace("/", "_"))
        # replace config 
        os.system("cat root" + cfile + " > "+cfile.replace("/", "_"))




