roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r312945 - in /incubator/roller/branches/roller_2.0: src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java web/WEB-INF/classes/ApplicationResources.properties web/WEB-INF/classes/roller.properties
Date Tue, 11 Oct 2005 19:53:25 GMT
Author: snoopdave
Date: Tue Oct 11 12:53:21 2005
New Revision: 312945

URL: http://svn.apache.org/viewcvs?rev=312945&view=rev
Log:
Improvement ROL-839 'Allow configuration of list of allowable trackbacks (for internal corporate
blogs)'

Modified:
    incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
    incubator/roller/branches/roller_2.0/web/WEB-INF/classes/ApplicationResources.properties
    incubator/roller/branches/roller_2.0/web/WEB-INF/classes/roller.properties

Modified: incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java?rev=312945&r1=312944&r2=312945&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
(original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
Tue Oct 11 12:53:21 2005
@@ -19,6 +19,8 @@
 import java.util.List;
 import java.util.ListIterator;
 import java.util.ResourceBundle;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.mail.MessagingException;
 import javax.mail.Session;
@@ -43,6 +45,7 @@
 import org.apache.struts.util.RequestUtils;
 import org.roller.RollerException;
 import org.roller.RollerPermissionsException;
+import org.roller.config.RollerConfig;
 import org.roller.model.IndexManager;
 import org.roller.model.Roller;
 import org.roller.model.RollerFactory;
@@ -909,64 +912,89 @@
 
                if (form.getTrackbackUrl() != null)
                {
-                   try
-                   {
-                       // Construct data
-
-                       String data = URLEncoder.encode("title", "UTF-8")
-                           +"="+URLEncoder.encode(title, "UTF-8");
-
-                       data += ("&" + URLEncoder.encode("excerpt", "UTF-8")
-                                 +"="+URLEncoder.encode(excerpt,"UTF-8"));
-
-                       data += ("&" + URLEncoder.encode("url", "UTF-8")
-                                 +"="+URLEncoder.encode(url,"UTF-8"));
-
-                       data += ("&" + URLEncoder.encode("blog_name", "UTF-8")
-                                 +"="+URLEncoder.encode(blog_name,"UTF-8"));
-
-                       // Send data
-                       URL tburl = new URL(form.getTrackbackUrl());
-                       URLConnection conn = tburl.openConnection();
-                       conn.setDoOutput(true);
+            	   // by default let all trackbacks to be sent
+            	   boolean allowTrackback = true;
 
-                       OutputStreamWriter wr =
-                           new OutputStreamWriter(conn.getOutputStream());
-                       BufferedReader rd = null;
-                       try
-                       {
-                           wr.write(data);
-                           wr.flush();
-    
-                           // Get the response
-                           rd = new BufferedReader(new InputStreamReader(
-                               conn.getInputStream()));
-    
-                           String line;
-                           StringBuffer resultBuff = new StringBuffer();
-                           while ((line = rd.readLine()) != null)
-                           {
-                               resultBuff.append(
-                                   Utilities.escapeHTML(line, true));
-                               resultBuff.append("<br />");
-                           }
-                           
-                           ActionMessages resultMsg = new ActionMessages();
-                           resultMsg.add(ActionMessages.GLOBAL_MESSAGE,
-                               new ActionMessage("weblogEdit.trackbackResults", 
-                               resultBuff));
-                           saveMessages(request, resultMsg);
-                       }
-                       finally
+            	   String allowedURLs = RollerConfig.getProperty("trackback.allowedURLs");
+                   if (allowedURLs != null)
+                   {
+                	   // in the case that the administrator has enabled trackbacks
+                	   // for only specific URLs, set it to false by default
+                	   allowTrackback = false;
+                       String[] splitURLs = allowedURLs.split("\\|\\|");
+                       for (int i=0; i<splitURLs.length; i++)
                        {
-                           wr.close();
-                           rd.close();
+                    	   Matcher m = Pattern.compile(splitURLs[i]).matcher(form.getTrackbackUrl());
+                    	   if (m.matches()) {
+                    		   allowTrackback = true;
+                    		   break;
+                    	   }
                        }
                    }
-                   catch (IOException e)
-                   {
-                       errors.add(ActionErrors.GLOBAL_ERROR,
-                           new ActionError("error.trackback",e));
+                   
+                   if(!allowTrackback) {
+              	     errors.add(ActionErrors.GLOBAL_ERROR,
+	                           new ActionError("error.trackbackNotAllowed"));
+                   } else {
+	                   try
+	                   {
+	                       // Construct data
+	
+	                       String data = URLEncoder.encode("title", "UTF-8")
+	                           +"="+URLEncoder.encode(title, "UTF-8");
+	
+	                       data += ("&" + URLEncoder.encode("excerpt", "UTF-8")
+	                                 +"="+URLEncoder.encode(excerpt,"UTF-8"));
+	
+	                       data += ("&" + URLEncoder.encode("url", "UTF-8")
+	                                 +"="+URLEncoder.encode(url,"UTF-8"));
+	
+	                       data += ("&" + URLEncoder.encode("blog_name", "UTF-8")
+	                                 +"="+URLEncoder.encode(blog_name,"UTF-8"));
+	
+	                       // Send data
+	                       URL tburl = new URL(form.getTrackbackUrl());
+	                       URLConnection conn = tburl.openConnection();
+	                       conn.setDoOutput(true);
+	
+	                       OutputStreamWriter wr =
+	                           new OutputStreamWriter(conn.getOutputStream());
+	                       BufferedReader rd = null;
+	                       try
+	                       {
+	                           wr.write(data);
+	                           wr.flush();
+	    
+	                           // Get the response
+	                           rd = new BufferedReader(new InputStreamReader(
+	                               conn.getInputStream()));
+	    
+	                           String line;
+	                           StringBuffer resultBuff = new StringBuffer();
+	                           while ((line = rd.readLine()) != null)
+	                           {
+	                               resultBuff.append(
+	                                   Utilities.escapeHTML(line, true));
+	                               resultBuff.append("<br />");
+	                           }
+	                           
+	                           ActionMessages resultMsg = new ActionMessages();
+	                           resultMsg.add(ActionMessages.GLOBAL_MESSAGE,
+	                               new ActionMessage("weblogEdit.trackbackResults", 
+	                               resultBuff));
+	                           saveMessages(request, resultMsg);
+	                       }
+	                       finally
+	                       {
+	                           wr.close();
+	                           rd.close();
+	                       }
+	                   }
+	                   catch (IOException e)
+	                   {
+	                       errors.add(ActionErrors.GLOBAL_ERROR,
+	                           new ActionError("error.trackback",e));
+	                   }
                    }
                }
                else

Modified: incubator/roller/branches/roller_2.0/web/WEB-INF/classes/ApplicationResources.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/web/WEB-INF/classes/ApplicationResources.properties?rev=312945&r1=312944&r2=312945&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/web/WEB-INF/classes/ApplicationResources.properties
(original)
+++ incubator/roller/branches/roller_2.0/web/WEB-INF/classes/ApplicationResources.properties
Tue Oct 11 12:53:21 2005
@@ -352,6 +352,8 @@
 
 error.trackback=Error sending trackback. Possible cause: incorrect \
 trackback URL. {0}
+error.trackbackNotAllowed=Error sending trackback. The site administrator \
+has disabled sending tracbacks to the URL you specified.
 
 errorPage.title=Unexpected Exception
 errorPage.message=Roller has encountered and logged an unexpected exception.

Modified: incubator/roller/branches/roller_2.0/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/web/WEB-INF/classes/roller.properties?rev=312945&r1=312944&r2=312945&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/web/WEB-INF/classes/roller.properties (original)
+++ incubator/roller/branches/roller_2.0/web/WEB-INF/classes/roller.properties Tue Oct 11
12:53:21 2005
@@ -256,6 +256,10 @@
 General,Status,Java,Music,Politics,Music
 
 #----------------------------------
+# trackback protection
+trackback.allowedURLs=http://w3.ibm.com/.*||http://another.example.com/.*
+
+#----------------------------------
 # misc settings
 
 loginfilter.rememberme.enabled=true



Mime
View raw message