Icon="shellinabox-plugin.png"
Menu="NetworkServices"
Title="Command Line"
---
<?php
$sName = "shellinaboxd";
$shellinabox_cfg = parse_plugin_cfg("shellinabox-plugin");
$shellinabox_service = isset($shellinabox_cfg['SERVICE']) ? $shellinabox_cfg['SERVICE'] : "disable";
$shellinabox_screen = isset($shellinabox_cfg['SCREEN'])	 ? $shellinabox_cfg['SCREEN']	 : "disable";
$shellinabox_backup = isset($shellinabox_cfg['BACKUP'])	 ? $shellinabox_cfg['BACKUP']	 : "disable";
$shellinabox_ssl = isset($shellinabox_cfg['SSL']) 			 ? $shellinabox_cfg['SSL'] 	 : "disable";
$shellinabox_runas = isset($shellinabox_cfg['RUNAS']) 	 ? $shellinabox_cfg['RUNAS'] 	 : "nobody";
$shellinabox_ipaddr = isset($shellinabox_cfg['IPADDR'])   ? $shellinabox_cfg['IPADDR']  : "disable";
$shellinabox_host = ($shellinabox_ipaddr == "disable")    ? $var['NAME'] 					 : $var['IPADDR'];
$shellinabox_cert = isset($shellinabox_cfg['CERT']) 		 ? $shellinabox_cfg['CERT'] 	 :  "certificate.pem";
$shellinabox_port = (isset($shellinabox_cfg['PORT']) && is_numeric($shellinabox_cfg['PORT']) && $shellinabox_cfg['PORT'] > 0 && $shellinabox_cfg['PORT'] < 65535 ) ? $shellinabox_cfg['PORT'] : "4200";
$shellinabox_running = trim(shell_exec( "[ -f /proc/`cat /var/run/shellinaboxd.pid 2> /dev/null`/exe ] && echo 1 || echo 0 2> /dev/null" ));
$shellinabox_version = shell_exec( "/usr/sbin/shellinaboxd --version 2>&1 | grep ShellInABox | sed -e 's/^ShellInABox version //;s/(.*//'" );
$shellinabox_port_status = ($shellinabox_running) ? 
	"<a style='color:green;' target='_blank' href='http://".$shellinabox_host.":".$shellinabox_port."' title='Click on link then accept security, then /Tools/CommandLine will work'><b>$shellinabox_port</b></a>":
	"<b><font style='color:orange;'>$shellinabox_port</font></b>";
exec("awk -F':' '{ if ( $3 >= 1000 ) print $1}' /etc/passwd", $shellinabox_users); // get array of group users
?>

<form markdown="1" name="shellinabox_settings" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" name="#file" value="shellinabox-plugin/shellinabox-plugin.cfg" />
<input type="hidden" id="command" name="#command" value="" />

Enable Shellinabox Server <?=$shellinabox_version;?>:
: <select id="SERVICE" name="SERVICE" size="1" onChange="checkRUNNING(this.form);">
  <?=mk_option($shellinabox_service, "disable", "No");?>
  <?=mk_option($shellinabox_service, "enable", "Yes");?>
  </select>

Port (<?=$shellinabox_port_status;?>):
: <input style="width:135px" id="PORT" type="text" class="shellinabox-run" name="PORT" maxlength="40" value="<?=$shellinabox_port;?>" title="port must be 0-65535" placeholder="Default Port is 8000" >

Run as User:
: <select id="USERS" class="shellinabox-run" title="select user, cannot be root" size="1" onChange="checkUSER(this.form, '<?=$shellinabox_runas;?>');">
  <?=mk_option($aesir_runas, "nobody", "nobody");?>
  <?php foreach($shellinabox_users as $shellinabox_user){echo mk_option($shellinabox_runas, trim($shellinabox_user), trim($shellinabox_user));};?>
  <option value='other' <?=($shellinabox_runas != "root" && $shellinabox_runas != "nobody" && !in_array($shellinabox_runas, $shellinabox_users))?"selected=yes":"";?>>other</option>
  <?=mk_option($shellinabox_runas, "root", "root");?>
  </select>
  <input type="hidden" name="RUNAS" style="width:222px" maxlength="40" value=<?=$shellinabox_runas;?> >

Connect by IP Address:
: <select id="IPADDR" name="IPADDR" size="1" class="shellinabox-run">
  <?=mk_option($shellinabox_ipaddr, "disable", "No");?>
  <?=mk_option($shellinabox_ipaddr, "enable", "Yes");?>
  </select>

Enable SSL connection:
: <select id="SSL" name="SSL" size="1" class="shellinabox-run">
  <?=mk_option($shellinabox_ssl, "disable", "No");?>
  <?=mk_option($shellinabox_ssl, "enable", "Yes");?>
  </select>

Enable Command Line Screenshot:
: <select id="SCREEN" name="SCREEN" size="1" title="shows screenshot when you log in">
  <?=mk_option($shellinabox_screen, "disable", "No");?>
  <?=mk_option($shellinabox_screen, "enable", "Yes");?>
  </select>

Enable Home Directory Backup:
: <select id="BACKUP" name="BACKUP" size="1" title="shows screenshot when you log in">
  <?=mk_option($shellinabox_backup, "disable", "No");?>
  <?=mk_option($shellinabox_backup, "enable", "Yes");?>
  </select>

<input id="DEFAULT" class="shellinabox-run" type="submit" value="Default" onClick="resetDATA(this.form)">
: <input id="btnApply" type="submit" value="Apply" onClick="verifyDATA(this.form)"><input type="button" value="Done" onClick="done()"><!--<button id="btnCert" type="button" onclick="window.location.href='http://<?=$shellinabox_host;?>/boot/config/plugins/shellinabox-plugin/<?=$shellinabox_cert;?>'"> Download Cert </button>-->
</form>

<script type="text/javascript">
$(function(){
	showStatus('<?=$sName;?>');
	checkRUNNING(document.shellinabox_settings);
	checkUSER(document.shellinabox_settings,'<?=$shellinabox_runas;?>');
});

function resetDATA(form) {
	form.IPADDR.value = "disable";
	form.SSL.value = "disable";
	form.SCREEN.value = "disable";
	form.BACKUP.value = "disable";
	form.PORT.value = "4200";
	form.RUNAS.value = "nobody";
	form.USERS.value = "nobody";
}

function checkRUNNING(form) {
	if ("<?=$shellinabox_running;?>" == true)
	{
		$(".shellinabox-run").prop("disabled", true);
		form.btnApply.disabled = true;	
		//form.btnCert.disabled = false;
   }else{
   	$(".shellinabox-run").prop("disabled", false);
   	//form.btnCert.disabled = true;
 }

	if (form.SERVICE.value == "enable")
		form.command.value = "/usr/local/emhttp/plugins/shellinabox-plugin/scripts/start";
	else {
		form.command.value = "/usr/local/emhttp/plugins/shellinabox-plugin/scripts/stop";
	 	form.btnApply.disabled = (form.SERVICE.value == "enable");
	}
}

function checkUSER(form, currentUSER) {
	if (form.USERS.value != "other" ) {
		form.RUNAS.value = form.USERS.options[form.USERS.selectedIndex].value;
		form.RUNAS.type = "hidden";
	}
	else
	{
		form.RUNAS.value = currentUSER;
		if (form.RUNAS.value == "root")
			form.RUNAS.value = "nobody";
		form.RUNAS.type = "text";
		form.RUNAS.title = "Run As User Cannot be Root";
	}
}

function verifyDATA(form) {
	if (!isNumber(form.PORT.value) || form.PORT.value < 0 || form.PORT.value > 65535){
			form.PORT.value = "4200";
	}
	if (form.RUNAS.value == null || form.RUNAS.value == ""){
		form.RUNAS.value = "nobody";
		$shellinabox_runas = "nobody";
	}
	form.SERVICE.value = form.SERVICE.value.replace(/ /g,"_");
	form.IPADDR.value = form.IPADDR.value.replace(/ /g,"_");
	form.SSL.value = form.SSL.value.replace(/ /g,"_");
	form.SCREEN.value = form.SCREEN.value.replace(/ /g,"_");
	form.PORT.value = form.PORT.value.replace(/ /g,"_");
	form.RUNAS.value = form.RUNAS.value.replace(/ /g,"_");
}

</script>