Advertisement
sergio_educacionit

apache_tools

May 29th, 2023
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. #!/bin/python3
  2.  
  3.  
  4. import sys
  5. import os
  6.  
  7. comandos = [ 'newhost', 'delhost', 'modhost' ]
  8.  
  9. error_comando = "Debe ingresar un comando."
  10.  
  11. # Antes de evaluar el comando ingresado al programa
  12. # debemos asegurarnos que se indique algun comando.
  13.  
  14. if len(sys.argv) < 2:
  15.  
  16.     print(error_comando)
  17.     exit(1)
  18.  
  19.  
  20. # si se ingreso al menos un argumento
  21. # entonces evaluar cual ese argumento y si corresponde a
  22. # algun comando. 0 = newhost
  23.  
  24. if sys.argv[1] == comandos[0]:
  25.  
  26.     # Validar que el comando 'newhost' tenga al menso un argumento.
  27.  
  28.     if len(sys.argv) < 3:
  29.  
  30.         print("...newhost <sitename>")
  31.         exit(1)
  32.  
  33.  
  34.     # Obtenemos el ultimo valor de la lista con '-1'... '-2' para el anteultimo y asi.
  35.     server_name = sys.argv[-1]
  36.  
  37.    
  38.     # Procesar la opcion '-p'.
  39.  
  40.     puerto = 80
  41.     indice = 0
  42.  
  43.     for argumentos in sys.argv:
  44.  
  45.         if argumentos == "-p":
  46.  
  47.             puerto = sys.argv[indice + 1]
  48.  
  49.         indice +=1
  50.  
  51.  
  52.  
  53.  
  54.  
  55.     document_root = "/var/www/???"
  56.  
  57.  
  58.     virtual_host = f'<VirtualHost *:{puerto}>\n\n\tDocumentRoot {document_root}\n\tServerName {server_name}\n\n</VirtualHost>'
  59.  
  60.  
  61.  
  62.     print(virtual_host)
  63.  
  64. elif sys.argv[1] == comandos[1]:
  65.  
  66.     print(sys.argv[1])
  67.  
  68. elif sys.argv[1] == comandos[2]:
  69.  
  70.     print(sys.argv[1])
  71.  
  72. else:
  73.  
  74.     print(error_comando)
  75.     exit(1)
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement