<?php
	class MassImportComponent extends Component {
		function GetUUIDs() {
			$uuids[] = 'admin\/massimport$';
			return $uuids;
		}

		function Run($page, $matches) {
		        if (!_hasflag(FLAG_MASSIMPORT)) {
        		        header("Location: /admin");
				die();
			}

		        _page_header(SITE_NAME." :: Admin :: Database Import Tool");

			if (!isset($_REQUEST['ipdata']))
			{
?>
<a href="/">home</a> / <a href="/admin">administrate</a> / database import tool
<h2>Database Import Tool</h2>
<p>
	This form will allow you to import IP data into <?=SITE_NAME?>. The syntax is a list of IPs, with a class definition above each group of IPs you wish to import, 
	an example is below:
</p>
<p>
	<pre>
		:1:Testing data
		127.0.0.2
		127.0.0.3
		192.168.0.1

		:8:Open Socks Proxy
		213.35.21.27
	</pre>
</p>
<p>
	It is imperative that this format be used, other formats will be rejected, or result in invalid importations. Class definitions must be used or they will be placed 
	in an undefined class, which is undesirable.
</p>
<h3>Import data</h3>
<form method="post" action="/admin/mass_import">
	<table>
		<tr>
			<td><textarea cols="50" rows="15" name="ipdata"></textarea></td>
		</tr>
		<tr>
			<td align="right"><input type="submit" value="Import IPs"></td>
		</tr>
	</table>
</form>
<?php
			}
			else
			{
?>
<pre>
<?php
				$fp = fopen("/tmp/dronebl_socks.txt", "w");
				fwrite($fp, $_REQUEST['ipdata']);
				fclose($fp);

				echo `/usr/bin/dos2unix /tmp/dronebl_socks.txt && /bin/cat /tmp/dronebl_socks.txt | /usr/bin/perl importer.pl`;
				unlink("/tmp/dronebl_socks.txt");
?>
</pre>
<?php
			}
			_page_footer();
		}
	};
	new MassImportComponent;
?>
