Pastebin

cloudflare zone id

cloudflare zone id from Pastebin

Cloudflare zone id Pastebin Cloudflare zone identifier paste Cloudflare zone id获取 details Get cloudflare zone id code Cloudflare api zone identifier snippet Cloudflare get zone id api text Cloudfl
    
        key = new \Cloudflare\API\Auth\APIKey('loginemail', 'apitoken');
        $this->adapter = new Cloudflare\API\Adapter\Guzzle($this->key);
        $this->user = new \Cloudflare\API\Endpoints\User($this->adapter);
        $this->zones = new \Cloudflare\API\Endpoints\Zones($this->adapter);
    }

    public function getUserID()
    {
        return $this->user->getUserID();
    }


/**
 * Imported methods from other project;
 */
    public function listzones()
    {
        $zones = array();
        foreach ($this->zones->listZones()->result as $zone) {
            $zones[$zone->name] = $zone->plan->name;
        }
        return $zones;
    }

    /**
     * return string
     * ex: Cache purge for zone: successful | failed
     */

    public function cachepurge()
    {
        $resultdata = array();

        foreach ($this->zones->listZones()->result as $zone) {
            //echo "Cache purge for " . $zone->name . ": ";
            $resultdata[ $this->zones->cachePurgeEverything($zone->id) == true ? "successful" : "failed"][] = $zone->name;
            return $resultdata;
        }
    }

    /**
     * Creating Page Rules (kimaradt, nézz utána)
     */
    
    /**
     * add dns records
     * param string zoneid ex: zone
     * param string TYPE ex:A, CNAME
     * param string name (subdomain name)
     * param string content ex: zone
     * param int TTL 0|1
     * param bool proxied
     */

    public function addrecord($zone_id = '', $type = '', $name = '', $content = '', $ttl = 1, $proxied = true)
    {
        $resultdata = array();
        $zoneID = $this->zones->getZoneID($zone_id);
        $dns = new \Cloudflare\API\Endpoints\DNS($this->adapter);
        $resultdata[ $dns->addRecord($zoneID, $type, $name, $content, $ttl, $proxied)? "successful" : "failed"][] = $name.$zone_id;
        return $resultdata;
    }

    /**
     * Return string  (record identification)
     * param string domain
     * param type ex: A, CNAME, TXT
     * return string
     */
    public function getrecordid(string $zone_id = '', string $type = '', string $name = '')
    {
        $zoneID = $this->zones->getZoneID($zone_id, $type, $name);

        $dns = new \Cloudflare\API\Endpoints\DNS($this->adapter);

        foreach ($dns->listRecords($zoneID, $type, $name.'.'.$zone_id)->result as $record)
        {
            return $record->id;
        }
    }

    public function delrecord($zone_id = '', $recordID = '')
    {
        $zoneID = $this->zones->getZoneID($zone_id);
        $recordID = $this->getrecordid();

        try {
            $user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID);

            $this->body = json_decode($user->getBody());

            if (isset($this->body->result->id)) {
                echo "TÖRÖLVE";
                return true;
            }
            echo "Nincs törölve";

            return false;
        } catch (Exception $e) {
            echo $e->getmessage();
        }
    }

}