<?php

session_start();
ob_start();

if (empty($_SESSION["WRS_INFO"])){

	$wrsinfogenerator = "/var/www/data/wrs-info-generator.php";
	shell_exec("/usr/bin/php-cgi ".$wrsinfogenerator."> /dev/null 2>&1 &");
	sleep(2);
}
if (is_file("data/wrs-info.php")) include "data/wrs-info.php";

if (empty($_SESSION["WRS_INFO"])){
	$_SESSION["WRS_INFO"] = $GLOBALS["WRS_INFO"];
}

if(empty($_SESSION["KCONFIG"])){
	load_kconfig();
}

if(empty($_SESSION["WRSVERSION"])){
	$_SESSION["WRSVERSION"] = shell_exec("/wr/bin/wrs_version -g");
}

// Forms are firstly generated by default, but can be modified by users.

$WRS_TABLE_INFO = Array (
	'DASHBOARD' => Array(
		'DASHBOARD_00' => Array(
			'name' => 'Hostname',
			'value' => $_SESSION["WRS_INFO"][HOSTNAME],
		),
		'DASHBOARD_02' => Array(
			'name' => 'IP Address',
			'value' => $_SESSION["WRS_INFO"][IPADDRESS],
		),
		'DASHBOARD_03' => Array(
			'name' => 'MAC Address',
			'value' => $_SESSION["WRS_INFO"][MACADDRESS],
		),
		'DASHBOARD_04' => Array(
			'name' => 'Kernel Version',
			'value' => $_SESSION["WRS_INFO"][KERNEL],
		),
		'DASHBOARD_05' => Array(
			'name' => 'Firmware Version',
			'value' => $_SESSION["WRS_INFO"][FIRMWARE],
		),
		'DASHBOARD_06' => Array(
			'name' => 'Hardware Version',
			'value' => $_SESSION["WRS_INFO"][HARDWARE],
		),
		'DASHBOARD_07' => Array(
			'name' => 'FPGA type',
			'value' => $_SESSION["WRS_INFO"][FPGA],
		),
		'DASHBOARD_08' => Array(
			'name' => 'Manufacturer',
			'value' => $_SESSION["WRS_INFO"][MANUFACTURER],
		),
		'DASHBOARD_09' => Array(
			'name' => 'Serial Number',
			'value' => $_SESSION["WRS_INFO"][SERIALNUMBER],
		),
		'DASHBOARD_10' => Array(
			'name' => 'Kernel Compiled Date',
			'value' => $_SESSION["WRS_INFO"][KERNELCOMPILEDDATE],
		),
	),
	'CONTACT' => Array (
		'CONTACT_00' => Array(
			'name' => 'Firmware Version',
			'value' => $_SESSION["WRS_INFO"][FIRMWARE],
		),
		'CONTACT_01' => Array(
			'name' => 'Kernel Version',
			'value' => $_SESSION["WRS_INFO"][KERNEL],
		),
		'CONTACT_02' => Array(
			'name' => 'Compiled By',
			'value' => $_SESSION["WRS_INFO"][COMPILEDBY],
		),
		'CONTACT_03' => Array(
			'name' => 'Kernel Compiled Date',
			'value' => $_SESSION["WRS_INFO"][KERNELCOMPILEDDATE],
		),
		'CONTACT_04' => Array(
			'name' => 'Hardware Version',
			'value' => $_SESSION["WRS_INFO"][HARDWARE],
		),
		'CONTACT_05' => Array(
			'name' => 'FPGA Version',
			'value' => $_SESSION["WRS_INFO"][FPGA],
		),
		'CONTACT_06' => Array(
			'name' => 'Manufacturer',
			'value' => $_SESSION["WRS_INFO"][MANUFACTURER],
		),
		'CONTACT_07' => Array(
			'name' => 'Serial Number',
			'value' => $_SESSION["WRS_INFO"][SERIALNUMBER],
		),
		'CONTACT_08' => Array(
			'name' => 'Gateware Version',
			'value' => $_SESSION["WRS_INFO"][GATEWARE],
		),
		'CONTACT_09' => Array(
			'name' => 'Gateware Build',
			'value' => $_SESSION["WRS_INFO"][GATEWAREBUILD],
		),
		'CONTACT_10' => Array(
			'name' => 'WR Switch HDL Commit',
			'value' => $_SESSION["WRS_INFO"][WRSHDLCOMMIT],
		),
		'CONTACT_11' => Array(
			'name' => 'General Cores Commit',
			'value' => $_SESSION["WRS_INFO"][GCORESCOMMIT],
		),
		'CONTACT_12' => Array(
			'name' => 'WR Cores Commit',
			'value' => $_SESSION["WRS_INFO"][WRCORESCOMMIT],
		),
	),
);

$WRS_FORMS = Array(
	'DNS_SETUP' => Array(
		'DNS_SETUP_00' => Array(
			'key' => "CONFIG_DNS_SERVER",
			'name' => "DNS Server",
			'value' => $_SESSION["KCONFIG"]["CONFIG_DNS_SERVER"],
			'vname' => "dnsserver",
		),
		'DNS_SETUP_01' => Array(
			'key' => "CONFIG_DNS_DOMAIN",
			'name' => "DNS Domain",
			'value' => $_SESSION["KCONFIG"]["CONFIG_DNS_DOMAIN"],
			'vname' => "dnsdomain",
		),
	),

	'SYSTEM_LOGS' => Array(
		'SYSTEM_LOGS_00' => Array(
			'key' => "CONFIG_WRS_LOG_HAL",
			'name' => "Logging directions for the WR HAL",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_HAL"],
			'vname' => "loghal",
		),
		'SYSTEM_LOGS_01' => Array(
			'key' => "CONFIG_WRS_LOG_LEVEL_HAL",
			'name' => "Logging verbosity level for the WR HAL",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_LEVEL_HAL"],
			'vname' => "loglevelhal",
		),

		'SYSTEM_LOGS_02' => Array(
			'key' => "CONFIG_WRS_LOG_RTU",
			'name' => "Logging directions for the RTU daemon",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_RTU"],
			'vname' => "logrtu",
		),
		'SYSTEM_LOGS_03' => Array(
			'key' => "CONFIG_WRS_LOG_LEVEL_RTU",
			'name' => "Logging verbosity level for the RTU daemon",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_LEVEL_RTU"],
			'vname' => "loglevelrtu",
		),

		'SYSTEM_LOGS_04' => Array(
			'key' => "CONFIG_WRS_LOG_PTP",
			'name' => "Logging directions for the PTP daemon",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_PTP"],
			'vname' => "logptp",
		),
		'SYSTEM_LOGS_05' => Array(
			'key' => "CONFIG_WRS_LOG_LEVEL_PTP",
			'name' => "Logging verbosity level for the PTP daemon",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_LEVEL_PTP"],
			'vname' => "loglevelptp",
		),

		'SYSTEM_LOGS_06' => Array(
			'key' => "CONFIG_WRS_LOG_OTHER",
			'name' => "Logging directions for other programs",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_OTHER"],
			'vname' => "logother",
		),
		'SYSTEM_LOGS_07' => Array(
			'key' => "CONFIG_WRS_LOG_LEVEL_OTHER",
			'name' => "Logging verbosity level for other programs",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_LEVEL_OTHER"],
			'vname' => "loglevelother",
		),

		'SYSTEM_LOGS_08' => Array(
			'key' => "CONFIG_WRS_LOG_MONIT",
			'name' => "Monit log",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_MONIT"],
			'vname' => "logmonit",
		),
		'SYSTEM_LOGS_09' => Array(
			'key' => "CONFIG_WRS_LOG_SNMPD",
			'name' => "SNMPd log",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRS_LOG_SNMPD"],
			'vname' => "logsnmp",
		),
	),

	'NETWORK_SETUP' => Array(
		'NETWORK_SETUP_00' => Array(
			'key' => "CONFIG_ETH0_IP",
			'name' => IPADDRESS,
			'value' => $_SESSION["WRS_INFO"][IPADDRESS],
			'vname' => "ethip",
		),
		'NETWORK_SETUP_01' => Array(
			'key' => "CONFIG_ETH0_MASK",
			'name' => NETMASK,
			'value' => $_SESSION["WRS_INFO"][NETMASK],
			'vname' => "ethnetmask",
		),
		'NETWORK_SETUP_02' => Array(
			'key' => "CONFIG_ETH0_BROADCAST",
			'name' => BROADCAST,
			'value' => $_SESSION["WRS_INFO"][BROADCAST],
			'vname' => "ethbroadcast",
		),
		'NETWORK_SETUP_03' => Array(
			'key' => "CONFIG_ETH0_MAC",
			'name' => MACADDRESS,
			'value' => $_SESSION["WRS_INFO"][MACADDRESS],
			'vname' => "ethmac",
		),
	),

	'CONFIG_PPSI' => Array(
		'CONFIG_PPSI_00' => Array(
			'name' => "Clock Class",
			'value' => "",
			'vname' => "clkclass",
		),
		'CONFIG_PPSI_01' => Array(
			'name' => "Clock Accuracy",
			'value' => "",
			'vname' => "clkacc",
		),
	),

	'CONFIG_WRSAUXCLK' => Array(
		'CONFIG_WRSAUXCLK_00' => Array(
			'key' => "CONFIG_WRSAUXCLK_FREQ",
			'name' => "Frequency",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRSAUXCLK_FREQ"],
			'vname' => "auxclkfreq",
		),
		'CONFIG_WRSAUXCLK_01' => Array(
			'key' => "CONFIG_WRSAUXCLK_DUTY",
			'name' => "Duty",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRSAUXCLK_DUTY"],
			'vname' => "auxclkduty",
		),
		'CONFIG_WRSAUXCLK_02' => Array(
			'key' => "CONFIG_WRSAUXCLK_CSHIFT",
			'name' => "C. Shift",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRSAUXCLK_CSHIFT"],
			'vname' => "auxclkcshift",
		),
		'CONFIG_WRSAUXCLK_03' => Array(
			'key' => "CONFIG_WRSAUXCLK_SIGDEL",
			'name' => "Signal",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRSAUXCLK_SIGDEL"],
			'vname' => "auxclksigdel",
		),
		'CONFIG_WRSAUXCLK_04' => Array(
			'key' => "CONFIG_WRSAUXCLK_PPSHIFT",
			'name' => "PP. Shift",
			'value' => $_SESSION["KCONFIG"]["CONFIG_WRSAUXCLK_PPSHIFT"],
			'vname' => "auxclkppshift",
		),
		'CONFIG_WRSAUXCLK_05' => Array(
			'key' => "CONFIG_EXT_PPS_LATENCY_PS",
			'name' => "EXT PPS LATENCY",
			'value' => $_SESSION["KCONFIG"]["CONFIG_EXT_PPS_LATENCY_PS"],
			'vname' => "extppslatency",
		),
	),

);

?>




