]> Raphaƫl G. Git Repositories - acme/blob - letsconf
Final bin files
[acme] / letsconf
1 #! /usr/bin/php
2 <?php
3
4 # Verify filename
5 if (count($argv) != 2) {
6 echo 'Usage: genconfig /etc/acmepl/config'."\n";
7 exit(1);
8 }
9
10 # Directory do not exists
11 if (!is_dir(dirname($argv[1]))) {
12 echo 'Directory '.dirname($argv[1]).' do not exists'."\n";
13 exit(1);
14 }
15
16 # Directory do not exists
17 if (file_exists($argv[1]) && !in_array(filetype($argv[1]), array('file','link'))) {
18 echo 'File '.$argv[1].' exists and is not a file'."\n";
19 exit(1);
20 }
21
22 # Symlink target do not exists
23 if (is_link($argv[1]) && !file_exists($argv[1])) {
24 # Read final link
25 $target = $argv[1];
26 # Extract last link
27 do {
28 # Update to next link
29 $target = readlink($target);
30 } while (is_link($target));
31 echo 'Symlink '.$argv[1].' target '.$target.' do not exists'."\n";
32 exit(1);
33 }
34
35 # Not writable
36 if (
37 (is_file($argv[1]) && !is_writable($argv[1])) ||
38 (!file_exists($argv[1]) && !is_writable(dirname($argv[1])))
39 ) {
40 echo 'Unable to open '.$argv[1].' for writing'."\n";
41 exit(1);
42 }
43
44 // Generate config
45 $config = json_encode(
46 // Root array
47 array(
48 // Certificate object
49 array(
50 // Public cert
51 //XXX: required
52 'cert' => '/etc/pki/tls/certs/httpd.pem',
53 // Private key
54 //XXX: required
55 'key' => '/etc/pki/tls/private/httpd.pem',
56 // Mail address
57 //XXX: required
58 'mail' => 'example@example.com',
59 // Domain list
60 //XXX: required
61 'domains' => array(
62 'www.example.com',
63 'example.com'
64 ),
65 // Production certificate
66 //XXX: optional
67 //XXX: set to 1 for production
68 'prod' => 0
69 ),
70 // Other certificate
71 array(
72 'cert' => '/etc/ssl/certs/apache.crt',
73 'key' => '/etc/ssl/private/apache.key',
74 'mail' => 'example@example.com',
75 'domains' => array(
76 'other.example.com',
77 'example.com'
78 ),
79 'prod' => 0
80 ),
81 #...
82 )
83 );
84
85 # Send to stdout
86 if ($argv[1] == '-') {
87 echo $config;
88 # Save to file
89 } else {
90 file_put_contents($argv[1], $config);
91 }