-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup_admin.php
154 lines (135 loc) · 4.83 KB
/
setup_admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
require_once("include/common.php");
require_once("include/linknx.php");
header('Content-Type: text/html; charset=UTF-8');
tpl()->addJs('js/setup_admin.js');
tpl()->assignByRef("lang",$lang);
tpl()->assign('progstatus', (isset($_GET['progstatus'])));
tpl()->assign('configknxweb', (isset($_GET['configknxweb'])));
tpl()->assign('logobjects', (isset($_GET['logobjects'])));
tpl()->assign('loglinknx', (isset($_GET['loglinknx'])));
tpl()->assign('networksetup', false);
$Fnetwork ='/etc/network/interfaces';
$log_Linknx =''; // /tmp/linknx.log ou autre exemple : /var/lib/linknx/linknx.log
$pathLog = ''; // exemple : "/var/lib/linknx/log"
$logType = ''; // '' / 'file' / 'mysql'
if (isset($_GET['logobjects']) || isset($_GET['loglinknx']))
{
$linknx=new Linknx($_config['linknx_host'], $_config['linknx_port']);
$info=$linknx->getLogging();
if ($info!==false) {
$log_Linknx = $info['logging']['output'];
}
$info=$linknx->getServices();
if ($info!==false) {
$logType = $info['persistence']['type'];
if ($logType == 'file') $pathLog = $info['persistence']['logpath'];
}
if ($logType == 'file') {
$objects=$linknx->getObjects();
//$logfile = glob( dirname(dirname(__FILE__)) .$pathLog.'*.log');
$logfile = glob($pathLog.'*.log');
$order = array( $pathLog , '.log' );
foreach ($logfile as $value) {
$id = str_replace($order, '', $value);
$type = $objects[$id]["type"];
$listobjectlog[$id] = $value . '_type_' . $type;
}
}
if ($logType == 'mysql') {
// requete sur la base mysql $info['persistence'][] host/user/pass/db/table/logtable
// $listobjectlog[$object] = $object
$serveur = $info['persistence']['host'];
$login = $info['persistence']['user'];
$password = $info['persistence']['pass'];
$base = $info['persistence']['db']; //"linknx";
$table = $info['persistence']['logtable']; //"log";
// structure de la table logtable
$ts = "ts";
$object = "object";
$value = "value";
// On ouvre la connexion à Mysql
$db = mysql_connect($serveur, $login, $password) or die('<h1>Connexion au serveur impossible !</h1>');
mysql_select_db($base,$db) or die('<h1>Connexion impossible à la base</h1>');
$sql = "SELECT DISTINCT ".$object." AS obj FROM ".$table;
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$nbenreg = mysql_num_rows($req);
$nbenreg--;
while ($nbenreg > 0 ){
// récupérer prochaine occurence de la table
$data = mysql_fetch_array($req);
$type = $objects[$data["obj"]]["type"];
$listobjectlog[$data["obj"]] = $data["obj"] . '_type_' . $type;
$nbenreg--;
}
mysql_close();
}
}
tpl()->assignByRef('logFile', $listobjectlog );
tpl()->assignByRef('logType',$logType);
if (isset($_GET['progstatus']))
{
require("include/admin.php");
tpl()->assign('networksetup', true);
} else {
$network=array();
$linknxLog="";
$eibd_running="";
$eibd_running_param="";
$linknx_running="";
$linknx_running_param="";
$widgetscss = "widgets/widgets.css";
$widgetscssexist = false;
$widgetscss = "";
}
if (isset($_GET['configknxweb']))
{
$widgetscss = "widgets/widgets.css";
$widgetscssexist = false;
$widgetscssiswritable = false;
if ( file_exists($widgetscss) ) {
$widgetscssexist = true;
$widgetscssiswritable = is_writable( $widgetscss );
$contentwidgetscss = '';
//if ( !$error && filesize($widgetscss) > 0 ) {
if (filesize($widgetscss) > 0 ) {
$f = fopen($widgetscss, 'r');
$contentwidgetscss = fread($f, filesize($widgetscss));
}
} else {
$widgetscss = "";
}
}
if (file_exists('/etc/init.d/eibd')) {
$eibd_initd = true;
} else $eibd_initd = false;
tpl()->assignByRef('eibd_initd', $eibd_initd);
if (file_exists('/etc/init.d/linknx')) {
$linknx_initd = true;
} else $linknx_initd = false;
tpl()->assignByRef('linknx_initd', $linknx_initd);
tpl()->assignByRef('_SERVER', $_SERVER);
tpl()->assignByRef('eibd_running', $eibd_running);
tpl()->assignByRef('eibd_running_param', $eibd_running_param);
tpl()->assignByRef('linknx_running', $linknx_running);
tpl()->assignByRef('linknx_running_param', $linknx_running_param);
tpl()->assignByRef('network', $network);
tpl()->assignByRef('linknxLog', $linknxLog);
tpl()->assignByRef('widgetscss', $widgetscss);
tpl()->assignByRef('widgetscssiswritable', $widgetscssiswritable);
tpl()->assignByRef('contentwidgetscss', $contentwidgetscss);
/* gestions des pgm supplémentaire utilisateurs */
if (file_exists("include/pgmrunning.php") && isset($_GET['progstatus'])) {
$pgmrunning = array();
$pgmrunning_param = array();
require_once("include/pgmrunning.php");
} else {
$pgmrunning = array();
$pgmrunning_param = array();
}
tpl()->assignByRef("pgmrunning",$pgmrunning);
tpl()->assignByRef("pgmrunning_param",$pgmrunning_param);
$uitheme = getUiThemes();
tpl()->assignByRef('uitheme', $uitheme);
tpl()->display('setup_admin.tpl');
?>