Skip to content

Commit

Permalink
[powermax] Do not log messages containing the PIN code (openhab#7755)
Browse files Browse the repository at this point in the history
Relative to openhab#3990

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored and andrewfg committed Aug 31, 2020
1 parent 965a643 commit 2854a33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public boolean requestArmMode(PowermaxArmMode armMode, String pinCode) {
dynPart[1] = (byte) Integer.parseInt(pinCode.substring(0, 2), 16);
dynPart[2] = (byte) Integer.parseInt(pinCode.substring(2, 4), 16);

done = sendMessage(new PowermaxBaseMessage(PowermaxSendType.ARM, dynPart), false, 0);
done = sendMessage(new PowermaxBaseMessage(PowermaxSendType.ARM, dynPart), false, 0, true);
} catch (NumberFormatException e) {
logger.debug("Powermax alarm binding: requested arm mode {} rejected due to invalid PIN code",
armMode.getShortName());
Expand Down Expand Up @@ -422,7 +422,7 @@ public boolean sendZoneBypass(boolean bypass, byte zone, String pinCode) {
dynPart[i++] = (byte) ((val >> 16) & 0x000000FF);
dynPart[i++] = (byte) ((val >> 24) & 0x000000FF);

done = sendMessage(new PowermaxBaseMessage(PowermaxSendType.BYPASS, dynPart), false, 0);
done = sendMessage(new PowermaxBaseMessage(PowermaxSendType.BYPASS, dynPart), false, 0, true);
if (done) {
done = sendMessage(new PowermaxBaseMessage(PowermaxSendType.BYPASSTAT), false, 0);
}
Expand Down Expand Up @@ -494,7 +494,7 @@ public boolean requestEventLog(String pinCode) {
dynPart[0] = (byte) Integer.parseInt(pinCode.substring(0, 2), 16);
dynPart[1] = (byte) Integer.parseInt(pinCode.substring(2, 4), 16);

done = sendMessage(new PowermaxBaseMessage(PowermaxSendType.EVENTLOG, dynPart), false, 0);
done = sendMessage(new PowermaxBaseMessage(PowermaxSendType.EVENTLOG, dynPart), false, 0, true);
} catch (NumberFormatException e) {
logger.debug("Powermax alarm binding: requested event log rejected due to invalid PIN code");
}
Expand Down Expand Up @@ -590,16 +590,22 @@ public boolean sendMessageLater(PowermaxSendType msgType, int waitTime) {
return sendMessage(new PowermaxBaseMessage(msgType), false, waitTime);
}

private synchronized boolean sendMessage(PowermaxBaseMessage msg, boolean immediate, int waitTime) {
return sendMessage(msg, immediate, waitTime, false);
}

/**
* Send a message or delay the sending if time frame for receiving response is not ended
*
* @param msg the message to be sent
* @param immediate true if the message has to be send without considering timing
* @param waitTime the delay in seconds to wait
* @param doNotLog true if the message contains data that must not be logged
*
* @return true if the message was sent or the sending is delayed; false in other cases
*/
private synchronized boolean sendMessage(PowermaxBaseMessage msg, boolean immediate, int waitTime) {
private synchronized boolean sendMessage(PowermaxBaseMessage msg, boolean immediate, int waitTime,
boolean doNotLog) {
if ((waitTime > 0) && (msg != null)) {
logger.debug("sendMessage(): delay ({} s) sending message (type {})", waitTime, msg.getSendType());
// Don't queue the message
Expand Down Expand Up @@ -649,7 +655,7 @@ private synchronized boolean sendMessage(PowermaxBaseMessage msg, boolean immedi

if (logger.isDebugEnabled()) {
logger.debug("sendMessage(): sending {} message {}", msgToSend.getSendType(),
HexUtils.bytesToHex(msgToSend.getRawData()));
doNotLog ? "***" : HexUtils.bytesToHex(msgToSend.getRawData()));
}
boolean done = sendMessage(msgToSend.getRawData());
if (done) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,78 +814,4 @@ public String getInfo() {
}
return "Powermax alarm binding:" + str;
}

/**
* Log information about the current settings
*/
public void log() {
logger.info("{}", getInfo());
}

/**
* Log help information relative to items and sitemap entries to be created
*/
public void helpItems() {
int zoneCnt = panelType.getWireless() + panelType.getWired();

String items = "Help for defining items:\n" + "\nGroup GPowermax \"Alarm\""
+ "\nString Powermax_partition_status \"Partition status [%s]\" (GPowermax) {powermax=\"partition_status\"}"
+ "\nSwitch Powermax_partition_ready \"Partition ready\" (GPowermax) {powermax=\"partition_ready\", autoupdate=\"false\"}"
+ "\nSwitch Powermax_partition_bypass \"Partition bypass\" (GPowermax) {powermax=\"partition_bypass\", autoupdate=\"false\"}"
+ "\nSwitch Powermax_partition_alarm \"Partition alarm\" (GPowermax) {powermax=\"partition_alarm\", autoupdate=\"false\"}"
+ "\nSwitch Powermax_panel_trouble \"Panel trouble\" (GPowermax) {powermax=\"panel_trouble\", autoupdate=\"false\"}"
+ "\nSwitch Powermax_panel_alert_in_mem \"Panel alert in memory\" (GPowermax) {powermax=\"panel_alert_in_memory\", autoupdate=\"false\"}"
+ "\nSwitch Powermax_partition_armed \"Partition armed\" (GPowermax) {powermax=\"partition_armed\", autoupdate=\"false\"}"
+ "\nString Powermax_partition_arm_mode \"Partition arm mode [%s]\" (GPowermax) {powermax=\"partition_arm_mode\", autoupdate=\"false\"}";

String sitemap = "Help for defining sitemap:\n" + "\nText label=\"Security\" icon=\"lock\" {"
+ "\nSwitch item=Powermax_partition_armed mappings=[OFF=\"Disarmed\", ON=\"Armed\"]"
+ "\nSwitch item=Powermax_partition_arm_mode mappings=[Disarmed=\"Disarmed\", Stay=\"Armed home\", Armed=\"Armed away\"] valuecolor=[==\"Armed\"=\"green\",==\"Stay\"=\"orange\"]"
+ "\nSwitch item=Powermax_command mappings=[get_event_log=\"Event log\", download_setup=\"Get setup\", log_setup=\"Log setup\", help_items=\"Help items\"]";

for (int i = 1; i <= zoneCnt; i++) {
if (zoneSettings[i - 1] != null) {
items += String.format(
"\nSwitch Powermax_zone%d_status \"Zone %d status\" (GPowermax) {powermax=\"zone_status:%d\", autoupdate=\"false\"}"
+ "\nContact Powermax_zone%d_status2 \"Zone %d status [%%s]\" (GPowermax) {powermax=\"zone_status:%d\"}"
+ "\nDateTime Powermax_zone%d_last_trip \"Zone %d last trip [%%1$tH:%%1$tM]\" (GPowermax) {powermax=\"zone_last_trip:%d\"}"
+ "\nSwitch Powermax_zone%d_bypassed \"Zone %d bypassed\" (GPowermax) {powermax=\"zone_bypassed:%d\", autoupdate=\"false\"}"
+ "\nSwitch Powermax_zone%d_armed \"Zone %d armed\" (GPowermax) {powermax=\"zone_armed:%d\", autoupdate=\"false\"}"
+ "\nSwitch Powermax_zone%d_low_battery \"Zone %d low battery\" (GPowermax) {powermax=\"zone_low_battery:%d\", autoupdate=\"false\"}",
i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
}
}

items += "\nString Powermax_command \"Command\" (GPowermax) {powermax=\"command\", autoupdate=\"false\"}"
+ "\nString Powermax_event_log_1 \"Event log 1 [%s]\" (GPowermax) {powermax=\"event_log:1\"}"
+ "\nString Powermax_event_log_2 \"Event log 2 [%s]\" (GPowermax) {powermax=\"event_log:2\"}"
+ "\nString Powermax_event_log_3 \"Event log 3 [%s]\" (GPowermax) {powermax=\"event_log:3\"}"
+ "\nString Powermax_event_log_4 \"Event log 4 [%s]\" (GPowermax) {powermax=\"event_log:4\"}"
+ "\nString Powermax_event_log_5 \"Event log 5 [%s]\" (GPowermax) {powermax=\"event_log:5\"}"
+ "\nString Powermax_panel_mode \"Panel mode [%s]\" (GPowermax) {powermax=\"panel_mode\"}"
+ "\nString Powermax_panel_type \"Panel type [%s]\" (GPowermax) {powermax=\"panel_type\"}"
+ "\nString Powermax_panel_eeprom \"EPROM [%s]\" (GPowermax) {powermax=\"panel_eprom\"}"
+ "\nString Powermax_panel_software \"Software version [%s]\" (GPowermax) {powermax=\"panel_software\"}"
+ "\nString Powermax_panel_serial \"Serial [%s]\" (GPowermax) {powermax=\"panel_serial\"}";

if (x10Settings[0] != null && x10Settings[0].isEnabled()) {
items += "\nSwitch Powermax_PGM_status \"PGM status\" (GPowermax) {powermax=\"PGM_status\", autoupdate=\"false\"}";
}

for (int i = 1; i < NB_PGM_X10_DEVICES; i++) {
if (x10Settings[i] != null && x10Settings[i].isEnabled()) {
items += String.format(
"\nSwitch Powermax_X10_%d_status \"X10 %d status\" (GPowermax) {powermax=\"X10_status:%d\", autoupdate=\"false\"}"
+ "\nString Powermax_X10_%d_status2 \"X10 %d status [%%s]\" (GPowermax) {powermax=\"X10_status:%d\", autoupdate=\"false\"}",
i, i, i, i, i, i);
sitemap += String.format(
"\nSwitch item=Powermax_X10_%d_status2 mappings=[OFF=\"Off\", ON=\"On\", DIM=\"Dim\", BRIGHT=\"Bright\"]",
i);
}
}

sitemap += "\nGroup item=GPowermax label=\"Alarm\"" + "\n}";

logger.info("Powermax alarm binding:\n{}\n\n{}\n", items, sitemap);
}
}

0 comments on commit 2854a33

Please sign in to comment.