mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
auth
This commit is contained in:
@@ -110,7 +110,7 @@ public class BridgeSettings extends BackupHandler {
|
||||
theBridgeSettings.setVeraAddress(theVeraList);
|
||||
|
||||
theFibaroAddress = System.getProperty("fibaro.address");
|
||||
IpList theFibaroList = null;
|
||||
IpList theFibaroList = null;
|
||||
if(theFibaroAddress != null) {
|
||||
try {
|
||||
theFibaroList = new Gson().fromJson(theFibaroAddress, IpList.class);
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package com.bwssystems.HABridge.plugins.fibaro;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bwssystems.HABridge.NamedIP;
|
||||
import com.bwssystems.HABridge.plugins.http.HTTPHandler;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class FibaroInfo
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(FibaroInfo.class);
|
||||
private HTTPHandler httpClient;
|
||||
private NamedIP fibaroAddress;
|
||||
|
||||
// You can disable it if you want
|
||||
@@ -22,7 +26,6 @@ public class FibaroInfo
|
||||
public FibaroInfo(NamedIP addressName)
|
||||
{
|
||||
super();
|
||||
httpClient = new HTTPHandler();
|
||||
fibaroAddress = addressName;
|
||||
}
|
||||
|
||||
@@ -35,10 +38,8 @@ public class FibaroInfo
|
||||
Device[] all_devices = getAllDevices();
|
||||
int count = 0;
|
||||
for(Device d : all_devices)
|
||||
{
|
||||
if(d.roomID > 0 && useSaveLogs ? "true".equals(d.properties.saveLogs) : true)
|
||||
count++;
|
||||
}
|
||||
|
||||
Device[] devices = new Device[count];
|
||||
int i = 0;
|
||||
@@ -62,7 +63,7 @@ public class FibaroInfo
|
||||
d.fibaroname = fibaroAddress.getName();
|
||||
}
|
||||
|
||||
log.debug("Founded: " + devices.length + " devices");
|
||||
log.info("Founded: " + devices.length + " devices");
|
||||
|
||||
return devices;
|
||||
}
|
||||
@@ -92,7 +93,7 @@ public class FibaroInfo
|
||||
s.fibaroaddress = fibaroAddress.getIp();
|
||||
s.fibaroname = fibaroAddress.getName();
|
||||
}
|
||||
System.out.println("Founded: " + count + " scenes");
|
||||
log.info("Founded: " + count + " scenes");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -125,7 +126,35 @@ public class FibaroInfo
|
||||
private String request(String theUrl)
|
||||
{
|
||||
theUrl = "http://" + fibaroAddress.getIp() + "/api/" + theUrl;
|
||||
return httpClient.doHttpRequest(theUrl, null, null, null, null);
|
||||
String auth = new String(Base64.encodeBase64((fibaroAddress.getUsername() + ":" + fibaroAddress.getPassword()).getBytes()));
|
||||
java.net.URL url;
|
||||
java.net.HttpURLConnection connection;
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
url = new URL(theUrl);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setRequestProperty("Authorization", "Basic " + auth);
|
||||
connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
|
||||
connection.setRequestProperty("X-Requested-With", "XMLHttpRequest");
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36");
|
||||
connection.connect();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
String line;
|
||||
while((line = br.readLine()) != null)
|
||||
buffer.append(line).append("\n");
|
||||
br.close();
|
||||
result = buffer.toString();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
log.info("Error while get getJson: " + theUrl);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String replaceDigits(String name)
|
||||
|
||||
@@ -1331,14 +1331,16 @@ app.controller ('SystemController', function ($scope, $location, bridgeService,
|
||||
}
|
||||
}
|
||||
};
|
||||
$scope.addFibarotoSettings = function (newfibaroname, newfibaroip) {
|
||||
$scope.addFibarotoSettings = function (newfibaroname, newfibaroip, newfibarousername, newfibaropassword) {
|
||||
if($scope.bridge.settings.fibaroaddress === undefined || $scope.bridge.settings.fibaroaddress === null) {
|
||||
$scope.bridge.settings.fibaroaddress = { devices: [] };
|
||||
}
|
||||
var newFibaro = {name: newfibaroname, ip: newfibaroip }
|
||||
var newFibaro = {name: newfibaroname, ip: newfibaroip, username: newfibarousername, password: newfibaropassword }
|
||||
$scope.bridge.settings.fibaroaddress.devices.push(newFibaro);
|
||||
$scope.newfibaroname = null;
|
||||
$scope.newfibaroip = null;
|
||||
$scope.newfibarousername = null;
|
||||
$scope.newfibaropassword = null;
|
||||
};
|
||||
$scope.removeFibarotoSettings = function (fibaroname, fibaroip) {
|
||||
for(var i = $scope.bridge.settings.fibaroaddress.devices.length - 1; i >= 0; i--) {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<li role="presentation"><a href="#!/">Bridge Devices</a></li>
|
||||
<li role="presentation"><a href="#!/system">Bridge Control</a></li>
|
||||
<li role="presentation"><a href="#!/logs">Logs</a></li>
|
||||
<li role="presentation"><a href="#!/veradevices">Vera Devices</a></li>
|
||||
<li role="presentation"><a href="#!/verascenes">Vera Scenes</a></li>
|
||||
<li ng-if="bridge.showVera" role="presentation"><a href="#!/veradevices">Vera Devices</a></li>
|
||||
<li ng-if="bridge.showVera" role="presentation"><a href="#!/verascenes">Vera Scenes</a></li>
|
||||
<li role="presentation" class="active"><a href="#!/fibarodevices">Fibaro Devices</a></li>
|
||||
<li role="presentation"><a href="#!/fibaroscenes">Fibaro Scenes</a></li>
|
||||
<li ng-if="bridge.showHarmony" role="presentation"><a
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<li role="presentation"><a href="#!/">Bridge Devices</a></li>
|
||||
<li role="presentation"><a href="#!/system">Bridge Control</a></li>
|
||||
<li role="presentation"><a href="#!/logs">Logs</a></li>
|
||||
<li role="presentation"><a href="#!/veradevices">Vera Devices</a></li>
|
||||
<li role="presentation"><a href="#!/verascenes">Vera Scenes</a></li>
|
||||
<li ng-if="bridge.showVera" role="presentation"><a href="#!/veradevices">Vera Devices</a></li>
|
||||
<li ng-if="bridge.showVera" role="presentation"><a href="#!/verascenes">Vera Scenes</a></li>
|
||||
<li role="presentation"><a href="#!/fibarodevices">Fibaro Devices</a></li>
|
||||
<li role="presentation" class="active"><a href="#!/fibaroscenes">Fibaro Scenes</a></li>
|
||||
<li ng-if="bridge.showHarmony" role="presentation"><a
|
||||
|
||||
@@ -142,12 +142,17 @@
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>IP</th>
|
||||
<th>Username</th>
|
||||
<th>Password </th>
|
||||
<th>Manage</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr ng-repeat="fibaro in bridge.settings.fibaroaddress.devices">
|
||||
<td>{{fibaro.name}}</td>
|
||||
<td>{{fibaro.ip}}</td>
|
||||
<td>{{fibaro.username}}</td>
|
||||
<td ng-if="fibaro.password">*******</td>
|
||||
<td ng-if="!fibaro.password"> </td>
|
||||
<td><button class="btn btn-danger" type="submit"
|
||||
ng-click="removeFibarotoSettings(fibaro.name, fibaro.ip)">Del</button></td>
|
||||
</tr>
|
||||
@@ -158,8 +163,14 @@
|
||||
<td><input id="bridge-settings-next-fibaro-ip"
|
||||
class="form-control" type="text" ng-model="newfibaroip"
|
||||
placeholder="192.168.1.2"></td>
|
||||
<td><input id="bridge-settings-next-fibaro-username"
|
||||
class="form-control" type="text" ng-model="newfibarousername"
|
||||
placeholder="Fibaro username"></td>
|
||||
<td><input id="bridge-settings-next-fibaro-password"
|
||||
class="form-control" type="password" ng-model="newfibaropassword"
|
||||
placeholder="Fibaro password"></td>
|
||||
<td><button class="btn btn-success" type="submit"
|
||||
ng-click="addFibarotoSettings(newfibaroname, newfibaroip)">Add</button></td>
|
||||
ng-click="addFibarotoSettings(newfibaroname, newfibaroip, newfibarousername, newfibaropassword)">Add</button></td>
|
||||
</tr>
|
||||
</table></td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user