mirror of
				https://github.com/uklans/cache-domains
				synced 2025-11-04 08:38:52 +01:00 
			
		
		
		
	moving unbound config maiking file to plugins and adding support for cli and web
This commit is contained in:
		
							parent
							
								
									5545fb78f7
								
							
						
					
					
						commit
						016bdb45fa
					
				
							
								
								
									
										77
									
								
								scripts/plugins/unbound.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								scripts/plugins/unbound.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,77 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* Class to make unbound config file
 | 
			
		||||
*/
 | 
			
		||||
class unbound
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
    function __construct($mode)
 | 
			
		||||
    {
 | 
			
		||||
        if ($mode == "web") 
 | 
			
		||||
        {
 | 
			
		||||
            header("Content-Type: text/plain");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function make($mode, $services, $server)
 | 
			
		||||
    {
 | 
			
		||||
        /// Files - Always finde the correct path in cli
 | 
			
		||||
        $dir_path = __FILE__;
 | 
			
		||||
        $dir_path = str_replace("unbound.php", "", $dir_path);
 | 
			
		||||
        $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)) 
 | 
			
		||||
            {
 | 
			
		||||
                $output .= "# File: " . scrape_between($file, "../../", ".txt");
 | 
			
		||||
                foreach (file($file) as $key => $line) 
 | 
			
		||||
                {
 | 
			
		||||
                    $line = trim($line, " \t\n\r\0\x0B");
 | 
			
		||||
                    if (substr($line, 0,1) == "#") 
 | 
			
		||||
                    {
 | 
			
		||||
                        // Comment handling
 | 
			
		||||
                        $output .= $line;
 | 
			
		||||
                    }
 | 
			
		||||
                    elseif (substr($line, 0,1) == "*") 
 | 
			
		||||
                    {
 | 
			
		||||
                        // Wildcard handling
 | 
			
		||||
                        $line = ltrim($line, '*');
 | 
			
		||||
                        $line = ltrim($line, '.');
 | 
			
		||||
 | 
			
		||||
                        // Output for wildcard
 | 
			
		||||
                        $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 .= "# ---------------------------------------------------- #";
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        $output .= 'local-data: "' . $line . ' A ' . $server . '"';
 | 
			
		||||
                    }
 | 
			
		||||
                    $output .= PHP_EOL;
 | 
			
		||||
                }
 | 
			
		||||
                $output .= PHP_EOL;
 | 
			
		||||
                $output .= PHP_EOL;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if ($mode == "cli") 
 | 
			
		||||
        {
 | 
			
		||||
            return $output;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            echo $output;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
@ -1,55 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* Class to make unbound config file
 | 
			
		||||
*/
 | 
			
		||||
class unbound_conf
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
    function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        header("Content-Type: text/plain");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function print()
 | 
			
		||||
    {
 | 
			
		||||
        //Steamcache server ip
 | 
			
		||||
        $server = $_POST["ip"];
 | 
			
		||||
 | 
			
		||||
        $files = glob("../*.txt");
 | 
			
		||||
 | 
			
		||||
        foreach($files as $file) 
 | 
			
		||||
        {
 | 
			
		||||
            echo "# File: " . substr($file, 3);
 | 
			
		||||
            echo PHP_EOL;
 | 
			
		||||
            foreach (file($file) as $key => $value) 
 | 
			
		||||
            {
 | 
			
		||||
                $value = trim($value, " \t\n\r\0\x0B");
 | 
			
		||||
                if (substr($value, 0,1) == "#") 
 | 
			
		||||
                {
 | 
			
		||||
                    $content = $value;
 | 
			
		||||
                }
 | 
			
		||||
                elseif (substr($value, 0,1) == "*") 
 | 
			
		||||
                {
 | 
			
		||||
                    $value = ltrim($value, '*');
 | 
			
		||||
                    $value = ltrim($value, '.');
 | 
			
		||||
 | 
			
		||||
                    $content = "# ------ Wildcard replaced with local-zone data ------ #" . PHP_EOL;
 | 
			
		||||
                    $content = $content . 'local-zone: "' . $value . '" redirect' . PHP_EOL;
 | 
			
		||||
                    $content = $content . 'local-data: "' . $value . ' A ' . $server . '"' . PHP_EOL;
 | 
			
		||||
                    $content = $content . "# ---------------------------------------------------- #";
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    $content = 'local-data: "' . $value . ' A ' . $server . '"';
 | 
			
		||||
                }
 | 
			
		||||
                echo $content;
 | 
			
		||||
                echo PHP_EOL;
 | 
			
		||||
            }
 | 
			
		||||
            echo PHP_EOL;
 | 
			
		||||
            echo PHP_EOL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user