Search by

nawasara / cloudflare

pringgojsnawasara

Cloudflare management dashboard for Nawasara — DNS records, zones, firewall rules, page rules, SSL settings, and analytics, with DB-cached snapshots and queue-backed mutations.

Package info

github.com/nawasara/cloudflare

pkg:composer/nawasara/cloudflare

Statistics

Installs: 443

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.3.6 2026-11-30 02:56 UTC

This package is auto-updated.

Last update: 2026-11-30 02:58:11 UTC


README

Cloudflare management dashboard for the Nawasara superapp framework. It covers DNS records, zones, firewall rules, page rules, SSL settings, cache, and analytics, all read from a local DB snapshot for speed and mutated through queue jobs for auditability.

Features

  • Zone management: list domains with SSL mode, security level, plan, name servers, and per-zone settings
  • DNS records: full CRUD across A, AAAA, CNAME, MX, TXT, NS, and SRV types, with comment and tags preserved on update
  • Firewall rules: CRUD WAF custom rules per zone
  • Page rules: CRUD URL-pattern rules
  • Analytics: request volume, bandwidth, threats blocked, and unique visitors with per-OPD rollup
  • Cache purge: purge the entire cache or specific URLs
  • Under Attack mode: toggle the security level when a zone is under DDoS pressure
  • Sync info bar on every page showing the last successful sync time, pending mutation count, and a link to the audit log

The package follows the DB-cache plus queue pattern from nawasara/sync: reads come from local snapshot tables (paginated, fast); writes dispatch queue jobs that update Cloudflare and the snapshot via content-hash conflict detection.

Installation

composer require nawasara/cloudflare
php artisan migrate
php artisan db:seed --class="Nawasara\Cloudflare\Database\Seeders\PermissionSeeder" --force

The package is auto-discovered by Laravel, so no manual provider registration is required.

Cloudflare API Token Setup

1. Sign in to the Cloudflare dashboard

Go to dash.cloudflare.com and sign in to the account that manages your domains.

2. Open the API Tokens page

Click your profile icon (top right) → My Profile → API Tokens tab.

3. Create a custom token

Click Create Token, then choose Create Custom Token at the bottom of the templates list.

4. Configure permissions

Name the token (e.g. Nawasara Dashboard) and add the following permissions depending on which features you plan to use:

Permission Access Used for
Zone → Zone Read List zones, zone detail
Zone → Zone Settings Edit SSL mode, security level, Under Attack mode
Zone → DNS Edit CRUD DNS records
Zone → Firewall Services Edit CRUD firewall rules
Zone → Analytics Read Dashboard analytics
Zone → Cache Purge Purge Cache purge (all / per URL)

Edit permission already implies Read, so there's no need to add Read separately for DNS, Firewall, or Zone Settings.

5. Zone Resources

Choose the scope:

  • All zones: the token can access every domain in the account
  • Specific zone: restrict to one or a few domains (recommended if you only manage a subset)

6. (Optional) IP Address Filtering

If your Nawasara server has a static IP, add Client IP Address Filtering → Is in and enter the IP. This protects against the token being used from anywhere else if it leaks.

7. (Optional) Token lifetime

Set Start Date and End Date for a temporary token. Leave blank for a permanent one.

8. Create the token

Click Continue to summary, review, then Create Token.

Copy the displayed token immediately, because Cloudflare only shows it once.

9. Note the Account ID

Find your Account ID:

  • Open any zone's Overview page
  • The Account ID is in the right sidebar under API

Or read it from any dashboard URL: dash.cloudflare.com/{ACCOUNT_ID}/...

Storing credentials in Vault

  1. Open Nawasara → /nawasara-vault
  2. Choose the Cloudflare group
  3. Fill in:
    • API Token: paste the token from step 8
    • Account ID: from step 9
  4. Save

The package picks up credentials from Vault automatically.

Verification

Open Cloudflare → Zones in the sidebar. Your domain list should appear after the first sync.

If it doesn't, check:

  • The token is pasted exactly (no leading or trailing whitespace)
  • Account ID matches the destination account
  • Token permissions include every feature you want to use
  • Zone Resources includes the domains you intend to manage

Registry asset and PIC

Every A, AAAA, and CNAME record below the zone apex is a subdomain asset in nawasara/registry. The OPD and penanggung jawab chosen in the DNS form are put on that asset (DnsAssetPic): on create by CreateCloudflareDnsRecordJob right after Cloudflare returns the record id, on edit directly.

  • Before 30 November 2026 the form dropped both fields. save() never read them, and the asset only appeared at the next registry sync with the zone's defaults, so new subdomains had no PIC. Don't move the PIC step back into the registry sync.
  • The primary PIC goes through PicAssignmentService, the registry's only way to appoint one (it refreshes SIMAS employment and membership). SIMAS being unreachable does not block a DNS record: the OPD chosen here is used.
  • The create job is never retried ($tries = 1). Cloudflare accepts two A records with one name, so a retry after anything that failed past the Cloudflare call would publish the record twice. The local copy and the registry link are best effort after that call: a failure is logged (cloudflare.dns.local_copy.failed, cloudflare.dns.asset_link.failed), the next DNS sync writes the copy, and an admin sets the PIC.
  • Only a changed penanggung jawab must be a member of the chosen OPD. One inherited from the zone often is not, and must not stop staff from editing a record's content.

API (nawasara/api token)

Scopes are registered as cloudflare.dns.read and cloudflare.dns.write. Both endpoints share a limit of 30 calls per minute per token, because each one is a live Cloudflare call.

GET /api/v1/cloudflare/dns/availability?zone=ponorogo.go.id&name=sipd (cloudflare.dns.read)

{ "data": { "zone": "ponorogo.go.id", "name": "sipd.ponorogo.go.id", "available": false, "reason": "dns_record_exists" } }

reason is dns_record_exists, registry_asset_exists, or null. name may be a label or a full name; the zone apex and wildcards are refused (invalid_name, 422).

  • Asked of Cloudflare live, not of the synced copy. The copy can be minutes behind, and "available" for a name someone just took would promise one address to two OPDs.
  • A failed Cloudflare call is 503 cloudflare_unavailable, never available: true. findDnsRecordsByName() throws instead of returning an empty list for that reason.
  • Any record type makes a name taken, and so does an active registry asset with that name (a subdomain can be reserved for an OPD before it has DNS).

POST /api/v1/cloudflare/dns (cloudflare.dns.write)

{
  "zone": "ponorogo.go.id", "name": "sipd", "type": "A", "content": "103.109.206.10",
  "ttl": 1, "proxied": true, "comment": "SIPD Bappeda", "tags": ["opd:bappeda"],
  "opd_code": "BAPPEDA", "pic_nip": "199001012015011001", "backup_nips": ["199202022016021002"]
}

Answers 201 with the record and its registry owner (opd, pic, backup_pics as NIP and name), and meta.pic_applied. Errors are { "error": code, "message": text }: validation_failed (with errors), unknown_fields, invalid_content, invalid_name, opd_not_found, pic_not_found, backup_pic_not_found (422), zone_not_found (404), name_taken, name_busy (409), cloudflare_unavailable (503), cloudflare_rejected (502). meta.pic_error is a code: simas_unavailable, pic_rejected, pic_failed, asset_missing.

  • Only A, AAAA, and CNAME: those are the types the registry tracks as subdomain assets, so only they can carry a PIC.
  • The input is checked before Cloudflare is called, so a wrong OPD code or NIP never leaves a record without an owner. PIC accounts are provisioned from the Keycloak directory only after the name is known to be free.
  • One create per name at a time. A cache lock spans the availability check, the create, and the lookup; a second caller for the same name gets name_busy.
  • SIMAS decides the PIC's OPD, not the token. The primary PIC goes through PicAssignmentService without allowWithoutSimas: when SIMAS knows the person, their OPD there wins over opd_code; when SIMAS is unreachable, the PIC is not set (simas_unavailable), because a token naming an OPD must not move someone's membership and with it their data scope in other packages.
  • A PIC failure after the record exists is reported, not rolled back (meta.pic_applied: false). Deleting a record the caller asked for is worse than a PIC an admin can set in Registry. The exception text stays in the log.
  • Contacts stay in Nawasara. The response names PICs by NIP and name only; WhatsApp, email, internal ids, notes, and ticket references are left out (DnsRecordResource).

Permissions

Permission Description
cloudflare.zone.view View zone list
cloudflare.dns.view View DNS records
cloudflare.dns.create Create a DNS record
cloudflare.dns.edit Edit a DNS record
cloudflare.dns.delete Delete a DNS record
cloudflare.waf.view View firewall rules
cloudflare.waf.create Create a firewall rule
cloudflare.waf.edit Edit a firewall rule
cloudflare.waf.delete Delete a firewall rule
cloudflare.ssl.view View SSL status
cloudflare.ssl.manage Change SSL mode
cloudflare.analytics.view View analytics
cloudflare.cache.purge Purge cache
cloudflare.ddos.view View security level
cloudflare.ddos.manage Change security level / Under Attack mode

All permissions are auto-assigned to the developer role by the seeder.

Author

Pringgo J. Saputro <odyinggo@gmail.com>

License

MIT