dargslan-apache-analyzer 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dargslan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: dargslan-apache-analyzer
3
+ Version: 1.0.0
4
+ Summary: Apache HTTP Server configuration analyzer — check VirtualHosts, SSL, security modules, and common misconfigurations
5
+ Author-email: Dargslan <info@dargslan.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://dargslan.com
8
+ Project-URL: Documentation, https://dargslan.com/blog
9
+ Project-URL: Repository, https://github.com/Dargslan
10
+ Project-URL: Free Cheat Sheets, https://dargslan.com/cheat-sheets
11
+ Project-URL: Linux & DevOps Books, https://dargslan.com/books
12
+ Keywords: apache,httpd,webserver,config,ssl,security,linux,sysadmin,devops
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
19
+ Requires-Python: >=3.7
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Dynamic: license-file
23
+
24
+ # dargslan-apache-analyzer
25
+
26
+ **Apache HTTP Server Configuration Analyzer** — Check VirtualHosts, SSL, security modules, ServerTokens, directory listing, and common misconfigurations. Zero external dependencies.
27
+
28
+ [![PyPI version](https://img.shields.io/pypi/v/dargslan-apache-analyzer)](https://pypi.org/project/dargslan-apache-analyzer/)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install dargslan-apache-analyzer
35
+ ```
36
+
37
+ ## CLI Usage
38
+
39
+ ```bash
40
+ dargslan-apache report # Full analysis report
41
+ dargslan-apache vhosts # List VirtualHosts
42
+ dargslan-apache modules # Loaded modules
43
+ dargslan-apache issues # Security issues
44
+ dargslan-apache test # Config syntax test
45
+ dargslan-apache json # JSON output
46
+ ```
47
+
48
+ ## Python API
49
+
50
+ ```python
51
+ from dargslan_apache_analyzer import ApacheAnalyzer
52
+ aa = ApacheAnalyzer()
53
+ vhosts = aa.get_vhosts()
54
+ issues = aa.check_security()
55
+ aa.print_report()
56
+ ```
57
+
58
+ ## More from Dargslan
59
+
60
+ - [Dargslan.com](https://dargslan.com) — Linux & DevOps eBook Store
61
+ - [Free Cheat Sheets](https://dargslan.com/cheat-sheets)
62
+ - [Blog & Tutorials](https://dargslan.com/blog)
63
+
64
+ ## License
65
+
66
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,43 @@
1
+ # dargslan-apache-analyzer
2
+
3
+ **Apache HTTP Server Configuration Analyzer** — Check VirtualHosts, SSL, security modules, ServerTokens, directory listing, and common misconfigurations. Zero external dependencies.
4
+
5
+ [![PyPI version](https://img.shields.io/pypi/v/dargslan-apache-analyzer)](https://pypi.org/project/dargslan-apache-analyzer/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install dargslan-apache-analyzer
12
+ ```
13
+
14
+ ## CLI Usage
15
+
16
+ ```bash
17
+ dargslan-apache report # Full analysis report
18
+ dargslan-apache vhosts # List VirtualHosts
19
+ dargslan-apache modules # Loaded modules
20
+ dargslan-apache issues # Security issues
21
+ dargslan-apache test # Config syntax test
22
+ dargslan-apache json # JSON output
23
+ ```
24
+
25
+ ## Python API
26
+
27
+ ```python
28
+ from dargslan_apache_analyzer import ApacheAnalyzer
29
+ aa = ApacheAnalyzer()
30
+ vhosts = aa.get_vhosts()
31
+ issues = aa.check_security()
32
+ aa.print_report()
33
+ ```
34
+
35
+ ## More from Dargslan
36
+
37
+ - [Dargslan.com](https://dargslan.com) — Linux & DevOps eBook Store
38
+ - [Free Cheat Sheets](https://dargslan.com/cheat-sheets)
39
+ - [Blog & Tutorials](https://dargslan.com/blog)
40
+
41
+ ## License
42
+
43
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,189 @@
1
+ """
2
+ dargslan-apache-analyzer — Apache HTTP Server Configuration Analyzer
3
+
4
+ Analyze Apache configuration for security issues, VirtualHosts, SSL, and modules.
5
+ Zero external dependencies — uses only Python standard library.
6
+
7
+ Homepage: https://dargslan.com
8
+ Books: https://dargslan.com/books
9
+ Blog: https://dargslan.com/blog
10
+ """
11
+
12
+ __version__ = "1.0.0"
13
+ __author__ = "Dargslan"
14
+ __url__ = "https://dargslan.com"
15
+
16
+ import os
17
+ import re
18
+ import json
19
+ import subprocess
20
+ import glob as globmod
21
+
22
+
23
+ class ApacheAnalyzer:
24
+ """Analyze Apache HTTP Server configuration."""
25
+
26
+ SECURITY_HEADERS = [
27
+ 'X-Frame-Options', 'X-Content-Type-Options', 'X-XSS-Protection',
28
+ 'Strict-Transport-Security', 'Content-Security-Policy', 'Referrer-Policy',
29
+ ]
30
+
31
+ def __init__(self, config_path=None):
32
+ self.config_path = config_path or self._find_config()
33
+
34
+ def _find_config(self):
35
+ paths = ['/etc/apache2/apache2.conf', '/etc/httpd/conf/httpd.conf',
36
+ '/usr/local/apache2/conf/httpd.conf', '/etc/apache2/httpd.conf']
37
+ for p in paths:
38
+ if os.path.exists(p): return p
39
+ return '/etc/apache2/apache2.conf'
40
+
41
+ def _read_config(self, path=None):
42
+ path = path or self.config_path
43
+ try:
44
+ with open(path, 'r') as f: return f.read()
45
+ except (FileNotFoundError, PermissionError): return ''
46
+
47
+ def _find_includes(self, config_text):
48
+ base_dir = os.path.dirname(self.config_path)
49
+ includes = []
50
+ for match in re.finditer(r'(?:Include|IncludeOptional)\s+(.+)', config_text):
51
+ pattern = match.group(1).strip()
52
+ if not os.path.isabs(pattern):
53
+ pattern = os.path.join(base_dir, pattern)
54
+ for path in globmod.glob(pattern):
55
+ if os.path.isfile(path): includes.append(path)
56
+ return includes
57
+
58
+ def get_vhosts(self):
59
+ """Parse VirtualHost blocks."""
60
+ all_configs = [self.config_path]
61
+ main_config = self._read_config()
62
+ all_configs.extend(self._find_includes(main_config))
63
+
64
+ vhosts = []
65
+ for conf_path in all_configs:
66
+ content = self._read_config(conf_path)
67
+ if not content: continue
68
+ for match in re.finditer(r'<VirtualHost\s+([^>]+)>', content):
69
+ start = match.start()
70
+ end_match = re.search(r'</VirtualHost>', content[start:])
71
+ if not end_match: continue
72
+ block = content[start:start + end_match.end()]
73
+
74
+ server_name = re.search(r'ServerName\s+(\S+)', block)
75
+ doc_root = re.search(r'DocumentRoot\s+(\S+)', block)
76
+ ssl = 'SSLEngine on' in block or ':443' in match.group(1)
77
+
78
+ vhosts.append({
79
+ 'file': conf_path,
80
+ 'address': match.group(1).strip(),
81
+ 'server_name': server_name.group(1) if server_name else '_',
82
+ 'document_root': doc_root.group(1).strip('"') if doc_root else None,
83
+ 'ssl': ssl,
84
+ 'block': block,
85
+ })
86
+ return vhosts
87
+
88
+ def get_loaded_modules(self):
89
+ """Get loaded Apache modules."""
90
+ try:
91
+ for cmd in [['apache2ctl', '-M'], ['httpd', '-M'], ['apachectl', '-M']]:
92
+ try:
93
+ result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
94
+ if result.returncode == 0:
95
+ modules = []
96
+ for line in result.stdout.split('\n'):
97
+ line = line.strip()
98
+ if '_module' in line:
99
+ modules.append(line.split()[0])
100
+ return modules
101
+ except FileNotFoundError: continue
102
+ except subprocess.TimeoutExpired: pass
103
+ return []
104
+
105
+ def check_security(self):
106
+ """Check Apache security configuration."""
107
+ issues = []
108
+ main_config = self._read_config()
109
+ all_content = main_config
110
+ for inc in self._find_includes(main_config):
111
+ all_content += '\n' + self._read_config(inc)
112
+
113
+ if 'ServerTokens Prod' not in all_content and 'ServerTokens ProductOnly' not in all_content:
114
+ issues.append({'severity': 'warning', 'message': 'ServerTokens not set to Prod (version disclosure)'})
115
+
116
+ if 'ServerSignature Off' not in all_content:
117
+ issues.append({'severity': 'warning', 'message': 'ServerSignature not disabled'})
118
+
119
+ if 'TraceEnable Off' not in all_content:
120
+ issues.append({'severity': 'warning', 'message': 'TRACE method not disabled'})
121
+
122
+ modules = self.get_loaded_modules()
123
+ security_modules = ['security2_module', 'headers_module', 'ssl_module']
124
+ for mod in security_modules:
125
+ if mod not in modules:
126
+ sev = 'info' if mod != 'ssl_module' else 'warning'
127
+ issues.append({'severity': sev, 'message': f'Module not loaded: {mod}'})
128
+
129
+ for vhost in self.get_vhosts():
130
+ block = vhost['block']
131
+ for header in self.SECURITY_HEADERS:
132
+ if header.lower() not in block.lower():
133
+ issues.append({'severity': 'info', 'server': vhost['server_name'],
134
+ 'message': f"Missing: {header}"})
135
+
136
+ if vhost['ssl']:
137
+ if 'SSLProtocol' in block:
138
+ proto_match = re.search(r'SSLProtocol\s+(.+)', block)
139
+ if proto_match:
140
+ protos = proto_match.group(1)
141
+ if 'SSLv3' in protos or '+TLSv1 ' in protos:
142
+ issues.append({'severity': 'critical', 'server': vhost['server_name'],
143
+ 'message': f'Insecure SSL protocol: {protos.strip()}'})
144
+
145
+ if 'Options Indexes' in block or 'Options +Indexes' in block:
146
+ issues.append({'severity': 'high', 'server': vhost['server_name'],
147
+ 'message': 'Directory listing enabled'})
148
+
149
+ return issues
150
+
151
+ def test_config(self):
152
+ """Test Apache configuration syntax."""
153
+ for cmd in [['apache2ctl', '-t'], ['httpd', '-t'], ['apachectl', '-t']]:
154
+ try:
155
+ result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
156
+ return {'valid': result.returncode == 0, 'output': result.stderr.strip()}
157
+ except FileNotFoundError: continue
158
+ return {'valid': None, 'output': 'Apache not found'}
159
+
160
+ def print_report(self):
161
+ """Print formatted Apache analysis report."""
162
+ vhosts = self.get_vhosts()
163
+ modules = self.get_loaded_modules()
164
+ issues = self.check_security()
165
+
166
+ print(f"\n{'='*60}")
167
+ print(f" Apache Configuration Analysis")
168
+ print(f" Config: {self.config_path}")
169
+ print(f"{'='*60}")
170
+ print(f"\n VirtualHosts ({len(vhosts)}):")
171
+ for v in vhosts:
172
+ ssl = " [SSL]" if v['ssl'] else ""
173
+ print(f" {v['server_name']}{ssl} -> {v['address']}")
174
+
175
+ print(f"\n Loaded Modules: {len(modules)}")
176
+
177
+ if issues:
178
+ print(f"\n Issues ({len(issues)}):")
179
+ for i in sorted(issues, key=lambda x: {'critical':0,'high':1,'warning':2,'info':3}.get(x['severity'],4)):
180
+ srv = f" ({i['server']})" if 'server' in i else ""
181
+ print(f" [{i['severity'].upper():8s}]{srv} {i['message']}")
182
+
183
+ print(f"\n{'='*60}")
184
+ print(f" More tools: https://dargslan.com")
185
+ print(f" eBooks: https://dargslan.com/books")
186
+ print(f"{'='*60}\n")
187
+
188
+
189
+ __all__ = ["ApacheAnalyzer"]
@@ -0,0 +1,33 @@
1
+ """CLI for dargslan-apache-analyzer — https://dargslan.com"""
2
+ import argparse
3
+
4
+ def main():
5
+ parser = argparse.ArgumentParser(
6
+ description="Dargslan Apache Analyzer — Apache HTTP Server config analyzer",
7
+ epilog="More tools at https://dargslan.com | eBooks: https://dargslan.com/books",
8
+ )
9
+ parser.add_argument("command", nargs="?", default="report",
10
+ choices=["report", "vhosts", "modules", "issues", "test", "json"],
11
+ help="Command (default: report)")
12
+ parser.add_argument("-c", "--config", help="Apache config path")
13
+ args = parser.parse_args()
14
+
15
+ from dargslan_apache_analyzer import ApacheAnalyzer
16
+ aa = ApacheAnalyzer(config_path=args.config)
17
+ import json
18
+
19
+ if args.command == 'report': aa.print_report()
20
+ elif args.command == 'vhosts':
21
+ for v in aa.get_vhosts():
22
+ ssl = " [SSL]" if v['ssl'] else ""
23
+ print(f" {v['server_name']}{ssl} ({v['file']})")
24
+ elif args.command == 'modules':
25
+ for m in aa.get_loaded_modules(): print(f" {m}")
26
+ elif args.command == 'issues':
27
+ for i in aa.check_security(): print(f" [{i['severity'].upper()}] {i['message']}")
28
+ elif args.command == 'test':
29
+ r = aa.test_config()
30
+ print(f" Valid: {r['valid']}\n {r['output']}")
31
+ elif args.command == 'json': print(json.dumps(aa.check_security(), indent=2))
32
+
33
+ if __name__ == "__main__": main()
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: dargslan-apache-analyzer
3
+ Version: 1.0.0
4
+ Summary: Apache HTTP Server configuration analyzer — check VirtualHosts, SSL, security modules, and common misconfigurations
5
+ Author-email: Dargslan <info@dargslan.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://dargslan.com
8
+ Project-URL: Documentation, https://dargslan.com/blog
9
+ Project-URL: Repository, https://github.com/Dargslan
10
+ Project-URL: Free Cheat Sheets, https://dargslan.com/cheat-sheets
11
+ Project-URL: Linux & DevOps Books, https://dargslan.com/books
12
+ Keywords: apache,httpd,webserver,config,ssl,security,linux,sysadmin,devops
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
19
+ Requires-Python: >=3.7
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Dynamic: license-file
23
+
24
+ # dargslan-apache-analyzer
25
+
26
+ **Apache HTTP Server Configuration Analyzer** — Check VirtualHosts, SSL, security modules, ServerTokens, directory listing, and common misconfigurations. Zero external dependencies.
27
+
28
+ [![PyPI version](https://img.shields.io/pypi/v/dargslan-apache-analyzer)](https://pypi.org/project/dargslan-apache-analyzer/)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install dargslan-apache-analyzer
35
+ ```
36
+
37
+ ## CLI Usage
38
+
39
+ ```bash
40
+ dargslan-apache report # Full analysis report
41
+ dargslan-apache vhosts # List VirtualHosts
42
+ dargslan-apache modules # Loaded modules
43
+ dargslan-apache issues # Security issues
44
+ dargslan-apache test # Config syntax test
45
+ dargslan-apache json # JSON output
46
+ ```
47
+
48
+ ## Python API
49
+
50
+ ```python
51
+ from dargslan_apache_analyzer import ApacheAnalyzer
52
+ aa = ApacheAnalyzer()
53
+ vhosts = aa.get_vhosts()
54
+ issues = aa.check_security()
55
+ aa.print_report()
56
+ ```
57
+
58
+ ## More from Dargslan
59
+
60
+ - [Dargslan.com](https://dargslan.com) — Linux & DevOps eBook Store
61
+ - [Free Cheat Sheets](https://dargslan.com/cheat-sheets)
62
+ - [Blog & Tutorials](https://dargslan.com/blog)
63
+
64
+ ## License
65
+
66
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ dargslan_apache_analyzer/__init__.py
5
+ dargslan_apache_analyzer/cli.py
6
+ dargslan_apache_analyzer.egg-info/PKG-INFO
7
+ dargslan_apache_analyzer.egg-info/SOURCES.txt
8
+ dargslan_apache_analyzer.egg-info/dependency_links.txt
9
+ dargslan_apache_analyzer.egg-info/entry_points.txt
10
+ dargslan_apache_analyzer.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ dargslan-apache = dargslan_apache_analyzer.cli:main
@@ -0,0 +1 @@
1
+ dargslan_apache_analyzer
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dargslan-apache-analyzer"
7
+ version = "1.0.0"
8
+ description = "Apache HTTP Server configuration analyzer — check VirtualHosts, SSL, security modules, and common misconfigurations"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.7"
12
+ authors = [{name = "Dargslan", email = "info@dargslan.com"}]
13
+ keywords = ["apache", "httpd", "webserver", "config", "ssl", "security", "linux", "sysadmin", "devops"]
14
+ classifiers = [
15
+ "Development Status :: 5 - Production/Stable",
16
+ "Intended Audience :: System Administrators",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: POSIX :: Linux",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: Internet :: WWW/HTTP :: HTTP Servers",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://dargslan.com"
25
+ Documentation = "https://dargslan.com/blog"
26
+ Repository = "https://github.com/Dargslan"
27
+ "Free Cheat Sheets" = "https://dargslan.com/cheat-sheets"
28
+ "Linux & DevOps Books" = "https://dargslan.com/books"
29
+
30
+ [project.scripts]
31
+ dargslan-apache = "dargslan_apache_analyzer.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+