!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/usr/local/lib/node_modules/homebridge-camera-ui/services/mqtt/   drwxr-xr-x
Free 13.09 GB of 57.97 GB (22.58%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     mqtt.service.js (2.22 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
'use-strict';

const mqtt = require('mqtt');

const logger = require('../logger/logger.service');

const pluginHandler = require('../../plugin/services/handler.service');
const uiHandler = require('../../server/services/handler.service');

class Mqtt {
  start(config) {
    const mqttConfigs = config.mqttConfigs;

    const port = config.mqtt.port || '1883';
    const tls = config.mqtt.tls || false;

    logger.debug('Setting up MQTT connection for motion detection...', false, '[Mqtt]');

    const client = mqtt.connect((tls ? 'mqtts://' : 'mqtt://') + config.mqtt.host + ':' + port, {
      username: config.mqtt.username,
      password: config.mqtt.password,
    });

    client.on('connect', () => {
      logger.debug('MQTT connected', false, '[Mqtt]');

      for (const [topic] of mqttConfigs) {
        logger.debug(`Subscribing to MQTT topic: ${topic}`, false, '[Mqtt]');
        client.subscribe(topic + '/#');
      }
    });

    client.on('message', (topic, message) => {
      logger.debug(`Received a new MQTT message ${message.toString()} (${topic})`, false, '[Mqtt]');

      const cameraMqttConfig = mqttConfigs.get(topic);

      if (cameraMqttConfig) {
        message = message.toString();

        let name = cameraMqttConfig.camera;

        let target = cameraMqttConfig.motion ? 'motion' : 'doorbell';

        let active =
          target === 'doorbell'
            ? true
            : cameraMqttConfig.reset
            ? message === cameraMqttConfig.motionResetMessage
              ? false
              : undefined
            : message === cameraMqttConfig.motionMessage
            ? true
            : message === cameraMqttConfig.motionResetMessage
            ? false
            : undefined;

        if (active !== undefined) {
          pluginHandler.handle(target, name, active);
          uiHandler.handle(target, name, active);
        } else {
          logger.warn(
            `The incoming MQTT message (${message}) for the topic (${topic}) was not the same as set in config.json. Skip...`,
            false,
            '[Mqtt]'
          );
        }
      } else {
        logger.warn(`Can not assign the MQTT topic (${topic}) to a camera!`, false, '[Mqtt]');
      }
    });
  }
}

module.exports = new Mqtt();

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0056 ]--