001 package railo.runtime.config; 002 003 import java.io.IOException; 004 import java.util.Arrays; 005 import java.util.HashSet; 006 import java.util.Set; 007 008 import railo.commons.digest.MD5; 009 import railo.commons.net.IPRange; 010 import railo.runtime.type.Struct; 011 import railo.runtime.type.util.ListUtil; 012 013 public class DebugEntry { 014 015 private final String id; 016 private final String type; 017 private final String strIpRange; 018 private final IPRange ipRange; 019 private final String label; 020 private final Struct custom; 021 private final boolean readOnly; 022 private final String path; 023 private final String fullname; 024 025 public DebugEntry(String id, String type, String ipRange, String label, String path, String fullname, Struct custom) throws IOException { 026 this(id,type,IPRange.getInstance(ipRange),ipRange,label,path,fullname,custom,false); 027 } 028 029 private DebugEntry(String id, String type, IPRange ipRange,String strIpRange, String label, String path, String fullname, Struct custom, boolean readOnly) { 030 this.id=id; 031 this.type=type; 032 this.strIpRange=strIpRange; 033 this.ipRange=ipRange; 034 this.label=label; 035 this.custom=custom; 036 this.readOnly=readOnly; 037 this.path=path; 038 this.fullname=fullname; 039 } 040 041 /** 042 * @return the path 043 */ 044 public String getPath() { 045 return path; 046 } 047 048 /** 049 * @return the fullname 050 */ 051 public String getFullname() { 052 return fullname; 053 } 054 055 /** 056 * @return the readOnly 057 */ 058 public boolean isReadOnly() { 059 return readOnly; 060 } 061 062 /** 063 * @return the id 064 */ 065 public String getId() { 066 return id; 067 } 068 069 /** 070 * @return the type 071 */ 072 public String getType() { 073 return type; 074 } 075 076 /** 077 * @return the ipRange 078 */ 079 public String getIpRangeAsString() { 080 return strIpRange; 081 } 082 public IPRange getIpRange() { 083 return ipRange; 084 } 085 086 /** 087 * @return the label 088 */ 089 public String getLabel() { 090 return label; 091 } 092 093 /** 094 * @return the custom 095 */ 096 public Struct getCustom() { 097 return (Struct) custom.duplicate(false); 098 } 099 100 public DebugEntry duplicate(boolean readOnly) { 101 DebugEntry de = new DebugEntry(id, type, ipRange,strIpRange, label, path,fullname,custom,readOnly); 102 return de; 103 } 104 105 public static String organizeIPRange(String ipRange) { 106 String[] arr = ListUtil.trim(ListUtil.trimItems(ListUtil.listToStringArray(ipRange, ','))); 107 Set<String> set=new HashSet<String>(); 108 for(int i=0;i<arr.length;i++){ 109 set.add(arr[i]); 110 } 111 arr=set.toArray(new String[set.size()]); 112 Arrays.sort(arr); 113 return ListUtil.arrayToList(arr, ","); 114 } 115 116 117 public static String ipRangeToId(String ipRange) { 118 ipRange=organizeIPRange(ipRange); 119 try { 120 return MD5.getDigestAsString(ipRange); 121 } catch (IOException e) { 122 return ipRange; 123 } 124 } 125 126 /*public static void main(String[] args) { 127 print.o(ipRangeToId("*,127.0.0.1")); 128 print.o(ipRangeToId(",,,*,127.0.0.1")); 129 print.o(ipRangeToId(",,,*,127.0.0.1,*")); 130 }*/ 131 132 133 }