📄 fjp.java
字号:
catch(FileNotFoundException e){ temp = e.toString(); } catch(IOException e){ System.err.println("IO Exception"); temp = e.toString(); } catch(NumberFormatException e){ System.err.println("NumberFormatException"); e.printStackTrace(); temp = e.toString(); } try{ if(bufferedReader!=null) bufferedReader.close(); } catch(IOException e){} } /** * This method check if there is a cookie on the remote user machine; in affermative case, * the vote is not allowed. * @param req * @return b Boolean that represents the presence of a cookie; false means that a cookie is on * the remote user machine */ private boolean controllaCookie(HttpServletRequest req){ Cookie[] cookies = req.getCookies(); boolean b=true; if(cookies!=null){ for(int i=0;i<cookies.length;i++){ String nome = cookies[i].getName(); String valore = cookies[i].getValue(); if(nome.equalsIgnoreCase(HOSTCOOKIE) && valore.equalsIgnoreCase(VOTATO)) b=false; else b=true; } } else b=true; return b; } /** * This method set a cookie on the remote user machine after the vote has taken place. * @return c The new-created cookie */ private Cookie aggiungiCookie(){ Cookie c = new Cookie(HOSTCOOKIE, VOTATO); c.setVersion(1); c.setMaxAge(60*60*72); c.setComment("FreeJaPoll Web Survey by nkanter"); return c; } /** * This method register the ip of the remote user and add it to the default ip-log file. * @param req */ private synchronized void aggiungiIP(HttpServletRequest req){ File f = new File(IPLOG); try{ f.createNewFile(); } catch(IOException e){ temp2 = e.toString().concat("-ip log file .nk"); } FileWriter fileWriter = null; PrintWriter printWriter = null; try{ fileWriter = new FileWriter(f); printWriter = new PrintWriter(fileWriter); GregorianCalendar g = new GregorianCalendar(); printWriter.println(req.getRemoteAddr()+" ; "+g.get(GregorianCalendar.DAY_OF_MONTH)); } catch(IOException e){ temp2 = e.toString().concat("-ip log file .nk"); } if(printWriter!=null) printWriter.close(); } /** * This method check if the remote user's ip is already present in the default ip-log file; * in affermative case it checks if the log is older than two days; in affermative case * it allows the vote * @param req * @return b This boolean represents if the ip is already present in the default ip-log file * and valid(older than two days) or not */ private boolean controllaIP(HttpServletRequest req){ boolean b = true; FileReader fileReader =null; BufferedReader bufferedReader = null; try{ fileReader = new FileReader(IPLOG); bufferedReader = new BufferedReader(fileReader); String dati = bufferedReader.readLine(); while(dati!=null){ StringTokenizer st = new StringTokenizer(dati, ";"); String s = st.nextToken(); if(s.trim().equalsIgnoreCase(req.getRemoteAddr().trim())){ if(st.hasMoreTokens()){ int i = Integer.parseInt(st.nextToken().trim()); GregorianCalendar greg = new GregorianCalendar(); if((i+2)>greg.get(GregorianCalendar.DAY_OF_MONTH)) b=false; } } dati = bufferedReader.readLine(); } } catch(FileNotFoundException e){ temp2 = e.toString(); } catch(IOException e){ temp2 = e.toString(); } catch(NumberFormatException e){ temp2 = e.toString(); } try{ if(bufferedReader!=null) bufferedReader.close(); } catch(IOException e){} return b; } /** * If the "noTerrorist" flag is "Yes" this method check the provenience of the remote user; * if his request comes from one of the major musulman countries it make voting impossible and * it shows a predefinied warning page * @param req * @return b Boolean that represents the provenience of the remote user; if true the vote is not * allowed and the connection redirected to a warning page */ private boolean controllaTerrorista(HttpServletRequest req){ boolean b=false; if(noTerrorist.equalsIgnoreCase("Yes")){ String remoteHost = req.getRemoteHost(); if(remoteHost.endsWith(".af")) b=true; else if(remoteHost.endsWith(".bd")||remoteHost.endsWith(".dz")) b=true; else if(remoteHost.endsWith(".eg")||remoteHost.endsWith(".eh")) b=true; else if(remoteHost.endsWith(".iq")||remoteHost.endsWith(".ir")) b=true; else if(remoteHost.endsWith(".kg")||remoteHost.endsWith(".kw")) b=true; else if(remoteHost.endsWith(".kz")||remoteHost.endsWith(".lb")) b=true; else if(remoteHost.endsWith(".ma")||remoteHost.endsWith(".pk")) b=true; else if(remoteHost.endsWith(".qa")||remoteHost.endsWith(".sa")) b=true; else if(remoteHost.endsWith(".sd")||remoteHost.endsWith(".sy")) b=true; else if(remoteHost.endsWith(".th")||remoteHost.endsWith(".tj")) b=true; else if(remoteHost.endsWith(".tm")||remoteHost.endsWith(".tn")) b=true; else if(remoteHost.endsWith(".tr")) b=true; } return b; } /** * This method produces the html response file. * @param pw */ private void scriviHTML(PrintWriter pw){ if(this.headerLink==null || this.headerLink==""){ pw.println("<HTML>"); pw.println("<HEAD>"); pw.println("<TITLE>"+pageTitle+"</TITLE>"); pw.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">"); pw.println("</HEAD>"); pw.println("<BODY BGCOLOR="+backGroundColor+res1.getString("text_")+textColor+res1.getString("_link_000000_vlink")); pw.println("<script>"); pw.println("function highlight(which,color){"); pw.println("if (document.all||document.getElementById)"); pw.println("which.style.backgroundColor=color"); pw.println("}"); pw.println("</script>"); } else pw.println("<!--#include file=\""+headerLink+"\" -->"); pw.println("<table width=\"582\" border=\"1\" cellpadding=\"1\" align=\"center\" height=\"241\" bordercolor=\""+tableBorderColor+"\" bgcolor=\""+tableColor+"\">"); pw.println(" <tr> "); pw.println(" <td valign=\"top\"> "); pw.println(" <blockquote> "); pw.println(" <p> </p>"); pw.println(" </blockquote>"); pw.println(res1.getString("_h3_align_center_font")+resultTitle ); pw.println(" </font></h3>"); pw.println(" <blockquote> "); pw.println(" <blockquote> "); pw.println(" <blockquote> "); pw.println(" <blockquote> "); pw.println(" <h3 align=\"left\"> </h3>"); pw.println(" </blockquote>"); pw.println(" </blockquote>"); pw.println(" </blockquote>"); pw.println(res1.getString("_table_width_700")); for(int i=0;i<this.numberOfChoice;i++){ pw.println(" <tr>"); pw.println(res1.getString("_td_width_192_font")); pw.println( labelChoose[i]+" => "+ String.valueOf(arrayValori[i])+"</font></td>"); if(arrayValori[i]!=0) pw.println(" <td width=\"468\" height=\"18\" valign=\"middle\"><img src=\""+this.imageBar+"\" width=\""+calcolaMoltiplicatorePercentuale(arrayValori[i]) +"\" height=\"15\"><img src=\""+imageBarEnd +"\" width=\"28\" height=\"15\"></td>"); else pw.println(" <td width=\"468\" height=\"18\" valign=\"middle\"></td>"); pw.println(" </tr>"); } pw.println("</table>"); pw.println(" </blockquote>"); pw.println(res1.getString("_p_align_center_font")); pw.println(" <a href=\""+this.returnLink+res1.getString("_onMouseOver")); pw.println(this.returnString+" </a></b></font></p>"); pw.println(" <blockquote> "); pw.println(" <p> </p>"); pw.println(" </blockquote>"); pw.println(" </td>"); pw.println(" </tr>"); pw.println("</table>"); pw.println("<p align=\"center\"><img src=\"../immagini/pollo2.jpg\" width=\"61\" height=\"61\"><br><font size=\"2\" face=\"Courier New, Courier, mono\" color=\"#FFFFFF\">Powered by FreeJaPoll 1.0<br>"); pw.println(" -= by nkanter =-</font></p>"); if(temp!=null && temp!="") pw.println("<p align=\"center\"><font size=\"2\" face=\"Courier New, Courier, mono\" color=\"#000000\">"+temp+"</p>"); if(temp2!=null && temp2!="") pw.println("<p align=\"center\"><font size=\"2\" face=\"Courier New, Courier, mono\" color=\"#000000\">"+temp2+"</p>"); if(this.footerLink!=null || this.footerLink!=""){ pw.println("</BODY>"); pw.println("</HTML>"); } else pw.println("<!--#include file= \""+footerLink+"\" -->"); } //////////////}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -