예제 #1
0
def get_verbosity():
   """
   <Purpose>
      Returns the current verbosity level:
        4 - ULTRAVERBOSE aka DEBUG
        3 - VERYVERBOSE aka DEBUG
        2 - VERBOSE
        1 - QUIET
        0 - VERYQUIET
       -1 - ABSOLUTE SILENCE
 
   <Arguments>   
      None. 
   
   <Exceptions>
      None.
   
   <Side Effects>
      None.

   <Returns>
      Returns the current verbosity level.  See "Purpose", above.
   """
   verbosity = arizonaconfig.get_option("verbose")
   if verbosity == None:
      arizonaconfig.init_options("arizonareport")
      # stork default (--verbose)
      return 2            
   else: 
      return verbosity  
예제 #2
0
def set_verbosity(verbosity):
   """
   <Purpose>
      Sets the current verbosity level.

   <Arguments>   
      verbosity:
              The new verbosity level:
                4 - ULTRAVERBOSE aka DEBUG
                3 - VERYVERBOSE aka DEBUG
                2 - VERBOSE
                1 - QUIET
                0 - VERYQUIET
               -1 - ABSOLUTE SILENCE
   
   <Exceptions>
      None.
   
   <Side Effects>
      Changes the storkconfig "verbose" setting. 

   <Returns>
      None.
   """
   # check params
   if not isinstance(verbosity, int): 
      raise TypeError, "The parameter 'verbosity' of the function 'set_verbosity' must be an integer."
   if verbosity < -1 or verbosity > 4:
      raise TypeError, "The parameter 'verbosity' of the function 'set_verbosity' must be from -1 to 4, inclusive."

   if arizonaconfig.get_option("verbose") == None:
      arizonaconfig.init_options("arizonareport")
      
   arizonaconfig.set_option("verbose", verbosity)
예제 #3
0
 def test_get_version(self):
    # test version not set, result = None
    arizonaconfig.init_options()
    self.assertEqual(arizonaconfig.get_version(), None)
    
    # test setting the version
    arizonaconfig.init_options(version="1.2.3")
    self.assertEqual(arizonaconfig.get_version(), "1.2.3")
   def test_rank_packages(self):

      self.reset_options()

      try: 
         arizonaconfig.init_options("stork.py", configfile_optvar="configfile", version="2.0")
      
         # Create two public/private key pairs
         joe_privk = "/tmp/joe.privatekey"
         arizonacrypt.generate_privatekey_fn(joe_privk)
         joe_pubk_sl = arizonacrypt.extract_publickey_sl_from_privatekey_fn(joe_privk)
         joe_pubk = arizonacrypt.sl_to_fn(joe_pubk_sl)
         joe_pubk_string = arizonacrypt.publickey_sl_to_fnstring(joe_pubk_sl)

         jim_privk = "/tmp/jim.privatekey"
         arizonacrypt.generate_privatekey_fn(jim_privk)
         jim_pubk_sl = arizonacrypt.extract_publickey_sl_from_privatekey_fn(jim_privk)
         jim_pubk = arizonacrypt.sl_to_fn(jim_pubk_sl)
         jim_pubk_string = arizonacrypt.publickey_sl_to_fnstring(jim_pubk_sl)

         # Set up options so that we are "joe"
         arizonaconfig.set_option("username","joe")
         arizonaconfig.set_option("publickeyfile",joe_pubk)
         arizonaconfig.set_option("tpdir","/tmp")
         arizonaconfig.set_option("tpdtd","trustedpackages.dtd")

         # Create example trustedpackages files
         joe_tp_fn = "/tmp/joe."+joe_pubk_string+".tpfile"
         jim_tp_fn = "/tmp/jim."+jim_pubk_string+".tpfile"

         joe_tp_sl = ['<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>', '', '<TRUSTEDPACKAGES>', '    <FILE PATTERN="a.rpm" HASH="a8924367f832d012c56db" ACTION="allow" />', '    <USER PATTERN="foo*" USERNAME="******" PUBLICKEY="'+jim_pubk_string+'" ACTION="allow">', '     lasdfasdf asldf as df asfa sdf lasfadsfasfasdfakjlkjlkjl ', '    </USER>', '    <USER PATTERN="stork*" USERNAME="******" PUBLICKEY="'+jim_pubk_string+'" ACTION="allow" />', '    <FILE PATTERN="*.rpm" HASH="a89247f832d012c56db" ACTION="deny" />', '    <FILE PATTERN="*.deb" HASH="*" ACTION="deny" />', '</TRUSTEDPACKAGES>']
         temp_joe_fn = arizonacrypt.sl_to_fn(joe_tp_sl)
         os.rename(temp_joe_fn, joe_tp_fn)

         arizonacrypt.XML_sign_file_using_privatekey_fn(joe_tp_fn, joe_privk)

         jim_tp_sl = ['<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>', '', '<TRUSTEDPACKAGES>', '    <FILE PATTERN="*.rpm" HASH="joea8923732d012c56db" ACTION="allow"/>', '    <FILE PATTERN="*.rpm" HASH="joea237832d012c56db" ACTION="allow"/>', '</TRUSTEDPACKAGES>']
         temp_jim_fn = arizonacrypt.sl_to_fn(jim_tp_sl)
         os.rename(temp_jim_fn, jim_tp_fn)
      
         arizonacrypt.XML_sign_file_using_privatekey_fn(jim_tp_fn, jim_privk)

         self.assertEquals(rank_packages([("abc.rpm","joea8923732d012c56db","unknown")]),([], [], [('abc.rpm', 'joea8923732d012c56db', 'unknown')]))
         self.assertEquals(rank_packages([("foo.rpm","joea8923732d012c56db","allow")]), ([('foo.rpm', 'joea8923732d012c56db', 'allow')], [], []))
         self.assertEquals(rank_packages([("foo.deb","anyhash","deny")]), ([],[('foo.deb', 'anyhash', 'deny')], []))
         self.assertEquals(rank_packages([("abc.rpm","joea8923732d012c56db","unknown"), ("foo.rpm","joea8923732d012c56db","allow"), ("foo.deb","anyhash","deny")]), ([ ("foo.rpm","joea8923732d012c56db","allow")],[ ("foo.deb","anyhash","deny")], [("abc.rpm","joea8923732d012c56db","unknown")]))

      finally:
         try:
            # Clean up
            os.remove(joe_tp_fn)
            os.remove(joe_pubk)
            os.remove(joe_privk)
            os.remove(jim_tp_fn)
            os.remove(jim_pubk)
            os.remove(jim_privk)
         except:
            pass
예제 #5
0
def Main():
   # usage: experiment1_client.py <remote_host> <remote_dir> <tmpfs_dir>
   
   remote_host = sys.argv[1]
   remote_dir = os.path.join( "/", sys.argv[2] )
   tmpfs_dir = os.path.join( "/", sys.argv[3] )
   if tmpfs_dir[-1] != "/":
      tmpfs_dir += "/"
   
   # get the remote file listing
   f = urllib2.urlopen( "http://" + remote_host + ":8000" + os.path.join( remote_dir, "files.txt" ) )
   files = []
   dat = f.read()
   f.close()
   for f in dat.split("\n"):
      files.append( os.path.join( remote_dir, f ) )

   
   # get the remote file hashes
   f = urllib2.urlopen( "http://" + remote_host + ":8000" + os.path.join( remote_dir, "hashes.txt" ) )
   hashes = f.read().split("\n")
   f.close()
   
   # get the remote file sizes
   f = urllib2.urlopen( "http://" + remote_host + ":8000" + os.path.join( remote_dir, "sizes.txt" ) )
   sizes = f.read().split("\n")
   f.close()

   arizonaconfig.init_options("experiment2_client.py", configfile_optvar="configfile")
  
   print "files: " + str(files)
   print "sizes: " + str(sizes)
   
   # empirically-calculated times for the 100MB file from experiment 1
   #urllib2_time = 1.646
   #arizonatransfer_time = 4.0068
   #iftd_time = 3.9965
   
   
   for i in xrange(len(files)-2, len(files)-1):
      file = files[i]
      size = sizes[i]
      fhash = hashes[i]
      
      # spawn a thread for urllib2 transfer, so we can block at the right time
      #test_urllib2( file, remote_host, tmpfs_dir )
      #os.popen("rm -rf " + file).close()
      #test_arizonatransfer( file, fhash, size, remote_host, tmpfs_dir )
      #os.popen("rm -rf " + file).close()
      #os.popen("rm -rf " + tmpfs_dir + "*")
      test_iftd( file, fhash, size, remote_host, tmpfs_dir )
      os.popen("rm -rf " + file).close()
      print ""
      
   
   return 0
예제 #6
0
def Main():
   # usage: experiment1_client.py <remote_host> <remote_dir> <tmpfs_dir>
   
   remote_host = sys.argv[1]
   remote_dir = os.path.join( "/", sys.argv[2] )
   tmpfs_dir = os.path.join( "/", sys.argv[3] )
   if tmpfs_dir[-1] != "/":
      tmpfs_dir += "/"
   
   # get the remote file listing
   f = urllib2.urlopen( "http://" + remote_host + ":8000" + os.path.join( remote_dir, "files.txt" ) )
   files = []
   dat = f.read()
   f.close()
   for f in dat.split("\n"):
      files.append( os.path.join( remote_dir, f ) )

   
   # get the remote file hashes
   f = urllib2.urlopen( "http://" + remote_host + ":8000" + os.path.join( remote_dir, "hashes.txt" ) )
   hashes = f.read().split("\n")
   f.close()
   
   # get the remote file sizes
   f = urllib2.urlopen( "http://" + remote_host + ":8000" + os.path.join( remote_dir, "sizes.txt" ) )
   sizes = f.read().split("\n")
   f.close()

   arizonaconfig.init_options("experiment1_client.py", configfile_optvar="configfile")
  
   print "files: " + str(files)
   print "sizes: " + str(sizes)
 
   for i in xrange(0, len(files)-1):
      file = files[i]
      size = sizes[i]
      fhash = hashes[i]
      
      print "Testing file " + str(file)
      test_urllib2( file, remote_host, tmpfs_dir )
      os.popen("rm -rf " + file).close()
      test_arizonatransfer( file, fhash, size, remote_host, tmpfs_dir )
      os.popen("rm -rf " + file).close()
      os.popen("rm -rf " + tmpfs_dir + "*")
      test_iftd( file, fhash, size, remote_host, tmpfs_dir )
      os.popen("rm -rf " + file).close()
      print ""
   
   return 0
예제 #7
0
   def test_config_prefix(self):

      # Init config options...
      arizonaconfig.init_options()

      # Get a valid publickey file
      priv_sl = arizonacrypt.generate_privatekey_sl()
      pubkey_sl = arizonacrypt.extract_publickey_sl_from_privatekey_sl(priv_sl)
      publickey_fn = arizonacrypt.sl_to_fn(pubkey_sl)

      # Since I don't know the publickey, I assume this is okay if 
      # config_prefix() doesn't throw an exception
      arizonaconfig.set_option("username","abc")
      arizonaconfig.set_option("publickeyfile",publickey_fn)
      storkusername.config_prefix()

      # make sure that the embedded name is used if all are set.
      arizonaconfig.set_option("embeddedusername","abc123")
      #This is now hashed
      #self.assertEquals(storkusername.config_prefix(),"abc123")

      # unset options
      arizonaconfig.set_option("username","")
      arizonaconfig.set_option("publickeyfile","")
      arizonaconfig.set_option("embeddedusername","")
      
      # Nothing set, should throw TypeError
      self.assertException(TypeError, storkusername.config_prefix())

      # Only username, should throw TypeError
      arizonaconfig.set_option("username","abc")
      self.assertException(TypeError, storkusername.config_prefix())

      # Only publickeyfile, should throw TypeError
      arizonaconfig.set_option("username","")
      arizonaconfig.set_option("publickeyfile",publickey_fn)
      self.assertException(TypeError, storkusername.config_prefix())

      # Invalid publickeyfile, should throw TypeError
      arizonaconfig.set_option("username","abc")
      arizonaconfig.set_option("publickeyfile","/bin/ls")
      self.assertException(TypeError, storkusername.config_prefix())

      # Missing publickeyfile, should throw TypeError
      arizonaconfig.set_option("username","abc")
      arizonaconfig.set_option("publickeyfile","/ajldf/asflas")
      self.assertException(TypeError, storkusername.config_prefix())

      os.remove(publickey_fn)
예제 #8
0
def download_repo_Tar():
   # parse command line and options
   args = arizonaconfig.init_options("s3downloadrepo.py", configfile_optvar="configfile", version="2.0")

   arizonaconfig.set_option("awsbucket", "stork-repository-import")

   storks3.init()

   print "reading directory"
   storks3.dumpdir()

   print "getting repository tar files..."

   for entry in storks3.readdir():
      if not entry.key.startswith("reposplit"):
          print "   ignoring: " + entry.key
          continue

      fn = os.path.join("/mnt", entry.key)
      print "   getting " + entry.key + " to " + fn
      try:
          storks3.get_file(entry.key, fn)
      except TypeError, e:
          print "download of " + entry.key + " failed with error " + str(e) + " trying again"
          try:
              storks3.get_file(entry.key, fn)
          except TypeError, e:
              print "upload of " + entry.key + " failed with error " + str(e) + " gave up"
예제 #9
0
def main():
   # use error reporting tool
   storkerror.init_error_reporting("stork_nest_comm.py")

   # process command line and initialize variables
   args = arizonaconfig.init_options('stork_nest_comm.py', configfile_optvar='configfile', version=stork_nest_version.VERREL)

   arizonareport.set_output_function(output_func_pid)

   # there should not be any leftover options
   if args:
      arizonareport.send_error(0, "Arguments not understood: " + str(args))
      sys.exit(1)

   arizona_share.init()

   # run as a daemon
   if arizonaconfig.get_option("daemon"):
      arizonageneral.make_daemon("stork_nest_comm.py")

   # display ready message
   if not arizonaconfig.get_option("daemon"):
      print "Ready for connections..." 
      
   # infinite loop (daemon must keep running)
   #while True:
      # Handle incoming connections
      #try:
   arizonacomm.listen("localhost", arizonaconfig.get_option("listenport"), handle_connection) 
예제 #10
0
   def test_set_option(self):
      # try to set option when arizonaconfig hasn't been initialized
      reload(arizonaconfig)
      self.assertException(UnboundLocalError, arizonaconfig.set_option, "xyz", "abc")

      self.set_cmdline([])
      arizonaconfig.init_options()

      # test invalid/missing params
      self.assertException(TypeError, arizonaconfig.set_option, True, "123")
      self.assertException(TypeError, arizonaconfig.set_option, "missing")

      # try setting option which does not yet exist (create new option)
      arizonaconfig.set_option("xyz", "abc")
      self.assertEqual(arizonaconfig.get_option("xyz"), "abc")

      # change existing option
      self.assertEqual(arizonaconfig.get_option("digest"), "sha1")
      arizonaconfig.set_option("digest", "pgp")
      self.assertEqual(arizonaconfig.get_option("digest"), "pgp")
예제 #11
0
def GroupFileParse(dtd, group_file_name):
   """Creates the parser for the groups.xml file and parses it.
   Returns a dictionary of group members."""
   
   arizonaconfig.init_options('arizonagroup.py', usage=usagemsg)
   #print arizonaconfig.get_option("usesignedfiles")
   try:
      # SMB - storkpackagelist.find_file() already checked the signature for
      # us, so we can assume the file is valid and extract the contents
      if arizonaconfig.get_option('usesignedfiles'):
	 #print "Reading signed file"
         temp_contents = arizonacrypt.XML_retrieve_originalfile_from_signedfile(group_file_name)
         #print temp_contents
      else:
	 #print "Reading unsigned file"
	 temp_contents = group_file_name
         
   except TypeError, e:
      arizonareport.send_error(0, str(e))
      sys.exit(1)
예제 #12
0
   def test_package_exists(self):
      self.reset_options()
      

      # should return None if None is passed:
      self.assertEquals(None, storkpackagelist.package_exists(None))

      # pass invalid input
      self.assertRaises(Exception, storkpackagelist.package_exists, 3.0)

      # ON HOLD-- docs may be wrong
      ## pass names that are not known packages without initializing the options.
      ## Should return None:
      #self.assertEquals(None, storkpackagelist.package_exists(" "))
      #self.assertEquals(None, storkpackagelist.package_exists("some unknown package"))

      # pass names that are not known packages, but initialize options first
      # since arizonaconfig.get_options() is used:
      prefix = os.environ.get("TESTPREFIX")
      arizonaconfig.init_options("storkpackagelist.py", alt_paths=[prefix], version='2.0')
      #arizonaconfig.set_option("localpdir", ["some string"]) <- this should not be set manually
      # now set the "localinfo" variable and call init().
      arizonaconfig.set_option("localinfo", "/usr/local/stork/var/packageinfo")
      arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
      arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
      storkpackagelist.init()
      self.assertFalse(storkpackagelist.package_exists("hello"))
      self.assertFalse(storkpackagelist.package_exists("some unknown name"))
      self.assertFalse(storkpackagelist.package_exists("gnuchess"))
      self.assertFalse(storkpackagelist.package_exists(" "))

      # this test was from Jeffry Johnston.
      # NOTE that currently, it only works if the metadata exists on the system.
      arizonaconfig.init_options("storkpackagelist.py", alt_paths = [prefix], version = '2.0')
      arizonaconfig.set_option("updatedb", False)
      arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist/"])
      arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
      storkpackagelist.init()
      self.assertTrue(storkpackagelist.package_exists("gnuchess"))
예제 #13
0
   def test_get_sections(self):
      # try to get option when arizonaconfig hasn't been initialized
      reload(arizonaconfig)
      self.assertEqual(arizonaconfig.get_sections("digest"), [])

      # pass bad/missing params (string expected)
      self.assertException(TypeError, arizonaconfig.get_sections)
      self.assertException(TypeError, arizonaconfig.get_sections, None)
      self.assertException(TypeError, arizonaconfig.get_sections, True)
      self.assertException(TypeError, arizonaconfig.get_sections, ["digest"])

      # empty string should be okay
      self.assertEqual(arizonaconfig.get_sections(""), [])

      # with config file, no command line
      self.set_cmdline([])
      arizonaconfig.init_options(TEST_FILE, configfile_optvar='configfile')

      self.assertEqual(arizonaconfig.get_sections("rv0"), [])
      self.assertEqual(arizonaconfig.get_sections("rv1"), ["rep1", "rep3"])
      self.assertEqual(arizonaconfig.get_sections("rv2"), ["rep2"])
      self.assertEqual(arizonaconfig.get_sections("rv3"), ["rep1", "rep2"])
예제 #14
0
def main():
	#should work with the current arizonaconfig code
	configlib.init_options(configfile_optvar='configfile')
        if get_option("storknestupdatedebug").strip().lower()=="true":
           debugmode=True
	else:
           debugmode=False #despite being declared above, this is still necessary...

	#use config settings to override settings from the config file
	configlib.set_option('transfermethod',get_option("storknestupdatetransfermethods"))
	if debugmode:
           print "Transfermethod changed:",get_option("transfermethod")
	if not debugmode:
           arizonageneral.make_daemon("stork_nest_update.py")
	if debugmode:
           print "Configuration loaded.\nDaemonizing blocked by debugmode."

	ldaemon=ListenerDaemon(get_option("storknestupdatelistenerport"), 10, True, debugmode)
        udaemon=UpdateDaemon(ldaemon.send, debugmode)
	pdaemon=NestPsEPRDaemon(None, None, udaemon, debugmode)
        udaemon.start()
	if debugmode:
           print "All Deamons started."
예제 #15
0
def main():
   # get command line and config file options
   args = arizonaconfig.init_options("profileview.py", usage="profileview.py [options] filename", version="2.0")

   if len(args) != 1:
      arizonaconfig.print_help()
      sys.exit(1)
   
   stats = hotshot.stats.load(args[0])
   stats.strip_dirs()
   stats.sort_stats("time", "calls")
   numstats = arizonaconfig.get_option("numstats")
   if numstats == 0:
      stats.print_stats()
   else:
      stats.print_stats(numstats)
예제 #16
0
def main():
   # process command line arguments
   args = arizonaconfig.init_options("storkmetafileupdate.py", configfile_optvar="configfile", version="2.0")
   if len(args) < 1:
      arizonareport.send_error(1, "Usage: storkextractmeta.py [OPTION(s)] tarball(s)")
      sys.exit(1)
   
   # prepare metafile directory and filename
   metafiledir = arizonaconfig.get_option("metafiledir")
   if metafiledir[-1] != "/": # add trailing slash if there isn't one
      metafiledir += "/" 
   if not os.path.isdir(metafiledir):   
      try:   
         os.makedirs(metafiledir)
      except OSError, e:
         arizonareport.send_error(1, "Could not create metafile directory: " + metafiledir + " (" + str(e) + ")")
         sys.exit(1)
예제 #17
0
def main():
     args = arizonaconfig.init_options("storkpseprattempt.py", configfile_optvar="configfile", version="2.0")
     # SMB: doubled it to 32 seconds
     wait = 32;
     global pid_file;

     # SMB: changed filename to psepr.pid to disambiguate from other pid files
     pid_file =  "/repository/psepr.pid"

     # SMB: removed check for existing pid file, since it appears to be done
     # already by attemptpsepr.init
     pid = os.getpid()
     pid_file_obj = open(pid_file, "w")
     pid_file_obj.write(str(pid))
     pid_file_obj.close()
     
     if len(args) < 3:
         print "incorrect usage."
         os.unlink(pid_file)
         sys.exit(-1)
         
    # print args[0]
    # print args[1]
    # print args[2]
     
     pseprpath = "/usr/local/stork/bin/pseprpusher.py"
     
     if not os.path.isfile(pseprpath):
         print "could not find "+pseprpath
         
     command = pseprpath + " " + args[0] + " " + args[1] + " " + args[2]

     finished_ok = False

     finished_ok ,status = arizonageneral.system_timeout_backoff(command, 5, wait, 9)

     if finished_ok:
         print command + " FINISHED OK"
     else:
         print command + " FAILED"
    
     os.unlink(pid_file)
예제 #18
0
def init():
   """
   <Purpose>
      Processes and handles some command line arguments.

   <Arguments>
      None.

   <Exceptions>
      None.

   <Side Effects>
      None.

   <Returns>
      A list of unhandled command line arguments.
   """
   
   # get command line and config file options
   args = arizonaconfig.init_options('storkquery.py', configfile_optvar='configfile', version='2.0')

   # init package lists
   storkpackagelist.init()
   
   """global storkpm
   #### Set up the packaging tool
                                                                                
   # Right now only use rpm...   Could change this to work with deb
   if glo_options.pmtype=='rpm':
      import storkrpm as storkpm
   else:
      arizonareport.send_error(0, "Unknown package manager '" + 
                             glo_options.pmtype + "'")
      sys.exit(1)
                                                                                
   # Figure out what the package tool can do...
   arizonareport.send_out(2, "Fetching information about our packaging " + 
                           "tool (" + glo_options.pmtype + ")")
   storkpm.init_package_manager()
   """

   return args
예제 #19
0
def main():

   args = arizonaconfig.init_options('replace.py', usage='usage: replace.py [options] FILE...', version='2.0')

   find_text = arizonaconfig.get_option("findstr")
   if find_text == None:
      print "Must specify string to find.  See --help."
      return

   replace_text = arizonaconfig.get_option("replacestr")
   if replace_text == None:
      print "Must specify replacement string.  See --help."
      return

   (status, failed_list) = arizonageneral.text_replace_files_in_fnlist(find_text, replace_text, args)

   if not status:
      print "Cannot locate or access: " + " ".join(failed_list)

   return
예제 #20
0
def main():
   # prepare error reporting tool
   storkerror.init_error_reporting("storklog.py")
   
   # parse command line and options
   args = arizonaconfig.init_options(module="storklog.py", version="2.0")

   # check for root
   if os.geteuid() > 0:
      arizonareport.send_error(0, "You must be root to run this program...")
      sys.exit(1)

   # grab the storklog mutex. This prevents multiple copies of storklog from
   # running at the same time.
   storklogLock = arizonageneral.mutex_lock("storklog", arizonaconfig.get_option("lockdir"))
   if not storklogLock:
       arizonareport.send_error(0, "Another copy of storklog is already running...")
       sys.exit(0)

   # rotate, upload, and delete logs
   rotate_logs()
예제 #21
0
def main():
    args = arizonaconfig.init_options("storkvalidatepublickey.py")
  
    
    if len(args) != 1:
        arizonareport.send_error(1, "usage: storkvalidatepublickey.py <potential public key>")
        sys.exit(1)
        
    
    if not os.path.isfile(args[0]):
        arizonareport.send_error(1, "error: " + args[0] + " is not a file.")
        sys.exit(1)
        
    
    # use arizonacrypt to see if this filecontains a valid pubkey
    (isvalidkey, keycontents) = arizonacrypt.publickey_fn_to_sl(args[0],"rsa")
    
    if( isvalidkey ):
        arizonareport.send_out(1, args[0] + " is a valid public key file")
        sys.exit(0)
    else:
        arizonareport.send_error(1, args[0] + " is NOT a valid public key file")
        sys.exit(1)
예제 #22
0
def main():
   # parse command line and options
   args = arizonaconfig.init_options("s3uploadrepo.py", configfile_optvar="configfile", version="2.0")

   if len(args) == 0:
      help()

   if args[0] == "downloadrepotar":
      download_repo_tar()
   elif args[0] == "uploadrepotar":
      upload_repo_tar()
   elif args[0] == "destroy":
      destroy_repo()
   elif args[0] == "dump":
      dump_repo()
   elif args[0] == "listbuckets":
      list_buckets()
   elif args[0] == "downloadrepo":
      download_repo()
   elif args[0] == "putfile":
      put_file(args[1])
   else:
      help()
예제 #23
0
                                lo.close()
                    except Exception, e:
                        lo=open(self.log,"a")
                        lo.write(str(currenttime())+":")
                        lo.write("TorrentMakerTimer - "+str(e)+'\n')
                        lo.close()

if __name__ == '__main__':
    uiname = 'btlaunchmany'

    defaults = get_defaults(uiname)

    set=defaultset[:]
    #conffile=None
    #if os.path.isfile(glo_confname):conffile=glo_confname
    arizonaconfig.init_options(sys.argv[0],'.',[],None,"arizonabittorrentshareconfig")#conffile)

    set[0]=get_option("arizonabittorrentcheckinterval",set[0])
    set[1]=get_option("arizonabittorrentfiledir",set[1])
    set[2]=get_option("arizonabittorrentupdatedir",set[2])
    set[3]=get_option("arizonabittorrentuploadrate",set[3])
    set[4]=get_option("arizonabittorrentsharing",str(set[4])).lower().strip()=="true"
    set[5]=get_option("arizonabittorrenttrackerhost",set[5])
    glo_possibleserverdomain=set[5]
    set[6]=get_option("arizonabittorrenttrackerport",set[6])
    set[8]=get_option("arizonabittorrentsharelogging",set[8])
    set[9]=get_option("arizonabittorrentsharelogginginterval",set[9])
    if get_option("arizonabittorrentsharing","true").lower()=="false":
       #this program should not be running...
       sys.exit()
   
예제 #24
0
import os
import storkvalidatepubkey

class test(arizonaunittest.TestCase):
    
   #Test the only method in the test, which checks via arizonacrypt whether the key is valid
   def test_main(self):
      #Test with blank filename
      self.set_cmdline([""])
      self.assertException(SystemExit,storkvalidatepubkey.main)
      self.assertEquals( "error:  is not a file.", arizonareport.message)
        
      #Test a valid key generated with storkutil.py
      self.set_cmdline(["test/testkeys.publickey"])
      self.assertException(SystemExit,storkvalidatepubkey.main)
      self.assertEquals("test/testkeys.publickey is a valid public key file",arizonareport.message)
        
      #Test invalid key, some bytes deleted in a valid key
      self.set_cmdline(["test/invalid.publickey"])        
      self.assertException(SystemExit,storkvalidatepubkey.main)
      self.assertEquals("test/invalid.publickey is NOT a valid public key file",arizonareport.message)
        
      #Test invalid key, some bytes changed in valid key
      self.set_cmdline(["test/invalid2.publickey"])        
      self.assertException(SystemExit,storkvalidatepubkey.main)
      self.assertEquals("test/invalid2.publickey is NOT a valid public key file",arizonareport.message)

if __name__=='__main__':
   arizonaconfig.init_options()
   arizonaunittest.main()
예제 #25
0
def main():
   
   #get command line options
   args = arizonaconfig.init_options("storkverifysignedfile.py", configfile_optvar="configfile", version="2.0")
   if len(args) != 1:
      arizonareport.send_error(1, "Usage: storkverifysignedfile.py [OPTION(s)] signedfile")
      sys.exit(-1)
   
   
   tmpuploaddir = arizonaconfig.get_option("tmpuploaddir")
   endfiledir    = arizonaconfig.get_option("endfiledir")
   

   if tmpuploaddir[-1] != "/": # add trailing slash if there isn't one
      tmpuploaddir += "/" 
   if not os.path.isdir(tmpuploaddir): 
       arizonareport.send_out(1, tmpuploaddir + " does not exist, could not verify authenticity of "+args[0])
       sys.exit(-1);
   if endfiledir[-1] != "/": # add trailing slash if there isn't one
      endfiledir += "/" 
   if not os.path.isdir(endfiledir): 
       arizonareport.send_out(1, endfiledir + " does not exist, could not verify authenticity of "+args[0])
       sys.exit(-1);
   
       
   filename = args[0];
   
   timestamp1 = verify_file(filename, tmpuploaddir)
   if timestamp1 > 0:
       arizonareport.send_out(2, "File " + filename + " has been verified.")
   else:
       arizonareport.send_out(2, "File " + filename + " has a bad signature.")
       sys.exit(1)

   #check to see if there is another copy of
   #this tp file in the tp file dir
   if os.path.isfile(endfiledir+filename):
       #there is another copy, get the timestamp
       timestamp2 = verify_file(filename,endfiledir)
       if timestamp2 < 0:
           #something is wrong... once validily signed tp file
           #is no longer valid... should I report this to someone?
           arizonareport.send_out(0, "Once valid signed file " + endfiledir+filename + " is no longer valid.")
           sys.exit(-1)
       
       # now check to see if the new file has a newer timestamp then the old
       # file... if it does, replace it
       if timestamp1 > timestamp2:
           arizonareport.send_out(2,"Overwriting " + filename + " with newer version of tp file...")
           move_file(tmpuploaddir+filename,endfiledir+filename)
           sys.exit(2);
       # the file they tried to upload is older then then the file in the repository... so dont
       # replace it
       else:
           arizonareport.send_out(2,"Will not overwrite " + filename + " with older or same version of uploaded file.")
           sys.exit(3)
   else:               
       # this tp file is not in the repository yet.... move it there now
       arizonareport.send_out(2,"Moving " + filename + " to the tp file dir now...")
       move_file(tmpuploaddir+filename,endfiledir+filename)
       sys.exit(4)       
예제 #26
0
def main():
   global done, pipe

   # parse command line and options
   args = arizonaconfig.init_options(module="stracedaemon.py", version="2.0")

   # run as a daemon
   arizonageneral.make_daemon(DAEMONNAME)

   # make it easy to kill the daemon
   outfile = open(DAEMONPIDFILE, "w")
   outfile.write(str(os.getpid()))
   outfile.close()

   # check to make sure the service we want to monitor exists
   if not os.path.exists(INPUT_PIDFILE):
       # sleep a few seconds and try again, just in case stork_nest_comm
       # was launched, but has not yet written its pidfile
       time.sleep(10)
       if not os.path.exists(INPUT_PIDFILE):
           # raise an exception to generate an error report
           raise Exception, "the stork nest is not running"
           # the following does not happen
           arizonareport.send_error(0, "the stork nest is not running")
           sys.exit(-1)

   # get the pid we want to monitor from INPUT_PIDFILE
   input_pidfile = open(INPUT_PIDFILE)
   input_pid = input_pidfile.read()
   input_pidfile.close()

   arizonareport.send_out(0, "monitoring pid " + str(input_pid))

   command = '(strace -f -ttt -e trace=network -p ' + str(input_pid)+ ' 2>&1 1>/dev/null)' + \
             ' | (egrep "AF_INET")'

#             ' | egrep "connect\([0-9]+, \{sa_family=AF_INET.* = 0" 2>/dev/null' + \
#             ' | fgrep -v "127.0.0.1"' + \
#             ' | awk \'"*" { gsub("(\\[pid )|(\\])|(sin_port=htons\\()|(\\),)|(sin_addr=inet_addr\\(.)|(.\\)\\},)","", $0); print $1 " " $2 " " $5 " " $6; }\''


   arizonareport.send_out(0, "executing: " + command)

   # set up I/O
   # XXX run the command
   pipe = os.popen(command, "r")

   # set up hangup signal handler
   signal.signal(signal.SIGHUP, handler_sighup)

   lasttime = 0

   while not done:
      # is it time to change log file?
      currtime = time.time()
      if currtime - lasttime >= arizonaconfig.get_option("interval"):
         lasttime = currtime

         # build filename
         filename = None
         try:
            filename = arizonageneral.gethostname()
         except:
            pass
         if filename == None:
            filename = "unknown_host"
         try:
            username = arizonageneral.getusername()
         except:
            username = "******"
         filename = arizonaconfig.get_option("logdir") + "/" + filename \
                    + "^" + username + "^" + str(currtime) + LOGSUFFIX

         # close old file
         try:
            outfile.flush()
         except:
            pass
         try:
            outfile.close()
         except:
            pass
            
         # create current.packetlog file
         try:
            tempfile = open(arizonaconfig.get_option("logdir") + "/" + CURRENTFILE, "w")
            tempfile.write(filename)
            tempfile.close()
         except:
            pass
            
         # open new file   
         try:    
            outfile = open(filename, "a")
         except:   
            pass
   
      # read stdin
      if not done:    
         try:
            line = pipe.readline()
         except:
            done = True

      # write to file
      if not done:    
         try:
            outfile.write(line)
         except: 
            pass   
      if not done:    
         try:
            outfile.flush()
         except: 
            pass   
   
      #dont eat up cycles
      time.sleep(1)

   # clean up
   try:
      outfile.close()
   except: 
      pass   
      
   os.system("/bin/rm -f " + DAEMONPIDFILE + " &> /dev/null")
예제 #27
0
      self.assertTrue(os.path.isfile("../test/PyXML-0.8.3-6.i386.rpm"))
      tl = storktransaction.tl_create()
      storktransaction.tl_install(tl,"../test/PyXML-0.8.3-6.i386.rpm")
      storkrpm.execute(tl)





   #------------------------------------------------------------------
   # package_list -> void, IOError, NameError, TypeError
   #------------------------------------------------------------------
   def test_remove(self):
      pass

 
""" 
      self.assertException(TypeError, arizonaconfig.init_options, 100)
      self.set_cmdline(["--help"])
      self.reset_stdout()
      self.reset_stderr()
      reload(arizonaconfig)
"""

# Run tests
if __name__ == '__main__':
   storkrpm.initialize()
   arizonaconfig.init_options("storkrpmTest") 
   arizonaconfig.set_option("transfermethod", ['http', 'ftp'])
   arizonaunittest.main()
예제 #28
0
def main(): 
   global done, pipe

   # parse command line and options
   args = arizonaconfig.init_options(module="tcpdumpdaemon.py", version="2.0")

   # run as a daemon 
   arizonageneral.make_daemon("tcpdumpd")
   
   # make it easy to kill the daemon 
   outfile = open("/tmp/tcpdump.pid", "w")
   outfile.write(str(os.getpid()))
   outfile.close()
   
   # set up I/O
   pipe = os.popen("/usr/sbin/tcpdump -tt -v -nn 2> /dev/null", "r")
   
   # set up hangup signal handler
   signal.signal(signal.SIGHUP, handler_sighup)

   lasttime = 0
   
   while not done:
      # is it time to change log file?
      currtime = time.time()
      if currtime - lasttime >= arizonaconfig.get_option("interval"): 
         lasttime = currtime 

         # build filename
         filename = None
         try:
            filename = arizonageneral.gethostname()
         except:
            pass
         if filename == None:
            filename = "unknown_host"
         try:
            username = arizonageneral.getusername()
         except:
            username = "******"
         filename = arizonaconfig.get_option("logdir") + "/" + filename \
                    + "^" + username + "^" + str(currtime) + "^packetlog" 
         
         # close old file
         try:
            outfile.flush()
         except:
            pass
         try:
            outfile.close()
         except:
            pass
            
         # create current.packetlog file
         try:
            tempfile = open(arizonaconfig.get_option("logdir") + "/current.packetlog", "w")
            tempfile.write(filename)
            tempfile.close()
         except:
            pass   
            
         # open new file   
         try:    
            outfile = open(filename, "a")
         except:   
            pass
   
      # read stdin
      if not done:    
         try:
            line = pipe.readline()
         except:
            done = True
          
      # write to file      
      if not done:    
         try:
            outfile.write(line)
         except: 
            pass   
      if not done:    
         try:
            outfile.flush()
         except: 
            pass   
   
      #dont eat up cycles
      time.sleep(1)

   # clean up
   try:
      outfile.close()
   except: 
      pass   
      
   os.system("/bin/rm -f /tmp/tcpdump.pid &> /dev/null")
예제 #29
0
         pass





def main(args):
   # check command line args
   if len(args) < 2:
      arizonareport.send_error(2, "Usage: storkextractmeta.py [OPTION(s)] file(s) metadestdir")
      sys.exit(1)

   # nestrpm is unnecessary and prints some useless warnings, so remove it
   # from the list of package managers
   packmans = arizonaconfig.get_option("packagemanagers")
   if 'nestrpm' in packmans:
       packmans = [packman for packman in packmans if packman != "nestrpm"]
       arizonaconfig.set_option("packagemanagers", packmans)

   # extract the metadata
   extract_metadata(args[:-1], args[-1])





# Start main
if __name__ == "__main__":
   args = arizonaconfig.init_options("storkextractmeta.py", configfile_optvar="configfile", version="2.0")
   main(args)
예제 #30
0
      # The empty string
      self.assertException(arizonageneral.Exception_Data ,storktar.remove, [""])

      # invalid package name
      self.assertException(arizonageneral.Exception_Data ,storktar.remove, ["dhsfkj"])



   def __check_files(self, pack):
      (out, err, status) = arizonageneral.popen5("tar -Pztf " + pack)

      if out[0][0] != "/":
         path_head = os.getenv("HOME") + "/"
      else:
         path_head = ""

      for afile in out:
         afile = afile.strip('\n')

         if not os.path.exists(path_head + afile):
            print "\nsome of files on package " + pack + " has not installed"
            os._exit(1)

#=====================================================================
# Run tests
#=====================================================================
if __name__=='__main__':
   arizonaconfig.init_options("tarpackinfopath") 
   arizonaconfig.set_option("tarpackinfopath", "/tmp/tar_packinfo")
   arizonaunittest.main()