TorNet.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. #!/usr/bin/python
  2. #
  3. # Copyright 2011 Nick Mathewson, Michael Stone
  4. # Copyright 2013 The Tor Project
  5. #
  6. # You may do anything with this work that copyright law would normally
  7. # restrict, so long as you retain the above notice(s) and this license
  8. # in all redistributed copies and derived works. There is no warranty.
  9. from __future__ import with_statement
  10. # Get verbose tracebacks, so we can diagnose better.
  11. import cgitb
  12. cgitb.enable(format="plain")
  13. import os
  14. import signal
  15. import subprocess
  16. import sys
  17. import re
  18. import errno
  19. import time
  20. import chutney.Templating
  21. import chutney.Traffic
  22. def mkdir_p(d, mode=0777):
  23. """Create directory 'd' and all of its parents as needed. Unlike
  24. os.makedirs, does not give an error if d already exists.
  25. """
  26. try:
  27. os.makedirs(d,mode=mode)
  28. except OSError, e:
  29. if e.errno == errno.EEXIST:
  30. return
  31. raise
  32. class Node(object):
  33. """A Node represents a Tor node or a set of Tor nodes. It's created
  34. in a network configuration file.
  35. This class is responsible for holding the user's selected node
  36. configuration, and figuring out how the node needs to be
  37. configured and launched.
  38. """
  39. ## Fields:
  40. # _parent
  41. # _env
  42. # _builder
  43. # _controller
  44. ########
  45. # Users are expected to call these:
  46. def __init__(self, parent=None, **kwargs):
  47. self._parent = parent
  48. self._env = self._createEnviron(parent, kwargs)
  49. self._builder = None
  50. self._controller = None
  51. def getN(self, N):
  52. return [ Node(self) for _ in xrange(N) ]
  53. def specialize(self, **kwargs):
  54. return Node(parent=self, **kwargs)
  55. ######
  56. # Chutney uses these:
  57. def getBuilder(self):
  58. """Return a NodeBuilder instance to set up this node (that is, to
  59. write all the files that need to be in place so that this
  60. node can be run by a NodeController).
  61. """
  62. if self._builder is None:
  63. self._builder = LocalNodeBuilder(self._env)
  64. return self._builder
  65. def getController(self):
  66. """Return a NodeController instance to control this node (that is,
  67. to start it, stop it, see if it's running, etc.)
  68. """
  69. if self._controller is None:
  70. self._controller = LocalNodeController(self._env)
  71. return self._controller
  72. def setNodenum(self, num):
  73. """Assign a value to the 'nodenum' element of this node. Each node
  74. in a network gets its own nodenum.
  75. """
  76. self._env['nodenum'] = num
  77. #####
  78. # These are internal:
  79. def _createEnviron(self, parent, argdict):
  80. """Return an Environ that delegates to the parent node's Environ (if
  81. there is a parent node), or to the default environment.
  82. """
  83. if parent:
  84. parentenv = parent._env
  85. else:
  86. parentenv = self._getDefaultEnviron()
  87. return TorEnviron(parentenv, **argdict)
  88. def _getDefaultEnviron(self):
  89. """Return the default environment. Any variables that we can't find
  90. set for any particular node, we look for here.
  91. """
  92. return _BASE_ENVIRON
  93. class _NodeCommon(object):
  94. """Internal helper class for functionality shared by some NodeBuilders
  95. and some NodeControllers."""
  96. # XXXX maybe this should turn into a mixin.
  97. def __init__(self, env):
  98. self._env = env
  99. def expand(self, pat, includePath=(".",)):
  100. return chutney.Templating.Template(pat, includePath).format(self._env)
  101. def _getTorrcFname(self):
  102. """Return the name of the file where we'll be writing torrc"""
  103. return self.expand("${torrc_fname}")
  104. class NodeBuilder(_NodeCommon):
  105. """Abstract base class. A NodeBuilder is responsible for doing all the
  106. one-time prep needed to set up a node in a network.
  107. """
  108. def __init__(self, env):
  109. _NodeCommon.__init__(self, env)
  110. def checkConfig(self, net):
  111. """Try to format our torrc; raise an exception if we can't.
  112. """
  113. def preConfig(self, net):
  114. """Called on all nodes before any nodes configure: generates keys as
  115. needed.
  116. """
  117. def config(self, net):
  118. """Called to configure a node: creates a torrc file for it."""
  119. def postConfig(self, net):
  120. """Called on each nodes after all nodes configure."""
  121. class NodeController(_NodeCommon):
  122. """Abstract base class. A NodeController is responsible for running a
  123. node on the network.
  124. """
  125. def __init__(self, env):
  126. _NodeCommon.__init__(self, env)
  127. def check(self, listRunning=True, listNonRunning=False):
  128. """See if this node is running, stopped, or crashed. If it's running
  129. and listRunning is set, print a short statement. If it's
  130. stopped and listNonRunning is set, then print a short statement.
  131. If it's crashed, print a statement. Return True if the
  132. node is running, false otherwise.
  133. """
  134. def start(self):
  135. """Try to start this node; return True if we succeeded or it was
  136. already running, False if we failed."""
  137. def stop(self, sig=signal.SIGINT):
  138. """Try to stop this node by sending it the signal 'sig'."""
  139. class LocalNodeBuilder(NodeBuilder):
  140. ## Environment members used:
  141. # torrc -- which torrc file to use
  142. # torrc_template_path -- path to search for torrc files and include files
  143. # authority -- bool -- are we an authority?
  144. # bridgeauthority -- bool -- are we a bridge authority?
  145. # relay -- bool -- are we a relay?
  146. # bridge -- bool -- are we a bridge?
  147. # nodenum -- int -- set by chutney -- which unique node index is this?
  148. # dir -- path -- set by chutney -- data directory for this tor
  149. # tor_gencert -- path to tor_gencert binary
  150. # tor -- path to tor binary
  151. # auth_cert_lifetime -- lifetime of authority certs, in months.
  152. # ip -- IP to listen on (used only if authority or bridge)
  153. # ipv6_addr -- IPv6 address to listen on (used only if ipv6 bridge)
  154. # orport, dirport -- (used only if authority)
  155. # fingerprint -- used only if authority
  156. # dirserver_flags -- used only if authority
  157. # nick -- nickname of this router
  158. ## Environment members set
  159. # fingerprint -- hex router key fingerprint
  160. # nodenum -- int -- set by chutney -- which unique node index is this?
  161. def __init__(self, env):
  162. NodeBuilder.__init__(self, env)
  163. self._env = env
  164. def _createTorrcFile(self, checkOnly=False):
  165. """Write the torrc file for this node. If checkOnly, just make sure
  166. that the formatting is indeed possible.
  167. """
  168. fn_out = self._getTorrcFname()
  169. torrc_template = self._getTorrcTemplate()
  170. output = torrc_template.format(self._env)
  171. if checkOnly:
  172. # XXXX Is it time-cosuming to format? If so, cache here.
  173. return
  174. with open(fn_out, 'w') as f:
  175. f.write(output)
  176. def _getTorrcTemplate(self):
  177. """Return the template used to write the torrc for this node."""
  178. template_path = self._env['torrc_template_path']
  179. return chutney.Templating.Template("$${include:$torrc}",
  180. includePath=template_path)
  181. def _getFreeVars(self):
  182. """Return a set of the free variables in the torrc template for this
  183. node.
  184. """
  185. template = self._getTorrcTemplate()
  186. return template.freevars(self._env)
  187. def checkConfig(self, net):
  188. """Try to format our torrc; raise an exception if we can't.
  189. """
  190. self._createTorrcFile(checkOnly=True)
  191. def preConfig(self, net):
  192. """Called on all nodes before any nodes configure: generates keys as
  193. needed.
  194. """
  195. self._makeDataDir()
  196. if self._env['authority']:
  197. self._genAuthorityKey()
  198. if self._env['relay']:
  199. self._genRouterKey()
  200. def config(self, net):
  201. """Called to configure a node: creates a torrc file for it."""
  202. self._createTorrcFile()
  203. #self._createScripts()
  204. def postConfig(self, net):
  205. """Called on each nodes after all nodes configure."""
  206. #self.net.addNode(self)
  207. pass
  208. def _makeDataDir(self):
  209. """Create the data directory (with keys subdirectory) for this node.
  210. """
  211. datadir = self._env['dir']
  212. mkdir_p(os.path.join(datadir, 'keys'))
  213. def _genAuthorityKey(self):
  214. """Generate an authority identity and signing key for this authority,
  215. if they do not already exist."""
  216. datadir = self._env['dir']
  217. tor_gencert = self._env['tor_gencert']
  218. lifetime = self._env['auth_cert_lifetime']
  219. idfile = os.path.join(datadir,'keys',"authority_identity_key")
  220. skfile = os.path.join(datadir,'keys',"authority_signing_key")
  221. certfile = os.path.join(datadir,'keys',"authority_certificate")
  222. addr = self.expand("${ip}:${dirport}")
  223. passphrase = self._env['auth_passphrase']
  224. if all(os.path.exists(f) for f in [idfile, skfile, certfile]):
  225. return
  226. cmdline = [
  227. tor_gencert,
  228. '--create-identity-key',
  229. '--passphrase-fd', '0',
  230. '-i', idfile,
  231. '-s', skfile,
  232. '-c', certfile,
  233. '-m', str(lifetime),
  234. '-a', addr]
  235. print "Creating identity key %s for %s with %s"%(
  236. idfile,self._env['nick']," ".join(cmdline))
  237. p = subprocess.Popen(cmdline, stdin=subprocess.PIPE)
  238. p.communicate(passphrase+"\n")
  239. assert p.returncode == 0 #XXXX BAD!
  240. def _genRouterKey(self):
  241. """Generate an identity key for this router, unless we already have,
  242. and set up the 'fingerprint' entry in the Environ.
  243. """
  244. datadir = self._env['dir']
  245. tor = self._env['tor']
  246. idfile = os.path.join(datadir,'keys',"identity_key")
  247. cmdline = [
  248. tor,
  249. "--quiet",
  250. "--list-fingerprint",
  251. "--orport", "1",
  252. "--dirserver",
  253. "xyzzy 127.0.0.1:1 ffffffffffffffffffffffffffffffffffffffff",
  254. "--datadirectory", datadir ]
  255. p = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
  256. stdout, stderr = p.communicate()
  257. fingerprint = "".join(stdout.split()[1:])
  258. assert re.match(r'^[A-F0-9]{40}$', fingerprint)
  259. self._env['fingerprint'] = fingerprint
  260. def _getAltAuthLines(self):
  261. """Return a combination of AlternateDirAuthority,
  262. AlternateHSAuthority and AlternateBridgeAuthority lines for
  263. this Node, appropriately. Non-authorities return ""."""
  264. if not self._env['authority']:
  265. return ""
  266. datadir = self._env['dir']
  267. certfile = os.path.join(datadir,'keys',"authority_certificate")
  268. v3id = None
  269. with open(certfile, 'r') as f:
  270. for line in f:
  271. if line.startswith("fingerprint"):
  272. v3id = line.split()[1].strip()
  273. break
  274. assert v3id is not None
  275. if self._env['bridgeauthority']:
  276. # Bridge authorities return AlternateBridgeAuthority with
  277. # the 'bridge' flag set.
  278. options = ("AlternateBridgeAuthority",)
  279. self._env['dirserver_flags'] += " bridge"
  280. else:
  281. # Directory authorities return AlternateDirAuthority with
  282. # the 'hs' and 'v3ident' flags set.
  283. # XXXX This next line is needed for 'bridges' but breaks
  284. # 'basic'
  285. #options = ("AlternateDirAuthority",)
  286. options = ("DirServer",)
  287. self._env['dirserver_flags'] += " hs v3ident=%s" % v3id
  288. authlines = ""
  289. for authopt in options:
  290. authlines += "%s %s orport=%s %s %s:%s %s\n" %(
  291. authopt, self._env['nick'], self._env['orport'],
  292. self._env['dirserver_flags'], self._env['ip'],
  293. self._env['dirport'], self._env['fingerprint'])
  294. return authlines
  295. def _getBridgeLines(self):
  296. """Return potential Bridge line for this Node. Non-bridge
  297. relays return "".
  298. """
  299. if not self._env['bridge']:
  300. return ""
  301. bridgelines = "Bridge %s:%s\n" % (self._env['ip'],
  302. self._env['orport'])
  303. if self._env['ipv6_addr'] is not None:
  304. bridgelines += "Bridge %s:%s\n" % (self._env['ipv6_addr'],
  305. self._env['orport'])
  306. return bridgelines
  307. class LocalNodeController(NodeController):
  308. def __init__(self, env):
  309. NodeController.__init__(self, env)
  310. self._env = env
  311. def getPid(self):
  312. """Assuming that this node has its pidfile in ${dir}/pid, return
  313. the pid of the running process, or None if there is no pid in the
  314. file.
  315. """
  316. pidfile = os.path.join(self._env['dir'], 'pid')
  317. if not os.path.exists(pidfile):
  318. return None
  319. with open(pidfile, 'r') as f:
  320. return int(f.read())
  321. def isRunning(self, pid=None):
  322. """Return true iff this node is running. (If 'pid' is provided, we
  323. assume that the pid provided is the one of this node. Otherwise
  324. we call getPid().
  325. """
  326. if pid is None:
  327. pid = self.getPid()
  328. if pid is None:
  329. return False
  330. try:
  331. os.kill(pid, 0) # "kill 0" == "are you there?"
  332. except OSError, e:
  333. if e.errno == errno.ESRCH:
  334. return False
  335. raise
  336. # okay, so the process exists. Say "True" for now.
  337. # XXXX check if this is really tor!
  338. return True
  339. def check(self, listRunning=True, listNonRunning=False):
  340. """See if this node is running, stopped, or crashed. If it's running
  341. and listRunning is set, print a short statement. If it's
  342. stopped and listNonRunning is set, then print a short statement.
  343. If it's crashed, print a statement. Return True if the
  344. node is running, false otherwise.
  345. """
  346. # XXX Split this into "check" and "print" parts.
  347. pid = self.getPid()
  348. running = self.isRunning(pid)
  349. nick = self._env['nick']
  350. dir = self._env['dir']
  351. if running:
  352. if listRunning:
  353. print "%s is running with PID %s"%(nick,pid)
  354. return True
  355. elif os.path.exists(os.path.join(dir, "core.%s"%pid)):
  356. if listNonRunning:
  357. print "%s seems to have crashed, and left core file core.%s"%(
  358. nick,pid)
  359. return False
  360. else:
  361. if listNonRunning:
  362. print "%s is stopped"%nick
  363. return False
  364. def hup(self):
  365. """Send a SIGHUP to this node, if it's running."""
  366. pid = self.getPid()
  367. running = self.isRunning()
  368. nick = self._env['nick']
  369. if self.isRunning():
  370. print "Sending sighup to %s"%nick
  371. os.kill(pid, signal.SIGHUP)
  372. return True
  373. else:
  374. print "%s is not running"%nick
  375. return False
  376. def start(self):
  377. """Try to start this node; return True if we succeeded or it was
  378. already running, False if we failed."""
  379. if self.isRunning():
  380. print "%s is already running"%self._env['nick']
  381. return True
  382. torrc = self._getTorrcFname()
  383. cmdline = [
  384. self._env['tor'],
  385. "--quiet",
  386. "-f", torrc,
  387. ]
  388. p = subprocess.Popen(cmdline)
  389. # XXXX this requires that RunAsDaemon is set.
  390. p.wait()
  391. if p.returncode != 0:
  392. print "Couldn't launch %s (%s): %s"%(self._env['nick'],
  393. " ".join(cmdline),
  394. p.returncode)
  395. return False
  396. return True
  397. def stop(self, sig=signal.SIGINT):
  398. """Try to stop this node by sending it the signal 'sig'."""
  399. pid = self.getPid()
  400. if not self.isRunning(pid):
  401. print "%s is not running"%self._env['nick']
  402. return
  403. os.kill(pid, sig)
  404. DEFAULTS = {
  405. 'authority' : False,
  406. 'bridgeauthority' : False,
  407. 'relay' : False,
  408. 'bridge' : False,
  409. 'connlimit' : 60,
  410. 'net_base_dir' : 'net',
  411. 'tor' : 'tor',
  412. 'auth_cert_lifetime' : 12,
  413. 'ip' : '127.0.0.1',
  414. 'ipv6_addr' : None,
  415. 'dirserver_flags' : 'no-v2',
  416. 'chutney_dir' : '.',
  417. 'torrc_fname' : '${dir}/torrc',
  418. 'orport_base' : 5000,
  419. 'dirport_base' : 7000,
  420. 'controlport_base' : 8000,
  421. 'socksport_base' : 9000,
  422. 'authorities' : "AlternateDirAuthority bleargh bad torrc file!",
  423. 'bridges' : "Bridge bleargh bad torrc file!",
  424. 'core' : True,
  425. }
  426. class TorEnviron(chutney.Templating.Environ):
  427. """Subclass of chutney.Templating.Environ to implement commonly-used
  428. substitutions.
  429. Environment fields provided:
  430. orport, controlport, socksport, dirport:
  431. dir:
  432. nick:
  433. tor_gencert:
  434. auth_passphrase:
  435. torrc_template_path:
  436. Environment fields used:
  437. nodenum
  438. tag
  439. orport_base, controlport_base, socksport_base, dirport_base
  440. chutney_dir
  441. tor
  442. XXXX document the above. Or document all fields in one place?
  443. """
  444. def __init__(self,parent=None,**kwargs):
  445. chutney.Templating.Environ.__init__(self, parent=parent, **kwargs)
  446. def _get_orport(self, my):
  447. return my['orport_base']+my['nodenum']
  448. def _get_controlport(self, my):
  449. return my['controlport_base']+my['nodenum']
  450. def _get_socksport(self, my):
  451. return my['socksport_base']+my['nodenum']
  452. def _get_dirport(self, my):
  453. return my['dirport_base']+my['nodenum']
  454. def _get_dir(self, my):
  455. return os.path.abspath(os.path.join(my['net_base_dir'],
  456. "nodes",
  457. "%03d%s"%(my['nodenum'], my['tag'])))
  458. def _get_nick(self, my):
  459. return "test%03d%s"%(my['nodenum'], my['tag'])
  460. def _get_tor_gencert(self, my):
  461. return my['tor']+"-gencert"
  462. def _get_auth_passphrase(self, my):
  463. return self['nick'] # OMG TEH SECURE!
  464. def _get_torrc_template_path(self, my):
  465. return [ os.path.join(my['chutney_dir'], 'torrc_templates') ]
  466. class Network(object):
  467. """A network of Tor nodes, plus functions to manipulate them
  468. """
  469. def __init__(self,defaultEnviron):
  470. self._nodes = []
  471. self._dfltEnv = defaultEnviron
  472. self._nextnodenum = 0
  473. def _addNode(self, n):
  474. n.setNodenum(self._nextnodenum)
  475. self._nextnodenum += 1
  476. self._nodes.append(n)
  477. def _checkConfig(self):
  478. for n in self._nodes:
  479. n.getBuilder().checkConfig(self)
  480. def configure(self):
  481. network = self
  482. altauthlines = []
  483. bridgelines = []
  484. builders = [ n.getBuilder() for n in self._nodes ]
  485. self._checkConfig()
  486. # XXX don't change node names or types or count if anything is
  487. # XXX running!
  488. for b in builders:
  489. b.preConfig(network)
  490. altauthlines.append(b._getAltAuthLines())
  491. bridgelines.append(b._getBridgeLines())
  492. self._dfltEnv['authorities'] = "".join(altauthlines)
  493. self._dfltEnv['bridges'] = "".join(bridgelines)
  494. for b in builders:
  495. b.config(network)
  496. for b in builders:
  497. b.postConfig(network)
  498. def status(self):
  499. statuses = [ n.getController().check() for n in self._nodes]
  500. n_ok = len([x for x in statuses if x])
  501. print "%d/%d nodes are running"%(n_ok,len(self._nodes))
  502. def restart(self):
  503. self.stop()
  504. self.start()
  505. def start(self):
  506. print "Starting nodes"
  507. return all([n.getController().start() for n in self._nodes])
  508. def hup(self):
  509. print "Sending SIGHUP to nodes"
  510. return all([n.getController().hup() for n in self._nodes])
  511. def stop(self):
  512. controllers = [ n.getController() for n in self._nodes ]
  513. for sig, desc in [(signal.SIGINT, "SIGINT"),
  514. (signal.SIGINT, "another SIGINT"),
  515. (signal.SIGKILL, "SIGKILL")]:
  516. print "Sending %s to nodes"%desc
  517. for c in controllers:
  518. if c.isRunning():
  519. c.stop(sig=sig)
  520. print "Waiting for nodes to finish."
  521. for n in xrange(15):
  522. time.sleep(1)
  523. if all(not c.isRunning() for c in controllers):
  524. return
  525. sys.stdout.write(".")
  526. sys.stdout.flush()
  527. for c in controllers:
  528. n.check(listNonRunning=False)
  529. def verify(self):
  530. sys.stdout.write("Verifying data transmission: ")
  531. sys.stdout.flush()
  532. status = self._verify_traffic()
  533. if status:
  534. print("Success")
  535. else:
  536. print("Failure")
  537. return status
  538. def _verify_traffic(self):
  539. """Verify (parts of) the network by sending traffic through it
  540. and verify what is received."""
  541. LISTEN_PORT = 4747 # FIXME: Do better! Note the default exit policy.
  542. DATALEN = 10*1024 # Octets.
  543. TIMEOUT = 3 # Seconds.
  544. with open('/dev/urandom', 'r') as randfp:
  545. tmpdata = randfp.read(DATALEN)
  546. bind_to = ('localhost', LISTEN_PORT)
  547. tt = chutney.Traffic.TrafficTester(bind_to, tmpdata, TIMEOUT)
  548. for op in filter(lambda n: n._env['tag'] == 'c', self._nodes):
  549. tt.add(chutney.Traffic.Source(tt, bind_to, tmpdata,
  550. ('localhost', int(op._env['socksport']))))
  551. return tt.run()
  552. def ConfigureNodes(nodelist):
  553. network = _THE_NETWORK
  554. for n in nodelist:
  555. network._addNode(n)
  556. def usage(network):
  557. return "\n".join(["Usage: chutney {command} {networkfile}",
  558. "Known commands are: %s" % (
  559. " ".join(x for x in dir(network) if not x.startswith("_")))])
  560. def runConfigFile(verb, f):
  561. _GLOBALS = dict(_BASE_ENVIRON= _BASE_ENVIRON,
  562. Node=Node,
  563. ConfigureNodes=ConfigureNodes,
  564. _THE_NETWORK=_THE_NETWORK)
  565. exec f in _GLOBALS
  566. network = _GLOBALS['_THE_NETWORK']
  567. if not hasattr(network, verb):
  568. print usage(network)
  569. print "Error: I don't know how to %s." % verb
  570. return
  571. getattr(network,verb)()
  572. def main():
  573. global _BASE_ENVIRON
  574. global _THE_NETWORK
  575. _BASE_ENVIRON = TorEnviron(chutney.Templating.Environ(**DEFAULTS))
  576. _THE_NETWORK = Network(_BASE_ENVIRON)
  577. if len(sys.argv) < 3:
  578. print usage(_THE_NETWORK)
  579. print "Error: Not enough arguments given."
  580. sys.exit(1)
  581. f = open(sys.argv[2])
  582. runConfigFile(sys.argv[1], f)
  583. if __name__ == '__main__':
  584. main()