<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,21 @@
+Trachouse v1.0.0 fork (adds basic authentication support)
+Author: Maxim Chernyak
+Email: max@bitsonnet.com
+
+This fork adds a simple trac basic authentication support.
+
+USE:
+	Follow instructions in the original README below
+	There are 3 more commented sections you need to edit:
+		- set @trac_basic_auth to true
+		- set @trac_http_user to your basic auth username
+		- set @trac_http_pass to your basic auth password
+
+
+
+Original README
+-------------------------------
+
 Trachouse v1.0.0
 Trac to Lighthouse ticket importer
 Author: Shay Arnett </diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,23 +1,39 @@
+# Trachouse v1.0.0 fork (adds basic authentication support)
+# Author: Maxim Chernyak
+# Email: max@bitsonnet.com
+# 
+# This fork adds a simple trac basic authentication support.
+# 
+# USE:
+#   Follow instructions in the original README below
+#   There are 3 more commented sections you need to edit:
+#     - set @trac_basic_auth to true
+#     - set @trac_http_user to your basic auth username
+#     - set @trac_http_pass to your basic auth password
+# 
+# 
+# 
+# Original README
+# -------------------------------
+# 
 # Trachouse v1.0.0
 # Trac to Lighthouse ticket importer
-# Author: Shay Arnett
+# Author: Shay Arnett 
 # Website: http://shayarnett.com/trachouse (soonish)
 # Email: shayarnett@gmail.com
 # 
-# You will need to obtain a copy of Lighthouse.rb from the Lighthouse API
+# You will need to obtain a copy of lighthouse.rb from the Lighthouse API
 # http://forum.activereload.net/forums/6/topics/44
-#
-# Please read all commented sections, as most have something you
-# will need to change directly below it
+# 
+# Please read all commented sections, as most have something you will need to change directly below it
 # 
 # USE:
-#
+# 
 #   @tickets = populate_tickets # grabs all tickets from trac
 #   import_tickets(@tickets) # import tickets to lighthouse
 #   # profit
-#   # you may want to inspect @tickets or only import a couple of 
-#   # tickets to verify format before processing all tickets
-#
+#   # you may want to inspect @tickets or only import a couple of tickets to verify format before processing all tickets
+# 
 # Copyright (c) 2008 Shay Arnett
 # 
 # Permission is hereby granted, free of charge, to any person
@@ -41,6 +57,7 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 # OTHER DEALINGS IN THE SOFTWARE.
 
+
 require 'Rubygems'
 require 'hpricot'
 require 'open-uri'
@@ -75,6 +92,15 @@ class Ticket &lt; ActiveResource::Base
 
     # @domain + this is the url for logging into track
     @login = '/login'
+    
+    # set to true if your trac is using basic http authentication (provide credentials below)
+    @trac_basic_auth = false
+    
+    # trac http username for trac's basic authentication
+    @trac_http_user = 'http_user'
+    
+    # trac http password for trac's basic authentication
+    @trac_http_pass = 'http_password'
 
     # setup headers for grabbing cookie and tiket info
     @headers = {
@@ -204,6 +230,10 @@ class Ticket &lt; ActiveResource::Base
 
   def unescapeHTML(string)
     # from CGI.rb - don't need the slow just the unescape
+    if string == nil
+      return ''
+    end
+    
     string.gsub(/&amp;(.*?);/n) do
       match = $1.dup
       case match
@@ -258,8 +288,20 @@ class Ticket &lt; ActiveResource::Base
   end
 
   def get_html_for_ticket(ticket)
-    # change url in get2() if you go somewhere other than /ticket/1 to pull up ticket #1
-    resp, data = @http.get2(&quot;/ticket/#{ticket}&quot;,@headers)
+    #change url if you go somewhere other than /ticket/1 to pull up ticket #1
+    ticket_url = &quot;/ticket/#{ticket}&quot;
+    
+    if @trac_basic_auth
+      resp = Net::HTTP.start(@domain) do |http|
+        req = Net::HTTP::Get.new(ticket_url)
+        req.basic_auth @trac_http_user, @trac_http_pass
+        resp = http.request(req)
+      end
+      data = resp.body
+    else  
+      # change url in get2() if you go somewhere other than /ticket/1 to pull up ticket #1
+      resp, data = @http.get2(ticket_url, @headers)
+    end
     Hpricot(unescapeHTML(data)) if resp.code == '200'
   end
 
@@ -272,7 +314,10 @@ class Ticket &lt; ActiveResource::Base
   end
   
   def import_tickets(tickets)
-    steal_cookie
+    if not @trac_basic_auth
+      steal_cookie
+    end
+    
     new_tickets = []
     tickets.each do |ticket|
       # grab the page for this ticket
@@ -294,7 +339,17 @@ class Ticket &lt; ActiveResource::Base
     # all components
     url = &quot;/report/3&quot;
     ticket_list = []
-    resp, html = @http.get2(url, {'User-Agent' =&gt; @useragent})
+    
+    if @trac_basic_auth
+      resp = Net::HTTP.start(@domain) do |http|
+        req = Net::HTTP::Get.new(url)
+        req.basic_auth @trac_http_user, @trac_http_pass
+        resp = http.request(req)
+      end
+      html = resp.body
+    else
+      resp, html = @http.get2(url, {'User-Agent' =&gt; @useragent})
+    end
     html = Hpricot(html)
     (html/&quot;.ticket&quot;).each do |a|
      a.inner_html =~ /\#(\d{1,3})/</diff>
      <filename>trachouse.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1448eb469530d754ec720738264785c115d9d8d2</id>
    </parent>
  </parents>
  <author>
    <name>max</name>
    <email>max@bitsonnet.com</email>
  </author>
  <url>http://github.com/maxim/trachouse/commit/92cb30ebba8f13e8f4a9f9eef5f3fe2322511962</url>
  <id>92cb30ebba8f13e8f4a9f9eef5f3fe2322511962</id>
  <committed-date>2008-04-25T10:00:59-07:00</committed-date>
  <authored-date>2008-04-25T10:00:59-07:00</authored-date>
  <message>added basic authentication support for trac

	- Added basic authentication support for trac
	- Fixed bug with empty ticket description
	- Updated docs</message>
  <tree>30f19d0b02961c19cabd6919bbf7ce138e4697ed</tree>
  <committer>
    <name>max</name>
    <email>max@bitsonnet.com</email>
  </committer>
</commit>
