/* Launch gateway/device logic All the gateway/device logic is broken into include files that are only loaded into the particular worker fork which is using that gateway. If we can't load it for some reason we should fail with an error to all the apps. */ if (!$config[$section]["gw_type"]) { $log->error_fatal("There is no gateway set! Unable to proceed!"); } $gatewayfile = realpath(dirname(__FILE__)) . "/include/gateways/" . $config[$section]["gw_type"] . ".php"; if (!file_exists($gatewayfile)) { $log->error_fatal("The gateway include {$gatewayfile} could not be located - is this the correct gateway name?"); } include $gatewayfile; $gateway = new device_gateway(); if (!$gateway->set_path($config[$section]["gw_path"])) { $log->error("Invalid syntax for gw_path option! Please check your configuration"); } /* Start Message Processer */ // track whom we are chatting with $current_chat = null; $current_status = null; // generate a message type ID we can use to listen on $msg_mylistener = intval(base_convert(hash("crc32", $section, false), 16, 10)); // handle posix signals in a sane way pcntl_signal(SIGTERM, "sig_handler_child"); pcntl_signal(SIGHUP, "sig_handler_child"); pcntl_signal(SIGINT, "sig_handler_child");
if (!$config[$device]) { header('HTTP/1.1 500 Internal Server Error'); $log->error_fatal("[listener] An invalid destination device was requested - make sure you are using the correct ?device=example tag"); } if (!$config[$device]["gw_type"]) { header('HTTP/1.1 500 Internal Server Error'); $log->error_fatal("[listener] There is no gateway set! Unable to proceed!"); } $gatewayfile = "include/gateways/" . $config[$device]["gw_type"] . ".php"; if (!file_exists($gatewayfile)) { header('HTTP/1.1 500 Internal Server Error'); $log->error("[listener] The gateway include {$gatewayfile} could not be located - is this the correct gateway name?"); $log->error_fatal("[listener] Sorry, there is no such destination device - please check your input."); } include $gatewayfile; $gateway = new device_gateway(); /* Fetch the message details & input validate. Whilst there's no SQL DB to worry about, we do need to filter the phone number and body to ensure they're valid and that there's no sneaky XML injection taking place that could mess with the generated XMPP message. Format: $message_raw["phone"] Source phone number $message_raw["body"] Message string */ $message_raw = $gateway->message_listen(); if (!$message_raw) { header('HTTP/1.1 500 Internal Server Error'); $log->error_fatal("[listener] An invalid message request was recieved, unable to process."); } $message = array();