Procházet zdrojové kódy

refactor files

tags/v2.0.0
Robin Thoni před 8 roky
rodič
revize
059f6fd5bd

+ 137
- 0
.gitignore Zobrazit soubor

@@ -1 +1,138 @@
1 1
 *.swp
2
+/tests/etc
3
+/sitegen/hooks-enabled
4
+
5
+# Byte-compiled / optimized / DLL files
6
+__pycache__/
7
+*.py[cod]
8
+*$py.class
9
+
10
+# C extensions
11
+*.so
12
+
13
+# Distribution / packaging
14
+.Python
15
+env/
16
+build/
17
+develop-eggs/
18
+dist/
19
+downloads/
20
+eggs/
21
+.eggs/
22
+lib/
23
+lib64/
24
+parts/
25
+sdist/
26
+var/
27
+*.egg-info/
28
+.installed.cfg
29
+*.egg
30
+
31
+# PyInstaller
32
+#  Usually these files are written by a python script from a template
33
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+*.manifest
35
+*.spec
36
+
37
+# Installer logs
38
+pip-log.txt
39
+pip-delete-this-directory.txt
40
+
41
+# Unit test / coverage reports
42
+htmlcov/
43
+.tox/
44
+.coverage
45
+.coverage.*
46
+.cache
47
+nosetests.xml
48
+coverage.xml
49
+*,cover
50
+.hypothesis/
51
+
52
+# Translations
53
+*.mo
54
+*.pot
55
+
56
+# Django stuff:
57
+*.log
58
+local_settings.py
59
+
60
+# Flask stuff:
61
+instance/
62
+.webassets-cache
63
+
64
+# Scrapy stuff:
65
+.scrapy
66
+
67
+# Sphinx documentation
68
+docs/_build/
69
+
70
+# PyBuilder
71
+target/
72
+
73
+# Jupyter Notebook
74
+.ipynb_checkpoints
75
+
76
+# pyenv
77
+.python-version
78
+
79
+# celery beat schedule file
80
+celerybeat-schedule
81
+
82
+# dotenv
83
+.env
84
+
85
+# virtualenv
86
+.venv/
87
+venv/
88
+ENV/
89
+
90
+# Spyder project settings
91
+.spyderproject
92
+
93
+# Rope project settings
94
+.ropeproject
95
+
96
+
97
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
98
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
99
+
100
+# User-specific stuff:
101
+.idea/workspace.xml
102
+.idea/tasks.xml
103
+
104
+# Sensitive or high-churn files:
105
+.idea/dataSources/
106
+.idea/dataSources.ids
107
+.idea/dataSources.xml
108
+.idea/dataSources.local.xml
109
+.idea/sqlDataSources.xml
110
+.idea/dynamic.xml
111
+.idea/uiDesigner.xml
112
+
113
+# Gradle:
114
+.idea/gradle.xml
115
+.idea/libraries
116
+
117
+# Mongo Explorer plugin:
118
+.idea/mongoSettings.xml
119
+
120
+## File-based project format:
121
+*.iws
122
+
123
+## Plugin-specific files:
124
+
125
+# IntelliJ
126
+/out/
127
+
128
+# mpeltonen/sbt-idea plugin
129
+.idea_modules/
130
+
131
+# JIRA plugin
132
+atlassian-ide-plugin.xml
133
+
134
+# Crashlytics plugin (for Android Studio and IntelliJ)
135
+com_crashlytics_export_strings.xml
136
+crashlytics.properties
137
+crashlytics-build.properties
138
+fabric.properties

+ 6
- 0
.idea/encodings.xml Zobrazit soubor

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="Encoding">
4
+    <file url="PROJECT" charset="UTF-8" />
5
+  </component>
6
+</project>

+ 14
- 0
.idea/misc.xml Zobrazit soubor

@@ -0,0 +1,14 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectLevelVcsManager" settingsEditedManually="false">
4
+    <OptionsSetting value="true" id="Add" />
5
+    <OptionsSetting value="true" id="Remove" />
6
+    <OptionsSetting value="true" id="Checkout" />
7
+    <OptionsSetting value="true" id="Update" />
8
+    <OptionsSetting value="true" id="Status" />
9
+    <OptionsSetting value="true" id="Edit" />
10
+    <ConfirmationsSetting value="0" id="Add" />
11
+    <ConfirmationsSetting value="0" id="Remove" />
12
+  </component>
13
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.4.3 (/usr/bin/python3.4)" project-jdk-type="Python SDK" />
14
+</project>

+ 8
- 0
.idea/modules.xml Zobrazit soubor

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/.idea/sitegen.iml" filepath="$PROJECT_DIR$/.idea/sitegen.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 11
- 0
.idea/sitegen.iml Zobrazit soubor

@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="PYTHON_MODULE" version="4">
3
+  <component name="NewModuleRootManager">
4
+    <content url="file://$MODULE_DIR$" />
5
+    <orderEntry type="inheritedJdk" />
6
+    <orderEntry type="sourceFolder" forTests="false" />
7
+  </component>
8
+  <component name="TestRunnerService">
9
+    <option name="PROJECT_TEST_RUNNER" value="Unittests" />
10
+  </component>
11
+</module>

+ 6
- 0
.idea/vcs.xml Zobrazit soubor

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

sitegen.completion → bash/sitegen.completion Zobrazit soubor

@@ -11,4 +11,4 @@ _sitegen()
11 11
     COMPREPLY=()
12 12
   fi
13 13
 }
14
-complete -F _sitegen sitegen
14
+#complete -F _sitegen sitegen

+ 0
- 23
cert-check.sh Zobrazit soubor

@@ -1,23 +0,0 @@
1
-#! /usr/bin/env sh
2
-
3
-if [ $# -ne 2 ]
4
-then
5
-  echo "Usage: cert-check directory checkend" >&2
6
-  exit 64
7
-fi
8
-
9
-dir="$1"
10
-checkend="$2"
11
-
12
-for cert in ${dir}/*.crt
13
-do
14
-  openssl x509 -noout -in "${cert}" -checkend "${checkend}"
15
-  will_expire="$?"
16
-  date="$(openssl x509 -noout -in "${cert}" -enddate | cut -d= -f2)"
17
-  if [ "${will_expire}" -eq 1 ]
18
-  then
19
-    site=$(basename "${cert}")
20
-    site=$(echo "${site}" | sed -re 's/(.+).crt/\1/')
21
-    echo "${site}" "${date}"
22
-  fi
23
-done

+ 0
- 23
cert-renew-all.sh Zobrazit soubor

@@ -1,23 +0,0 @@
1
-#! /usr/bin/env sh
2
-
3
-if [ $# -ne 2 ]
4
-then
5
-    name=$(basename "$0")
6
-    echo "Usage: ${name} directory checkend" >&2
7
-    exit 64
8
-fi
9
-
10
-dir="$1"
11
-checkend="$2"
12
-
13
-certs=$(cert-check "${dir}" "${checkend}")
14
-
15
-echo "${certs}"
16
-
17
-sites=$(echo "${certs}" | cut -d' ' -f1)
18
-
19
-for site in ${sites}
20
-do
21
-  echo
22
-  generate-ssl-cert "${site}"
23
-done

+ 3
- 0
cron/sitegen-cert-renew Zobrazit soubor

@@ -0,0 +1,3 @@
1
+SHELL=/bin/sh
2
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
3
+12 00  * * 1   root    sitegen --cert-renew

+ 0
- 18
fake-letsencrypt.sh Zobrazit soubor

@@ -1,18 +0,0 @@
1
-#! /usr/bin/env sh
2
-
3
-dir="$(dirname $(readlink -f "${0}"))"
4
-host="${1}"
5
-
6
-if [ "${host}" = "error.com" ]
7
-then
8
-    echo "Failed to get certificate" >&2
9
-    exit 1
10
-fi
11
-
12
-leDir="${dir}/tests/etc/letsencypt/live/${host}"
13
-
14
-sleep 1
15
-
16
-mkdir -p "${leDir}"
17
-touch "${leDir}/cert.pem" "${leDir}/privkey.pem" "${leDir}/chain.pem"
18
-echo "Generation successful"

+ 0
- 21
generate-ssl-cert.sh Zobrazit soubor

@@ -1,21 +0,0 @@
1
-#! /usr/bin/env bash
2
-
3
-if [ $# -eq 0 ]
4
-then
5
-  echo "Usage: generate-ssl-cert hostname [options]" >&2
6
-  exit 64
7
-fi
8
-
9
-host="$1"
10
-
11
-letsencrypt --agree-tos --renew-by-default --standalone --standalone-supported-challenges http-01 --http-01-port 9999 --server https://acme-v01.api.letsencrypt.org/directory certonly -d $*
12
-
13
-if [ $? -ne 0 ]
14
-then
15
-  echo "Failed to generate certificate" >&2
16
-  exit 1
17
-fi
18
-
19
-ln -sf /etc/letsencrypt/live/${host}/cert.pem /etc/ssl/private/${host}.crt
20
-ln -sf /etc/letsencrypt/live/${host}/privkey.pem /etc/ssl/private/${host}.key
21
-ln -sf /etc/letsencrypt/live/${host}/chain.pem /etc/ssl/private/${host}-chain.crt

+ 4
- 8
install Zobrazit soubor

@@ -8,19 +8,15 @@ then
8 8
   cp -r "${dir}/sitegen" /etc/sitegen
9 9
 fi &&
10 10
 
11
-cp "${dir}/sitegen.sh" /usr/local/bin/sitegen &&
12
-cp "${dir}/sitegen.completion" /etc/bash_completion.d/sitegen &&
13
-
14
-cp "${dir}/generate-ssl-cert.sh" /usr/local/bin/generate-ssl-cert &&
15
-cp "${dir}/cert-check.sh" /usr/local/bin/cert-check &&
16
-cp "${dir}/cert-renew-all.sh" /usr/local/bin/cert-renew-all &&
11
+cp "${dir}/sitegen.py" /usr/local/bin/sitegen &&
12
+cp "${dir}/bash/sitegen.completion" /etc/bash_completion.d/sitegen &&
17 13
 
18 14
 cp "${dir}/apache/letsencrypt.conf" /etc/apache2/conf-available/letsencrypt.conf &&
19 15
 a2enconf letsencrypt &&
20 16
 service apache2 reload &&
21 17
 
22
-if [ ! -e /etc/cron.d/cert-renew ]
18
+if [ ! -e /etc/cron.d/sitegen-cert-renew ]
23 19
 then
24
-  echo '12 00  * * 1   root    cert-renew-all /etc/ssl/private $((60 * 60 * 24 * 31))' > /etc/cron.d/cert-renew
20
+  cp "${dir}/cron/sitegen-cert-renew" /etc/cron.d/sitegen-cert-renew
25 21
 fi &&
26 22
 service cron reload

+ 5
- 8
sitegen/hooks-available/cert/000-print Zobrazit soubor

@@ -1,13 +1,10 @@
1
+#! /usr/bin/env sh
1 2
 host="${1}"
2 3
 cert_file="${2}"
3 4
 key_file="${3}"
4
-conf_include="${4}"
5
-site_conf="${5}"
6
-site_include="${6}"
5
+chain_file="${4}"
7 6
 
8 7
 echo "Host: ${host}"
9
-echo "Root Document: ${root_dir}"
10
-echo "Http Configuration Source: ${conf_conf}"
11
-echo "Site Configuration Source: ${conf_include}"
12
-echo "Http Configuration Destination: ${site_conf}"
13
-echo "Site Configuration Destination: ${site_include}"
8
+echo "Certificate File: ${cert_file}"
9
+echo "Key File: ${key_file}"
10
+echo "Chain File: ${chain_file}"

+ 1
- 0
sitegen/hooks-available/site/000-print Zobrazit soubor

@@ -1,3 +1,4 @@
1
+#! /usr/bin/env sh
1 2
 host="${1}"
2 3
 root_dir="${2}"
3 4
 conf_conf="${3}"

+ 1
- 0
sitegen/hooks-available/site/050-letsencrypt Zobrazit soubor

@@ -1,3 +1,4 @@
1
+#! /usr/bin/env sh
1 2
 host="${1}"
2 3
 root_dir="${2}"
3 4
 conf_conf="${3}"

+ 1
- 0
sitegen/hooks-available/site/100-chown Zobrazit soubor

@@ -1,3 +1,4 @@
1
+#! /usr/bin/env sh
1 2
 host="${1}"
2 3
 root_dir="${2}"
3 4
 conf_conf="${3}"

+ 1
- 0
sitegen/hooks-available/site/200-a2ensite Zobrazit soubor

@@ -1,3 +1,4 @@
1
+#! /usr/bin/env sh
1 2
 host="${1}"
2 3
 root_dir="${2}"
3 4
 conf_conf="${3}"

+ 1
- 0
sitegen/hooks-available/site/300-reload Zobrazit soubor

@@ -1,3 +1,4 @@
1
+#! /usr/bin/env sh
1 2
 host="${1}"
2 3
 root_dir="${2}"
3 4
 conf_conf="${3}"

+ 9
- 0
sitegen/sitegen.json Zobrazit soubor

@@ -0,0 +1,9 @@
1
+{
2
+  "siteConfDir": "/etc/apache2/sites-available/",
3
+  "siteDir": "/var/",
4
+  "confDir": "/etc/sitegen/",
5
+  "certRenewTime": 5356800,
6
+  "letsencryptCommand": "letsencrypt --agree-tos --renew-by-default --standalone --standalone-supported-challenges http-01 --http-01-port 9999 --server https://acme-v01.api.letsencrypt.org/directory certonly",
7
+  "letsencryptDir": "/etc/letsencrypt/live/",
8
+  "certDir": "/etc/ssl/private/"
9
+}

+ 22
- 0
tests/fake-letsencrypt.sh Zobrazit soubor

@@ -0,0 +1,22 @@
1
+#! /usr/bin/env sh
2
+
3
+dir="$(dirname $(readlink -f "${0}"))"
4
+host="${1}"
5
+
6
+if [ "${host}" = "error.com" ]
7
+then
8
+    echo "Failed to get certificate" >&2
9
+    exit 1
10
+fi &&
11
+
12
+if [ "${host}" = "" ]
13
+then
14
+    echo "No domain" >&2
15
+    exit 1
16
+fi &&
17
+
18
+leDir="${dir}/tests/etc/letsencrypt/live/${host}"
19
+
20
+
21
+mkdir -p "${leDir}" &&
22
+scp serv3:/etc/letsencrypt/live/${host}/* tests/etc/letsencrypt/live/${host}/

+ 9
- 0
tests/sitegen.json Zobrazit soubor

@@ -0,0 +1,9 @@
1
+{
2
+  "siteConfDir": "./tests/etc/apache2/sites-available/",
3
+  "siteDir": "./tests/var/",
4
+  "confDir": "./sitegen/",
5
+  "certRenewTime": 5356800,
6
+  "letsencryptCommand": "./tests/fake-letsencrypt.sh",
7
+  "letsencryptDir": "./tests/etc/letsencrypt/live/",
8
+  "certDir": "./tests/etc/ssl/private/"
9
+}

Načítá se…
Zrušit
Uložit