def check_required (self, opt):
      option = self.get_option(opt)

      # Assumes the option's 'default' is set to None!
      if getattr(self.values, option.dest) is None:
          self.error("%s option not supplied" % option)


cmd_parser = OptionParser()
cmd_parser.add_option("--host", help="address of this small server (typically, it's the ip of this computer)")
cmd_parser.add_option("--publication", help="address of the publication (e.g. http://localhost:9080/erp5Serv)")
cmd_parser.add_option("-p", "--port", type="int", help="port used by this server (default is 1234)", default=1234)

(options, args) = cmd_parser.parse_args()

cmd_parser.check_required("--publication")
cmd_parser.check_required("--host")



#CONFIGURATION SECTION

#address of this small server :
#Host = '192.168.242.247'
Host = options.host

#address of the publication :
#publication_url = 'http://localhost:9080/erp5Serv'
publication_url = options.publication

#address use to transmit the message received from the external client :
            self.error("%s option not supplied" % option)

#
# Command Line Options
#

parser = OptionParser()
parser.add_option("-f", "--file", action="store", dest="file", metavar="FILE", help="File to read greppable nmap output from (required)")
parser.add_option("-o", "--output", action="store", dest="output", metavar="OUTPUT", help="Output file for the results to be written to")
parser.add_option("-v", "--verbose", action="store", dest="verbose", metavar="VERBOSE", default="0", choices=["0","1"], help="Verbose output 1=yes 0=no (defaults to no)")

# Get the command line options
(options, args) = parser.parse_args()

# Mandate an nmap file
parser.check_required("-f")

if options.file:
    file = options.file
else:
    sys.exit(0)

if options.output:
    output = options.output
else:
    output = ''

if options.verbose:
    verbose = int(options.verbose)
else:
    verbose = 0
Beispiel #3
0
#

parser = OptionParser()
parser.add_option("-t", "--target", action="store", dest="target", metavar="TARGET", help="Target IP address or hostname (required)")
parser.add_option("-p", "--port", action="store", dest="port", type= "int", metavar="PORT", help="Port to connect to (required)")
parser.add_option("-c", "--channel", action="store", dest="channel", metavar="CHANNEL", help="Channel to connect to (defaults to SYSTEM.DEF.SVRCONN)")
parser.add_option("-s", "--ssl", action="store", dest="ssl", metavar="SSL", type="choice", default="0", choices=["0","1"], help="Use SSL 1=yes 0=no cipher and SSL version must be specified (defaults to no)")
parser.add_option("-v", "--verbose", action="store", dest="verbose", metavar="VERBOSE", default="0", choices=["0","1"], help="Verbose output 1=yes 0=no (defaults to no)")
parser.add_option("-i", "--cipher", action="store", dest="cipher", metavar="CIPHER", help="SSL cipher to use for connection (defaults to NULL-SHA)")
parser.add_option("-e", "--version", action="store", dest="version", metavar="VERSION", type="choice", default="0", choices=["0","1"], help="SSL version to use for connection 0=SSLv3 1=TLSv1 (defaults to SSLv3)")

# Get the command line options
(options, args) = parser.parse_args()

# Mandate the use of a target and port
parser.check_required("-t")
parser.check_required("-p")

if options.target:
    target = options.target
else:
    sys.exit(0)

if options.port:
    port = options.port
else:
    sys.exit(0)

if options.channel:
    channel = options.channel
else:
Beispiel #4
0
parser = OptionParser()
parser.add_option("-i", "--interface1", action="store", 
dest="ap1",help="Network interface for first Access Point (required)")
parser.add_option("-j", "--interface2", action="store", dest="ap2", 
help="Network interface for second Access Point (required)")
parser.add_option("-s", "--ssid1", action="store", dest="ssid1",  
help="SSID for first Access Point.  Between double quotes (\"\") if 
special characters are used (required)")
parser.add_option("-t", "--ssid2", action="store", dest="ssid2", 
help="SSID for second Access Point.  Between double quotes (\"\") if 
special characters are used (required)")

(options, args) = parser.parse_args()

parser.check_required("-i")
if options.ap1:
    ap1 = options.ap1
else:
    sys.exit(0)
    
parser.check_required("-j")
if options.ap2:
    ap2 = options.ap2
else:
    sys.exit(0)
    
parser.check_required("-s")
if options.ssid1:
    ssid1 = options.ssid1
else:
Beispiel #5
0
cmd_parser.add_option(
    "--host",
    help=
    "address of this small server (typically, it's the ip of this computer)")
cmd_parser.add_option(
    "--publication",
    help="address of the publication (e.g. http://localhost:9080/erp5Serv)")
cmd_parser.add_option("-p",
                      "--port",
                      type="int",
                      help="port used by this server (default is 1234)",
                      default=1234)

(options, args) = cmd_parser.parse_args()

cmd_parser.check_required("--publication")
cmd_parser.check_required("--host")

#CONFIGURATION SECTION

#address of this small server :
#Host = '192.168.242.247'
Host = options.host

#address of the publication :
#publication_url = 'http://localhost:9080/erp5Serv'
publication_url = options.publication

#address use to transmit the message received from the external client :
to_url = publication_url + "/portal_synchronizations/readResponse"
Beispiel #6
0
class OptionParser (optparse.OptionParser):

    def check_required (self, opt):
        option = self.get_option(opt)

        if getattr(self.values, option.dest) is None:
            self.error("%s option not supplied" % option)

parser = OptionParser()
parser.add_option("-i", "--interface", action="store", dest="hwr",help="Network Interface (required)")
parser.add_option("-t", "--target", action="store", dest="server", help="DHCP Server IP address (required)")
parser.add_option("-p", "--hostname", action="store", dest="payload",  help="DHCP Hostname. Between double quotes (\"\") if special characters are used (required)")

(options, args) = parser.parse_args()

parser.check_required("-i")
if options.hwr:
    hwr = options.hwr
else:
    sys.exit(0)
    
parser.check_required("-t")
if options.server:
    server = options.server
else:
    sys.exit(0)
    
parser.check_required("-p")
if options.payload:
    payload = options.payload
else:
Beispiel #7
0
def parse():
  '''
  Parsing dei parametri da linea di comando
  '''

  config = ConfigParser()

  if (path.exists(paths.CONF_MAIN)):
    config.read(paths.CONF_MAIN)
    logger.info('Caricata configurazione da %s' % paths.CONF_MAIN)

  parser = OptionParser(version = __version__, description = '')
  parser.add_option('-T', '--test', dest = 'test', action = 'store_true',
                    help = 'test client functionality by executing a single task')
  parser.add_option('--task', dest = 'task',
                    help = 'path of an xml file with a task to execute (valid only if -T option is enabled)')

  # System options
  # --------------------------------------------------------------------------
  section = 'options'
  if (not config.has_section(section)):
    config.add_section(section)

  option = 'local'
  value = False
  try:
    value = config.getboolean(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('-L', '--local', dest = option, action = 'store_true', default = value,
                    help = 'perform tests without sending measure files to repository')

  option = 'killonerror'
  value = True
  try:
    value = config.getboolean(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('-K', '--killonerror', dest = option, action = 'store_true', default = value,
                    help = 'kill tests if an exception is raised during check')

  # System options
  # --------------------------------------------------------------------------
  section = 'system'
  if (not config.has_section(section)):
    config.add_section(section)

  # Task options
  # --------------------------------------------------------------------------
  section = 'task'
  if (not config.has_section(section)):
    config.add_section(section)

  option = 'tasktimeout'
  value = '3600'
  try:
    value = config.getint(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('--task-timeout', dest = option, type = 'int', default = value,
                    help = 'global timeout (in seconds) for each task [%s]' % value)

  option = 'testtimeout'
  value = '60'
  try:
    value = config.getint(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('--test-timeout', dest = option, type = 'float', default = value,
                    help = 'timeout (in seconds as float number) for each test in a task [%s]' % value)

  option = 'repository'
  value = 'https://finaluser.agcom244.fub.it/Upload'
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('-r', '--repository', dest = option, default = value,
                    help = 'upload URL for deliver measures\' files [%s]' % value)

  option = 'progressurl'
  value = 'https://finaluser.agcom244.fub.it/ProgressXML'
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('--progress-url', dest = option, default = value,
                    help = 'complete URL for progress request [%s]' % value)

  option = 'scheduler'
  value = 'https://finaluser.agcom244.fub.it/Scheduler'
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('-s', '--scheduler', dest = option, default = value,
                    help = 'complete url for schedule download [%s]' % value)

  option = 'httptimeout'
  value = '60'
  try:
    value = config.getint(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('--http-timeout', dest = option, type = 'int', default = value,
                    help = 'timeout (in seconds) for http operations [%s]' % value)

  option = 'polling'
  value = '300'
  try:
    value = config.getint(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('--polling-time', dest = option, type = 'int', default = value,
                    help = 'polling time in seconds between two scheduling requests [%s]' % value)

  # Client options
  # --------------------------------------------------------------------------
  section = 'client'
  if (not config.has_section(section)):
    config.add_section(section)

  option = 'clientid'
  value = None
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    pass
  parser.add_option('-c', '--clientid', dest = option, default = value,
                    help = 'client identification string [%s]' % value)

  option = 'geocode'
  value = None
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    logger.warning('Nessuna specifica geocode inserita.')
    pass
  parser.add_option('-g', '--geocode', dest = option, default = value,
                    help = 'geocode identification string [%s]' % value)

  option = 'username'
  value = 'anonymous'
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('--username', dest = option, default = value,
                    help = 'username for FTP login [%s]' % value)

  option = 'password'
  value = '@anonymous'
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    config.set(section, option, value)
  parser.add_option('--password', dest = option, default = value,
                    help = 'password for FTP login [%s]' % value)

  # Profile options
  # --------------------------------------------------------------------------
  section = 'profile'
  if (not config.has_section(section)):
    config.add_section(section)

  option = 'profileid'
  value = None
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    pass
  parser.add_option('-p', '--profileid', dest = option, default = value,
                    help = 'profile identification string [%s]' % value)

  option = 'bandwidthup'
  value = None
  try:
    value = config.getint(section, option)
  except (ValueError, NoOptionError):
    pass
  parser.add_option('--up', dest = option, default = value, type = 'int',
                    help = 'upload bandwidth [%s]' % value)

  option = 'bandwidthdown'
  value = None
  try:
    value = config.getint(section, option)
  except (ValueError, NoOptionError):
    pass
  parser.add_option('--down', dest = option, default = value, type = 'int',
                    help = 'download bandwidth [%s]' % value)

  # Isp options
  # --------------------------------------------------------------------------
  section = 'isp'
  if (not config.has_section(section)):
    config.add_section(section)

  option = 'ispid'
  value = None
  try:
    value = config.get(section, option)
  except (ValueError, NoOptionError):
    pass
  parser.add_option('--ispid', dest = option, default = value,
                    help = 'isp identification string [%s]' % value)

  option = 'certificate'
  value = None
  try:
    value = config.get(section, option)
    if not path.exists(value):
      config.remove_option(section, option)
      logger.warning('Trovata configurazione di certificato non esistente su disco. Cambiata configurazione')
      value = None
  except (ValueError, NoOptionError):
    logger.warning('Nessun certificato client specificato.')
    pass
  parser.add_option('--certificate', dest = option, default = value,
                    help = 'client certificate for schedule downloading and measure file signing [%s]' % value)

  with open(paths.CONF_MAIN, 'w') as file:
    config.write(file)

  (options, args) = parser.parse_args()

  # Verifica che le opzioni obbligatorie siano presenti
  # --------------------------------------------------------------------------

  try:

    parser.check_required('--clientid')
    config.set('client', 'clientid', options.clientid)

    parser.check_required('--up')
    config.set('profile', 'bandwidthup', options.bandwidthup)

    parser.check_required('--down')
    config.set('profile', 'bandwidthdown', options.bandwidthdown)

    parser.check_required('--profileid')
    config.set('profile', 'profileid', options.profileid)

    parser.check_required('--ispid')
    config.set('isp', 'ispid', options.ispid)

  finally:
    with open(paths.CONF_MAIN, 'w') as file:
      config.write(file)

  with open(paths.CONF_MAIN, 'r') as file:
    md5 = hashlib.md5(file.read()).hexdigest()

  return (options, args, md5)