<?php
	class FrontPageComponent extends Component {
		public function GetUUIDs() {
			$uuids[] = 'index(\.do){0,1}$';
			return $uuids;
		}

		public function Run($page, $matches) {
			_page_header(SITE_NAME);
?>
<div id="main">
	<article class="head">
		<strong>What is this?</strong><br />
		<p>
			This is a synopsis of recent activity in <?=SITE_NAME?>. <?=SITE_NAME?> is a realtime monitor of abusable IPs, which has the goal of stopping abuse of infected machines.<br/><br/><a href="/docs/what">Find out more about <?=SITE_NAME?></a>.
		</p>
	</article>
	<article>
		<strong><a href="/blog">News and updates about <?=SITE_NAME?></a></strong><br />
		<ul>
<?php
			$res = get_db_rows("SELECT title, id FROM blog_posts ORDER BY time DESC LIMIT 10");
			while ($row = get_db_tuple($res))
				echo tab(3).'<li><a href="/blog/'.$row['id'].'">'.$row['title'].'</a></li>'.PHP_EOL;
?>
		</ul>
	</article>
	
	<article>
		<strong>Are you listed in <?=SITE_NAME?>?</strong><br />
		<p>Use the quick delisting process to quickly request removal from <?=SITE_NAME?>.</p>
		<form method="get" action="/lookup" id="lookup">
			<div>
				IP: <input name="ip" type="text" value="<?=USERIP?>" onclick="$('#lookup input input[type=text]').val('');" style="width:250px" />
<?php
			if( isset( $_SESSION['username'] ) )
			{
?>
				<br />ID: <input name="id" type="text" onclick="$('#lookup input[type=text]').val('');" style="width:250px" />
<?php
			}
?>
				<input type="submit" value="Go!" />
			</div>
		</form>
		<p><a href="javascript:void(0);" onclick="addsearch()">Add this search to your browser</a></p>		
	</article>
	
	<article>
		<strong><a href="/activity_log">Last 10 changes made to <?=SITE_NAME?></a></strong><br />
		<table cellpadding="0" style="width: 100%;">
			<tbody>
<?php
			$res = get_db_rows("SELECT time, reftype, description FROM activity_log ORDER BY time DESC LIMIT 10");
			$iter = 0;
			while ($row = get_db_tuple($res))
			{
				$description = str_replace( ' by <strong></strong>', '', $row['description'] );
				$ips = array();
				if( preg_match( '/([0-9a-f]+:[0-9a-f]+:[0-9a-f:]+)/i', $description, $matches) || preg_match( '/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/', $description, $matches ) )
				{
					foreach( $matches AS $match )
					{
						if( in_array( $match, $ips ) || !is_valid_ip( $match ) )
							continue;
						array_push( $ips, $match);
						$description = str_replace( $match, '<a href="/lookup?ip=' . $match . '">' . $match . '</a>', $description );
					}
				}
?>
				<tr>
					<td><?= gmdate("M-d-Y H:i:s T", $row['time']) ?></td>
					<td style="text-align: right;"><?= _activity_log_name_from_type($row['reftype']) ?></td>
				</tr>
				<tr> 
					<td style="<?=(++$iter < 10 ? 'border-bottom: 1px solid #000;':'')?>font-size: 80%;" colspan="2"><?= $description ?></td>
				</tr>
<?php
			}
?>
			</tbody>
		</table>
		<br/>
		<a href="/activity_log">View other recent changes</a>.		
	</article>
	
	<article>
		<strong><?=SITE_NAME?> resources</strong><br />
		<p>The following resources will keep you informed about <?=SITE_NAME?> activity!</p>
		<p><strong>Discussion</strong></p>
		<ul>
			<li><a href="irc://irc.dronebl.org/dronebl" rel="external"><?=SITE_NAME?> IRC Channel</a></li>
		</ul>
		<p><strong>Documentation</strong></p>
		<ul>
			<li><a href="/docs/what">What is <?=SITE_NAME?>?</a></li>
			<li><a href="/docs/howtouse">How to use <?=SITE_NAME?></a></li>
			<li><a href="/docs/faq"><?=SITE_NAME?> FAQ</a></li>
		</ul>
		<p><strong>Development</strong></p>
		<ul>
			<li><a href="/docs/rpc2"><?=SITE_NAME?> RPC2 docs</a></li>
			<li><a href="/docs/rpc"><?=SITE_NAME?> RPC docs</a></li>
		</ul>
	</article>
</div>
<?php
			_page_footer();
		}
	};

	new FrontPageComponent;
?>
