mirror of
https://github.com/uklans/cache-domains
synced 2025-06-19 07:52:56 +02:00
adding a template file to help add support for more dns services, and by default support cli and web mode, but it is not total automatic, procect for code injection.
This commit is contained in:
parent
0dedf64140
commit
b718d19651
114
scripts/plugins/template.php
Normal file
114
scripts/plugins/template.php
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template class to support new dns services
|
||||||
|
/ There are 5 places to change data
|
||||||
|
*/
|
||||||
|
class template
|
||||||
|
{
|
||||||
|
|
||||||
|
function __construct($mode)
|
||||||
|
{
|
||||||
|
if ($mode != "cli")
|
||||||
|
{
|
||||||
|
header("Content-Type: text/plain");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function make($mode, $services, $server)
|
||||||
|
{
|
||||||
|
/// Files - Always finde the correct path in cli
|
||||||
|
$dir_path = __FILE__;
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change below me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
$dir_path = str_replace("template.php", "", $dir_path); // Change template.php to the corrent file name of the new file
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change above me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
$files = glob($dir_path . "../../*.txt");
|
||||||
|
|
||||||
|
foreach ($services as $key => $service)
|
||||||
|
{
|
||||||
|
$services[$key] = scrape_between($service, "../../", ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = "";
|
||||||
|
|
||||||
|
foreach($files as $file)
|
||||||
|
{
|
||||||
|
if (in_array(scrape_between($file, "../../", ".txt"), $services))
|
||||||
|
{
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change below me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change the # to match comments in youre services (default # starts comment if not changed)
|
||||||
|
$output .= "# File: " . scrape_between($file, "../../", ".txt");
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change above me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
$output .= PHP_EOL;
|
||||||
|
foreach (file($file) as $key => $line)
|
||||||
|
{
|
||||||
|
$line = trim($line, " \t\n\r\0\x0B");
|
||||||
|
if (substr($line, 0,1) == "#")
|
||||||
|
{
|
||||||
|
// Comment handling
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change below me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
$output .= $line; // Change this to match comments in youre services (default # starts comment if not changed)
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change above me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
}
|
||||||
|
elseif (substr($line, 0,1) == "*")
|
||||||
|
{
|
||||||
|
// Wildcard handling change to match services
|
||||||
|
// Output for wildcard
|
||||||
|
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change below me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
$line = ltrim($line, '*'); // Removing the * in the line
|
||||||
|
$line = ltrim($line, '.'); // Removing the . in the line
|
||||||
|
|
||||||
|
// Append to the output file
|
||||||
|
// line is the corrent line in the file (domainname)
|
||||||
|
$output .= "# ------ Wildcard replaced with local-zone data ------ #" . PHP_EOL;
|
||||||
|
$output .= 'local-zone: "' . $line . '" redirect' . PHP_EOL;
|
||||||
|
$output .= 'local-data: "' . $line . ' A ' . $server . '"' . PHP_EOL;
|
||||||
|
$output .= "# ---------------------------------------------------- #";
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change above me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Single domain handling
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change below me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
$output .= 'local-data: "' . $line . ' A ' . $server . '"';
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
// Change above me
|
||||||
|
// ----------------------------------------------------------
|
||||||
|
}
|
||||||
|
$output .= PHP_EOL;
|
||||||
|
}
|
||||||
|
$output .= PHP_EOL;
|
||||||
|
$output .= PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($mode == "cli")
|
||||||
|
{
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo $output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue
Block a user