342 lines
8.1 KiB
PHP
342 lines
8.1 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=100vw, initial-scale=1.0">
|
|
<link rel="icon" type="image/png" href="images/favicon.png">
|
|
<link rel="stylesheet" href="style.css">
|
|
<title>RWAT</title>
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<div class="content">
|
|
|
|
<?php
|
|
set_time_limit(600);
|
|
session_start();
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
require "programs.php";
|
|
?>
|
|
|
|
<div class="header">
|
|
<img src="images/logo.png" alt="logo" />
|
|
<h1>RWAT (Resiga WebApi-Tool)</h1>
|
|
</div>
|
|
<h1 class="header"></h1>
|
|
|
|
<hr class="rounded">
|
|
<br>
|
|
|
|
<form method="post" action="index.php">
|
|
<div class="fancy-input">
|
|
<span class="fancy-input-first">
|
|
<label for="site">Site:</label>
|
|
<input type='text' name="site" id="site" value='<?php echo ($_SESSION['site'])?>'>
|
|
</span>
|
|
<span class="fancy-input-first">
|
|
<label for="host">Host:</label>
|
|
<input type='text' name="host" id="host" value='<?php echo ($_SESSION['host'])?>'>
|
|
</span>
|
|
<span class="fancy-input-first">
|
|
<label for="device" >Device:</label>
|
|
<input type='text' name="device" id="device" value='<?php echo ($_SESSION['device'])?>'>
|
|
</span>
|
|
</div>
|
|
|
|
<div class="fancy-input">
|
|
<span class="fancy-input">
|
|
<label for="user">User:</label>
|
|
<input type='text' name="user" id="user" value='<?php echo ($_SESSION['user'])?>'>
|
|
</span>
|
|
<span class="fancy-input">
|
|
<label for="password">Password:</label>
|
|
<input type='password' name="password" id="password" value='<?php echo ($_SESSION['password'])?>'>
|
|
</span>
|
|
<div>
|
|
<div>
|
|
<input type="submit" value="LOGIN" name="submit">
|
|
</span>
|
|
</form>
|
|
|
|
|
|
<?php
|
|
//if (!empty($_GET['host'])){
|
|
|
|
|
|
|
|
|
|
|
|
echo "<script>console.log('Session values updated');</script>";
|
|
|
|
if (($_SESSION['host'] !== $_POST['host']) && (!empty($_POST['host']))){
|
|
$_SESSION['trig'] = 0;
|
|
$_SESSION['host'] = $_POST['host'];
|
|
}
|
|
if (($_SESSION['site'] !== $_POST['site']) && (!empty($_POST['site']))){
|
|
$_SESSION['trig'] = 0;
|
|
$_SESSION['site'] = $_POST['site'];
|
|
}
|
|
if (($_SESSION['device'] !== $_POST['device']) && (!empty($_POST['site']))){
|
|
$_SESSION['trig'] = 0;
|
|
$_SESSION['device'] = $_POST['device'];
|
|
}
|
|
if (($_SESSION['user'] !== $_POST['user']) && (!empty($_POST['site']))){
|
|
$_SESSION['trig'] = 0;
|
|
$_SESSION['user'] = $_POST['user'];
|
|
}
|
|
if (($_SESSION['password'] !== $_POST['password']) && (!empty($_POST['site']))){
|
|
$_SESSION['trig'] = 0;
|
|
$_SESSION['password'] = $_POST['password'];
|
|
}
|
|
|
|
|
|
if ($_SESSION['trig'] < 1){
|
|
$_SESSION['trig']++;
|
|
echo "<script>location.reload();</script>";
|
|
}
|
|
|
|
if(empty($_SESSION['host'])){
|
|
echo ('<h2 class="error"> NO CONNECTION ESTABLISHED </h2>');
|
|
}
|
|
|
|
$host = $_SESSION['host'];
|
|
$site = $_SESSION['site'];
|
|
$device = $_SESSION['device'];
|
|
$user = $_SESSION['user'];
|
|
$password = $_SESSION['password'];
|
|
|
|
/// for debug purposes only
|
|
///echo '<h4>Values in Session:</h4> <h4>Site: '.$_SESSION['site'].' Host: '.$_SESSION['host'].' Device: '.$_SESSION['device'].'</h4>';
|
|
|
|
$auth = base64_encode($user . ":" . $password);
|
|
|
|
$headers = array(
|
|
"Authorization: Basic $auth",
|
|
"Accept: application/json",
|
|
"Content-Type: application/json"
|
|
);
|
|
|
|
|
|
|
|
$url = "http://".$host."/enteliweb/api/.bacnet/".$site."?alt=json";
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic $auth",
|
|
"Accept: application/json",
|
|
"Content-Type: application/json"));
|
|
$output = curl_exec($ch);
|
|
curl_close($ch);
|
|
$contents = json_decode($output, true);
|
|
|
|
|
|
$table = "";
|
|
$keys = array_keys($contents);
|
|
|
|
$keyId =1;
|
|
foreach ($contents as $content){
|
|
|
|
if ($content!="Collection"){
|
|
$table .= '<tr><td>'.$keys[$keyId].'</td><td>'.$content["displayName"].'</td><td class="tdDevType">'.$content["nodeType"].'</td></tr>';
|
|
$keyId++;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$html ="
|
|
|
|
<h2>Devices online:</h2>
|
|
<table>
|
|
<tr><th>Dev ID</th><th>Dev Dame</th><th>Dev Type</th></tr>
|
|
".$table."
|
|
</table>
|
|
";
|
|
echo $html;
|
|
|
|
$table="";
|
|
|
|
|
|
|
|
?>
|
|
<form enctype="multipart/form-data" action="index.php" method="POST">
|
|
<!-- MAX_FILE_SIZE must precede the file input field -->
|
|
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
|
|
<!-- Name of input element determines name in $_FILES array -->
|
|
Select File to upload: <input name="userfile" type="file" />
|
|
<input type="submit" value="UploadCSV" />
|
|
</form>
|
|
|
|
<?php
|
|
$uploaddir = './uploads/';
|
|
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
|
|
|
|
echo '<pre>';
|
|
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
|
|
echo "File is valid, and was successfully uploaded.\n";
|
|
}
|
|
|
|
$directory = "./uploads";
|
|
$filelist ='';
|
|
|
|
// Check if Path is a Directory
|
|
if ( is_dir ( $directory ))
|
|
{
|
|
// open directory
|
|
if ( $handle = opendir($directory) )
|
|
{
|
|
// read every file in directory
|
|
while (($file = readdir($handle)) !== false)
|
|
{
|
|
$rowfilelist++;
|
|
///create Dropdown
|
|
if ($rowfilelist > 2){
|
|
$filelist .= '<option value="'.$file.'">'.$file.'</option>';
|
|
}
|
|
}
|
|
closedir($handle);
|
|
}
|
|
}
|
|
;
|
|
?>
|
|
|
|
<form enctype="multipart/form-data" action="index.php" method="POST">
|
|
<div class="fancy-input">
|
|
|
|
<label class="fancy-input" for="files">Choose a file to write in Database:</label>
|
|
<select id="files" name="files">
|
|
|
|
<?php print_r($filelist);?>
|
|
|
|
</select>
|
|
|
|
<input type="submit" value="FIRE" name="fire" action="index.php"/>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
<br>
|
|
|
|
<?php
|
|
|
|
|
|
$table="";
|
|
$output ="";
|
|
|
|
|
|
if (!empty($_POST['files'])){
|
|
$url = "http://".$host."/enteliweb/api/.bacnet/".$site."/".$device."?alt=json";
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
$date = date("d.m.Y");
|
|
$datesimpl = date("d_m_Y");
|
|
$time = date("H:i");
|
|
$timesimpl = date("H_i");
|
|
$filename = '.\logs\log'.$datesimpl.'_'.$timesimpl.'.txt';
|
|
$logfile = fopen($filename, "a+");
|
|
echo "<script>console.log('Logfile created');</script>";
|
|
|
|
if (file_exists('counter')==TRUE){
|
|
unlink('counter');
|
|
echo "<script>console.log('Counter-File deleted');</script>";
|
|
}
|
|
|
|
|
|
$row = 1;
|
|
$csv ="";
|
|
if (($handle = fopen('./uploads/'.$_POST['files'],"r")) !== FALSE) {
|
|
|
|
$file = $_POST['files'];
|
|
|
|
echo "<script>console.log('File opened $file ');</script>";
|
|
|
|
|
|
while (($data = fgetcsv($handle, 0, ",","\"","\\")) !== FALSE) {
|
|
|
|
// usleep(500000);
|
|
|
|
$num = count($data);
|
|
|
|
echo "<script>console.log('while loop started row $row');</script>";
|
|
|
|
|
|
|
|
$row++;
|
|
|
|
|
|
if ($row>2){
|
|
$handlecounter=fopen('counter',"a+");
|
|
$data[13] = strtolower($data[13]);
|
|
|
|
|
|
analogvalue($data,$device,$ch,$row,$logfile);
|
|
|
|
binaryvalue($data,$device,$ch,$row,$logfile);
|
|
|
|
analoginput($data,$device,$ch,$row,$logfile);
|
|
|
|
analogoutput($data,$device,$ch,$row,$logfile);
|
|
|
|
binaryinput($data,$device,$ch,$row,$logfile);
|
|
|
|
binaryoutput($data,$device,$ch,$row,$logfile);
|
|
|
|
multistatevalue($data,$device,$ch,$row,$logfile);
|
|
|
|
program($data,$device,$ch,$row,$logfile);
|
|
|
|
schedule($data,$device,$ch,$row,$logfile);
|
|
|
|
controller($data,$device,$ch,$row,$logfile);
|
|
|
|
if ($data[13] == 'tl'){
|
|
|
|
trendlog($data,$device,$ch,$row,$logfile);
|
|
|
|
}
|
|
if ($data[13] == 'pgo'){
|
|
|
|
pgobject($data,$device,$ch,$row,$logfile);
|
|
|
|
}
|
|
$ctName = bacname($data);
|
|
fwrite($handlecounter,sprintf("%'.04d", $row).' | '.$ctName.' | '.$data[13].' '.$data[14]."\r\n");
|
|
fclose($handlecounter);
|
|
}
|
|
|
|
}
|
|
fclose($handle);
|
|
}
|
|
|
|
|
|
curl_close($ch);
|
|
fclose($datei); ///Logfile close
|
|
$handlecounter=fopen('counter',"a+");
|
|
fwrite($handlecounter,'Mainloop FINISHED'."\r\n");
|
|
fclose($handlecounter);
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
<script>
|
|
|
|
setInterval(function(){
|
|
fetch('counter')
|
|
.then(response => response.text())
|
|
.then(text => console.log(text))
|
|
// outputs the content of the text file
|
|
}, 3000);
|
|
|
|
</script>
|
|
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|