<?php
$pgtitle = "Services: strikeback - Settings";
	//	TomSchaefer.org strikeback package 2011
	//
	//	Notes: Find: ^(.*)$
	//		Replace: ob_start();\n$results = exec("cat countries.txt | grep XX");\nob_end_clean();\n\tif ($results == 'XX')\n\t\techo "\1";\n\telse\n\t\techo "\1";\n
	//
	//
	//
	//
	//require_once('config.inc');
	require("guiconfig.inc");
	include("head.inc");

	//set the config as a global variable
	global $config;

	$global_usage = '/usr/local/www/packages/countryblock/global_usage';
	//$fh = fopen($global_usage, 'r');

	//phpinfo();
	
	/* read DB into array */
function strikeback_read_db() {
		global $g;

		$sbdb = array();

		$sbdblck = lock('strikebackdb');
		$fd = @fopen("{$g['vardb_path']}/strikeback.db", "r");
		if ($fd) {
			while (!feof($fd)) {
				$line = trim(fgets($fd));
				if ($line) 
						$sbdb[] = explode(",", $line);
			}
			fclose($fd);
		}
		unlock($sbdblck);
		return $sbdb;
}

/* write DB */
function strikeback_write_db($sbdb) {
		global $g;

		$sbdblck = lock('strikebackdb', LOCK_EX);
		$fd = @fopen("{$g['vardb_path']}/strikeback.db", "w");
		if ($fd) {
			//foreach ($sbdb as $cpent) {
					//fwrite($fd, join(",", $cpent) . "\n");
					fwrite($fd, join(",", $sbdb) . "\n");
			//}
			fclose($fd);
		}
	unlock($sbdblck);
}
	
?>
<head>
<script type="text/javascript" src="http://jscolor.com/jscolor/jscolor.js"></script>

</head>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>

<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>
<form method=POST action="">

<?php if ($savemsg_cb) print_info_box($savemsg_cb); 
		//if ($output) print_info_box($output,$output2);
		echo($output);
		echo($output2);
	?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr><td class="tabnavtbl">
<?php
	$tab_array = array();
	$tab_array[0] = array("Log Viewer", false, "strikeback.php");
	$tab_array[1] = array("Settings", true, "settings.php");
	
	$tab_array[4] = array("Help", false, "help.php");
	//$tab_array[5] = array("Email", false, "email.php");
	$tab_array[6] = array("Results", false, "parse.php\" target=\"_blank\"");
	display_top_tabs($tab_array);
?>  
  </td></tr>
  
  <tr> 
    <td>
	<div id="mainarea">
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
       <tr> 
	<td class="listhdrr">Settings</td>
    
	  </tr>
      
    <tr> 
	<td class="listlr" valign="middle">
    
<?php

conf_mount_rw();



	if(isset($_POST['formSubmit'])) 
    {
		
		if(isset($_POST["log_ip"])) {
			$var_log_ip = "set log_ip true";	
		}else{
			$var_log_ip = "set log_ip false";
		}
		if(isset($_POST["ignore_dns"])) {
			$var_ignore_dns = "set ignore_dns";	
		}else{
			$var_ignore_dns = "# set ignore_dns";
		}
		if(isset($_POST["ignore_80"])) {
			$var_ignore_80 = "ignore tcp dport 80";	
		}else{
			$var_ignore_80 = "# ignore tcp dport 80";
		}
		if(isset($_POST["ignore_ICMP"])) {
			$var_ignore_ICMP = "ignore icmp type unreach \n ignore icmp type !echo";	
		}else{
			$var_ignore_ICMP = "# ignore icmp type unreach \n # ignore icmp type !echo";
		}
		$sbdbpost = array($_POST["https_color"],$_POST["imaps_color"],$_POST["ftp_color"],$_POST["submission_color"],$_POST["auth_color"],$_POST["netbios-ssn_color"],$_POST["smtp_color"],$_POST["pop3_color"],$_POST["telnet_color"],$_POST["blackjack_color"],$_POST["rap_color"],$_POST["rdp_color"],$_POST["portscan_color"],$_POST["dgram_color"],$_POST["ssh_color"],$_POST["runas"],$_POST["runasgrp"],$var_log_ip,$var_ignore_dns,$_POST["ignore_dns_sev1"],$_POST["ignore_dns_sev2"],$_POST["ignore_dns_sev3"],$var_ignore_80,$var_ignore_ICMP);
		
		strikeback_write_db($sbdbpost);
		
		//write settings file
		mwexec('touch /usr/local/etc/iplog.conf');
		$fp = fopen('/usr/local/etc/iplog.conf', 'w');
		//fwrite($fp, '/*'."\n".'** $Id: example-iplog.conf,v 1.2 2000/12/31 18:40:40 odin Exp $'."\n".'**'."\n".'** Example iplog configuration file.'."\n".'** Edit me and copy me to'."\n".'/usr/local/etc/iplog.conf'."\n".'**'."\n".'** See iplog.conf(5) for details on syntax and a full description'."\n".'** of available options.'."\n".'*/'."\n".'');
		fwrite($fp, 'user '.$_POST["runas"]."\n");
		fwrite($fp, 'group '.$_POST["runasgrp"]."\n");
		fwrite($fp, 'pid-file /var/run/iplog/iplog.pid'."\n");
		fwrite($fp, 'logfile /var/log/iplog'."\n".'facility log_daemon'."\n".'priority log_info'."\n");
		fwrite($fp, $var_log_ip."\n");
		fwrite($fp, 'set log_dest false'."\n");
		fwrite($fp, $var_ignore_dns."\n");
		fwrite($fp, 'ignore udp from '.$_POST["ignore_dns_sev1"].' sport 53'."\n");
		fwrite($fp, 'ignore udp from '.$_POST["ignore_dns_sev2"].' sport 53'."\n");
		fwrite($fp, 'ignore udp from '.$_POST["ignore_dns_sev3"].' sport 53'."\n");
		fwrite($fp, 'log tcp dport 1045:1055 sport ftp-data'."\n");
		fwrite($fp, 'ignore tcp dport 1024: sport 20'."\n");
		fwrite($fp, $var_ignore_80."\n");
		fwrite($fp, $var_ignore_ICMP."\n");
		fwrite($fp, 'ignore udp from 127.1.2/24'."\n");
		fwrite($fp, 'ignore udp from 127.1.2/255.255.255.0'."\n");
		fclose($fp);
		
	}
conf_mount_ro();
?>




</head>



<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td >
	

	</form>
	
	<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
	<?php
	global $sbdb;
	$sbdb = strikeback_read_db();
	
	?>
	<p>Log Viewer Color Settings <img src="color.png" height="20" width="20"></p>
    <hr>
    <table width="100%" border="0">
   
  <tr>
    <td>https<br />
	  <input type="text" name="https_color" class="color" value="<?php print_r($sbdb[0][0]); ?>"></td>
    <td>imaps<br />
	  <input type="text" name="imaps_color" class="color" value="<?php print_r($sbdb[0][1]); ?>"></td>
    <td>ftp<br />
	  <input type="text" name="ftp_color" class="color" value="<?php print_r($sbdb[0][2]); ?>"></td>
    <td>submission<br />
	  <input type="text" name="submission_color" class="color" value="<?php print_r($sbdb[0][3]); ?>"></td>
  </tr>
  <tr>
    <td>auth<br />
	  <input type="text" name="auth_color" class="color" value="<?php print_r($sbdb[0][4]); ?>"></td>
    <td>netbios-ssn<br />
	  <input type="text" name="netbios-ssn_color" class="color" value="<?php print_r($sbdb[0][5]); ?>"></td>
    <td>smtp<br />
	  <input type="text" name="smtp_color" class="color" value="<?php print_r($sbdb[0][6]); ?>"></td>
    <td>pop3<br />
	  <input type="text" name="pop3_color" class="color" value="<?php print_r($sbdb[0][7]); ?>"></td>
  </tr>
  <tr>
    <td>telnet<br />
	  <input type="text" name="telnet_color" class="color" value="<?php print_r($sbdb[0][8]); ?>"></td>
    <td>blackjack<br />
	  <input type="text" name="blackjack_color" class="color" value="<?php print_r($sbdb[0][9]); ?>"></td>
    <td>rap<br />
	  <input type="text" name="rap_color" class="color" value="<?php print_r($sbdb[0][10]); ?>"></td>
    <td>RDP<br />
	  <input type="text" name="rdp_color" class="color" value="<?php print_r($sbdb[0][11]); ?>"></td>
  </tr>
   <tr>
    <td>port scan<br />
	  <input type="text" name="portscan_color" class="color" value="<?php print_r($sbdb[0][12]); ?>"></td>
    <td>dgram<br />
	  <input type="text" name="dgram_color" class="color" value="<?php print_r($sbdb[0][13]); ?>"></td>
    <td>SSH<br />
	  <input type="text" name="ssh_color" class="color" value="<?php print_r($sbdb[0][14]); ?>"></td>
    
  </tr>
</table>
<br/><br/>
	<p>iplog Settings</p>
    <hr>
    <table width="100%" border="0">
  <tr>
    <td>Run as user<br />
	  <input type="text" name="runas" value="<?php print_r($sbdb[0][15]); ?>"></td>
    <td>Run as group<br />
	  <input type="text" name="runasgrp" value="<?php print_r($sbdb[0][16]); ?>"></td>
    <td>Log IP<br />
    	<?php
		if ($sbdb[0][17] == "set log_ip true"){
			echo "<input type='checkbox' checked name='log_ip'>";
		}else{
			echo "<input type='checkbox' name='log_ip'>";
		}
		?>
	 </td>
     
    <td>Ignore DNS<br />
    <?php
		if ($sbdb[0][18] == "set ignore_dns"){
			echo "<input type='checkbox' checked name='ignore_dns'>";
		}else{
			echo "<input type='checkbox' name='ignore_dns'>";
		}
		?>
	  </td>
  </tr>
  <tr>
    
    <td>Ignore DNS Server<br />
	  <input type="text" name="ignore_dns_sev1" value="<?php print_r($sbdb[0][19]); ?>"></td>
    <td>Ignore DNS Server 2<br />
	  <input type="text" name="ignore_dns_sev2" value="<?php print_r($sbdb[0][20]); ?>"></td>
    <td>Ignore DNS Server 3<br />
	  <input type="text" name="ignore_dns_sev3" value="<?php print_r($sbdb[0][21]); ?>"></td>
      <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Ignore port 80<br />
    <?php
		if ($sbdb[0][22] == "ignore tcp dport 80"){
			echo "<input type='checkbox' checked name='ignore_80'>";
		}else{
			echo "<input type='checkbox' name='ignore_80'>";
		}
		?>
	  </td>
    <td>Ignore ICMP<br />
    <?php
		if ($sbdb[0][23] == "ignore icmp type unreach"){
			echo "<input type='checkbox' checked name='ignore_ICMP'>";
		}else{
			echo "<input type='checkbox' name='ignore_ICMP'>";
		}
		?>
	  </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
</table>

	
	  <br />
	  <br/>
	  
	  
	  
	  
	  
	  
	  
	  <input type="submit" name="formSubmit" value="Save" /><br><br>
	  </p>
	  
	  <br/>
	  <a href="http://ojnk.sourceforge.net/stuff/iplog.readme">iplog</a> config file: /usr/local/etc/iplog.conf
	  
	  
	  </div>
	  <?php
	//This input guarantees that a POST is sent
	echo "<input type='hidden' name='zzz' value='required'>";
		?>
	  
	  </td>
	  </tr>
	  </table>
	  </td>
	  
	  
	  </tr>
	  
	  
	  </table>
	  </div>
	  <br>
	  
	  <br><br>
	  
	  </p>
	<p>
</p>
</td>
	</tr>
</table>
</form>
<?php include("fend.inc"); ?>
</body>
</html>