From 775d5b20114d187c058f6c75cdb9b54140b8792e Mon Sep 17 00:00:00 2001 From: root Date: Sun, 28 May 2023 09:29:47 -0700 Subject: [PATCH] Added System Scripts --- lib/scripts/distro_web_utils.php | 958 +++++++++++++++++++++++++++++++ lib/scripts/nif_operation.php | 31 + lib/scripts/restart_network.sh | 4 + lib/scripts/samba_off.sh | 11 + lib/scripts/samba_on.sh | 11 + lib/scripts/ssh_off.sh | 11 + lib/scripts/ssh_on.sh | 11 + lib/scripts/sys_utils.php | 679 ++++++++++++++++++++++ 8 files changed, 1716 insertions(+) create mode 100644 lib/scripts/distro_web_utils.php create mode 100755 lib/scripts/nif_operation.php create mode 100755 lib/scripts/restart_network.sh create mode 100755 lib/scripts/samba_off.sh create mode 100755 lib/scripts/samba_on.sh create mode 100755 lib/scripts/ssh_off.sh create mode 100755 lib/scripts/ssh_on.sh create mode 100644 lib/scripts/sys_utils.php diff --git a/lib/scripts/distro_web_utils.php b/lib/scripts/distro_web_utils.php new file mode 100644 index 0000000..70c8c97 --- /dev/null +++ b/lib/scripts/distro_web_utils.php @@ -0,0 +1,958 @@ + + + + + ARGUS Platform Configuration + + + + + + + + + + + + +
Platform Configuration
+
+
+ + + + + +
SSL Certificate
The SSL Certificate Must be signed by Dr. Frucht Certificate Autority and comply to the ROOT CA certificate
Please Upload This Host Certificate file
+
+
+ + + + + 4 ){ + ?> + + + 6 ){ + if( $SYS_CONFIG['NGINX_CERTIFICATE_ENABLED'] ){ + ?> + +
SSL Certificate Status

Certificate Subject is:$p ){ + echo "
{$k}:{$p}
"; + }; + ?>
Certificate Signed for Host(s):{$p}"; + }; + ?>

Enable SSL Certificate
Manage SSL Certificate

+ + ( 31-intval( $AI['prefixlen'] ) ); $i -- ) $NM |= ( 1 << $i ); + $ADDR['4']['netmask'] = sprintf( "%d.%d.%d.%d", + (( $NM >> 24 ) & 0xFF ), + (( $NM >> 16 ) & 0xFF ), + (( $NM >> 8 ) & 0xFF ), + ( $NM & 0xFF ) + ); + } else { + }; + }; + if( $ADDR['4']['addr'] == $_SERVER['HTTP_HOST'] ) $CONIF = true; + if( $TYPE != 'LO' ){ + ?>
Network Interfaces
IfTypeIP AddressMAC AddressConfig Type 
Settings
No Network Info Fetched!!

+ + + +
Connection Information
Connected VIA:
 

+ + + + +
Security Threat
No Access Password Defined!
Setup Now!
 

+ + + + + +
Application Info
Enable Web Application
Disable Web Application
Setup Now!
 

( 31-intval( $AI['prefixlen'] ) ); $i -- ) $NM |= ( 1 << $i ); + $ADDR['4']['netmask'] = sprintf( "%d.%d.%d.%d", + (( $NM >> 24 ) & 0xFF ), + (( $NM >> 16 ) & 0xFF ), + (( $NM >> 8 ) & 0xFF ), + ( $NM & 0xFF ) + ); + } else { + }; + }; + if( $ADDR['4']['addr'] == $_SERVER['HTTP_HOST'] ) $CONIF = true; + if( $DYNAMIC ){ + $ROENA = false; + } else { + $RCF = get_dhcpd_config(); + if( isset( $RFC['nifs'][$NAME] ) ) $ROENA = true; + }; +?> +
+ + + + + + + + +
Network Interface Editor
NOTE: You using this network interface to connect!
is Ethernet LAN interface []

+ + + + + + + +
Address Assignment Type
Static onclick="validate_dhcp();">
Dynamic (DHCP) onclick="validate_dhcp();">
Interface is Disabled onclick="validate_dhcp();">

+
+ + + + + + +
Network IPv4 Address
IP Address
NET Mask
NET Gateway

+
+ + + + + + +
Router/DHCP Service
NOTE: This service can not be enabled on dynamically assigned interfaces!
Service is Disabled onclick="validate_router();">
Enable DHCP Service on that interface onclick="validate_router();">

+
+ + + + + + +
DHCP Service Address Pool
Start IP Address
End IP Address
NET Mask
Lease Time
+
+ + is Wifi Network interface + + + + + + + + + +
Connection Mode
Provide Access Point (AP) onclick="validate_WIFI_MODE(1);">
Connect to existing AP onclick="validate_WIFI_MODE(2);">
Ad Hoc Connection onclick="validate_WIFI_MODE(3);">
Interface is Disabled onclick="validate_WIFI_MODE(0);">

+
+ + + + + + +
Access Point (AP) information to connect
Public SSID of AP to connect toScan SSIDs
Hidden SSID of AP to connect to 
AP's access passphrase 

+
+
+ + + + + + + +
Information of Platform's Access Point (AP)
WiFi Adapter Radio Bands
WiFi Radio Channel
SSID of Platform AP 
AP's access passphrase 

+
+
+ + + + + +
Address Assignment Type
Static onclick="validate_addr_mode();">
Dynamic (DHCP) onclick="validate_addr_mode();">

+
+
+ + + + + + +
Network IPv4 Address
IP Address
NET Mask
NET Gateway

+
+
+ + + + + + +
Router/DHCP Service
NOTE: This service can not be enabled on dynamically assigned interfaces!
Service is Disabled onclick="validate_dhcp_mode();">
Enable DHCP Service on that interface onclick="validate_dhcp_mode();">

+
+ + + + + + +
DHCP Service Address Pool
Start IP Address
End IP Address
NET Mask
Lease Time
+
+
+ + + + + +
 
Apply Settings
 
+
+
+ +
+ + + + + + + + + + +
Time Settings
Current Time ZoneSet Time Zone

Platform TimeSync To Browser

NTP Synchronization is EnabledDisable NTP SyncEnable NTP Sync
NTP Synchronized
 
+
+
+1, 'auto'=>1 ); + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['net'] = array(); + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['fam'] = 'inet'; + if( $_POST['ADYN'] == 1 ){ + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['mode'] = 'dhcp'; + } else { + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['mode'] = 'static'; + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['net']['address'] = $_POST['ADR']; + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['net']['netmask'] = $_POST['MASK']; + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['net']['network'] = get_Network( $_POST['ADR'], $_POST['MASK'] ); + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['net']['gateway'] = get_NetGateway( $_POST['ADR'], $_POST['MASK'] ); + $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['net']['broadcast'] = get_NetBroadcast( $_POST['ADR'], $_POST['MASK'] ); + }; + $CC = $SYS_CONFIG['NEW_NET_CONFIG'][$N['ifname']]['net']; + }; + save_system_config(); +?> + +
New Network Interface Configuration
+ + + + + + + + + +
Current ConfigNew Config
Assign Mode:Assign Mode:
Network:Network:
IPv4 Address:IPv4 Address:
Net Mask:Net Mask:
Gateway:Gateway:
Broadcast:Broadcast:
+ + + +
The Network Interface [] Will be Disabled!
+ + + +
Apply New Settings
+ + + + +
Waiting for Task to be accomplished
 
+ +
Platform Task Panel
+ + +
+ Reboot Platform + + Manage Access + Disable SSHEnable SSHStop SambaStart SambaDisable WiFiEnable WiFi
WiFi
+ Package Installer +
 

+ +$U ){ +?>$U ){ +?>
Platform Authorization Settings
The Authorization is Disabled
Enable Authorization
Delete
The Authorization is Disabled
No Access Credentials Exists
The Authorization is Enabled
Disable Authorization
Delete
+
+ + + + + + + + +
Add Credentials

Username:
Password:
 
Create Credentials
+
+
+ + + + + + + + + + +
Packages Vault
 
Apply Package
No Packages Uploaded yet
+
+ +
Your browser doesn't have Flash, Silverlight or HTML5 support.
+ + +
+

+
+
\ No newline at end of file
diff --git a/lib/scripts/nif_operation.php b/lib/scripts/nif_operation.php
new file mode 100755
index 0000000..d035e82
--- /dev/null
+++ b/lib/scripts/nif_operation.php
@@ -0,0 +1,31 @@
+#!/usr/bin/php
+ 2 ){
+	switch( strtolower( $argv[1] ) ){
+	    case 'e':
+	    case 'enable':{
+		switch(  strtolower( $argv[2] ) ){
+		    case 'samba':{
+			$OP_COMP = true;
+			break;
+		    };
+		};
+		break;
+	    };
+	    case 'd':
+	    case 'diasable':{
+		break;
+	    };
+	};
+    };
+    if( !$OP_COMP ){
+	echo "Using Utility: {$argv[0]} OPERATION OBJECT [ADDITIONAL_PARAMS]\n";
+    };
+?>
\ No newline at end of file
diff --git a/lib/scripts/restart_network.sh b/lib/scripts/restart_network.sh
new file mode 100755
index 0000000..1b6469f
--- /dev/null
+++ b/lib/scripts/restart_network.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+/etc/init.d/networking restart
+/etc/init.d/hostapd restart
diff --git a/lib/scripts/samba_off.sh b/lib/scripts/samba_off.sh
new file mode 100755
index 0000000..9a802b5
--- /dev/null
+++ b/lib/scripts/samba_off.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+
+
+systemctl stop smbd
+systemctl disable smbd
+/etc/init.d/smbd stop
+chmod 644 /etc/init.d/smbd
+
+
+
diff --git a/lib/scripts/samba_on.sh b/lib/scripts/samba_on.sh
new file mode 100755
index 0000000..731b2f0
--- /dev/null
+++ b/lib/scripts/samba_on.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+chmod 755 /etc/init.d/smbd
+systemctl enable smbd
+systemctl start smbd
+/etc/init.d/smbd start
+
+
+
+
+
diff --git a/lib/scripts/ssh_off.sh b/lib/scripts/ssh_off.sh
new file mode 100755
index 0000000..43e5a6c
--- /dev/null
+++ b/lib/scripts/ssh_off.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+
+
+systemctl stop ssh
+systemctl disable ssh
+/etc/init.d/ssh stop
+chmod 644 /etc/init.d/ssh
+
+
+
diff --git a/lib/scripts/ssh_on.sh b/lib/scripts/ssh_on.sh
new file mode 100755
index 0000000..71537d9
--- /dev/null
+++ b/lib/scripts/ssh_on.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+chmod 755 /etc/init.d/ssh
+systemctl enable ssh
+systemctl start ssh
+/etc/init.d/ssh start
+
+
+
+
+
diff --git a/lib/scripts/sys_utils.php b/lib/scripts/sys_utils.php
new file mode 100644
index 0000000..163321e
--- /dev/null
+++ b/lib/scripts/sys_utils.php
@@ -0,0 +1,679 @@
+ 1 ) $CL = $CArr[0];
+	    $CArr = explode( ';', $CL );
+	    if( count( $CArr ) > 1 ) $CL = $CArr[0];
+	    if( strlen( $CL ) ){
+		if( ( stripos( $CL, '[' ) !== false ) && ( stripos( $CL, '[' ) !== false ) ) {
+		    $cSection = str_replace(']','',str_replace('[','',$CL));
+		    $mumu_array[$cSection] = array();
+		} else {
+		    $TArr = explode( '=', $CL );
+		    if( count( $TArr ) == 2 ){
+			$Key = strtolower( trim( $TArr[0] ));
+			$Val = trim( $TArr[1] );
+			$mumu_array[$cSection][$Key] = $Val;
+		    };
+		};
+	    };
+	};
+    };
+    return $mumu_array;
+};
+
+function validate_samba_config( $file='', $dist='' ){
+    $rv = false;
+    if( $file == '' ) $file = '/etc/samba/smb.conf';
+    if( $dist == '' ) $dist = '/srv/etc/samba.json';
+    $Actual = parse_samba_config( $file );
+    //print_r( $Actual );
+    $Params = json_decode( file_get_contents( $dist ), true );
+    //print_r( $Params );
+    foreach( $Actual as $CS=>$MEMS ){
+	if( isset( $Params[$CS] ) )
+	    foreach( $MEMS as $CK=>$CV )
+		if( isset( $Params[$CS][$CK] ))
+		    if($Params[$CS][$CK]!= $CV ) {
+			    echo "{$CS}:{$CK} does not match {$Params[$CS][$CK]}!={$CV}\n";
+			    return false;
+		    };
+    };
+    return true;
+};
+
+
+function restart_samba(){
+    $CMD = 'service samba restart';
+    $R = `{$CMD}`;
+    if( stripos( $R, 'not found' ) !== false ){
+	$CMD = '/etc/init.d/samba-ad-dc restart';
+	$R = `{$CMD}`;
+	if( stripos( $R, 'not found' ) !== false ){
+	    $CMD = '/etc/init.d/nmbd restart';
+	    $R = `{$CMD}`;
+	    $CMD = '/etc/init.d/smbd restart';
+	    $R = `{$CMD}`;
+	};
+    };
+};
+
+
+function get_nif_config( ){
+    $CMD ='ip -j a';
+    $Data = json_decode(`{$CMD}`, true );
+    return $Data;
+};
+
+function set_nginx_certificate( $cert_file ){
+    
+};
+function sync_time(){
+	
+};
+
+function get_network_config(){
+	$Data = file_get_contents( '/etc/network/interfaces' );
+	$TArr = explode("\n", $Data );
+	$IFS = array();
+	$CI = '';
+	foreach( $TArr as $T ){
+		$CL = trim( $T );
+		$JJ = explode( '#', $CL );
+		if( is_array( $JJ ) ) if( strlen( $JJ[0] ) == 0 ) continue;
+		if( stripos( $CL, 'iface') !== false ){
+			$JJ = explode(' ', $CL );
+			$CI = $JJ[1];
+			if( !isset( $IFS[$JJ[1]] ) ) $IFS[$JJ[1]] = array();
+			if( !isset( $IFS[$JJ[1]]['flags'] ) ){
+				$IFS[$JJ[1]]['flags'] = array();
+				$IFS[$JJ[1]]['flags']['hotplug'] = 0;
+				$IFS[$JJ[1]]['flags']['auto'] = 0;
+			};
+			$IFS[$JJ[1]]['net'] = array();
+			$IFS[$JJ[1]]['fam'] = $JJ[2];
+			$IFS[$JJ[1]]['mode'] = $JJ[3];
+		} else if( stripos( $CL, 'auto') !== false ){
+			$JJ = explode( ' ', $CL );
+			if( count( $JJ ) > 2 ){
+				for( $i = 1; $i < count( $JJ ); $i++){
+					if( !isset( $IFS[$JJ[$i]] ) ) $IFS[$JJ[1]] = array();
+					if( !isset( $IFS[$JJ[$i]]['flags'] ) ){
+						$IFS[$JJ[$i]]['flags'] = array();
+						$IFS[$JJ[$i]]['flags']['hotplug'] = 0;
+						$IFS[$JJ[$i]]['flags']['auto'] = 0;
+					};
+					$IFS[$JJ[$i]]['flags']['auto'] = 1;
+				};
+			} else {
+				if( !isset( $IFS[$JJ[1]] ) ) $IFS[$JJ[1]] = array();
+				if( !isset( $IFS[$JJ[1]]['flags'] ) ){
+					$IFS[$JJ[1]]['flags'] = array();
+					$IFS[$JJ[1]]['flags']['hotplug'] = 0;
+					$IFS[$JJ[1]]['flags']['auto'] = 0;
+				};
+				$IFS[$JJ[1]]['flags']['auto'] = 1;
+			};
+		} else if( stripos( $CL, 'allow-hotplug' ) !== false ){
+			$JJ = explode( ' ', $CL );
+			if( count( $JJ ) > 2 ){
+				for( $i = 1; $i < count( $JJ ); $i++){
+					if( !isset( $IFS[$JJ[1]] ) ) $IFS[$JJ[1]] = array();
+					if( !isset( $IFS[$JJ[1]]['flags'] ) ){
+						$IFS[$JJ[$i]]['flags'] = array();
+						$IFS[$JJ[$i]]['flags']['hotplug'] = 0;
+						$IFS[$JJ[$i]]['flags']['auto'] = 0;
+					};
+					$IFS[$JJ[$i]]['flags']['hotplug'] = 1;
+				};
+			} else {
+				if( !isset( $IFS[$JJ[1]] ) ) $IFS[$JJ[1]] = array();
+				if( !isset( $IFS[$JJ[1]]['flags'] ) ){
+					$IFS[$JJ[1]]['flags'] = array();
+					$IFS[$JJ[1]]['flags']['hotplug'] = 0;
+					$IFS[$JJ[1]]['flags']['auto'] = 0;
+				};
+				$IFS[$JJ[1]]['flags']['hotplug'] = 1;
+			};
+		} else if( $CI!= '' ) {
+			$JJ = explode(' ', $CL );
+			$IFS[$CI]['net'][$JJ[0]] = $JJ[1];
+		};
+	};
+	return $IFS;
+};
+
+function get_NetGateway( $ADDR, $NM ){
+		$TArr = explode( '.', $ADDR );
+		$ba = 0xFFFFFFFF;
+		foreach( $TArr as $T ) {
+			$ba = ( $ba << 8 );
+			$ba |= intval( $T );
+		};
+		$ba &= 0xFFFFFFFF;
+		$TArr = explode( '.', $NM );
+		$bn = 0;
+		foreach( $TArr as $T ) {
+			$bn = ( $bn << 8 );
+			$bn += intval( $T );
+		};
+		$bc = ( $ba & $bn ) + 1;
+		$byteArray = unpack("C*", pack("L",$bc ) );
+		return sprintf( "%d.%d.%d.%d", $byteArray[4],$byteArray[3],$byteArray[2],$byteArray[1]);
+};
+function get_Network( $ADDR, $NM ){
+		$TArr = explode( '.', $ADDR );
+		$ba = 0xFFFFFFFF;
+		foreach( $TArr as $T ) {
+			$ba = ( $ba << 8 );
+			$ba |= intval( $T );
+		};
+		$ba &= 0xFFFFFFFF;
+		$TArr = explode( '.', $NM );
+		$bn = 0;
+		foreach( $TArr as $T ) {
+			$bn = ( $bn << 8 );
+			$bn += intval( $T );
+		};
+		$bc = ( $ba & $bn );
+		$byteArray = unpack("C*", pack("L",$bc ) );
+		return sprintf( "%d.%d.%d.%d", $byteArray[4],$byteArray[3],$byteArray[2],$byteArray[1]);
+};
+
+function get_NetBroadcast( $ADDR, $NM ){
+		$TArr = explode( '.', $ADDR );
+		$ba = 0xFFFFFFFF;
+		foreach( $TArr as $T ) {
+			$ba = ( $ba << 8 );
+			$ba |= intval( $T );
+		};
+		$ba &= 0xFFFFFFFF;
+		$TArr = explode( '.', $NM );
+		$bn = 0;
+		foreach( $TArr as $T ) {
+			$bn = ( $bn << 8 );
+			$bn += intval( $T );
+		};
+		$bc = ( $ba & $bn ) | ( ~ $bn );
+		$byteArray = unpack("C*", pack("L",$bc ) );
+		return sprintf( "%d.%d.%d.%d", $byteArray[4],$byteArray[3],$byteArray[2],$byteArray[1]);
+};
+
+function build_network_config( $NCFG, $FNAM = '' ){
+	if( !is_array( $NCFG ) ) return;
+	if( $FNAM == '' )$FNAM = '/etc/network/interfaces';
+	$FD = fopen( $FNAM, "w+" );
+	if( $FD ){
+		foreach( $NCFG as $Key=>$NIF ){
+			if( $NIF['flags']['auto'] ) fprintf( $FD, "auto %s\n", $Key );
+			if( $NIF['flags']['hotplug'] ) fprintf( $FD, "allow-hotplug %s\n", $Key );
+			fprintf( $FD, "iface %s %s %s\n", $Key, $NIF['fam'], $NIF['mode'] );
+			if( $NIF['mode'] == 'static' && count( $NIF['net'] ) ){
+				foreach( $NIF['net'] as $L=>$V ) fprintf( $FD, "\t%s %s\n", $L, $V );
+				/*
+				address 192.168.2.236
+				netmask 255.255.255.0
+				gateway 192.168.2.254
+				dns-domain sweet.home
+				dns-nameservers 192.168.2.254
+				*/
+			};
+		};
+		fclose( $FD );
+	};
+};
+
+function get_dhcpd_config(){
+	$Data = file_get_contents( '/etc/dnsmasq.conf' );
+	$TArr = explode("\n", $Data );
+	$IFS = array();
+	$IFS['dns'] = array();
+	$IFS['nifs'] = array();
+	$CANIF = '';
+	foreach( $TArr as $T ){
+		$CL = trim( $T );
+		$JJ = explode( '#', $CL );
+		if( is_array( $JJ ) ) if( strlen( $JJ[0] ) == 0 ) continue;
+		//echo $CL . "\n";		
+		if( stripos( $CL, 'interface') !== false ){
+			$JJ = explode('=', $CL );
+			$CANIF = trim( $JJ[1] );
+			$IFS['nifs'][$CANIF] = array();
+			$IFS['nifs'][$CANIF]['range'] = array();
+			$IFS['nifs'][$CANIF]['range']['start'] = '';
+			$IFS['nifs'][$CANIF]['range']['end'] = '';
+			$IFS['nifs'][$CANIF]['range']['netmask'] = '';
+			$IFS['nifs'][$CANIF]['range']['lease'] = '';
+		};
+		if( stripos( $CL, 'server') !== false ){
+			$JJ = explode('=', $CL );
+			$IFS['dns'][] = $JJ[1];
+		};
+		if( stripos( $CL, 'dhcp-range') !== false ){
+			$JJ = explode( '=', $CL );
+			$BB = explode( ',', $JJ[1] );			
+			$IFS['nifs'][$CANIF]['range']['start'] = $BB[0];
+			$IFS['nifs'][$CANIF]['range']['end'] = $BB[1];
+			if( count( $BB ) == 4 ){
+				$IFS['nifs'][$CANIF]['range']['netmask'] = $BB[2];
+				$IFS['nifs'][$CANIF]['range']['lease'] = $BB[3];
+			} else {
+				$IFS['nifs'][$CANIF]['range']['lease'] = $BB[2];
+			};
+		};
+	};
+	return $IFS;
+};
+
+function list_tz(){
+	$Data = `timedatectl list-timezones`;
+	return explode( "\n", $Data );
+};
+
+function get_tz_nfo(){
+	$Data = `timedatectl show`;
+	$TArr = explode( "\n", $Data );
+	$RData = array();
+	foreach( $TArr as $T ){
+		$CL = trim( $T );
+		if( stripos( $CL, 'NTPSynchronized' ) !== false ){
+			$BArr = explode( "=", $CL );
+			$RData['SYNC'] = $BArr[1];
+		} else {
+			if( stripos( $CL, 'CanNTP' ) !== false ){
+				$BArr = explode( "=", $CL );
+				$RData['NTA'] = $BArr[1];
+			} else {
+				if( stripos( $CL, 'Timezone' ) !== false ){
+					$BArr = explode( "=", $CL );
+					$RData['TZ'] = $BArr[1];
+				};
+				if( stripos( $CL, 'LocalRTC' ) !== false ){
+					$BArr = explode( "=", $CL );
+					$RData['RTC'] = $BArr[1];
+				};
+				if( stripos( $CL, 'TimeUSec' ) !== false ){
+					$BArr = explode( "=", $CL );
+					$RData['TIME'] = $BArr[1];
+				};
+				if( stripos( $CL, 'NTP' ) !== false  ){
+					$BArr = explode( "=", $CL );
+					$RData['NTP'] = $BArr[1];
+				};
+			};
+		};
+	};
+	return $RData;
+};
+function build_dhcp_config( $CFG, $FNAM='' ){
+	if( !is_array( $CFG ) ) return;
+	if( $FNAM == '' )$FNAM = '/etc/dnsmasq.conf';
+	$FD = fopen( $FNAM, "w+" );
+	if( $FD ){
+		foreach( $CFG['nifs'] as $Key=>$NIF ){
+			fprintf( $FD, "interface=%s\n", $Key );
+			if( $NIF['netmask']!=''){
+				fprintf( $FD, "dhcp-range=%s,%s,%s,%s\n", $NIF['range']['start'],$NIF['range']['end'],$NIF['range']['netmask'],$NIF['range']['lease'] );
+			} else {
+				fprintf( $FD, "dhcp-range=%s,%s,%s\n", $NIF['range']['start'],$NIF['range']['end'],$NIF['range']['netmask'],$NIF['range']['lease'] );
+			};
+		};
+		foreach( $CFG['dns'] as $DR ){
+			fprintf( $FD, "server=%s\n", $DR );
+		};
+		fclose( $FD );
+	};
+};
+
+function get_wifi_ap_configuration(){
+	$Data = file_get_contents( '/etc/hostapd/hostapd.conf' );
+	$TArr = explode("\n", $Data );
+	$IFS = array();	
+	foreach( $TArr as $T ){
+		$CL = trim( $T );
+		$JJ = explode( '#', $CL );
+		if( is_array( $JJ ) ) if( strlen( $JJ[0] ) == 0 ) continue;
+		$JJ = explode('=', $CL );
+		$IFS[$JJ[0]]=trim( $JJ[1] );
+	};
+	return $IFS;
+};
+
+function build_wifi_ap_configuration( $CFG, $FNAM='' ){
+	if( !is_array( $CFG ) ) return;
+	if( $FNAM == '' )$FNAM = '/etc/hostapd/hostapd.conf';
+	$FD = fopen( $FNAM, "w+" );
+	if( $FD ){
+		foreach( $CFG as $Key=>$Val ) fprintf( $FD, "%s=%s\n", $Key, $Val );
+		fclose( $FD );
+	};
+};
+
+function scan_WIFI_networks( $Dev = '' ){
+	if( $Dev == '' ) $Dev = 'wlan0';
+	$JAJA = `iw dev {$Dev} scan | grep SSID`;
+	
+};
+
+function apply_NGINX_AUTH( $ROOTDIR, $AFILE ){
+	$Data = file_get_contents( '/etc/nginx/sites-available/default' );
+	$TArr = explode( "\n", $Data );
+	$ACTIVE = false;
+	$FD = fopen( '/etc/nginx/sites-available/default.tmp', "w+");
+	if( $FD ){
+		foreach( $TArr as $T ){
+			$JU = explode( '#', $T );
+			$CL = trim( $JU[0] );
+			if( $CL == '' ) continue;
+			if( $ACTIVE ){
+				if( stripos( $CL, 'auth_basic' ) === false ) fprintf( $FD, "%s\n", $CL );
+			} else fprintf( $FD, "%s\n", $CL );
+			
+			if( stripos( $CL, 'root' ) !== false ) {
+				$BArr = explode( " ", $CL );
+				$CArr = explode( ';', $BArr[1] );
+				$ACTIVE = ( $CArr[0] == $ROOTDIR );
+				if( $ACTIVE ){
+					fprintf( $FD, "auth_basic \"Platform's Configuration\";\n" );
+					fprintf( $FD, "auth_basic_user_file %s;\n", $AFILE );
+				};
+			};		
+		};
+		fclose( $FD );
+		unlink( '/etc/nginx/sites-available/default' );
+		rename( '/etc/nginx/sites-available/default.tmp', '/etc/nginx/sites-available/default' );
+	};
+};
+
+function get_SERVICE_STATUS( $ServName ){
+	$Data = `service {$ServName} status`;
+	$TArr = explode( "\n", $Data );
+	$RD = array();
+	foreach( $TArr as $T ){
+		$CL = trim( $T );
+		if( stripos( $CL, 'loaded' ) !== false ){
+			$BArr = explode( ';', $CL );
+			if( count( $BArr ) > 1 ){
+				if( stripos( $BArr[1], 'enabled' )!==false ) {
+					$RD['ENA'] = true;
+				} else {
+					$RD['ENA'] = false;
+				};
+			};
+		};
+		if( stripos( $CL, 'active' ) !== false ){
+			if( stripos( $CL, 'inactive' )!==false ) {
+				$RD['WORKS'] = false;
+			} else {
+				$RD['WORKS'] = true;
+			};
+		};
+	};
+	return $RD;
+};
+
+function remove_NGINX_AUTH( $ROOTDIR ){
+	$Data = file_get_contents( '/etc/nginx/sites-available/default' );
+	$TArr = explode( "\n", $Data );
+	$ACTIVE = false;
+	$FD = fopen( '/etc/nginx/sites-available/default.tmp', "w+");
+	if( $FD ){
+		foreach( $TArr as $T ){
+			$JU = explode( '#', $T );
+			$CL = trim( $JU[0] );
+			if( $CL == '' ) continue;
+			if( $ACTIVE ){
+				if( stripos( $CL, 'auth_basic' ) === false ) fprintf( $FD, "%s\n", $CL );
+			} else fprintf( $FD, "%s\n", $CL );
+			if( stripos( $CL, 'root' ) !== false ) {
+				$BArr = explode( " ", $CL );
+				$CArr = explode( ';', $BArr[1] );
+				$ACTIVE = ( $CArr[0] == $ROOTDIR );				
+			};
+		};
+		fclose( $FD );
+		unlink( '/etc/nginx/sites-available/default' );
+		rename( '/etc/nginx/sites-available/default.tmp', '/etc/nginx/sites-available/default' );
+	};
+};
+
+function set_NGINX_APP_ENABLE(){
+	global $SYS_CONFIG; 
+	$Data = file_get_contents( '/etc/nginx/sites-available/default' );
+	$TArr = explode( "\n", $Data );
+	$BLOCKED = false;
+	$FD = fopen( '/etc/nginx/sites-available/default.tmp', "w+");
+	if( $FD ){
+		foreach( $TArr as $T ){
+			$JU = explode( '#', $T );
+			$CL = trim( $JU[0] );
+			if( $CL == '' ) continue;
+			if( stripos( $CL, 'server' ) === false ) {
+				if( !$BLOCKED ) fprintf( $FD, "%s\n", $CL );					
+			};
+			if( stripos( $CL, 'root' ) !== false ) {
+				$BArr = explode( " ", $CL );
+				$CArr = explode( ';', $BArr[1] );
+				$BLOCKED = ( $CArr[0] == '/srv/www/distro' ) && ( stripos( $CL, '8080' ) === false );
+				if( !$BLOCKED ){
+					fprintf( $FD, "server {\n %s\nserver_name _;\n", $CL );
+				};
+			};
+		};
+		//Output App Web
+		fprintf( $FD, "server {\nroot /srv/www/web; listen 80 default_server; listen [::]:80 default_server;\n" );
+		if( $SYS_CONFIG['NGINX_CERTIFICATE_INSTALLED'] ){
+			if( $SYS_CONFIG['NGINX_CERTIFICATE_ENABLED'] ){
+				fprintf( $FD, "listen 443 ssl default_server;listen [::]:443 ssl default_server;\n" );
+				fprintf( $FD, "include /srv/etc/nginx/self-signed.conf;\n" );
+				fprintf( $FD, "include /srv/etc/nginx/ssl-params.conf;\n" );
+			};
+		};
+		fprintf( $FD, "index index.html index.htm index.nginx-debian.html index.php;\n" );
+		fprintf( $FD, "server_name _;\n" );
+		fprintf( $FD, 'location / { try_files $uri $uri/ =404; index index.html index.php; }'."\n" );
+		fprintf( $FD, 'location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php-fpm.sock;}'."\n" );
+		fprintf( $FD, 'location ~* /jsapi_dynamic/.+\.js$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php-fpm.sock; }'."\n" );
+		fprintf( $FD, 'location /video_feed/ { proxy_pass  http://127.0.0.1:8972; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }'."\n" );
+		fprintf( $FD, "location ~ /\.ht {deny all;}\n}\n" );
+		fclose( $FD );
+		unlink( '/etc/nginx/sites-available/default' );
+		rename( '/etc/nginx/sites-available/default.tmp', '/etc/nginx/sites-available/default' );
+	};
+};
+
+function set_NGINX_APP_DISABLE(){
+	global $SYS_CONFIG; 
+	$Data = file_get_contents( '/etc/nginx/sites-available/default' );
+	$TArr = explode( "\n", $Data );
+	$BLOCKED = false;
+	$FD = fopen( '/etc/nginx/sites-available/default.tmp', "w+");
+	if( $FD ){
+		foreach( $TArr as $T ){
+			$JU = explode( '#', $T );
+			$CL = trim( $JU[0] );
+			if( $CL == '' ) continue;
+			if( stripos( $CL, 'server' ) === false ) {
+				if( !$BLOCKED ) fprintf( $FD, "%s\n", $CL );					
+			};
+			if( stripos( $CL, 'root' ) !== false ) {
+				$BArr = explode( " ", $CL );
+				$CArr = explode( ';', $BArr[1] );
+				$BLOCKED = ( $CArr[0] == '/srv/www/web' );
+				if( !$BLOCKED ){
+					fprintf( $FD, "server {\n %s\nserver_name _;\n", $CL );
+				};
+			};
+		};
+		//Output App Web
+		fprintf( $FD, "server {\nroot /srv/www/distro; listen 80 default_server; listen [::]:80 default_server;\n" );
+		if( $SYS_CONFIG['NGINX_CERTIFICATE_INSTALLED'] ){
+			
+		};
+		fprintf( $FD, "index index.html index.htm index.nginx-debian.html index.php;\n" );
+		fprintf( $FD, "server_name _;\n" );
+		fprintf( $FD, 'location / { try_files $uri $uri/ =404; index index.html index.php; }'."\n" );
+		fprintf( $FD, 'location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php-fpm.sock;}'."\n" );
+		fprintf( $FD, "location ~ /\.ht {deny all;}\n}\n" );
+		fclose( $FD );
+		unlink( '/etc/nginx/sites-available/default' );
+		rename( '/etc/nginx/sites-available/default.tmp', '/etc/nginx/sites-available/default' );
+	};
+};
+
+function stop_BACKEND_APPLICATION(){
+	$L = `killall starProcDaemon`;
+	sleep( 1 );
+	$L = `killall mojo_d`;
+	sleep(4);
+	$L = `killall mojo`;
+	sleep(4);
+};
+
+function verify_CERT( $ROOT, $CHEK ){
+	$DADA = trim( `/usr/bin/openssl verify -verbose -CAfile {$ROOT} {$CHEK}` );
+	$TArr = explode( ':', $DADA );
+	return ( stripos( $TArr[1],'ok' ) !== false );
+};
+
+function verify_CERT_KEY( $CERT, $KEY ){
+	$L = `/usr/bin/openssl rsa -in {$KEY} -check -noout`;
+	if( stripos( $L, 'RSA key ok' ) !== false ){
+		$A = `openssl x509 -noout -modulus -in {$CERT}`;
+		$B = `openssl rsa -noout -modulus -in {$KEY}`;
+		if( $A == $B ) return true;
+	};
+	return false;
+};
+
+function get_embed_data_CERT( $CERT ){
+	$DADA = `openssl x509 -text -noout -in {$CERT} -certopt no_header,no_version,no_serial,no_signame,no_validity,no_issuer,no_pubkey,no_sigdump,no_aux`;
+	$TArr = explode( "\n", $DADA );
+	$RD = array();
+	$RD['subject'] = array();
+	$RD['ip'] = array();
+	foreach( $TArr as $T ){
+		$CL = trim( $T );
+		if( stripos( $CL, 'Subject:')!== false ){
+			$BArr = explode( ':', $CL );
+			$RR = explode( ',', $BArr[1] );
+			foreach( $RR as $R ){
+				$ZZ = explode( '=', $R );
+				$RD['subject'][trim( $ZZ[0])]=trim($ZZ[1]);
+			};
+		};
+		if( stripos( $CL, 'IP Address' )!== false ){
+			$BArr = explode( ',', $CL );
+			foreach( $BArr as $B ){
+				$ZZ = explode( ':', $B );
+				$RD['ip'][] = trim( $ZZ[1] );
+			};
+		};
+	};
+	return $RD;
+};	
+
+function list_files( $Path, $Filter = '' ){
+	$RetVal = array();
+	if( is_dir( $Path ) ){
+		$DD = opendir( $Path );
+		if( $DD !== false ){
+			while(( $file = readdir($DD)) !== false ){
+				if( $Filter == '' && $file!= '.' && $file!= '..' ){
+					$RetVal[] = $file;
+				} else {
+					if( preg_match( $Filter, $file ) ) $RetVal[] = $file;
+				};
+			};
+			closedir($DD);
+		};
+	};
+	return $RetVal;
+};
+
+function list_AP_NEARBY( $DEV ){
+	$RV = array();
+	$L = `sudo ip link set {$DEV} up`;
+	$DATA = `sudo iw dev {$DEV} scan | grep SSID`;
+	$L = `sudo ip link set {$DEV} down`;
+	if( $DATA!= '' ){
+		$TArr = explode( "\n", $DATA );
+		foreach( $TArr as $T ){
+			$CL = trim( $T );
+			if( $CL!='' ){
+				$TBarr = explode( ':', $CL );
+				if( isset( $TBarr[1] ) ){
+					$RV[] = $TBarr[1];
+				};
+			};
+		};
+	};
+	return $RV;
+};
+
+?>
\ No newline at end of file