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.
This commit is contained in:
Erreur32 2025-03-22 20:44:02 +01:00
parent b459329429
commit da7872d823
3 changed files with 1480 additions and 1029 deletions

View file

@ -5,6 +5,7 @@ All notable changes to the npm-api.sh script will be documented in this file.
## [3.0.0] - 2025-03-15
### 🔄 Breaking Changes
- **Host Creation Command Simplified**
```diff
- 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.
The `-d` option has been removed in favor of a more intuitive positional argument after `--host-create`
### New Commands (2.8.0)
- `--access-list`: List all available access lists
- `--access-list-show <id>`: Show detailed information for a specific access list
- `--access-list-create`: Create a new access list
- `--access-list-update`: Update an existing access list
- `--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.
### Renamed Commands
- `--list-ssl-cert``--list-cert`
- `--create-user``--user-create`
- `--delete-user``--user-delete`
@ -30,11 +34,13 @@ All notable changes to the npm-api.sh script will be documented in this file.
- `--update-host``--host-update`
### Enhanced Commands
- `--generate-cert`: Added support for wildcard certificates and DNS challenges
- New parameters: `dns-provider` and `dns-api-key`
- Support for multiple DNS providers (Dynu, Cloudflare, DigitalOcean, etc.)
### Syntax Changes
- Host-related commands now consistently use the `--host-` prefix
- User-related commands now consistently use the `--user-` prefix
- 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.
* HSTS
* HSTS Subdomains
- **Enhanced Host Creation**
- Simplified command syntax with positional domain argument
- Improved parameter validation
@ -82,13 +87,20 @@ All notable changes to the npm-api.sh script will be documented in this file.
- DNS challenge management for wildcard certificates
- Support for multiple DNS providers (Cloudflare, DigitalOcean, etc.)
- New Access List Management Interface:
- Interactive access list creation
- Basic authentication support
- IP whitelist management
- Rule satisfaction options (ANY/ALL)
- **Enhanced Access List Management**:
- Detailed view for individual access lists
- Colored output for better readability
- Display of users and IP counts
- Clear visualization of allow/deny rules
- Authentication status indicators
- Satisfaction mode display (Any/All)
- Proxy host count integration
- Improved formatting and layout
- Better error handling for null values
- Comprehensive legend for status indicators
### 🛠️ Code Optimizations
- Removed redundant parameter validations
- Streamlined host creation logic
- Unified error message format
@ -103,28 +115,37 @@ All notable changes to the npm-api.sh script will be documented in this file.
- Better error handling
- Advanced configuration support
- Improved access list display with:
- Dynamic column sizing
- Proper null value handling
- Efficient data processing
- Better color management
- Enhanced table formatting
### 📚 Documentation
- Updated help messages with new command syntax
- Added more detailed examples
- Improved parameter descriptions
- Better organization of command options
- Updated access list command documentation:
- Added examples for detailed view
- Improved command descriptions
- Better parameter explanations
### 🔐 Security
- Enhanced input validation
- Better parameter sanitization
- Improved error handling for invalid inputs
### 🛠️ Fixes and Optimizations
- Fixed SSL certificate management bugs
- Improved user input validation
- Optimized API requests
- Enhanced HTTP error handling
## [2.7.0] - 2025-03-08
### Added
- DNS Challenge Support
- Added support for multiple DNS providers (Dynu, Cloudflare, DigitalOcean, etc.)
- 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.
- Enhanced certificate search to match wildcard patterns
### Changed
- Command Structure
- Modified --generate-cert command to accept DNS parameters after email:
```bash
@ -159,6 +181,7 @@ All notable changes to the npm-api.sh script will be documented in this file.
- Added clarification for supported DNS providers
### Improved
- Error Handling
- Added validation for DNS challenge parameters
- Enhanced error messages for certificate operations

View file

@ -174,7 +174,7 @@ API_PASS="changeme"
--host-ssl-enable id Enable SSL, HTTP/2, and HSTS for a proxy host
--host-ssl-disable id Disable SSL, HTTP/2, and HSTS for a proxy host
--list-ssl-cert List All SSL certificates availables (JSON)
--generate-cert domain email Generate certificate for the given domain and email
--cert-generate domain email Generate certificate for the given domain and email
--delete-cert domain Delete certificate for the given domain
--list-access List all available access lists (ID and name)
--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"
./npm-api.sh --host-create example.com -i 192.168.1.10 -p 8080
# Create host with SSL certificate and enable SSL (all-in-one)
./npm-api.sh --host-create sub.domain.com -i 192.168.0.1 -p 80 --generate-cert --host-ssl-enable -y
./npm-api.sh --host-create sub.domain.com -i 192.168.0.1 -p 80 --cert-generate --host-ssl-enable -y
# Create host with custom options
./npm-api.sh --host-create example.com -i 192.168.1.10 -p 8080 \
@ -220,11 +220,51 @@ API_PASS="changeme"
./npm-api.sh --host-show 42 # Show specific host details
🔒 SSL Management:
./npm-api.sh --list-ssl-cert # List all certificates
./npm-api.sh --generate-cert domain.com # Generate Let's Encrypt cert
./npm-api.sh --delete-cert domain.com # Delete certificate
./npm-api.sh --host-ssl-enable 42 # Enable SSL for host
./npm-api.sh --host-ssl-enable 42 33 # Enable SSL with specific cert ID
# List all certificates
./npm-api.sh --list-ssl-cert
# Generate standard Let's Encrypt certificate
./npm-api.sh --cert-generate example.com --cert-email admin@example.com
# Generate wildcard certificate with Cloudflare
./npm-api.sh --cert-generate "*.example.com" \
--cert-email admin@example.com \
--dns-provider cloudflare \
--dns-credentials '{"dns_cloudflare_email":"your@email.com","dns_cloudflare_api_key":"your_api_key"}'
# Delete certificate
./npm-api.sh --delete-cert domain.com
# Enable SSL for host
./npm-api.sh --host-ssl-enable 42
# Enable SSL with specific cert ID
./npm-api.sh --host-ssl-enable 42 33
🌟 Complete Examples with Wildcard Certificates:
# Create host with wildcard certificate using Cloudflare DNS
./npm-api.sh --host-create "*.example.com" -i 192.168.1.10 -p 8080 \
--cert-generate "*.example.com" \
--cert-email admin@example.com \
--dns-provider cloudflare \
--dns-credentials '{"dns_cloudflare_email":"your@email.com","dns_cloudflare_api_key":"your_api_key"}' \
--host-ssl-enable -y
# Same with DigitalOcean DNS
./npm-api.sh --host-create "*.example.com" -i 192.168.1.10 -p 8080 \
--cert-generate "*.example.com" \
--cert-email admin@example.com \
--dns-provider digitalocean \
--dns-credentials '{"dns_digitalocean_token":"your_token"}' \
--host-ssl-enable -y
# Same with GoDaddy DNS
./npm-api.sh --host-create "*.example.com" -i 192.168.1.10 -p 8080 \
--cert-generate "*.example.com" \
--cert-email admin@example.com \
--dns-provider godaddy \
--dns-credentials '{"dns_godaddy_key":"your_key","dns_godaddy_secret":"your_secret"}' \
--host-ssl-enable -y
🛡️ Access Control Lists:
./npm-api.sh --list-access # List all access lists
@ -249,10 +289,7 @@ API_PASS="changeme"
./npm-api.sh --update-host 42 forward_scheme=https
./npm-api.sh --update-host 42 forward_port=8443
🛡️ Custom Certificate:
./npm-api.sh --generate-cert example.com user@example.com
# Note: This will generate a Let's Encrypt certificate only
🔖 Full options:
./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}]'
```

2403
npm-api.sh

File diff suppressed because it is too large Load diff