Changeset 7411
- Timestamp:
- Oct 10, 2017, 9:48:11 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.classpath
r7400 r7411 32 32 <classpathentry kind="lib" path="lib/dist/hibernate-jpa-2.1-api-1.0.0.Final.jar"/> 33 33 <classpathentry kind="lib" path="lib/dist/parallelgzip-1.0.5.jar"/> 34 <classpathentry kind="lib" path="lib/dist/yauaa-2.2.jar"/> 34 35 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> 35 36 <classpathentry kind="output" path="xbin"/> -
trunk/doc/3rd-party-components.txt
r7400 r7411 348 348 License : javasysmon-LICENSE.txt 349 349 Files : javasysmon-0.3.5.jar 350 351 Yauaa: Yet Another UserAgent Analyzer 352 ------------------------------------- 353 A library for extracting information from the User-Agent header sent 354 by browsers. 355 356 More info : https://github.com/nielsbasjes/yauaa 357 Version : 2.2 358 License : Apache License, Version 2.0 (yauaa-LICENSE.txt) 359 Files : yauaa-2.2.jar, snakeyaml-1.18.jar, commons-collections4-4.1.jar 360 commons-lang3-3.6.jar 361 -
trunk/src/core/net/sf/basedb/core/SessionControl.java
r7410 r7411 45 45 import net.sf.basedb.util.EmailUtil; 46 46 import net.sf.basedb.util.Enumeration; 47 import net.sf.basedb.util.HttpUtil; 47 48 import net.sf.basedb.util.MD5; 48 49 import net.sf.basedb.util.extensions.ExtensionsInvoker; … … 793 794 String deviceToken = loginRequest.getDeviceToken(); 794 795 String userAgent = loginRequest.getAttribute("user-agent"); 796 String userAgentSummary = userAgent == null ? null : HttpUtil.getSummaryOfUserAgent(userAgent); 795 797 UserDeviceData device = null; 796 798 … … 815 817 // This device is already verified 816 818 // We update the user agent string since it may be different due to version upgrade 817 if (userAgent != null) device.setUserAgent(userAgent); 819 String oldUserAgent = device.getUserAgent(); 820 if (userAgent != null && !userAgent.equals(oldUserAgent)) 821 { 822 device.setUserAgent(userAgent); 823 // If the current name was auto-generated from the old "User-Agent" we update the name as well! 824 if (device.getName().equals(HttpUtil.getSummaryOfUserAgent(oldUserAgent))) 825 { 826 device.setName(userAgentSummary); 827 } 828 } 818 829 // And the lastUsed date 819 device.setLastUsed(new Date()); 830 device.setLastUsed(new Date()); 831 device.setLastRemoteId(getRemoteId()); 820 832 } 821 833 } … … 843 855 Date now = new Date(); 844 856 device = new UserDeviceData(); 845 device.setName( "New device");857 device.setName(userAgentSummary == null ? "New device" : userAgentSummary); 846 858 device.setUser(user); 847 859 device.setClient(client); 848 860 device.setEntryDate(now); 849 861 device.setLastUsed(now); 862 device.setLastRemoteId(getRemoteId()); 850 863 device.setToken(deviceToken); 851 864 device.setUserAgent(userAgent); -
trunk/src/core/net/sf/basedb/core/UserDevice.java
r7406 r7411 224 224 return getData().getUserAgent(); 225 225 } 226 227 226 227 /** 228 Get the remote ID of the host the user used for this device the last time. 229 Typically it is the IP-address of the user's computer. 230 @return A <code>String</code> object with remote ID 231 */ 232 public String getLastRemoteId() 233 { 234 return getData().getLastRemoteId(); 235 } 236 228 237 } 229 238 -
trunk/src/core/net/sf/basedb/core/data/UserDeviceData.java
r7406 r7411 170 170 } 171 171 172 /** 173 The maximum length of the remote ID that can be stored in the database. 174 @see #setRemoteId(String) 175 */ 176 public static final int MAX_REMOTE_ID_LENGTH = 255; 177 private String remoteId; 178 /** 179 Get the remote id (=ip address) of the last login from this device. 180 @hibernate.property column="`lastremote_id`" type="string" length="255" not-null="false" 181 */ 182 public String getLastRemoteId() 183 { 184 return remoteId; 185 } 186 public void setLastRemoteId(String remoteId) 187 { 188 this.remoteId = remoteId; 189 } 190 191 172 192 private Set<SessionData> sessions; 173 193 /** -
trunk/src/core/net/sf/basedb/util/HttpUtil.java
r6657 r7411 33 33 import org.apache.http.impl.client.CloseableHttpClient; 34 34 35 import nl.basjes.parse.useragent.UserAgent; 36 import nl.basjes.parse.useragent.UserAgentAnalyzer; 37 35 38 /** 36 39 Useful methods related to HTTP stuff in general and … … 46 49 private static final SimpleDateFormat HTTP_DATE_FORMAT = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.ENGLISH); 47 50 51 private static UserAgentAnalyzer userAgentAnalyzer; 52 48 53 /** 49 54 Get the content length from the headers in the response. … … 131 136 } 132 137 138 /** 139 Parse the User-Agent string from a HTTP request and return 140 information about what it actually means. 141 @see https://github.com/nielsbasjes/yauaa 142 @since 3.12 143 */ 144 public static synchronized UserAgent analyzeUserAgent(String userAgent) 145 { 146 if (userAgentAnalyzer == null) 147 { 148 userAgentAnalyzer = UserAgentAnalyzer.newBuilder().build(); 149 } 150 return userAgentAnalyzer.parse(userAgent); 151 } 152 153 /** 154 Get a summary of the user agent: 155 156 * Browser with major version 157 * Operating system with version 158 * Typy of device (eg. desktop, phone, etc.) 159 160 @since 3.12 161 */ 162 public static String getSummaryOfUserAgent(String userAgent) 163 { 164 UserAgent ua = analyzeUserAgent(userAgent); 165 return ua == null ? null : ua.getValue("AgentNameVersionMajor") + 166 " on " + ua.getValue("OperatingSystemNameVersion") + 167 " (" + ua.getValue("DeviceName") + ")"; 168 } 169 133 170 } -
trunk/www/views/devices/devices.js
r7407 r7411 38 38 Buttons.addClickHandler('close', App.closeWindow); 39 39 40 Events.addEventHandler('use-user-agent', 'click', devices.copyUserAgentToName); 41 40 42 // Tab validation 41 43 TabControl.addTabValidator('settings.info', devices.validateDevice); … … 75 77 return true; 76 78 } 79 80 devices.copyUserAgentToName = function(event) 81 { 82 var frm = document.forms['device']; 83 frm.name.value = Data.get(event.currentTarget, 'summary') || frm.name.value; 84 } 77 85 78 86 devices.save = function() -
trunk/www/views/devices/edit_device.jsp
r7407 r7411 22 22 @author Nicklas 23 23 --%> 24 <%@page import="net.sf.basedb.util.HttpUtil"%> 24 25 <%@ page pageEncoding="UTF-8" session="false" 25 26 import="net.sf.basedb.core.SessionControl" … … 54 55 try 55 56 { 56 String title = null;57 UserDevice device = null;58 59 57 if (itemId == 0) 60 58 { 61 59 throw new PermissionDeniedException(Permission.CREATE, "device"); 62 60 } 63 else 64 { 65 device = UserDevice.getById(dc, itemId); 66 device.checkPermission(Permission.WRITE); 67 cc.setObject("item", device); 68 title = "Edit device -- " + HTML.encodeTags(device.getName()); 69 } 61 UserDevice device = UserDevice.getById(dc, itemId); 62 device.checkPermission(Permission.WRITE); 63 cc.setObject("item", device); 64 String title = "Edit device -- " + HTML.encodeTags(device.getName()); 65 String summary = HTML.encodeTags(HttpUtil.getSummaryOfUserAgent(device.getUserAgent())); 70 66 JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), device); 71 67 ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext); … … 93 89 value="<%=HTML.encodeTags(device.getName())%>" 94 90 maxlength="<%=UserDevice.MAX_NAME_LENGTH%>"></td> 91 <td></td> 92 </tr> 93 <tr> 94 <th class="subprompt">User-agent</th> 95 <td> 96 <span title="<%=HTML.encodeTags(device.getUserAgent())%>"><%=summary %></span> 97 [<span id="use-user-agent" class="link" title="Use this as the name" data-summary="<%=summary%>">copy</span>] 98 </td> 95 99 <td></td> 96 100 </tr> -
trunk/www/views/devices/index.jsp
r7407 r7411 60 60 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> 61 61 <%! 62 private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,client,lastUsed, description");62 private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,client,lastUsed,lastRemoteId,description"); 63 63 private static final Item itemType = Item.USERDEVICE; 64 64 %> -
trunk/www/views/devices/list_devices.jsp
r7408 r7411 192 192 exportable="true" 193 193 formatter="<%=dateTimeFormatter%>" 194 /> 195 <tbl:columndef 196 id="lastRemoteId" 197 property="lastRemoteId" 198 datatype="string" 199 title="Last remote ID" 200 sortable="true" 201 filterable="true" 202 exportable="true" 194 203 /> 195 204 <tbl:columndef … … 393 402 <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" /> 394 403 <tbl:cell column="lastUsed" value="<%=item.getLastUsed()%>" /> 404 <tbl:cell column="lastRemoteId"><%=HTML.encodeTags(item.getLastRemoteId())%></tbl:cell> 395 405 <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell> 396 406 <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell> -
trunk/www/views/devices/view_device.jsp
r7407 r7411 35 35 import="net.sf.basedb.core.Project" 36 36 import="net.sf.basedb.util.Values" 37 import="net.sf.basedb.util.HttpUtil" 37 38 import="net.sf.basedb.clients.web.Base" 38 39 import="net.sf.basedb.clients.web.PermissionUtil" … … 162 163 </tr> 163 164 <tr> 165 <th>Last remote ID</th> 166 <td><%=HTML.encodeTags(device.getLastRemoteId())%></td> 167 </tr> 168 <tr> 164 169 <th>User</th> 165 170 <td><base:propertyvalue item="<%=device%>" property="user" /></td> … … 171 176 <tr> 172 177 <th>User agent</th> 173 <td><%=HTML.niceFormat(device.getUserAgent())%></td> 178 <td><%=HTML.encodeTags(HttpUtil.getSummaryOfUserAgent(device.getUserAgent()))%></td> 179 </tr> 180 <tr> 181 <th>User agent (raw)</th> 182 <td><%=HTML.encodeTags(device.getUserAgent())%></td> 174 183 </tr> 175 184 <tr>
Note: See TracChangeset
for help on using the changeset viewer.