/** * Used then instance is destroyed */ public function instanceDestroyed($params) { try { // Remove shared roasters erLhcoreClassExtensionXmppserviceHandler::instanceDestroyed(array('subdomain' => str_replace('.', '-', $params['instance']->address), 'xmpp_host' => $this->settings['xmpp_host'], 'node_api_server' => $this->settings['node_api_server'], 'handler' => $this->settings['handler'], 'rpc_server' => $this->settings['rpc_server'], 'rpc_username' => $this->settings['rpc_username'], 'rpc_password' => $this->settings['rpc_password'], 'rpc_account_host' => $this->settings['rpc_account_host'])); // Remove users foreach (erLhcoreClassModelXMPPAccount::getList(array('limit' => 1000000)) as $user) { $user->removeThis(); } } catch (Exception $e) { erLhcoreClassLog::write(print_r($e, true)); } }
/** * Arguments * array('chat' => & $chat) * */ public function sevabot($params) { $settings = (include 'extension/sevabot/settings/settings.ini.php'); // Format message content $chat = $params['chat']; $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id)))); $messagesContent = ''; foreach ($messages as $msg) { if ($msg->user_id == -1) { $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n"; } else { $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n"; } } $cfgSite = erConfigClassLhConfig::getInstance(); $secretHash = $cfgSite->getSetting('site', 'secrethash'); $chatDataItems = $settings['chat']; if (isset($settings['chat_dep'][$chat->dep_id]) && !empty($settings['chat_dep'][$chat->dep_id])) { $chatDataItems = array_merge($chatDataItems, $settings['chat_dep'][$chat->dep_id]); } // Global notifications foreach ($chatDataItems as $chatData) { $veryfyEmail = sha1(sha1($chatData['email'] . $secretHash) . $secretHash); $msgParsed = str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, erLhcoreClassXMP::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $chatData['email'], $chat->id, $chat->user_name), $settings['msg']); $md5 = md5($chatData['chat_id'] . $msgParsed . $settings['sevabot_secret']); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $settings['url']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, array('md5' => $md5, 'msg' => $msgParsed, 'chat' => $chatData['chat_id'])); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Some hostings produces wargning... $content = curl_exec($ch); if ($content != 'OK') { erLhcoreClassLog::write(print_r($content, true)); } } }
<?php /* This is what messages looks like $params = array( 'body' => 'PArasiau vartotojui zinute', 'sender' => 'remdex2', 'receiver' => 'visitor.6034.chat', 'server' => 'xmpp.livehelperchat.com' ); */ //erLhcoreClassLog::write(print_r($_POST,true)); if (erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['enabled'] == false) { erLhcoreClassModule::redirect('/'); exit; } $params = array('body' => isset($_POST['body']) ? $_POST['body'] : '', 'sender' => isset($_POST['sender']) ? $_POST['sender'] : '', 'receiver' => isset($_POST['receiver']) ? $_POST['receiver'] : '', 'server' => isset($_POST['server']) ? $_POST['server'] : ''); try { if (!empty($params['body']) && !empty($params['sender']) && !empty($params['receiver']) && !empty($params['server'])) { erLhcoreClassExtensionXmppserviceHandler::handleMessageFromOperator($params); } } catch (Exception $e) { if (erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['debug'] == true) { erLhcoreClassLog::write(print_r($e, true)); } } exit;
if ($instance->is_reseller) { $instance->reseller_request += $requestNumber; } else { $instance->request += $requestNumber; } if ($instance->expires == 0 || $instance->expires < time()) { $instance->expires = time() + (int) $periodDays * 24 * 3600; } else { $instance->expires += (int) $periodDays * 24 * 3600; } $instance->saveThis(); // Set expire inform status $instance->setExpireInformStatus(); $db->commit(); } catch (Exception $e) { $db->rollback(); throw $e; } } else { throw new Exception('This transaction was already processed'); } } catch (Exception $e) { erLhcoreClassLog::write(print_r($raw_post_data, true) . "\n" . $e->getMessage()); } } else { if (strcmp($res, "INVALID") == 0) { erLhcoreClassLog::write("Invalid"); erLhcoreClassLog::write(print_r($raw_post_data, true) . "\n" . $res); } } exit;
/** * Creates required shared roasters * * @todo add support for RPC * * */ public static function registerInstanceRoasters($params) { // First register visitors shared roaster $data[] = array("group" => "visitors." . $params['subdomain'], "host" => $params['xmpp_host'], "name" => "Visitors", "desc" => "Visitors", "display" => '\\"\\"', "display_array" => array()); // Register operators shared roaster $data[] = array("group" => "operators." . $params['subdomain'], "host" => $params['xmpp_host'], "name" => "Operators", "desc" => "Operators", "display" => '\\"operators.' . $params['subdomain'] . '\\\\nvisitors.' . $params['subdomain'] . '\\"', "display_array" => array('operators.' . $params['subdomain'], 'visitors.' . $params['subdomain'])); if ($params['handler'] == 'rpc') { try { $rpc = new \GameNet\Jabber\RpcClient(array('server' => $params['rpc_server'], 'host' => $params['xmpp_host'], 'account_host' => $params['rpc_account_host'], 'username' => $params['rpc_username'], 'password' => $params['rpc_password'])); foreach ($data as $groupData) { $infoSharedRoaster = $rpc->getInfoSharedRosterGroup($groupData['group']); if (empty($infoSharedRoaster)) { $rpc->createSharedRosterGroup($groupData['group'], $groupData['name'], $groupData['desc'], $groupData['display_array']); } } } catch (Exception $e) { if (erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['debug'] == true) { erLhcoreClassLog::write(print_r($e, true)); } } } else { foreach ($data as $groupData) { try { $response = self::sendRequest($params['node_api_server'] . '/xmpp-setup-instance-roasters', $groupData); if ($response['error'] == true) { throw new Exception($response['msg']); } } catch (Exception $e) { if (erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['debug'] == true) { erLhcoreClassLog::write(print_r($e, true)); } } } } }