check for existance of configuration file.
[stack/cam.git] / cam
1 #!/usr/bin/python
2
3
4 import os, sys
5 import logging
6 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), 'lib'))
7
8 from utils import *
9 from cfg import *
10
11 # commands
12 from gen import gen
13 from newca import newca
14 from list import list
15 from files import files
16 from initfs import initfs
17 from check import check
18
19
20 def Usage():
21     print '''
22 CAM v0.1 - (c)2006 by <ale@incal.net> 
23 A Certification Authority manager for complex situations.
24 Usage: %s <COMMAND> [<ARG>...]
25 Known commands:
26
27   init
28     Initialize the environment by creating the necessary
29     directory structure
30
31   newca [<RSA_CRT> [<DSA_CRT>]]
32     Create a new CA certificate (otherwise you can import
33     your own certificates)
34
35   gen <TAG>...
36     Create (or re-create) the certificates corresponding
37     to TAG
38
39   list
40     List all known certificates
41
42   files <TAG>...
43     Dump all the certificate-related files of this TAG
44
45   check
46     Should be run weekly from a cron job to warn you if
47     some certificates are about to expire (controlled by
48     the 'warning_days' parameter in the 'global' section
49     of the configuration)
50
51
52 The configuration will be read from '%s'.
53 It consists of a ini-style file, with one 'ca' section that
54 specifies global CA parameters, and more sections for each
55 tag with certificate-specific information. See the examples
56 for more details on how to write your own configuration.
57
58 ''' % (sys.argv[0], config_file_path)
59     sys.exit(0)
60
61
62 if len(sys.argv) < 2 or sys.argv[1] == 'help':
63     Usage()
64
65 cmd = sys.argv[1]
66 if cmd == 'init':
67     initfs()
68 elif cmd == 'gen':
69     for tag in sys.argv[2:]:
70         gen(tag)
71 elif cmd == 'newca':
72     newca()
73 elif cmd == 'list':
74     list(sys.argv[2:])
75 elif cmd == 'files':
76     for tag in sys.argv[2:]:
77         files(tag)
78 elif cmd == 'check':
79     check()
80 else:
81     print 'Unknown command \'%s\'.' % cmd
82     Usage()
83
84