Example #1
0
global $config;
// traverse captive portal zones
$configObj = Config::getInstance()->object();
if (isset($configObj->OPNsense->captiveportal->zones)) {
    foreach ($configObj->OPNsense->captiveportal->zones->children() as $zone) {
        $cert_refid = (string) $zone->certificate;
        $zone_id = (string) $zone->zoneid;
        // if the zone has a certificate attached, search for its contents
        if ($cert_refid != "") {
            foreach ($configObj->cert as $cert) {
                if ($cert_refid == (string) $cert->refid) {
                    // generate cert pem file
                    $pem_content = str_replace("\n\n", "\n", str_replace("\r", "", base64_decode((string) $cert->crt)));
                    $pem_content .= str_replace("\n\n", "\n", str_replace("\r", "", base64_decode((string) $cert->prv)));
                    $output_pem_filename = "/var/etc/cert-cp-zone" . $zone_id . ".pem";
                    file_put_contents($output_pem_filename, $pem_content);
                    chmod($output_pem_filename, 0600);
                    echo "certificate generated " . $output_pem_filename . "\n";
                    // generate ca pem file
                    if (!empty($cert->caref)) {
                        $output_pem_filename = "/var/etc/ca-cp-zone" . $zone_id . ".pem";
                        $ca = str_replace("\n\n", "\n", str_replace("\r", "", ca_chain($cert)));
                        file_put_contents($output_pem_filename, $pem_content);
                        chmod($output_pem_filename, 0600);
                        echo "certificate generated " . $output_pem_filename . "\n";
                    }
                }
            }
        }
    }
}
Example #2
0
global $config;
// traverse captive portal zones
$configObj = Config::getInstance()->object();
if (isset($configObj->OPNsense->captiveportal->zones)) {
    foreach ($configObj->OPNsense->captiveportal->zones->children() as $zone) {
        $cert_refid = (string) $zone->certificate;
        $zone_id = (string) $zone->zoneid;
        // if the zone has a certificate attached, search for its contents
        if ($cert_refid != "") {
            foreach ($configObj->cert as $cert) {
                if ($cert_refid == (string) $cert->refid) {
                    // generate cert pem file
                    $pem_content = str_replace("\n\n", "\n", str_replace("\r", "", base64_decode((string) $cert->crt)));
                    $pem_content .= str_replace("\n\n", "\n", str_replace("\r", "", base64_decode((string) $cert->prv)));
                    $output_pem_filename = "/var/etc/cert-cp-zone" . $zone_id . ".pem";
                    file_put_contents($output_pem_filename, $pem_content);
                    chmod($output_pem_filename, 0600);
                    echo "certificate generated " . $output_pem_filename . "\n";
                    // generate ca pem file
                    if (!empty($cert->caref)) {
                        $output_pem_filename = "/var/etc/ca-cp-zone" . $zone_id . ".pem";
                        $ca = ca_chain($cert);
                        file_put_contents($output_pem_filename, $pem_content);
                        chmod($output_pem_filename, 0600);
                        echo "certificate generated " . $output_pem_filename . "\n";
                    }
                }
            }
        }
    }
}