Skip to content

Commit

Permalink
Add new features and update README file with setup and usage instruct…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
yashodhank committed Jun 15, 2024
1 parent 9306ef6 commit 1bd007b
Show file tree
Hide file tree
Showing 2 changed files with 304 additions and 77 deletions.
253 changes: 182 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,108 +1,219 @@
# !!DO NOT USE THIS PROJECT IS IT NEVER TESTED FOR IT WORKING!!
----
# Cloudflare-Plesk-DNS-Sync

A script to synchronize ACME TXT records between Cloudflare and Plesk and provide additional DNS management automation.

# This script is still in it APLHA stage. DO NO USE IT FOR ANYTHING!
This project synchronizes ACME TXT records between Cloudflare and Plesk, renews SSL certificates, and cleans up stale DNS records. It is designed to run autonomously and can be executed either directly or within a Docker container.

## Features

- Synchronize ACME TXT records between Cloudflare and Plesk
- Automatically renew SSL certificates for Plesk domains
- Clean up stale or outdated DNS records on Cloudflare
- Monitor domain health and send alerts for any issues
- Manage domain redirection and DDoS protection settings
- Backup and restore DNS configurations
- Dynamic DNS updates for changing IP addresses
- Email notifications and detailed reports
- API integration for enhanced DNS management
- Custom DNS record management
- DNSSEC configuration and management
- Webhook integration for event-triggered automation
- Synchronizes ACME TXT records between Cloudflare and Plesk
- Automatically renews SSL certificates for Plesk domains
- Cleans up stale or outdated DNS records on Cloudflare without affecting records created or updated manually by human operators or by other automation
- Monitors domain health and sends alerts for any issues
- Manages domain redirection and DDoS protection settings
- Backs up and restores DNS configurations for autonomous operations and archiving for human-aided troubleshooting

## Installation

### Prerequisites

- Node.js (v16 or higher)
- Node.js (v16 or later)
- npm
- Docker (optional, for containerized deployment)
- Certbot (for SSL certificate renewal)

### Setup

1. Clone the repository:
```sh
cd /opt/
git clone https://github.com/yashodhank/Cloudflare-Plesk-DNS-Sync.git
cd /opt/Cloudflare-Plesk-DNS-Sync
```

```sh
git clone https://github.com/yashodhank/Cloudflare-Plesk-DNS-Sync.git
cd Cloudflare-Plesk-DNS-Sync
```

2. Install dependencies:
```sh
npm install
```

3. Run the setup script to configure your environment variables:
```sh
npm run setup
```
```sh
npm install
```

4. Build and run the Docker container (optional):
```sh
docker build -t cloudflare-plesk-dns-sync .
docker run --env-file .env cloudflare-plesk-dns-sync
```
3. Create a `.env` file based on the `.env.example`:

### Usage
```sh
cp .env.example .env
```

1. To run the DNS update process, use:
```sh
npm start
```
4. Fill in the `.env` file with your configuration details:

2. To manually run the setup again:
```sh
npm run setup
```
```env
PLESKKEY=<your-plesk-api-key>
CLOUDKEY=<your-cloudflare-api-key>
CLOUDEMAIL=<your-cloudflare-email>
CLOUDACCOUNTID=<your-cloudflare-account-id>
PLESKURL=<your-plesk-url>
EMAIL=<your-email>
SENDER=<sender-email>
SPASS=<sender-password>
HOST=<email-host>
```

3. To clean up stale DNS records:
```sh
npm run cleanup
```
## Usage

4. To renew SSL certificates:
```sh
npm run renew-ssl
```
### Running Directly

### Environment Variables
To run the DNS synchronization process directly:

The setup script will prompt you to enter the following environment variables:
```sh
node cli.js run
```

- `PLESKKEY`: Plesk API Key
- `PLESKURL`: Plesk URL
- `CLOUDKEY`: Cloudflare API Key
- `CLOUDEMAIL`: Cloudflare Email
- `CLOUDACCOUNTID`: Cloudflare Account ID
- `EMAIL`: Notification email
- `SENDER`: Sender email address
- `SPASS`: Sender email password
- `HOST`: SMTP host
To renew SSL certificates:

### Logging
```sh
node cli.js renew-ssl
```

Logs will be saved to `error.log` for errors and `combined.log` for general logs.
To clean up stale DNS records:

### Cron Job
```sh
node cli.js cleanup
```

To monitor domain health:

To run the script periodically (e.g., every night), add the following entry to your crontab:
```sh
crontab -e
node cli.js monitor-health
```
Then add:

To manage redirection and DDoS protection:

```sh
node cli.js manage-settings
```

To back up DNS configurations:

```sh
node cli.js backup
```

To restore DNS configurations:

```sh
node cli.js restore
```

### Running in Docker

#### Building the Docker Image

1. Build the Docker image:

```sh
docker build -t cloudflare-plesk-dns-sync .
```

2. Run the Docker container:

```sh
docker run --env-file .env cloudflare-plesk-dns-sync
```

#### Pulling the Docker Image from GitHub Packages

1. Authenticate to GitHub Packages:

```sh
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
```

2. Pull the Docker image:

```sh
docker pull ghcr.io/yashodhank/cloudflare-plesk-dns-sync:latest
```

3. Run the Docker container:

```sh
docker run --env-file .env ghcr.io/yashodhank/cloudflare-plesk-dns-sync:latest
```

## Testing

Run the tests using Jest:

```sh
0 3 * * * cd /opt/Cloudflare-Plesk-DNS-Sync && npm start
npm test
```

### License
## Continuous Integration

This project uses GitHub Actions for continuous integration and deployment. The workflow is defined in `.github/workflows/docker.yml` and performs the following tasks:

- Checks out the repository
- Sets up Node.js
- Installs dependencies
- Runs tests
- Builds and pushes a Docker image to GitHub Container Registry

### GitHub Actions Workflow

```yaml
name: Build, Test, and Publish Docker Image
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
push: true
tags: ghcr.io/${{ github.repository_owner }}/cloudflare-plesk-dns-sync:latest
```

## Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

## License

This project is licensed under the MIT License.
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
Loading

0 comments on commit 1bd007b

Please sign in to comment.