<?php
	class ThreatClassesComponent extends Component {
		function GetUUIDs() {
			$uuids[] = '(categories|classes)(\.do)?$';
			return $uuids;
		}

		function Run($page, $matches) {
			$res = get_db_rows("SELECT * FROM classes ORDER BY classid");
			if (isset($_REQUEST['format']))
			{
				switch ($_REQUEST['format'])
				{
					case 'txt':
						header("Content-type: text/plain");
						while ($row = get_db_tuple($res))
							echo $row['classid']."\t".$row['description']."\n";
						die();
					case 'csv':
						header("Content-type: text/csv");
						echo "\"class\",\"description\"\n";
						while ($row = get_db_tuple($res))
							echo "\"".$row['classid']."\",\"".$row['description']."\"\n";
						die();
				}
			}

			_page_header(SITE_NAME." :: Threat classes");
?>
<h2>Table of <?=SITE_NAME?> threat classes</h2>
<p>This is the list of classes under which a nefarious / compromised host can be categorized.
This list is also available <a href="?format=txt" rel="external">in plain text</a> or <a href="?format=csv" rel="external">as CSV</a> for scripting purposes.</p>
<table class="listing">
	<thead>
		<tr>
			<th>Id</th>
			<th>Description</th>
		</tr>
	</thead>
	<tbody>
<?php
			while ($row = get_db_tuple($res))
			{
?>
		<tr>
			<td align="right"><?= $row['classid'] ?></td>
			<td align="left"><?= $row['description'] ?></td>
		</tr>
<?php
			}
?>
	</tbody>
</table>
<?php
			_page_footer();
		}
	};

	new ThreatClassesComponent;
?>
