Skip to content

Commit da7872d

Browse files
committed
fix(ssl): Prevent double SSL certificate generation
- Add exit 0 after successful certificate generation in create_or_update_proxy_host - Prevent double certificate generation when using --host-create with --cert-generate - Improve wildcard certificate handling with DNS challenge This modification resolves the issue of duplicate SSL certificate generation that could occur when using --host-create and --cert-generate options simultaneously.
1 parent b459329 commit da7872d

File tree

3 files changed

+1449
-998
lines changed

3 files changed

+1449
-998
lines changed

CHANGELOG.md

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to the npm-api.sh script will be documented in this file.
55
## [3.0.0] - 2025-03-15
66

77
### 🔄 Breaking Changes
8+
89
- **Host Creation Command Simplified**
910
```diff
1011
- OLD: ./npm-api.sh -d example.com -i 192.168.1.10 -p 8080
@@ -13,7 +14,9 @@ All notable changes to the npm-api.sh script will be documented in this file.
1314
The `-d` option has been removed in favor of a more intuitive positional argument after `--host-create`
1415

1516
### New Commands (2.8.0)
17+
1618
- `--access-list`: List all available access lists
19+
- `--access-list-show <id>`: Show detailed information for a specific access list
1720
- `--access-list-create`: Create a new access list
1821
- `--access-list-update`: Update an existing access list
1922
- `--access-list-delete`: Delete an access list
@@ -22,6 +25,7 @@ All notable changes to the npm-api.sh script will be documented in this file.
2225

2326

2427
### Renamed Commands
28+
2529
- `--list-ssl-cert``--list-cert`
2630
- `--create-user``--user-create`
2731
- `--delete-user``--user-delete`
@@ -30,11 +34,13 @@ All notable changes to the npm-api.sh script will be documented in this file.
3034
- `--update-host``--host-update`
3135

3236
### Enhanced Commands
37+
3338
- `--generate-cert`: Added support for wildcard certificates and DNS challenges
3439
- New parameters: `dns-provider` and `dns-api-key`
3540
- Support for multiple DNS providers (Dynu, Cloudflare, DigitalOcean, etc.)
3641

3742
### Syntax Changes
43+
3844
- Host-related commands now consistently use the `--host-` prefix
3945
- User-related commands now consistently use the `--user-` prefix
4046
- Certificate-related commands now consistently use the `--cert-` prefix
@@ -57,7 +63,6 @@ All notable changes to the npm-api.sh script will be documented in this file.
5763
* HSTS
5864
* HSTS Subdomains
5965

60-
6166
- **Enhanced Host Creation**
6267
- Simplified command syntax with positional domain argument
6368
- Improved parameter validation
@@ -82,13 +87,20 @@ All notable changes to the npm-api.sh script will be documented in this file.
8287
- DNS challenge management for wildcard certificates
8388
- Support for multiple DNS providers (Cloudflare, DigitalOcean, etc.)
8489

85-
- New Access List Management Interface:
86-
- Interactive access list creation
87-
- Basic authentication support
88-
- IP whitelist management
89-
- Rule satisfaction options (ANY/ALL)
90+
- **Enhanced Access List Management**:
91+
- Detailed view for individual access lists
92+
- Colored output for better readability
93+
- Display of users and IP counts
94+
- Clear visualization of allow/deny rules
95+
- Authentication status indicators
96+
- Satisfaction mode display (Any/All)
97+
- Proxy host count integration
98+
- Improved formatting and layout
99+
- Better error handling for null values
100+
- Comprehensive legend for status indicators
90101

91102
### 🛠️ Code Optimizations
103+
92104
- Removed redundant parameter validations
93105
- Streamlined host creation logic
94106
- Unified error message format
@@ -103,28 +115,37 @@ All notable changes to the npm-api.sh script will be documented in this file.
103115
- Better error handling
104116
- Advanced configuration support
105117

118+
- Improved access list display with:
119+
- Dynamic column sizing
120+
- Proper null value handling
121+
- Efficient data processing
122+
- Better color management
123+
- Enhanced table formatting
124+
106125
### 📚 Documentation
107-
- Updated help messages with new command syntax
108-
- Added more detailed examples
109-
- Improved parameter descriptions
110-
- Better organization of command options
126+
127+
- Updated access list command documentation:
128+
- Added examples for detailed view
129+
- Improved command descriptions
130+
- Better parameter explanations
111131

112132
### 🔐 Security
133+
113134
- Enhanced input validation
114135
- Better parameter sanitization
115136
- Improved error handling for invalid inputs
116137

117138
### 🛠️ Fixes and Optimizations
139+
118140
- Fixed SSL certificate management bugs
119141
- Improved user input validation
120142
- Optimized API requests
121143
- Enhanced HTTP error handling
122144

123-
124-
125145
## [2.7.0] - 2025-03-08
126146

127147
### Added
148+
128149
- DNS Challenge Support
129150
- Added support for multiple DNS providers (Dynu, Cloudflare, DigitalOcean, etc.)
130151
- Implemented automatic DNS challenge detection for wildcard certificates
@@ -142,6 +163,7 @@ All notable changes to the npm-api.sh script will be documented in this file.
142163
- Enhanced certificate search to match wildcard patterns
143164

144165
### Changed
166+
145167
- Command Structure
146168
- Modified --generate-cert command to accept DNS parameters after email:
147169
```bash
@@ -159,6 +181,7 @@ All notable changes to the npm-api.sh script will be documented in this file.
159181
- Added clarification for supported DNS providers
160182

161183
### Improved
184+
162185
- Error Handling
163186
- Added validation for DNS challenge parameters
164187
- Enhanced error messages for certificate operations

README.md

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ API_PASS="changeme"
174174
--host-ssl-enable id Enable SSL, HTTP/2, and HSTS for a proxy host
175175
--host-ssl-disable id Disable SSL, HTTP/2, and HSTS for a proxy host
176176
--list-ssl-cert List All SSL certificates availables (JSON)
177-
--generate-cert domain email Generate certificate for the given domain and email
177+
--cert-generate domain email Generate certificate for the given domain and email
178178
--delete-cert domain Delete certificate for the given domain
179179
--list-access List all available access lists (ID and name)
180180
--host-acl-enable id,access_list_id Enable ACL for a proxy host by ID with an access list ID
@@ -195,7 +195,7 @@ API_PASS="changeme"
195195
./npm-api.sh --host-create example.com -i 192.168.1.10 -p 8080
196196

197197
# Create host with SSL certificate and enable SSL (all-in-one)
198-
./npm-api.sh --host-create sub.domain.com -i 192.168.0.1 -p 80 --generate-cert --host-ssl-enable -y
198+
./npm-api.sh --host-create sub.domain.com -i 192.168.0.1 -p 80 --cert-generate --host-ssl-enable -y
199199

200200
# Create host with custom options
201201
./npm-api.sh --host-create example.com -i 192.168.1.10 -p 8080 \
@@ -220,11 +220,51 @@ API_PASS="changeme"
220220
./npm-api.sh --host-show 42 # Show specific host details
221221

222222
🔒 SSL Management:
223-
./npm-api.sh --list-ssl-cert # List all certificates
224-
./npm-api.sh --generate-cert domain.com # Generate Let's Encrypt cert
225-
./npm-api.sh --delete-cert domain.com # Delete certificate
226-
./npm-api.sh --host-ssl-enable 42 # Enable SSL for host
227-
./npm-api.sh --host-ssl-enable 42 33 # Enable SSL with specific cert ID
223+
# List all certificates
224+
./npm-api.sh --list-ssl-cert
225+
226+
# Generate standard Let's Encrypt certificate
227+
./npm-api.sh --cert-generate example.com --cert-email admin@example.com
228+
229+
# Generate wildcard certificate with Cloudflare
230+
./npm-api.sh --cert-generate "*.example.com" \
231+
--cert-email admin@example.com \
232+
--dns-provider cloudflare \
233+
--dns-credentials '{"dns_cloudflare_email":"your@email.com","dns_cloudflare_api_key":"your_api_key"}'
234+
235+
# Delete certificate
236+
./npm-api.sh --delete-cert domain.com
237+
238+
# Enable SSL for host
239+
./npm-api.sh --host-ssl-enable 42
240+
241+
# Enable SSL with specific cert ID
242+
./npm-api.sh --host-ssl-enable 42 33
243+
244+
🌟 Complete Examples with Wildcard Certificates:
245+
# Create host with wildcard certificate using Cloudflare DNS
246+
./npm-api.sh --host-create "*.example.com" -i 192.168.1.10 -p 8080 \
247+
--cert-generate "*.example.com" \
248+
--cert-email admin@example.com \
249+
--dns-provider cloudflare \
250+
--dns-credentials '{"dns_cloudflare_email":"your@email.com","dns_cloudflare_api_key":"your_api_key"}' \
251+
--host-ssl-enable -y
252+
253+
# Same with DigitalOcean DNS
254+
./npm-api.sh --host-create "*.example.com" -i 192.168.1.10 -p 8080 \
255+
--cert-generate "*.example.com" \
256+
--cert-email admin@example.com \
257+
--dns-provider digitalocean \
258+
--dns-credentials '{"dns_digitalocean_token":"your_token"}' \
259+
--host-ssl-enable -y
260+
261+
# Same with GoDaddy DNS
262+
./npm-api.sh --host-create "*.example.com" -i 192.168.1.10 -p 8080 \
263+
--cert-generate "*.example.com" \
264+
--cert-email admin@example.com \
265+
--dns-provider godaddy \
266+
--dns-credentials '{"dns_godaddy_key":"your_key","dns_godaddy_secret":"your_secret"}' \
267+
--host-ssl-enable -y
228268

229269
🛡️ Access Control Lists:
230270
./npm-api.sh --list-access # List all access lists
@@ -249,10 +289,7 @@ API_PASS="changeme"
249289
./npm-api.sh --update-host 42 forward_scheme=https
250290
./npm-api.sh --update-host 42 forward_port=8443
251291

252-
🛡️ Custom Certificate:
253-
./npm-api.sh --generate-cert example.com user@example.com
254-
# Note: This will generate a Let's Encrypt certificate only
255-
292+
256293
🔖 Full options:
257294
./npm-api.sh --host-create example.com -i 192.168.1.10 -p 8080 -f https -c true -b true -w true -a 'proxy_set_header X-Real-IP $remote_addr;' -l '[{"path":"/api","forward_host":"192.168.1.11","forward_port":8081}]'
258295
```

0 commit comments

Comments
 (0)