diff --git a/docs/install.rst b/docs/install.rst index 6393d334..f8e0efa2 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -103,6 +103,25 @@ To specify the base url to your monitor installation, use the "--uri" argument, php status.cron.php --uri="http://www.phpservermonitor.org/mymonitor/" +CPanel +------- + +If you're work with cPanel you can follow these steps: + +1. Log into your cPanel account + +2. Go to cron jobs + +3. Add a new cronjob + +- Type `*/15` in the minute field + +- Type `*` in the other field + +- Type `php /home2//public_html/phpservermon/cron/status.cron.php` in the command field + +4. Submit + Troubleshooting +++++++++++++++ @@ -110,4 +129,4 @@ Troubleshooting If you have problems setting up or accessing your monitor and do not know why, enable debug mode to turn on error reporting. To enable debug mode, add the following line to your config.php file:: - define('PSM_DEBUG', true); \ No newline at end of file + define('PSM_DEBUG', true); diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index d32900cc..5346012f 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -221,22 +221,42 @@ function psm_update_conf($key, $value) { * everything should have been handled when calling this function * * @param string $server_id + * @param string $type * @param string $message + * + * @return int log_id */ -function psm_add_log($server_id, $type, $message, $user_id = null) { +function psm_add_log($server_id, $type, $message) { global $db; - $db->save( + return $db->save( PSM_DB_PREFIX.'log', array( 'server_id' => $server_id, 'type' => $type, 'message' => $message, - 'user_id' => ($user_id === null) ? '' : $user_id, ) ); } +/** + * This function just adds a user to the log_users table. + * + * @param $log_id + * @param $user_id + */ +function psm_add_log_user($log_id, $user_id) { + global $db; + + $db->save( + PSM_DB_PREFIX . 'log_users', + array( + 'log_id' => $log_id, + 'user_id' => $user_id, + ) + ); +} + /** * This function adds the result of a check to the uptime table for logging purposes. * @@ -503,6 +523,9 @@ function psm_build_sms() { case 'nexmo': $sms = new \psm\Txtmsg\Nexmo(); break; + case 'freemobilesms': + $sms = new \psm\Txtmsg\FreeMobileSMS(); + break; case 'octopush': $sms = new \psm\Txtmsg\Octopush(); break; } diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 23a3f4ac..eb2f77c0 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -211,6 +211,7 @@ $sm_lang = array( 'sms_gateway_octopush' => 'Octopush', 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', + 'sms_gateway_freemobilesms' => 'FreeMobileSMS', 'sms_gateway_nexmo' => 'Nexmo', 'sms_gateway_username' => 'Gateway username', 'sms_gateway_password' => 'Gateway password', diff --git a/src/lang/fr_FR.lang.php b/src/lang/fr_FR.lang.php index 776a1e3b..6c7edbdf 100644 --- a/src/lang/fr_FR.lang.php +++ b/src/lang/fr_FR.lang.php @@ -201,6 +201,7 @@ $sm_lang = array( 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_freemobilesms' => 'FreeMobileSMS', 'sms_gateway_username' => 'Nom utilisateur de la passerelle', 'sms_gateway_password' => 'Mot de passe de la passerelle', 'sms_from' => 'SMS de l\'expéditeur', diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php index 647403a4..f73bbdd4 100644 --- a/src/lang/nl_NL.lang.php +++ b/src/lang/nl_NL.lang.php @@ -130,7 +130,7 @@ $sm_lang = array( 'last_check' => 'Laatst gecontroleerd', 'last_online' => 'Laatst online', 'monitoring' => 'Monitoring', - 'no_monitoring' => 'No monitoring', + 'no_monitoring' => 'Geen monitoring', 'email' => 'Email', 'send_email' => 'Stuur email', 'sms' => 'SMS', @@ -209,7 +209,7 @@ $sm_lang = array( 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Voordat je Pushover kunt gebruiken moet je een App registreren via hun website, en daarvan de App API Token hier invullen.', 'alert_type' => 'Selecteer wanneer je een notificatie wilt', - 'alert_type_description' => 'Status change: '. + 'alert_type_description' => 'Status verandert: '. 'Je ontvangt alleen bericht wanneer een server van status verandert. Dus van online -> offline of offline -> online.
'. '
Offline: '. 'Je ontvangt bericht wanneer een server offline gaat voor de *EERSTE KEER*. Bijvoorbeeld, '. @@ -236,7 +236,7 @@ $sm_lang = array( 'settings_log' => 'Log instellingen', 'auto_refresh' => 'Auto-refresh', 'auto_refresh_servers' => - 'Auto-refresh servers pagina.
'. + 'Auto-herladen servers pagina.
'. ''. 'Tijd in seconden, als de tijd 0 is wordt de pagina niet ververst.'. '', diff --git a/src/lang/vi_VN.lang.php b/src/lang/vi_VN.lang.php new file mode 100644 index 00000000..29d745fd --- /dev/null +++ b/src/lang/vi_VN.lang.php @@ -0,0 +1,299 @@ +. + * + * @package phpservermon + * @author Loi Le + * @copyright Copyright (c) 2008-2014 Pepijn Over + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: v3.1.1 + * @link http://www.phpservermonitor.org/ + **/ + +$sm_lang = array( + 'name' => 'Tiếng Việt', + 'locale' => array('vi_VN.UTF-8', 'vi_VN', 'Việt Nam'), + 'system' => array( + 'title' => 'Server Monitor', + 'install' => 'Cài đặt', + 'action' => 'Hành động', + 'save' => 'Lưu', + 'edit' => 'Sửa', + 'delete' => 'Xóa', + 'date' => 'Ngày', + 'message' => 'Message', + 'yes' => 'Yes', + 'no' => 'No', + 'insert' => 'Thêm mới', + 'add_new' => 'Thêm mới', + 'update_available' => 'Phiên bản mới ({version}) có săn trên http://www.phpservermonitor.org.', + 'back_to_top' => 'Lên đầu trang', + 'go_back' => 'Quay lại', + 'ok' => 'OK', + 'cancel' => 'Cancel', + // date/time format according the strftime php function format parameter http://php.net/manual/function.strftime.php + 'short_day_format' => '%B %e', + 'long_day_format' => '%B %e, %Y', + 'yesterday_format' => 'Yesterday at %k:%M', + 'other_day_format' => '%A at %k:%M', + 'never' => 'Never', + 'hours_ago' => '%d giờ trước', + 'an_hour_ago' => 'khoảng một giờ trước', + 'minutes_ago' => '%d phút trước', + 'a_minute_ago' => 'khoảng một phút trước', + 'seconds_ago' => '%d giây trước', + 'a_second_ago' => 'một giây trước', + ), + 'menu' => array( + 'config' => 'Cấu hình', + 'server' => 'Servers', + 'server_log' => 'Log', + 'server_status' => 'Trạng thái', + 'server_update' => 'Cập nhật', + 'user' => 'Người dùng', + 'help' => 'Giúp đỡ', + ), + 'users' => array( + 'user' => 'Người dùng', + 'name' => 'Tên', + 'user_name' => 'Tên đăng nhập', + 'password' => 'Mật khẩu', + 'password_repeat' => 'Nhập lại mật khẩu', + 'password_leave_blank' => 'Leave blank to keep unchanged', + 'level' => 'Cấp độ', + 'level_10' => 'Administrator', + 'level_20' => 'User', + 'level_description' => 'Administrators có toàn quyền: họ có thể quản lý server, người dùng và chỉnh sửa cấu hình.
Users chỉ xem và chạy cập nhật cho servers được giao cho họ.', + 'mobile' => 'Di động', + 'email' => 'Email', + 'pushover' => 'Pushover', + 'pushover_description' => 'Pushover là một dịch vụ dễ dàng nhận các thông báo theo thời gian thực. Xem website của họ để biết thêm thông tin.', + 'pushover_key' => 'Pushover Key', + 'pushover_device' => 'Pushover Device', + 'pushover_device_description' => 'Tên thiết bị để gửi tin nhắn đến. Để trống để gửi cho tất cả các thiết bị.', + 'delete_title' => 'Xóa Người dùng', + 'delete_message' => 'Bạn có chắc chắn xóa người dùng \'%1\'?', + 'deleted' => 'Đã xóa người dùng.', + 'updated' => 'Đã cập nhật người dùng.', + 'inserted' => 'Đã thêm người dùng.', + 'profile' => 'Hồ sơ', + 'profile_updated' => 'Hồ sơ của bạn đã được cập nhật.', + 'error_user_name_bad_length' => 'Tên người dùng phải có từ 2 và 64 ký tự.', + 'error_user_name_invalid' => 'Tên người dùng chỉ có thể chứa các chữ cái(a-z, A-Z), số (0-9) và dấu gạch dưới (_).', + 'error_user_name_exists' => 'Tên người dùng đã tồn tại trong cơ sở dữ liệu.', + 'error_user_email_bad_length' => 'Địa chỉ email phải từ 5 đến 255 ký tự.', + 'error_user_email_invalid' => 'Địa chỉ email không hợp lệ.', + 'error_user_level_invalid' => 'Cấp độ người dùng không hợp lệ.', + 'error_user_no_match' => 'Người dùng không tìm thấy trong cơ sở dữ liệu.', + 'error_user_password_invalid' => 'Đặt mật khẩu không hợp lệ.', + 'error_user_password_no_match' => 'Các mật khẩu không khớp.', + ), + 'log' => array( + 'title' => 'Log entries', + 'type' => 'Loại', + 'status' => 'Trạng thái', + 'email' => 'Email', + 'sms' => 'SMS', + 'pushover' => 'Pushover', + 'no_logs' => 'No logs', + ), + 'servers' => array( + 'server' => 'Server', + 'status' => 'Trạng thái', + 'label' => 'Nhãn', + 'domain' => 'Domain/IP', + 'timeout' => 'Timeout', + 'timeout_description' => 'Số giây để đợi máy chủ phản hồi.', + 'port' => 'Cổng', + 'type' => 'Loại', + 'type_website' => 'Website', + 'type_service' => 'Dịch vụ', + 'pattern' => 'Tìm kiếm chuỗi/mẫu', + 'pattern_description' => 'Nếu mẫu không tìm thấy trên website, server sẽ được đánh dấu là offline. Biểu thức chính quy (Regular expressions) được cho phép.', + 'last_check' => 'Kiểm tra lần cuối', + 'last_online' => 'Trực tuyến lần cuối', + 'monitoring' => 'Giám sát', + 'no_monitoring' => 'Không giám sát', + 'email' => 'Email', + 'send_email' => 'Gửi Email', + 'sms' => 'SMS', + 'send_sms' => 'Gửi SMS', + 'pushover' => 'Pushover', + 'users' => 'Người dùng', + 'delete_title' => 'Xóa server', + 'delete_message' => 'Bạn có chắt chắn xóa server \'%1\'?', + 'deleted' => 'Đã xóa server.', + 'updated' => 'Đã cập nhật server.', + 'inserted' => 'Đã thêm server.', + 'latency' => 'Độ trễ', + 'latency_max' => 'Độ trễ (cao nhất)', + 'latency_min' => 'Độ trễ (thấp nhất)', + 'latency_avg' => 'Độ trễ (trung bình)', + 'uptime' => 'Thời gian hoạt động', + 'year' => 'Năm', + 'month' => 'Tháng', + 'week' => 'Tuần', + 'day' => 'Ngày', + 'hour' => 'Giờ', + 'warning_threshold' => 'Ngưỡng cảnh báo', + 'warning_threshold_description' => 'Số lần kiểm tra thất bại trước khi đánh đấu là offline.', + 'chart_last_week' => 'Tuần trước', + 'chart_history' => 'Lịch sử', + // Charts date format according jqPlot date format http://www.jqplot.com/docs/files/plugins/jqplot-dateAxisRenderer-js.html + 'chart_day_format' => '%Y-%m-%d', + 'chart_long_date_format' => '%Y-%m-%d %H:%M:%S', + 'chart_short_date_format' => '%m/%d %H:%M', + 'chart_short_time_format' => '%H:%M', + 'warning_notifications_disabled_sms' => 'SMS thông báo bị vô hiệu hóa.', + 'warning_notifications_disabled_email' => 'Email thông báo bị vô hiệu hóa.', + 'warning_notifications_disabled_pushover' => 'Pushover thông báo bị vô hiệu hóa.', + 'error_server_no_match' => 'Không tìm thấy server.', + 'error_server_label_bad_length' => 'Nhãn phải có từ 1 đến 255 ký tự.', + 'error_server_ip_bad_length' => 'The domain / IP Nhãn phải có từ 1 đến 255 ký tự.', + 'error_server_ip_bad_service' => 'Địa chỉ IP không hợp lệ.', + 'error_server_ip_bad_website' => 'URL website không hợp lệ.', + 'error_server_type_invalid' => 'Chọn loại server không hợp lệ.', + 'error_server_warning_threshold_invalid' => 'Ngưỡng cảnh báo phải là một số nguyên có giá trị lớn hơn 0.', + ), + 'config' => array( + 'general' => 'Tổng quát', + 'language' => 'Ngôn ngữ', + 'show_update' => 'Kiểm tra cập nhật?', + 'email_status' => 'Cho phép gửi email', + 'email_from_email' => 'Gửi email từ địa chỉ', + 'email_from_name' => 'Tên địa chỉ mail', + 'email_smtp' => 'Enable SMTP', + 'email_smtp_host' => 'SMTP host', + 'email_smtp_port' => 'SMTP port', + 'email_smtp_security' => 'SMTP security', + 'email_smtp_security_none' => 'None', + 'email_smtp_username' => 'SMTP username', + 'email_smtp_password' => 'SMTP password', + 'email_smtp_noauth' => 'Để trống nếu không có chứng thực', + 'sms_status' => 'Cho phép gửi tin nhắn văn bản', + 'sms_gateway' => 'Gateway sử dụng để gửi tin nhắn', + 'sms_gateway_mosms' => 'Mosms', + 'sms_gateway_mollie' => 'Mollie', + 'sms_gateway_spryng' => 'Spryng', + 'sms_gateway_inetworx' => 'Inetworx', + 'sms_gateway_clickatell' => 'Clickatell', + 'sms_gateway_textmarketer' => 'Textmarketer', + 'sms_gateway_smsglobal' => 'SMSGlobal', + 'sms_gateway_smsit' => 'Smsit', + 'sms_gateway_username' => 'Gateway username', + 'sms_gateway_password' => 'Gateway password', + 'sms_from' => 'Số điện thoại của người gửi', + 'pushover_status' => 'Cho phép gửi tin nhắn bằng Pushover', + 'pushover_description' => 'Pushover là một dịch vụ dễ dàng nhận các thông báo theo thời gian thực. Xem website của họ để biết thêm thông tin.', + 'pushover_clone_app' => 'Nhấn vào đây để tạo ứng dụng Pushover của bạn', + 'pushover_api_token' => 'Pushover App API Token', + 'pushover_api_token_description' => 'Trước khi bạn có thể sử dụng Pushover, bạn cần phải đăng ký một ứng dụng tại trang web của họ và nhập Token App API ở đây.', + 'alert_type' => 'Chọn khi bạn muốn được thông báo.', + 'alert_type_description' => 'Thay đổi trạng thái: '. + 'Bạn sẽ nhận được thông báo khi một máy chủ có một sự thay đổi trạng thái. Từ online -> offline hoặc offline -> online.
'. + '
Offline: '. + 'Bạn sẽ nhận được thông báo khi một máy chủ offline *MỘT LẦN DUY NHẤT*. Ví dụ, '. + 'cronjob của bạn hoạt động mỗi 15 phút và server của bạn down tại 01h00 cho đến 6h00. '. + 'Bạn sẽ nhận được 1 thông báo lúc 01h00 và đó là nó.
'. + '
Always: '. + 'Bạn sẽ nhận được thông báo mỗi khi chạy đoạn script và một trang web tắt, ngay cả khi trang web đã được offline trong nhiều giờ.', + 'alert_type_status' => 'Thay đổi trạng thái', + 'alert_type_offline' => 'Offline', + 'alert_type_always' => 'Always', + 'log_status' => 'Log status', + 'log_status_description' => 'Nếu log status được đặt là TRUE, màn hình sẽ đăng sự kiện này bất cứ khi nào các thiết lập thông báo được truyền.', + 'log_email' => 'Log emails gửi bởi script', + 'log_sms' => 'Log Tin nhăn văn bản gửi bởi script', + 'log_pushover' => 'Log tin nhắn pushover gửi bởi script', + 'updated' => 'Cấu hình đã được cập nhật.', + 'tab_email' => 'Email', + 'tab_sms' => 'SMS', + 'tab_pushover' => 'Pushover', + 'settings_email' => 'Thiết lặp email', + 'settings_sms' => 'Thiết lập tin nhăn văn bản', + 'settings_pushover' => 'Thiết lặp Pushover', + 'settings_notification' => 'Thiết lặp thông báo', + 'settings_log' => 'Thiết lặp Log', + 'auto_refresh' => 'Tự động làm mới', + 'auto_refresh_servers' => + 'Tự động làm mới servers page.
'. + ''. + 'Trong vài giây, nếu 0 trang sẽ không làm mới.'. + '', + 'seconds' => 'giây', + 'test' => 'Thử', + 'test_email' => 'Một email sẽ được gửi đến địa chỉ được xác định trong hồ sơ người dùng của bạn.', + 'test_sms' => 'Một SMS sẽ được gửi đến địa chỉ được xác định trong hồ sơ người dùng của bạn.', + 'test_pushover' => 'Một thông báo Pushover sẽ được gửi đến địa chỉ được xác định trong hồ sơ người dùng của bạn.', + 'send' => 'Gửi', + 'test_subject' => 'Thử nghiệm', + 'test_message' => 'tin nhắn thử nghiệm', + 'email_sent' => 'Gửi email', + 'email_error' => 'Lỗi trong khi gửi mail', + 'sms_sent' => 'Gửi SMS', + 'sms_error' => 'Lỗi trong khi gửi sms', + 'sms_error_nomobile' => 'Không thể gửi thử SMS: không có số điện thoại hợp lệ được tìm thấy trong hồ sơ của bạn.', + 'pushover_sent' => 'Gửi thông báo Pushover', + 'pushover_error' => 'Một lỗi đã xảy ra trong khi gửi thông báo Pushover: %s', + 'pushover_error_noapp' => 'Không thể gửi thử thông báo: không tìm thấy Pushover App API token trong cấu hình.', + 'pushover_error_nokey' => 'Không thể gửi thử thông báo: không tìm thấy Pushover key trong hồ sơ của bạn.', + 'log_retention_period' => 'Thời gian lưu giữ log', + 'log_retention_period_description' => 'Số ngày để giữ các bản ghi của các thông báo và tài liệu lưu trữ của thời gian hoạt động máy chủ. Nhập 0 để vô hiệu hóa dọn dẹp log.', + 'log_retention_days' => 'ngày', + ), + // for newlines in the email messages use
+ 'notifications' => array( + 'off_sms' => 'Server \'%LABEL%\' is DOWN: ip=%IP%, cổng=%PORT%. Lỗi=%ERROR%', + 'off_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is DOWN', + 'off_email_body' => "Không thể kết nối đến máy chủ sau:

Server: %LABEL%
IP: %IP%
Cổng: %PORT%
Lỗi: %ERROR%
Thời gian: %DATE%", + 'off_pushover_title' => 'Server \'%LABEL%\' is DOWN', + 'off_pushover_message' => "Không thể kết nối đến máy chủ:

Server: %LABEL%
IP: %IP%
Cổng: %PORT%
Lỗi: %ERROR%
Thời gian: %DATE%", + 'on_sms' => 'Server \'%LABEL%\' is RUNNING: ip=%IP%, port=%PORT%', + 'on_email_subject' => 'IMPORTANT: Server \'%LABEL%\' hoạt động', + 'on_email_body' => "Server '%LABEL%' hoạt động lại:

Server: %LABEL%
IP: %IP%
Cổng: %PORT%
Thời gian: %DATE%", + 'on_pushover_title' => 'Server \'%LABEL%\' hoạt động', + 'on_pushover_message' => 'Server \'%LABEL%\' hoạt động lại:

Server: %LABEL%
IP: %IP%
Cổng: %PORT%
Thời gian: %DATE%', + ), + 'login' => array( + 'welcome_usermenu' => 'Chào mừng, %user_name%', + 'title_sign_in' => 'Vui lòng đăng nhập', + 'title_forgot' => 'Quên mật khẩu?', + 'title_reset' => 'Khôi phục mật khẩu', + 'submit' => 'Gửi', + 'remember_me' => 'Ghi nhớ tôi', + 'login' => 'Đăng nhập', + 'logout' => 'Đăng xuất', + 'username' => 'Tên đăng nhập', + 'password' => 'Mật khẩu', + 'password_repeat' => 'Nhập lại mật khẩu', + 'password_forgot' => 'Quên mật khẩu?', + 'password_reset' => 'Khôi phục mật khẩu', + 'password_reset_email_subject' => 'Khôi phục lại mật khẩu của bạn cho PHP Server Monitor', + 'password_reset_email_body' => 'Vui lòng sử dụng liên kết sau đây để thiết lập lại mật khẩu của bạn. Xin lưu ý nó hết hạn trong 1 giờ.

%link%', + 'error_user_incorrect' => 'Tên người dùng cung cấp không thể tìm thấy.', + 'error_login_incorrect' => 'Thông tin không đúng.', + 'error_login_passwords_nomatch' => 'Mật khẩu được cung cấp không phù hợp.', + 'error_reset_invalid_link' => 'Liên kết đặt lại mà bạn cung cấp không hợp lệ.', + 'success_password_forgot' => 'Một email đã được gửi đến bạn với thông tin làm thế nào để khôi phục lại mật khẩu của bạn.', + 'success_password_reset' => 'Mật khẩu bạn được khôi phục thành công. Vui lòng đăng nhập.', + ), + 'error' => array( + '401_unauthorized' => 'Không được phép', + '401_unauthorized_description' => 'Bạn không có quyền xem trang này.', + ), +); diff --git a/src/psm/Module/Config/Controller/ConfigController.php b/src/psm/Module/Config/Controller/ConfigController.php index 6dcc295e..35d9d7e3 100644 --- a/src/psm/Module/Config/Controller/ConfigController.php +++ b/src/psm/Module/Config/Controller/ConfigController.php @@ -322,6 +322,7 @@ class ConfigController extends AbstractController { 'label_sms_gateway_smsglobal' => psm_get_lang('config', 'sms_gateway_smsglobal'), 'label_sms_gateway_nexmo' => psm_get_lang('config', 'sms_gateway_nexmo'), 'label_sms_gateway_octopush' => psm_get_lang('config', 'sms_gateway_octopush'), + 'label_sms_gateway_freemobilesms' => psm_get_lang('config', 'sms_gateway_freemobilesms'), 'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'), 'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'), 'label_sms_from' => psm_get_lang('config', 'sms_from'), diff --git a/src/psm/Module/Server/Controller/LogController.php b/src/psm/Module/Server/Controller/LogController.php index 951df2ba..ec1d3a36 100644 --- a/src/psm/Module/Server/Controller/LogController.php +++ b/src/psm/Module/Server/Controller/LogController.php @@ -60,14 +60,6 @@ class LogController extends AbstractServerController { ); $log_types = array('status', 'email', 'sms', 'pushover'); - // get users - $users = $this->db->select(PSM_DB_PREFIX.'users', null, array('user_id','name')); - - $users_labels = array(); - foreach ($users as $user) { - $users_labels[$user['user_id']] = $user['name']; - } - foreach($log_types as $key) { $records = $this->getEntries($key); $log_count = count($records); @@ -95,15 +87,12 @@ class LogController extends AbstractServerController { $record['datetime_format'] = psm_date($record['datetime']); // fix up user list - if(!empty($record['user_id'])) { + $users = $this->getLogUsers($record['log_id']); + if(!empty($users)) { $names = array(); - $users = explode(',', $record['user_id']); - foreach($users as $user_id) { - if(isset($users_labels[$user_id])) { - $names[] = $users_labels[$user_id]; - } + foreach($users as $user) { + $names[] = $user['name']; } - sort($names); $record['users'] = implode('
', $names); $record['user_list'] = implode(' • ', $names); } @@ -135,10 +124,10 @@ class LogController extends AbstractServerController { '`servers`.`ip`, '. '`servers`.`port`, '. '`servers`.`type` AS server_type, '. + '`log`.`log_id`, '. '`log`.`type`, '. '`log`.`message`, '. - '`log`.`datetime`, '. - '`log`.`user_id` '. + '`log`.`datetime` '. 'FROM `'.PSM_DB_PREFIX.'log` AS `log` '. 'JOIN `'.PSM_DB_PREFIX.'servers` AS `servers` ON (`servers`.`server_id`=`log`.`server_id`) '. $sql_join . @@ -148,4 +137,22 @@ class LogController extends AbstractServerController { ); return $entries; } + + /** + * Get all the user entries for a specific $log_id + * + * @param $log_id + * @return array + */ + protected function getLogUsers($log_id) { + return $this->db->query( + "SELECT + u.`user_id`, + u.`name` + FROM `" . PSM_DB_PREFIX . "log_users` AS lu + LEFT JOIN `" . PSM_DB_PREFIX . "users` AS u ON lu.`user_id` = u.`user_id` + WHERE lu.`log_id` = " . (int)$log_id . " + ORDER BY u.`name` ASC" + ); + } } diff --git a/src/psm/Txtmsg/FreeMobileSMS.php b/src/psm/Txtmsg/FreeMobileSMS.php new file mode 100755 index 00000000..9269d2c3 --- /dev/null +++ b/src/psm/Txtmsg/FreeMobileSMS.php @@ -0,0 +1,52 @@ +. + * + * @package phpservermon + * @author Michiel van der Wulp + * @copyright Copyright (c) 2008-2015 Pepijn Over + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: @package_version@ + * @link http://www.phpservermonitor.org/ + **/ + +namespace psm\Txtmsg; + +class FreeMobileSMS extends Core { + // ========================================================================= + // [ Fields ] + // ========================================================================= + public $gateway = 1; + public $resultcode = null; + public $resultmessage = null; + public $success = false; + public $successcount = 0; + +public function sendSMS($message) { + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "https://smsapi.free-mobile.fr/sendmsg?user=$this->username&pass=$this->password&msg=$message"); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + $result = curl_exec($ch); + curl_close($ch); + + return true; + } +} diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index 41683aef..6c3ee490 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -206,9 +206,13 @@ class Installer { `type` enum('status','email','sms','pushover') NOT NULL, `message` varchar(255) NOT NULL, `datetime` timestamp NOT NULL default CURRENT_TIMESTAMP, - `user_id` varchar(255) NOT NULL, PRIMARY KEY (`log_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", + PSM_DB_PREFIX . 'log_users' => "CREATE TABLE `" . PSM_DB_PREFIX . "log_users` ( + `log_id` int(11) UNSIGNED NOT NULL , + `user_id` int(11) UNSIGNED NOT NULL , + PRIMARY KEY (`log_id`, `user_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", PSM_DB_PREFIX . 'servers' => "CREATE TABLE `" . PSM_DB_PREFIX . "servers` ( `server_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `ip` varchar(500) NOT NULL, @@ -440,5 +444,29 @@ class Installer { $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `website_username` varchar(255) NULL, ADD `website_password` varchar(255) NULL AFTER `website_username`;"; $this->execSQL($queries); + + // Create log_users table + $this->execSQL("CREATE TABLE `" . PSM_DB_PREFIX . "log_users` ( + `log_id` int(11) UNSIGNED NOT NULL , + `user_id` int(11) UNSIGNED NOT NULL , + PRIMARY KEY (`log_id`, `user_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); + + // Migrate the data + $logs = $this->db->select(PSM_DB_PREFIX . 'log', null, array('log_id', 'user_id')); + foreach ($logs as $log) { + // Validation + if (empty($log['user_id']) || trim($log['user_id']) == '') { + continue; + } + + // Insert into new table + foreach (explode(',', $log['user_id']) as $user_id) { + psm_add_log_user($log['log_id'], $user_id); + } + } + + // Drop old user_id('s) column + $this->execSQL("ALTER TABLE `" . PSM_DB_PREFIX . "log` DROP COLUMN `user_id`;"); } } diff --git a/src/psm/Util/Server/Updater/StatusNotifier.php b/src/psm/Util/Server/Updater/StatusNotifier.php index a87f5547..0edfde98 100644 --- a/src/psm/Util/Server/Updater/StatusNotifier.php +++ b/src/psm/Util/Server/Updater/StatusNotifier.php @@ -198,8 +198,6 @@ class StatusNotifier { * @return boolean */ protected function notifyByEmail($users) { - $userlist = array(); - // build mail object with some default values $mail = psm_build_mail(); $mail->Subject = utf8_decode(psm_parse_msg($this->status_new, 'email_subject', $this->server)); @@ -209,19 +207,21 @@ class StatusNotifier { $mail->Body = utf8_decode($body); $mail->AltBody = str_replace('
', "\n", $body); + if(psm_get_conf('log_email')) { + $log_id = psm_add_log($this->server_id, 'email', $body); + } + // go through empl foreach ($users as $user) { + if(!empty($log_id)) { + psm_add_log_user($log_id, $user['user_id']); + } + // we sent a seperate email to every single user. - $userlist[] = $user['user_id']; $mail->AddAddress($user['email'], $user['name']); $mail->Send(); $mail->ClearAddresses(); } - - if(psm_get_conf('log_email')) { - // save to log - psm_add_log($this->server_id, 'email', $body, implode(',', $userlist)); - } } /** @@ -231,38 +231,51 @@ class StatusNotifier { * @return boolean */ protected function notifyByPushover($users) { - $userlist = array(); - $pushover = psm_build_pushover(); + // Remove users that have no pushover_key + foreach($users as $k => $user) { + if (trim($user['pushover_key']) == '') { + unset($users[$k]); + } + } - if($this->status_new === true) { - $pushover->setPriority(0); - } else { - $pushover->setPriority(2); - $pushover->setRetry(300); //Used with Priority = 2; Pushover will resend the notification every 60 seconds until the user accepts. - $pushover->setExpire(3600); //Used with Priority = 2; Pushover will resend the notification every 60 seconds for 3600 seconds. After that point, it stops sending notifications. - } - $message = psm_parse_msg($this->status_new, 'pushover_message', $this->server); + // Validation + if (empty($users)) { + return; + } + // Pushover + $message = psm_parse_msg($this->status_new, 'pushover_message', $this->server); + $pushover = psm_build_pushover(); + if($this->status_new === true) { + $pushover->setPriority(0); + } else { + $pushover->setPriority(2); + $pushover->setRetry(300); //Used with Priority = 2; Pushover will resend the notification every 60 seconds until the user accepts. + $pushover->setExpire(3600); //Used with Priority = 2; Pushover will resend the notification every 60 seconds for 3600 seconds. After that point, it stops sending notifications. + } $pushover->setTitle(psm_parse_msg($this->status_new, 'pushover_title', $this->server)); $pushover->setMessage(str_replace('
', "\n", $message)); $pushover->setUrl(psm_build_url()); $pushover->setUrlTitle(psm_get_lang('system', 'title')); + // Log + if(psm_get_conf('log_pushover')) { + $log_id = psm_add_log($this->server_id, 'pushover', $message); + } + foreach($users as $user) { - if(trim($user['pushover_key']) == '') { - continue; - } - $userlist[] = $user['user_id']; + // Log + if(!empty($log_id)) { + psm_add_log_user($log_id, $user['user_id']); + } + + // Set recipient + send $pushover->setUser($user['pushover_key']); if($user['pushover_device'] != '') { $pushover->setDevice($user['pushover_device']); } $pushover->send(); - } - - if(psm_get_conf('log_pushover')) { - psm_add_log($this->server_id, 'pushover', $message, implode(',', $userlist)); - } + } } /** @@ -277,24 +290,26 @@ class StatusNotifier { return false; } - // we have to build an userlist for the log table.. - $userlist = array(); + $message = psm_parse_msg($this->status_new, 'sms', $this->server); + + // Log + if(psm_get_conf('log_sms')) { + $log_id = psm_add_log($this->server_id, 'sms', $message); + } // add all users to the recipients list foreach ($users as $user) { - $userlist[] = $user['user_id']; + // Log + if(!empty($log_id)) { + psm_add_log_user($log_id, $user['user_id']); + } + $sms->addRecipients($user['mobile']); } - $message = psm_parse_msg($this->status_new, 'sms', $this->server); - // Send sms $result = $sms->sendSMS($message); - if(psm_get_conf('log_sms')) { - // save to log - psm_add_log($this->server_id, 'sms', $message, implode(',', $userlist)); - } return $result; } diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 0ff33a69..84b147e1 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -145,7 +145,7 @@ class StatusUpdater { // save response time $starttime = microtime(true); - $fp = fsockopen ($this->server['ip'], $this->server['port'], $errno, $this->error, 10); + $fp = @fsockopen ($this->server['ip'], $this->server['port'], $errno, $this->error, 10); $status = ($fp === false) ? false : true; $this->rtime = (microtime(true) - $starttime); diff --git a/src/templates/default/module/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html index d7d55ca2..08fc0fc1 100644 --- a/src/templates/default/module/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -171,6 +171,7 @@ + diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index 7af848a4..2378d21e 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -1,5 +1,5 @@ {% import 'main/macros.tpl.html' as macro %} -
+ {{ macro.csrf_input() }}
{{ titlemode }} @@ -63,7 +63,7 @@ -
+
@@ -82,13 +82,13 @@
- +
- +
@@ -156,4 +156,4 @@ {{ label_go_back }} -
\ No newline at end of file +