<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Misc extends MY_Controller
{
	public function __construct()
	{
		parent::__construct();
	}

	public function safe_redirect()
	{
		$url = $this->input->get('url');
		$is_url_valid = filter_var(base64_decode($url), FILTER_VALIDATE_URL);
		if (!$is_url_valid) {
			show_404();
		} else {
			$data['url'] = base64_decode($url);
			$data['host'] = parse_url($data['url'])['host'];
			// All our domains
			$domains = ['yggtorrent.top','ygg.re', 'yggtorrent.cool', 'yggtorrent.qa', 'yggtorrent.gg', 'yggtorrent.lol', 'yggtorrent.to', 'yggtorrent.is', 'yggtracker.org', 'ygg.is', 'marmota.tv', 'ygg.to', 'yggtorrent.ch', 'yggtorrent.pe', 'yggtorrent.ws', 'yggtorrent.se', 'yggtorrent.si', 'yggtorrent.li', 'yggtorrent.nz', 'yggtorrent.re', 'yggtorrent.la', 'yggtorrent.fi', 'yggtorrent.do', 'yggtorrent.wtf'];
			preg_match('/[^\.\/]+\.[^\.\/]+$/', $data['host'], $matches);
			if (in_array($matches[0], $domains)) {
				//echo $matches[0];
				redirect($data['url']);
			} else {
				//echo $matches[0];
				$this->load->view('misc/redirect_url', $data);
			}
		}
	}


}
