File indexing completed on 2025-05-04 05:29:12
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Default_Model_LoginHistory extends Default_Model_DbTable_LoginHistory 0024 { 0025 0026 /** 0027 * @param int $objectId 0028 * @param int $projectId 0029 * @param int $userId 0030 * @param int $activity_type_id 0031 * @param array $data array with ([type_id], [pid], description, title, image_small) 0032 * 0033 * @throws Zend_Exception 0034 */ 0035 public static function log($memberId, $ip = null, $ipv4 = null, $ipv6 = null, $user_agent = null, $fingerprint = null) 0036 { 0037 0038 $newEntry = array( 0039 'member_id' => $memberId, 0040 'ip' => $ip, 0041 'ip_inet' => null!=$ip?inet_pton($ip):null, 0042 'ipv4' => $ipv4, 0043 'ipv4_inet' => null!=$ipv4?inet_pton($ipv4):null, 0044 'ipv6' => $ipv6, 0045 'ipv6_inet' => null!=$ipv6?inet_pton($ipv6):null, 0046 'browser' => Default_Model_LoginHistory::getBrowser($user_agent), 0047 'os' => Default_Model_LoginHistory::getOS($user_agent), 0048 'architecture' => Default_Model_LoginHistory::getArchitecture($user_agent), 0049 'fingerprint' => $fingerprint, 0050 'user_agent' => $user_agent 0051 ); 0052 0053 $sql = " 0054 INSERT INTO `login_history` 0055 SET `member_id` = :member_id, 0056 `ip` = :ip, 0057 `ip_inet` = :ip_inet, 0058 `ipv4` = :ipv4, 0059 `ipv4_inet` = :ipv4_inet, 0060 `ipv6` = :ipv6, 0061 `ipv6_inet` = :ipv6_inet, 0062 `browser` = :browser, 0063 `os` = :os, 0064 `architecture` = :architecture, 0065 `fingerprint` = :fingerprint, 0066 `user_agent` = :user_agent 0067 ; 0068 "; 0069 0070 try { 0071 Zend_Db_Table::getDefaultAdapter()->query($sql, $newEntry); 0072 } catch (Exception $e) { 0073 Zend_Registry::get('logger')->err(__METHOD__ . ' - ERROR write activity log - ' . print_r($e, true)); 0074 } 0075 } 0076 0077 public static function getOS($user_agent) { 0078 0079 $os_platform = "Unknown OS Platform"; 0080 0081 if(null == $user_agent) { 0082 return $os_platform; 0083 } 0084 0085 0086 $os_array = array( 0087 '/windows nt 10/i' => 'Windows 10', 0088 '/windows nt 6.3/i' => 'Windows 8.1', 0089 '/windows nt 6.2/i' => 'Windows 8', 0090 '/windows nt 6.1/i' => 'Windows 7', 0091 '/windows nt 6.0/i' => 'Windows Vista', 0092 '/windows nt 5.2/i' => 'Windows Server 2003/XP x64', 0093 '/windows nt 5.1/i' => 'Windows XP', 0094 '/windows xp/i' => 'Windows XP', 0095 '/windows nt 5.0/i' => 'Windows 2000', 0096 '/windows me/i' => 'Windows ME', 0097 '/win98/i' => 'Windows 98', 0098 '/win95/i' => 'Windows 95', 0099 '/win16/i' => 'Windows 3.11', 0100 '/macintosh|mac os x/i' => 'Mac OS X', 0101 '/mac_powerpc/i' => 'Mac OS 9', 0102 '/linux/i' => 'Linux', 0103 '/ubuntu/i' => 'Ubuntu', 0104 '/iphone/i' => 'iPhone', 0105 '/ipod/i' => 'iPod', 0106 '/ipad/i' => 'iPad', 0107 '/android/i' => 'Android', 0108 '/blackberry/i' => 'BlackBerry', 0109 '/webos/i' => 'Mobile' 0110 ); 0111 0112 foreach ($os_array as $regex => $value) { 0113 if (preg_match($regex, $user_agent)) { 0114 $os_platform = $value; 0115 } 0116 } 0117 return $os_platform; 0118 } 0119 0120 public static function getArchitecture($user_agent) { 0121 0122 $os_platform = "Unknown"; 0123 0124 if(null == $user_agent) { 0125 return $os_platform; 0126 } 0127 0128 0129 $os_array = array( 0130 '/x64/i' => 'x86_64', 0131 '/x86_64/i' => 'x86_64', 0132 '/x32/i' => 'x86_32', 0133 '/x86_32/i' => 'x86_32', 0134 '/iPhone/i' => 'iPhone', 0135 '/Android/i' => 'ARM' 0136 ); 0137 0138 foreach ($os_array as $regex => $value) { 0139 if (preg_match($regex, $user_agent)) { 0140 $os_platform = $value; 0141 } 0142 } 0143 return $os_platform; 0144 } 0145 0146 public static function getBrowser($user_agent) { 0147 0148 $browser = "Unknown Browser"; 0149 0150 $browser_array = array( 0151 '/msie/i' => 'Internet Explorer', 0152 '/firefox/i' => 'Firefox', 0153 '/safari/i' => 'Safari', 0154 '/chrome/i' => 'Chrome', 0155 '/edge/i' => 'Edge', 0156 '/opera/i' => 'Opera', 0157 '/netscape/i' => 'Netscape', 0158 '/maxthon/i' => 'Maxthon', 0159 '/konqueror/i' => 'Konqueror', 0160 '/mobile/i' => 'Handheld Browser' 0161 ); 0162 0163 foreach ($browser_array as $regex => $value) { 0164 if (preg_match($regex, $user_agent)) { 0165 $browser = $value; 0166 } 0167 } 0168 0169 return $browser; 0170 } 0171 0172 0173 }