PRO: ChatGPT & DNS for SPF-Test

This pages shows you how to get the SPF-Setting of a Domain and ask ChatGPT if this setting is ok.

Step 1: Create a simple PHP-Page to ask an DNS-Server

Create a PHP-Page on your Webserver with this code:

<?php
$doin = $_GET["d"] ?? '';

function is_valid_domain_name($domain_name)
{
    return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) 
            && preg_match("/^.{1,253}$/", $domain_name) 
            && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)   ); 
}

$result = array();
if (is_valid_domain_name($doin)) {
	$result = dns_get_record($doin, DNS_ALL);
}
echo json_encode($result);
?>

The URL of this page is URL_DNS_REQUEST (you need that in Step 2). By URL_DNS_REQUEST?d=DOMAIN you get DNS-data (if dns_get_record works on your Server).

Step 2: Create a new JCI-Template

Name: spfcheck
URL:

{% set dom = "json-content-importer.com" %}{% if urlparam.d %}{% set dom = urlparam.d %}{% endif %}URL_DNS_REQUEST?d={{dom | e}}

URLParam: d
Method: CURL-GET
Curloptions: leave empty
Cachetime: 60000 (for testing – each ChatGPT requests costs ChatGPT-Token)
Timeout: 30 (give ChatGPT a bit time to answer)

Twig:

{% set dom = "json-content-importer.com" %}{% if urlparam.d %}{% set dom = urlparam.d  %}{% endif %}

<form action="/spf-check/">
    <input type=text name=d value="{{ dom | e}}" size=150>
    <br>
    <input type=submit>
</form>

<hr>
Domain: {{dom}}
{% set fno = 0 %}
<hr>
{% for i in _context %}
    {% if i.type=="TXT" %}
        {% if i.txt matches "/spf/" %}
            SPF-Setting DNS: <strong>{{i.txt}}</strong><br>
            {% set gptprompt = 'der spf-eintrag für ' ~ dom ~ ' ist \'' ~ '' ~ i.txt ~ '\'. ist dieser eintrag syntaktisch korrekt und was bedeutet er?' %}
            {#gptprompt: {{gptprompt}}<br>#}
            {% set sc = '[jsoncontentimporterpro nameoftemplate="chtgpt" param1="'~gptprompt~'"]' %}
            {#sc: {{sc}}#}
            {% set scexe = (sc | doshortcode) %}
            {% set scjson = (scexe | json_decode(TRUE)) %}
            {#scexe: {{ scjson | dump}}#}
            ChatGPT gefragt: "Ist dieser Eintrag syntaktisch korrekt und was bedeutet er?"<br>
            {{scjson.choices.0.text}}
            {% set fno = 1 %}
        {% endif %}
    {% endif %}
{% endfor %}
{% if fno==0 %}
Kein SPF-Eintrag gefunden. Wenn die Domain nicht für Mails verwendet wird, ist das ok.
{% endif %}

Step 3: Create and publish a page

URL of this page: /spf-check/ (to match the Form in the twig-template)
On this page:

[jsoncontentimporterpro nameoftemplate="spfcheck" orderofshortcodeeval=10]

Step 4: Create another JCI-Template

Name: chtgpt
URL:

https://api.openai.com/v1/completions

URLParam: q
Method: CURL-POST
Curloptions:

CURLOPT_HTTPHEADER=Authorization: Bearer YOUR_CHAT_GPT_TOKEN##Content-Type: application/json;CURLOPT_POSTFIELDS={     "model": "text-davinci-003",     "prompt": "##param1##",     "max_tokens": 700,     "temperature": 0   }  


Cachetime: 60000 (for testing – each ChatGPT requests costs ChatGPT-Token)
Timeout: 30 (give ChatGPT a bit time to answer)

Twig:

{{ _context | json_encode() }}