def items(): while True: remote_start.remote_start() os.system("tput setaf 10") print(''' [1] INSTALL DOCKER [100] CHANGE LOCATION [2] GENERAL [3] DOCKER CONTAINER [4] DOCKER IMAGE [5] DOCKER COMPOSE [6] DOCKER NETWORK [7] DOCKER STORAGE [0] EXIT ''') os.system("tput setaf 15") i = int(input("ENTER CHOICE : ")) if i == 1: repo = sp.getoutput( f"ssh {remoteIP} rpm -q docker-ce | cut -c 1-9") if repo == "docker-ce": os.system( f"tput setaf 4 && echo -e 'DOCKER IS ALREADY INSTALLED' && tput setaf 15" ) else: os.system( f"ssh {remoteIP} echo -e '[docker]\nbaseurl=https://download.docker.com/linux/centos/7/x86_64/stable/\ngpgcheck=0' > /etc/yum.repos.d/docker.repo && ssh {remoteIP} dnf install docker-ce -y" ) elif i == 2: remote_general.remote_general() elif i == 3: remote_docker_container.remote_docker_container() elif i == 4: remote_docker_image.remote_docker_image() elif i == 5: remote_docker_compose.remote_docker_compose() elif i == 6: remote_docker_network.remote_docker_network() elif i == 7: remote_docker_storage.remote_docker_storage() elif i == 100: docker.main() elif i == 0: os.system("reset") exit() else: os.system( "tput setaf 9 && echo -e 'OPTION NOT SUPPORTED !!!' && tput setaf 15" ) time.sleep(1) os.system("tput setaf 4") inp = input("enter to continue.......") os.system("tput setaf 15 && clear")
def remote_main_menu(): remote_start.remote_start() global remoteIP remoteIP = input("\n\tENTER YOUR IP ADDRESS : ") fileoutput = 'power_ranger.txt' output = sp.getoutput(f"nmap -sT {remoteIP} | grep ^H | cut -c 1-4") if "Host" in output and os.path.isfile( fileoutput) == True and remoteIP in open( 'power_ranger.txt').read(): items() elif "Host" in output: os.system("ssh-keygen") os.system(f"ssh-copy-id {remoteIP}") if os.path.isfile(fileoutput) == True: os.system(f"echo -e {remoteIP} >> power_ranger.txt") else: os.system(f"echo -e {remoteIP} > power_ranger.txt") items() else: os.system( "tput setaf 9 && echo -e 'HOST IS NOT UP !!!' && tput setaf 15") time.sleep(3) remote_main_menu()
def remote_general(): os.system("clear") while True: remote_start.remote_start() os.system("tput setaf 10") print(''' [1] RUN NEW COMMAND [2] HELP [3] RUN CONTAINER [4] DOCKER INFO [5] RAM CONSUMPTION [6] ALL STOPPED / RUNNING CONTAINERS [7] REMOVE ALL (stopped + running) DOCKER CONTAINER [8] CREATE IMAGE [9] CONTAINER DETAIL [10] CPU SHARE [11] PORTS RUNNING [12] CONTAINER LOGS [13] YUM WHATPROVIDES [14] KERNAL VERSION [15] ID OF ALL CONTAINERS [16] PROCESS TREE [17] IPTABLES [0] BACK [99] EXIT ''') os.system("tput setaf 15") i = int(input("ENTER CHOICE : ")) if i == 1: inp = input("COMMAND : ") os.system(f"ssh {remote_main_menu.remoteIP} {inp}") elif i == 2: inp = input("COMMAND INFO : ") os.system(f"ssh {remote_main_menu.remoteIP} man {inp}") elif i == 15: os.system( f"ssh {remote_main_menu.remoteIP} docker container ls -a -q") elif i == 3: inp = input("ENTER THE IMAGE_NAME:VERSION : ") os.system(f"ssh {remote_main_menu.remoteIP} docker run -dit {inp}") elif i == 4: os.system(f"ssh {remote_main_menu.remoteIP} docker info") elif i == 5: os.system(f"ssh {remote_main_menu.remoteIP} free -m") elif i == 6: os.system(f"ssh {remote_main_menu.remoteIP} docker ps -a") elif i == 7: os.system( f"ssh {remote_main_menu.remoteIP} docker container rm -f $(ssh {remote_main_menu.remoteIP} docker container ls -q -a)" ) elif i == 8: inp = input("ENTER THE CONTAINER NAME : ") inp1 = input("ENTER THE IMAGENAME WITH VERSION : ") os.system( f"ssh {remote_main_menu.remoteIP} docker commit {inp} {inp1}") elif i == 9: inp = input("ENTER THE CONTAINER NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker container inspect {inp}" ) elif i == 10: os.system(f"ssh {remote_main_menu.remoteIP} lscpu") elif i == 11: os.system(f"ssh {remote_main_menu.remoteIP} netstat -tnlp") elif i == 12: inp = input("ENTER THE CONTAINER NAME : ") os.system(f"ssh {remote_main_menu.remoteIP} docker logs -f {inp}" ) # -f -> to show logs in real time elif i == 13: inp = input("ENTER THE SOFTWARE NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} yum whatprovides {inp}") elif i == 14: os.system(f"ssh {remote_main_menu.remoteIP} uname -r") elif i == 16: os.system(f"ssh {remote_main_menu.remoteIP} pstree") elif i == 17: os.system( f"ssh {remote_main_menu.remoteIP} iptables -F && ssh {remote_main_menu.remoteIP} iptables -nvL" ) elif i == 0: remote_main_menu.items() elif i == 99: os.system("reset") exit() else: os.system( "tput setaf 9 && echo -e 'OPTION NOT SUPPORTED !!!' && tput setaf 15" ) time.sleep(1) os.system("tput setaf 4") inp = input("enter to continue..........") os.system("tput setaf 15 && clear")
def remote_docker_compose(): os.system("clear") while True: remote_start.remote_start() os.system("tput setaf 10") print(''' [1] INSTALL DOCKER COMPOSE [2] MAKE A NEW FILE [3] SEE COMPOSE FILE [4] RUN PREMADE CONTAINER [0] BACK [99] EXIT ''') os.system("tput setaf 15") i = int(input("ENTER CHOICE : ")) if i == 1: os.system( f'ssh {remote_main_menu.remoteIP} curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && ssh {remote_main_menu.remoteIP} chmod +x /usr/local/bin/docker-compose' ) elif i == 2: inp = input("ENTER THE FOLDER NAME : ") os.system(f"ssh {remote_main_menu.remoteIP} mkdir /root/{inp}") os.system( f"ssh {remote_main_menu.remoteIP} touch /root/{inp}/docker-compose.yml" ) elif i == 3: inp = input("ENTER THE FILE PATH : ") os.system( f"ssh {remote_main_menu.remoteIP} gedit {inp}/docker-compose.yml" ) elif i == 4: while True: remote_start.remote_start() os.system( "tput setaf 10 && echo -e '[1] WORDPRESS CONTAINER\n[2] OWNCLOUD CONTAINER\n[3] NGINX SERVER\n[4] PHP\n\n[0] BACK\n[99] EXIT' && tput setaf 15" ) inp = int(input("\nCHOICE : ")) if inp == 1: inp1 = input("ENTER THE PATH TO SAVE : ") os.system(f"echo -e '''\ version: \"3\"\n\ services:\n\ dbos:\n\ image: mysql:5.7\n\ environment:\n\ MYSQL_ROOT_PASSWORD: nfsmw\n\ MYSQL_USER: milind\n\ MYSQL_PASSWORD: nfsmw\n\ MYSQL_DATABASE: mydb\n\ volumes:\n\ - mysql_storage_new:/var/lib/mysql\n\ restart: always\n\ \n\ wpos:\n\ image: wordpress:5.1.1-php7.3-apache\n\ restart: always\n\ environment:\n\ WORDPRESS_DB_HOST: dbos\n\ WORDPRESS_DB_USER: milind\n\ WORDPRESS_DB_PASSWORD: redhat\n\ WORDPRESS_DB_NAME: mydb\n\ volumes:\n\ - wp_storage_new:/var/www/html\n\ ports:\n\ - 8081:80\n\ depends_on:\n\ - dbos\n\ \n\ volumes:\n\ wp_storage_new:\n\ mysql_storage_new:''' | ssh {remote_main_menu.remoteIP} -T 'cat > {inp1}/docker-compose.yml' && ssh -t {remote_main_menu.remoteIP} 'cd {inp1};docker-compose up'" ) elif inp == 2: inp1 = input("ENTER THE PATH TO SAVE : ") os.system(f"echo -e '''\ version: \"3\"\n\ services:\n\ dbos:\n\ image: mysql:5.7\n\ environment:\n\ MYSQL_ROOT_PASSWORD: nfsmw\n\ MYSQL_USER: milind\n\ MYSQL_PASSWORD: nfsmw\n\ MYSQL_DATABASE: mydb\n\ volumes:\n\ - mysql_storage_new:/var/lib/mysql\n\ restart: always\n\ owncloud:\n\ image: owncloud\n\ restart: always\n\ volumes:\n\ - owncloud_server:/var/www/html\n\ ports:\n\ - 8080:80\n\ depends_on:\n\ - dbos\n\ volumes:\n\ owncloud_server:\n\ mysql_storage_new:''' | ssh {remote_main_menu.remoteIP} -T 'cat > {inp1}/docker-compose.yml' && ssh -t {remote_main_menu.remoteIP} 'cd {inp1};docker-compose up'" ) elif inp == 3: inp1 = input("ENTER THE PATH TO SAVE : ") os.system(f"echo -e '''\ version: \"3\"\n\ services:\n\ server:\n\ image: nginx\n\ ports:\n\ - 8000:80\n\ volumes:\n\ - nginx_storage_new:/var/www/html\n\ restart: always\n\ volumes:\n\ nginx_storage_new:''' | ssh {remote_main_menu.remoteIP} -T 'cat > {inp1}/docker-compose.yml' && ssh -t {remote_main_menu.remoteIP} 'cd {inp1};docker-compose up'" ) elif inp == 4: inp1 = input("ENTER THE PATH TO SAVE : ") os.system(f"echo -e '''\ version: \"3\"\n\ services:\n\ php:\n\ image: mysql:5.7\n\ build:\n\ expose:\n\ - 9000\n\ volumes:\n\ - ./php/www:/var/www/html\n\ restart: always\n\ apache:\n\ image: web:v1\n\ args:\n\ - PHP_SOCKET: php:9000\n\ volumes:\n\ - ./php/www:/var/www/html\n\ ports:\n\ - 80:80\n\ - 443:443\n\ links:\n\ -php''' | ssh {remote_main_menu.remoteIP} -T 'cat > {inp1}/docker-compose.yml' && ssh -t {remote_main_menu.remoteIP} 'cd {inp1};docker-compose up'" ) elif inp == 0: remote_docker_compose() elif inp == 99: os.system("reset") exit() else: os.system( "tput setaf 9 && echo -e 'OPTION NOT SUPPORTED !!!' && tput setaf 15" ) time.sleep(1) os.system("tput setaf 4") inp = input("enter to continue.......") os.system("tput setaf 15 && clear") elif i == 0: remote_main_menu.items() elif i == 99: os.system("reset") exit() else: os.system( "tput setaf 9 && echo -e 'OPTION NOT SUPPORTED !!!' && tput setaf 15" ) time.sleep(1) os.system("tput setaf 4") inp = input("enter to continue.......") os.system("tput setaf 15 && clear")
def remote_docker_storage(): os.system("clear") while True: remote_start.remote_start() os.system("tput setaf 10") print(''' [1] CREATE VOLUME [2] VOLUME INFO [3] ATTACH VOLUME TO CONTAINER [4] SHOW VOLUMES [5] REMOVE VOLUMES [6] REMOVE ALL VOLUMES [0] BACK [99] EXIT ''') os.system("tput setaf 15") i = int(input("ENTER CHOICE : ")) if i == 1: inp = input("VOLUME NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker volume create {inp}") elif i == 2: inp = input("VOLUME NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker volume inspect {inp}") elif i == 3: inp = input("CONTAINER NAME : ") inp1 = input("VOLUME NAME : ") inp2 = input("IMAGE NAME : ") inp3 = input("ATTACH VOLUME TO ANY FOLDER (y/n) : ") if inp3.lower()[0] == 'y': inp4 = input("PATH TO FOLDER : ") os.system( f"ssh {remote_main_menu.remoteIP} docker run -dit --name {inp} -v {inp1}:{inp4} {inp2}" ) else: os.system( f"ssh {remote_main_menu.remoteIP} docker run -dit --name {inp} -v {inp1} {inp2}" ) elif i == 4: os.system(f"ssh {remote_main_menu.remoteIP} docker volume ls") elif i == 5: inp = input("VOLUME NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker volume rm {inp}") elif i == 6: os.system(f"ssh {remote_main_menu.remoteIP} docker volume prune") elif i == 0: remote_main_menu.items() elif i == 99: os.system("reset") exit() else: os.system( "tput setaf 9 && echo -e 'OPTION NOT SUPPORTED !!!' && tput setaf 15" ) time.sleep(1) os.system("tput setaf 4") inp = input("enter to continue.......") os.system("tput setaf 15 && clear")
def remote_docker_network(): os.system("clear") while True: remote_start.remote_start() os.system("tput setaf 10") print(''' [1] SHOW NETWORK [2] CREATE NETWORK [3] DISCONNECT NETWORK [4] RUN CONTAINER IN USERMADE NETWORK [5] INFO OF A NETWORK [6] REMOVE NETWORK [0] BACK [99] EXIT ''') os.system("tput setaf 15") i = int(input("CHOICE : ")) if i == 1: os.system(f"ssh {remote_main_menu.remoteIP} docker network ls") elif i == 2: inp = input("NETWORK NAME : ") inp1 = input("DRIVER NAME : ") inp2 = input("SUBNET RANGE : ") os.system( f"ssh {remote_main_menu.remoteIP} docker network create --driver {inp1} --subnet {inp2} {inp}" ) elif i == 3: inp = input("NETWORK NAME : ") inp1 = input("CONTAINER NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker network disconnect {inp} {inp1}" ) elif i == 4: inp = input("CONTAINER NAME : ") inp1 = input("NETWORK NAME : ") inp2 = input("IMAGE NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker run -it --name {inp} --network {inp1} {inp2}" ) elif i == 5: inp = input("NETWORK NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker network inspect {inp}" ) elif i == 6: inp = input("NETWORK NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker network rm {inp}") elif i == 0: remote_main_menu.items() elif i == 99: os.system("reset") exit() else: os.system( "tput setaf 9 && echo -e 'OPTION NOT SUPPORTED !!!' && tput setaf 15" ) time.sleep(1) os.system("tput setaf 4") inp = input("enter to continue.......") os.system("tput setaf 15 && clear")
def remote_docker_container(): os.system("clear") while True: remote_start.remote_start() os.system("tput setaf 10") print(''' [1] RUN NEW COMMAND [2] HELP [3] RUN CONTAINER [4] SHOW RUNNING CONTAINERS [5] SHOW (RUNNING + STOPPED) CONTAINERS [6] REMOVE ALL CONTAINERS [7] START THE STOPPED CONTAINER [8] RUN COMMAND IN CONTAINER WITHOUT GOING IN [9] CONTAINER IP [10] CONTAINER DETAIL [0] BACK [99] EXIT ''') os.system("tput setaf 15") i = int(input("ENTER CHOICE : ")) if i == 1: inp = input("COMMAND : ") os.system(f"ssh {remote_main_menu.remoteIP} {inp}") elif i == 2: inp = input("COMMAND DETAILS : ") os.system(f"ssh {remote_main_menu.remoteIP} man {inp}") elif i == 3: os.system("clear") while True: remote_start.remote_start() os.system("tput setaf 10") print( "[1] RUN NORMAL CONTAINER\n[2] RUN SPECIFIC CONTAINER\n\n[0] BACK\n[99] EXIT" ) os.system("tput setaf 15") inp = int(input("\nENTER CHOICE : ")) if inp == 1: inp = input("ENTER THE IMAGE_NAME:VERSION : ") os.system( f"ssh {remote_main_menu.remoteIP} docker run -dit {inp}" ) elif inp == 2: st = f"ssh {remote_main_menu.remoteIP} docker run -dit" i = input("\nENTER CONTAINER NAME : ") st1 = st if i == '' else st + " --name " + i i1 = input( "RUN CONTAINER IN BACKGROUND (if NO, press enter) : ") st2 = st1 if i1 == '' else st1 + " -d " i2 = input( "ENTER THE NETWORK NAME ( host / null / your own network name / default ( press enter ) ) : " ) st3 = st2 if i2 == '' else st2 + " --network " + i2 i4 = input( "ENTER THE VOLUME NAME:PATH TO THE FOLDER (if NO, press enter) : " ) st4 = st3 if i4 == '' else st3 + " -v " + i4 i6 = input( "ENTER THE PORT TO RUN CONTAINER WITH PORT NATTING (if NO, press enter) : " ) st6 = st4 if i6 == '' else st4 + " -p " + i6 i5 = input( "FOR LINKING ENTER THE CONTAINER NAME (if NO, press enter) : " ) st5 = st6 if i5 == '' else st6 + " --link " + i5 i3 = input("ENTER THE IMAGE NAME:VERSION : ") st5 = st5 + " " + i3 os.system(st5) elif inp == 0: remote_docker_container() elif inp == 99: os.system("reset") exit() else: os.system( "tput setaf 9 && echo -e 'OPTION NOT SUPPORTED !!!' && tput setaf 15" ) time.sleep(1) os.system("tput setaf 4") inp = input("enter to continue.......") os.system("tput setaf 15 && clear") elif i == 4: os.system(f"ssh {remote_main_menu.remoteIP} docker container ps") elif i == 5: os.system(f"ssh {remote_main_menu.remoteIP} docker ps -a") elif i == 6: os.system( f"ssh {remote_main_menu.remoteIP} docker container rm -f $(ssh {remote_main_menu.remoteIP} docker container ls -q -a)" ) elif i == 7: inp = input("ENTER THE CONTAINER NAME : ") os.system(f"ssh {remote_main_menu.remoteIP} docker start {inp}") os.system( "tput setaf 4 && echo -e 'CONTAINER STARTED' && tput setaf 15") elif i == 8: inp = input("ENTER THE CONTAINER NAME (or ID) : ") inp1 = input("ENTER THE COMMAND : ") os.system( f"ssh {remote_main_menu.remoteIP} docker exec {inp} {inp1}") elif i == 9: inp = input("ENTER THE CONTAINER NAME : ") os.system( f"ssh {remote_main_menu.remoteIP} docker container inspect --format '{{.NetworkSettings.IPAddress}}' " + inp) elif i == 10: inp = input("ENTER THE CONTAINER NAME :") os.system( f"ssh {remote_main_menu.remoteIP} docker container inspect {inp}" ) elif i == 0: remote_main_menu.items() elif i == 99: os.system("reset") exit() else: os.system( "tput setaf 9 && echo -e 'OPTION NOT SUPPORTED !!!' && tput setaf 15" ) time.sleep(1) os.system("tput setaf 4") inp = input("enter to continue.......") os.system("tput setaf 15 && clear")