From db1b51ae8ac98cb58e9084ad9cd3234b0f9fb226 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 9 Apr 2013 15:45:10 +0000 Subject: [PATCH] Add an ability to run cron job --- src/messenger/webim/cron.php | 31 +++++++++++++++++++ src/messenger/webim/libs/classes/settings.php | 6 +++- src/messenger/webim/libs/common/constants.php | 9 ++++++ src/messenger/webim/locales/en/properties | 3 ++ src/messenger/webim/locales/ru/properties | 3 ++ src/messenger/webim/operator/settings.php | 17 +++++++++- src/messenger/webim/view/settings.php | 9 ++++++ 7 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/messenger/webim/cron.php diff --git a/src/messenger/webim/cron.php b/src/messenger/webim/cron.php new file mode 100644 index 00000000..eb0942bb --- /dev/null +++ b/src/messenger/webim/cron.php @@ -0,0 +1,31 @@ +triggerEvent('cronRun'); + +?> \ No newline at end of file diff --git a/src/messenger/webim/libs/classes/settings.php b/src/messenger/webim/libs/classes/settings.php index 32eb0a30..1d7a632d 100644 --- a/src/messenger/webim/libs/classes/settings.php +++ b/src/messenger/webim/libs/classes/settings.php @@ -52,9 +52,11 @@ Class Settings { /** * Settings class constructor. Set default values and load setting from database. * @global $home_locale Specifies home locale. Defined in libs/config.php + * @global $default_cron_key Default value for cron security key. Defined + * in libs/common/constants.php */ protected function __construct() { - global $home_locale; + global $home_locale, $default_cron_key; // Set default values $this->settings = array( 'dbversion' => 0, @@ -100,6 +102,8 @@ Class Settings { 'visitors_limit' => 20, /* Number of visitors to look over */ 'invitation_lifetime' => 60, /* Lifetime for invitation to chat */ 'tracking_lifetime' => 600, /* Time to store tracked old visitors' data */ + + 'cron_key' => $default_cron_key ); // Load values from database diff --git a/src/messenger/webim/libs/common/constants.php b/src/messenger/webim/libs/common/constants.php index 284482ba..1531b71f 100644 --- a/src/messenger/webim/libs/common/constants.php +++ b/src/messenger/webim/libs/common/constants.php @@ -36,6 +36,15 @@ $featuresversion = '1.6.4'; */ $session_prefix = md5($mysqlhost.'##'.$mysqldb.'##'.$mysqlprefix) . '_'; +/** + * Default value for cron security key. + * Another value can be set at operator/settings.php page. + */ +$default_cron_key = md5( + $mysqlhost . '##' . $mysqldb . '##' . $mysqllogin. '##' . + $mysqlpass . '##' . $mysqlprefix . '##' +); + /** * Name for cookie to track visitor */ diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index bce42121..8c7300f8 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -487,6 +487,8 @@ settings.chatstyle.description=A preview all pages for each style is available < settings.chatstyle=Select a style for your chat windows settings.company.title.description=Enter your company title settings.company.title=Company title +settings.cronkey=Cron security key +settings.cronkey.description=To run cron use link {0}. settings.email.description=Enter an email to receive system messages settings.email=Email settings.enableban.description=Using it you can block attacks from specific IPs @@ -555,6 +557,7 @@ settings.usernamepattern.description=How to build visitor's identifying string f settings.usernamepattern=Visitor's identifier settings.visitorslimit.description=Specify the number of items to display in tracked visitors list. Default is 20. Set 0 for all visitors (not recommended). settings.visitorslimit=Limit for tracked visitors list +settings.wrong.cronkey=Use only Latin letters(upper and lower case) and numbers in cron key. settings.wrong.email=Enter a valid email address settings.wrong.onehostconnections="Max number of threads" field should be a number settings.wrong.threadlifetime="Thread lifetime" field should be a number diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index 72b8f9f1..0c3c39df 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -486,6 +486,8 @@ settings.chatstyle.description= settings.chatstyle=Выберите вид вашего чат окна settings.company.title.description=Введите название Вашей компании settings.company.title=Название компании +settings.cronkey=Ключ безопасности cron +settings.cronkey.description=Для запуска cron используйте ссылку {0}. settings.email.description=Введите адрес электронной почты для получения сообщений от системы settings.email=Адрес электронной почты settings.enableban.description=С ее помощью можно блокировать атаки с определенных адресов @@ -557,6 +559,7 @@ settings.usernamepattern.description= settings.usernamepattern=Отображаемое имя посетителя settings.visitorslimit.description=Укажите количество выводимых в списке отслеживаемых посетителей сайта. По умолчанию, 20. Укажите 0 для снятия ограничения (не рекомендуется). settings.visitorslimit=Ограничение на число выводимых в списке отслеживаемых посетителей +settings.wrong.cronkey=Используйте только Латинские буквы(верхнего и нижнего регистра) и цифры в ключе безопасности cron. settings.wrong.email=Введите правильный адрес электронной почты settings.wrong.onehostconnections=Поле "Максимальное количество диалогов" должно быть числом settings.wrong.threadlifetime=Поле "Время жизни диалога" должно быть числом diff --git a/src/messenger/webim/operator/settings.php b/src/messenger/webim/operator/settings.php index 9281c4a7..4b2761e6 100644 --- a/src/messenger/webim/operator/settings.php +++ b/src/messenger/webim/operator/settings.php @@ -31,7 +31,8 @@ $stylelist = get_style_list("../styles/dialogs"); $options = array( 'email', 'title', 'logo', 'hosturl', 'usernamepattern', - 'chatstyle', 'chattitle', 'geolink', 'geolinkparams', 'sendmessagekey'); + 'chatstyle', 'chattitle', 'geolink', 'geolinkparams', + 'sendmessagekey', 'cron_key'); if (Settings::get('enabletracking')) { $options[] = 'invitationstyle'; @@ -53,6 +54,7 @@ if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) { $params['geolink'] = getparam('geolink'); $params['geolinkparams'] = getparam('geolinkparams'); $params['sendmessagekey'] = verifyparam('sendmessagekey', "/^c?enter$/"); + $params['cron_key'] = getparam('cronkey'); $params['chatstyle'] = verifyparam("chatstyle", "/^\w+$/", $params['chatstyle']); if (!in_array($params['chatstyle'], $stylelist)) { @@ -78,6 +80,10 @@ if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) { } } + if (preg_match("/^[0-9A-z]*$/", $params['cron_key']) == 0) { + $errors[] = getlocal("settings.wrong.cronkey"); + } + if (count($errors) == 0) { foreach ($options as $opt) { Settings::set($opt,$params[$opt]); @@ -101,6 +107,15 @@ $page['formsendmessagekey'] = $params['sendmessagekey']; $page['availableChatStyles'] = $stylelist; $page['stored'] = isset($_GET['stored']); $page['enabletracking'] = Settings::get('enabletracking'); +$page['formcronkey'] = $params['cron_key']; + +$page['cron_path'] = (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') + ? 'http://' + : 'https://'; +$page['cron_path'] .= $_SERVER['SERVER_NAME'] . $webimroot . '/cron.php'; +$page['cron_path'] .= empty($params['cron_key']) + ? '' + : '?cron_key='.$params['cron_key']; if (Settings::get('enabletracking')) { $page['forminvitationstyle'] = $params['invitationstyle']; diff --git a/src/messenger/webim/view/settings.php b/src/messenger/webim/view/settings.php index fbefd0a9..da0e44b1 100644 --- a/src/messenger/webim/view/settings.php +++ b/src/messenger/webim/view/settings.php @@ -113,6 +113,15 @@ require_once('inc_errors.php');
+
+
+
+ +
+
+
+
+