<commit_before><?php

include ("common.php");

$mylogsrc = LOG_SRC_TWIPNSMS;
$mylogdst = LOG_DST_SYSLOG;

$confirm = SMS_CONFIRM_DEFAULT;
$field_delim = SMS_FIELD_DELIM;

if (!is_null($people[$_REQUEST['From']])) {
	$name = $people[$_REQUEST['From']];
} else {
	$name = NULL;
}

$txt = $_REQUEST['Body'];

// render TwiML
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<?php

if ($name) {
	$tmp = explode($field_delim, $txt, 5);
	$command = strtoupper(ltrim($tmp[0], ' '));
	$ipaddr = $tmp[1];
	$port = $tmp[2];
	$duration = $tmp[3];
	if (count($tmp) == 5) {
		$confirm = strtoupper($tmp[4]);
	}

	// sanity check arguments before use
	if (ValidCommand($command) && ValidIpAddress($ipaddr) && ValidPort($port) && ValidDuration($duration)) {
		switch ($command) {
		case 'O':
			$output = shell_exec("sudo /usr/local/bin/iptables_wrapper_script.sh -a $ipaddr $port $duration ");
			$msg = "open $ipaddr:$port for $duration minutes";
			LogAction($mylogsrc, $mylogdst, "$name requested to " . $msg);
			break;
		case 'C':
			$output = shell_exec("sudo /usr/local/bin/iptables_wrapper_script.sh -d $ipaddr $port 0 ");
			$msg = "close $ipaddr:$port";
			LogAction($mylogsrc, $mylogdst, "$name requested to " . $msg);
			break;
		case 'M':
			$output = shell_exec("sudo /usr/local/bin/iptables_wrapper_script.sh -m $ipaddr 0 60 ");
			$msg = "allow access to the mpd stream and control port";
			LogAction($mylogsrc, $mylogdst, "$name requested to " . $msg);
			break;
		default:
			$msg = "!! bug in command validation function? !!";
			LogAction($mylogsrc, $mylogdst, $msg);
			break;
		}
		if ($confirm == 'C') { // send confirmation SMS ?>
			<Sms>TwiPN SMS API: Completed request from <?php echo $name; ?> to <?php echo $msg; ?></Sms>
			</Response>
		<?php
		} else { ?>
			</Response>
		<?php
		}
	} else {
		LogAction($mylogsrc, $mylogdst, $name . "posted a request with wrong syntax, no command was executed"); ?>
		<Sms>TwiPN SMS API: request from <?php echo $name; ?> had wrong TwiPN syntax, no command was executed</Sms>
		</Response>
	<?php
	}
} else {
	LogAction($mylogsrc, $mylogdst, "Unkown phone " . $_REQUEST['From'] . " posted a request, no command was executed"); ?>
	<Sms>TwiPN SMS API: This phone number is not allowed to execute commands, you may want to update the whitelist</Sms>
	</Response>
<?php
}
?><commit_msg>add space %trivial%<commit_after><?php

include ("common.php");

$mylogsrc = LOG_SRC_TWIPNSMS;
$mylogdst = LOG_DST_SYSLOG;

$confirm = SMS_CONFIRM_DEFAULT;
$field_delim = SMS_FIELD_DELIM;

if (!is_null($people[$_REQUEST['From']])) {
	$name = $people[$_REQUEST['From']];
} else {
	$name = NULL;
}

$txt = $_REQUEST['Body'];

// render TwiML
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<?php

if ($name) {
	$tmp = explode($field_delim, $txt, 5);
	$command = strtoupper(ltrim($tmp[0], ' '));
	$ipaddr = $tmp[1];
	$port = $tmp[2];
	$duration = $tmp[3];
	if (count($tmp) == 5) {
		$confirm = strtoupper($tmp[4]);
	}

	// sanity check arguments before use
	if (ValidCommand($command) && ValidIpAddress($ipaddr) && ValidPort($port) && ValidDuration($duration)) {
		switch ($command) {
		case 'O':
			$output = shell_exec("sudo /usr/local/bin/iptables_wrapper_script.sh -a $ipaddr $port $duration ");
			$msg = "open $ipaddr:$port for $duration minutes";
			LogAction($mylogsrc, $mylogdst, "$name requested to " . $msg);
			break;
		case 'C':
			$output = shell_exec("sudo /usr/local/bin/iptables_wrapper_script.sh -d $ipaddr $port 0 ");
			$msg = "close $ipaddr:$port";
			LogAction($mylogsrc, $mylogdst, "$name requested to " . $msg);
			break;
		case 'M':
			$output = shell_exec("sudo /usr/local/bin/iptables_wrapper_script.sh -m $ipaddr 0 60 ");
			$msg = "allow access to the mpd stream and control port";
			LogAction($mylogsrc, $mylogdst, "$name requested to " . $msg);
			break;
		default:
			$msg = "!! bug in command validation function? !!";
			LogAction($mylogsrc, $mylogdst, $msg);
			break;
		}
		if ($confirm == 'C') { // send confirmation SMS ?>
			<Sms>TwiPN SMS API: Completed request from <?php echo $name; ?> to <?php echo $msg; ?></Sms>
			</Response>
		<?php
		} else { ?>
			</Response>
		<?php
		}
	} else {
		LogAction($mylogsrc, $mylogdst, $name . " posted a request with wrong syntax, no command was executed"); ?>
		<Sms>TwiPN SMS API: request from <?php echo $name; ?> had wrong TwiPN syntax, no command was executed</Sms>
		</Response>
	<?php
	}
} else {
	LogAction($mylogsrc, $mylogdst, "Unkown phone " . $_REQUEST['From'] . " posted a request, no command was executed"); ?>
	<Sms>TwiPN SMS API: This phone number is not allowed to execute commands, you may want to update the whitelist</Sms>
	</Response>
<?php
}
?>
{'fraction_non_alphanumeric': 0.18424900772926675, 'fraction_numerical': 0.005849174848548151, 'mean_word_length': 4.193058568329718, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 2, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1943451', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1762, 'n_words': 462}