Giter Club home page Giter Club logo

cloudflare-dns-creator's Introduction

cloudflare-dns-creator

A simple PHP script to create DNS records using the Cloudflare PHP API.

Installation

You will need:

  • Cloudflare
  • Web server (PHP)
  • Domain name
git clone https://github.com/reckr/cloudflare-dns-creator.git

Alternatively, download as a ZIP-archive and extract the files to your web server. When everything is on place, running a correctly configured web server, you can begin with modifying the files.

OPTIONAL: Rename the file "htaccess.txt" to ".htaccess" to get the recommended settings for an Apache HTTP server.

include "$_SERVER[DOCUMENT_ROOT]/CloudFlare/Api.php";
include "$_SERVER[DOCUMENT_ROOT]/CloudFlare/Zone/Dns.php";

$result = "";

$key = "Your Cloudflare Zone ID goes here"; 
// Above Cloudflare Zone ID, find it in Domain Overview --> Domain Summary --> Zone ID
$id = new \Cloudflare\Api("Your Cloudflare Email", "Your Cloudflare Global API Key");
// Above Cloudflare Email + Cloudflare Global API Key (https://www.cloudflare.com/a/profile) --> Global API Key
$dns = new \Cloudflare\Zone\Dns($id);

if(!empty($_POST["name"]) and !empty($_POST["value"]) and !empty($_POST["record"])) {
    $response = $dns->create($key, $_POST["record"], $_POST["name"] . ".yourdomain.name", $_POST["value"], 1);
    // Make sure to enter your domain name above (.yourdomain.name), or else the script won't work
    if ($response->success) {
        $result = '<div class="toast toast-success" style="margin: 0 auto; width:714px;text-align: center;"><b>Success!</b> Your hostname <b>' . $_POST['name'] . '.yourdomain.name</b> is now online!</div>';
    } else {
        $result = '<div class="toast toast-error" style="margin: 0 auto; width:714px;text-align: center;"><b>Sorry!</b> Your hostname <b>' . $_POST['name'] . '.yourdomain.name</b> could not be created!</div>';
    }
    
}

In the "index.php" file (code snippet above), make sure to edit the the $key = "Your Cloudflare Zone ID goes here"; and $id = new \Cloudflare\Api("Your Cloudflare Email", "Your Cloudflare Global API Key"). There are comments below each one of these lines, if you need help with finding your Cloudflare keys. Also make sure to replace all entries of yourdomain.name with your actual domain name.

Made using …

License

MIT License — see the LICENSE.md for more details.

cloudflare-dns-creator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.