Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gitlab-cloudflare-ddns
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public
gitlab-cloudflare-ddns
Commits
e808f6ae
Commit
e808f6ae
authored
4 years ago
by
Dean Lovett
Browse files
Options
Downloads
Patches
Plain Diff
Initial Commit
parent
3a8466cb
No related branches found
No related tags found
No related merge requests found
Pipeline
#9076
canceled
4 years ago
Stage: build
Stage: test
Stage: production
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Dockerfile
+9
-0
9 additions, 0 deletions
Dockerfile
cloudflare.sh
+65
-0
65 additions, 0 deletions
cloudflare.sh
with
74 additions
and
0 deletions
Dockerfile
0 → 100644
+
9
−
0
View file @
e808f6ae
FROM
alpine
RUN
apk add
--no-cache
jq curl bind-tools
COPY
--chown=root:root . ./
ENV
CF_API=https://api.cloudflare.com/client/v4
CMD
sh ./cloudflare.sh
\ No newline at end of file
This diff is collapsed.
Click to expand it.
cloudflare.sh
0 → 100755
+
65
−
0
View file @
e808f6ae
#!/usr/bin/with-contenv sh
cloudflare
()
{
curl
-sSL
\
-H
"Accept: application/json"
\
-H
"Authorization: Bearer
$API_KEY
"
\
-H
"Content-Type:application/json"
\
"
$@
"
}
verifyToken
()
{
cloudflare
-o
/dev/null
"
$CF_API
"
/user/tokens/verify
}
getZoneId
()
{
Result
=
$(
cloudflare
"
$CF_API
/zones?name=
$ZONE
"
)
echo
$Result
| jq
-rc
'.result[0].id'
}
getDnsRecordName
()
{
if
[
!
-z
"
$SUBDOMAIN
"
]
;
then
echo
$SUBDOMAIN
.
$ZONE
else
echo
$ZONE
fi
}
getDnsRecordId
()
{
cloudflare
"
$CF_API
/zones/
$1
/dns_records?type=
$RRTYPE
&name=
$2
"
| jq
-r
'.result[0].id'
}
createDnsRecord
()
{
cloudflare
-X
POST
-d
"{
\"
type
\"
:
\"
$RRTYPE
\"
,
\"
name
\"
:
\"
$2
\"
,
\"
content
\"
:
\"
$3
\"
,
\"
proxied
\"
:true,
\"
ttl
\"
:1 }"
"
$CF_API
/zones/
$1
/dns_records"
| jq
-r
'.result.id'
}
updateDnsRecord
()
{
cloudflare
-X
PATCH
-d
"{
\"
type
\"
:
\"
$RRTYPE
\"
,
\"
name
\"
:
\"
$3
\"
,
\"
content
\"
:
\"
$4
\"
,
\"
proxied
\"
:true,
\"
ttl
\"
:1 }"
"
$CF_API
/zones/
$1
/dns_records/
$2
"
| jq
-r
'.result.id'
}
echo
"Verifying token..."
verifyToken
echo
"Token verified!"
echo
"Retreiving Zone ID..."
CFZoneId
=
$(
getZoneId
)
echo
"Zone ID found:
$CFZoneId
"
echo
"Finding DNS record..."
CFDnsRecordName
=
$(
getDnsRecordName
)
CFDnsRecordId
=
$(
getDnsRecordId
$CFZoneId
$CFDnsRecordName
)
echo
$CFDnsRecordId
if
[
"
$CFDnsRecordId
"
!=
"null"
]
;
then
echo
"DNS Record found:
$CFDnsRecordId
, updating..."
CFDnsRecordId
=
$(
updateDnsRecord
$CFZoneId
$CFDnsRecordId
$CFDnsRecordName
$IP_ADDRESS
)
echo
"Updated DNS Record:
$CFDnsRecordId
"
else
echo
"No DNS Record for
$CFDnsRecordName
, creating..."
CFDnsRecordId
=
$(
createDnsRecord
$CFZoneId
$CFDnsRecordName
$IP_ADDRESS
)
echo
$CFDnsRecordId
echo
"Created DNS Record:
$CFDnsRecordId
"
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment