1 10 package org.mmbase.util; 11 12 import java.net.InetAddress ; 13 import java.net.UnknownHostException ; 14 import java.util.Vector ; 15 16 import javax.servlet.ServletConfig ; 17 import javax.servlet.ServletContext ; 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 20 21 import org.mmbase.module.ProcessorInterface; 22 import org.mmbase.module.sessionInfo; 23 import org.mmbase.module.sessionsInterface; 24 import org.mmbase.servlet.JamesServlet; 25 import org.mmbase.util.logging.Logger; 26 import org.mmbase.util.logging.Logging; 27 28 41 public class scanpage extends PageInfo { 42 private static Logger log = Logging.getLoggerInstance(scanpage.class.getName()); 44 45 50 public Vector params; 51 56 public ProcessorInterface processor; 57 61 public HttpPost poster; 62 65 public sessionInfo session=null; 66 69 public String sname=null; 70 71 public String name=null; 72 public int rstatus=0; 73 public String body; 74 public String req_line; 75 public String wantCache=null; 76 public String mimetype=null; 77 public String querystring=null; 78 public int partlevel=0; 79 public String loadmode="cache"; 80 84 public boolean reload=false; 85 86 90 public scanpage() {} 91 92 95 public scanpage(JamesServlet servlet, HttpServletRequest req, HttpServletResponse res, sessionsInterface sessions) { 96 super(req,res); 97 req_line = req.getServletPath(); 98 querystring = req.getQueryString(); 99 100 ServletConfig sc = servlet.getServletConfig(); 102 ServletContext sx = sc.getServletContext(); 103 mimetype = sx.getMimeType(req_line); 104 if (mimetype==null) mimetype = "text/html"; 105 106 sname = servlet.getCookie(req, res); 107 if (sessions != null) session = sessions.getSession(this, sname); 108 CheckEditorReload(); 109 } 110 111 119 private final static int EXPIRE = 120; 120 121 void CheckEditorReload() { 122 reload = false; 123 if (session==null) return; 125 String s=session.getValue("RELOAD"); 126 if ((s==null) || !s.equals("R")) return; 127 s = session.getValue("RELOADTIME"); 129 if (s!=null) { 130 try { 131 int then=Integer.parseInt(s); 132 int now= (int)(System.currentTimeMillis()/1000); 133 if ((now-then)<EXPIRE) { 134 reload = true; 135 if (log.isDebugEnabled()) { 136 log.debug("CheckEditorReload remote user:"+HttpAuth.getRemoteUser(req)); 137 } 138 } else { 139 if (log.isDebugEnabled()) log.debug("CheckEditorReload, reload expired for remote user:"+HttpAuth.getRemoteUser(req)); 140 } 141 } catch(Exception e) {} 142 } 143 if (!reload) session.setValue("RELOAD","N"); 144 } 145 146 150 public void setReq(HttpServletRequest req) { 151 setRequest(req); 152 } 153 154 158 public void setRes(HttpServletResponse res) { 159 setResponse(res); 160 } 161 162 167 public String getParam(int num) { 168 String str; 169 if (params==null) { 170 params=buildparams(); 171 } 172 try { 173 str=(String )params.elementAt(num); 174 } catch(IndexOutOfBoundsException e) { 175 str=null; 176 } 177 return str; 178 } 179 180 181 185 private Vector buildparams() { 186 Vector params=new Vector (); 187 if (querystring!=null) { 188 String paramline=querystring; 189 int pos=paramline.indexOf("+"); 191 while(pos!=-1) { 192 params.addElement(paramline.substring(0,pos)); 193 paramline=paramline.substring(pos+1); 194 pos=paramline.indexOf("+"); 195 } 196 params.addElement(paramline); 197 } 198 return params; 199 } 200 201 205 public boolean setParamsVector(Vector params) { 206 this.params=params; 207 return true; 208 } 209 210 214 public Vector getParamsVector() { 215 if (params==null) params=buildparams(); 216 if (params.size()==0) return null; 217 return params; 218 } 219 220 221 225 public boolean setParamsLine(String paramline) { 226 this.params=new Vector (); 227 int pos=paramline.indexOf("+"); 230 while(pos!=-1) { 231 params.addElement(paramline.substring(0,pos)); 232 paramline=paramline.substring(pos+1); 233 pos=paramline.indexOf("+"); 234 } 235 params.addElement(paramline); 236 return true; 237 } 238 239 244 public String getHeader(String name) { 245 if (req!=null) { 246 return req.getHeader(name); 247 } else { 248 return null; 249 } 250 } 251 252 255 public String getSessionName() { 256 return sname; 257 } 258 259 262 public void setSessionName(String name) { 263 this.sname=name; 264 } 265 266 268 271 public String getUrl() { 272 String result = null; 273 if( req != null ) { 274 result = req.getRequestURI(); 275 if( req.getQueryString() != null ) 276 result += "?" + req.getQueryString(); 277 return result; 278 } else { 279 return null; 280 } 281 } 282 283 285 private static String VPROProxyName = "vpro6d.vpro.nl"; private static String VPROProxyAddress = "145.58.172.6"; 288 291 301 public String getAddress() { 302 String result = null; 303 boolean fromProxy = false; 304 String addr = req.getRemoteHost(); 305 306 if( addr != null && (addr.indexOf( VPROProxyName ) != -1 || addr.indexOf( VPROProxyAddress ) != -1 )) { 311 fromProxy = true; 313 addr = req.getHeader("X-Forwarded-For"); 314 } 315 if (addr != null) { 316 result = getHostNames( addr ); 318 319 if( fromProxy ) { 323 result = "zen.vpro.nl->" + result; 324 } 325 } 326 return result; 327 } 328 329 336 private String getHostNames(String host) { 337 String result = null; 338 String hn = null; 339 if( host.indexOf(",") != -1 ) { 342 int pos; 343 while( (pos = host.indexOf(",")) != -1 ) { 346 hn = host.substring( 0, pos ); 347 host = host.substring( pos + 2 ); 348 if( result == null ) 349 result = getHostName( hn ); 350 else 351 result += "->" + getHostName( hn ); 352 } 353 } else { 355 result = getHostName( host ); 356 } 357 return result; 358 } 359 360 367 private String getHostName( String hostname ) { 368 String hn = hostname; 370 if( hn != null && !hn.equals("")) { 371 try { 372 hn = InetAddress.getByName( hostname ).getHostName(); 373 } catch( UnknownHostException e) { 374 } 375 } 376 return hn; 377 } 378 379 384 public String getReferer() { 385 if (req==null) { 386 log.error("scanpage:getReferer: req="+req+", can't get referer."); 387 return null; 388 } else { 389 return req.getHeader("Referer"); 390 } 391 } 392 393 397 public scanpage duplicate() { 398 scanpage dup=new scanpage(); 399 dup.res=null; 400 dup.req=null; 401 dup.params=null; 402 dup.processor=this.processor; 403 dup.session=this.session; 404 dup.sname=this.sname; 405 dup.name=this.name; 406 dup.rstatus=this.rstatus; 407 dup.body=this.body; 408 dup.req_line=this.req_line; 409 dup.wantCache=this.wantCache; 410 dup.mimetype=this.mimetype; 411 dup.querystring=this.querystring; 412 dup.partlevel=this.partlevel; 413 dup.loadmode=this.loadmode; 414 dup.reload=this.reload; 415 return dup; 416 } 417 } 418 | Popular Tags |