This file is indexed.

/usr/share/tdiary/misc/plugin/tlink.rb is in tdiary-plugin 3.2.2-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# -*- coding: utf-8 -*-
# tlink.rb
#
# title 属性付 anchor plugin
#
# 使い方
#   <%= tlink( "URL", "文字列", "title 属性の中身(省略可)" ) %>
#
#   第 3 パラメータを省略した時、URL の末尾が c#?? ならば、
#   そのツッコミの内容が最初の行だけ表示されます。
#   末尾が p#?? ならば、サブタイトルがあればサブタイトルが、
#   なければ最初のパラグラフが表示されます。
#
#   例. <%= tlink( "http://tdiary.tdiary.net/20020131.html#c01", "このツッコミ" ) %>
#       出力結果:
#       <a href="http://tdiary.tdiary.net/20020131.html#c01", title="テストでござるよ">このツッコミ</a>
#
# Copyright(C) 2002 NT <nt@24i.net>
# Distributed under the GPL.
#
# Modified: by abbey <inlet@cello.no-ip.org>
#
=begin ChangeLog
2003-03-03 NT <nt@be.to>
	* add the function to try regetting a subtitle.

2003-01-29 NT <nt@be.to>
	* fix a critical bug.

2003-01-28 NT <nt@be.to>
	* correspond to change in movile mode.

2002-11-19 NT <nt@24i.net>
	* add require 'pstore'.

2002-07-01 NT <nt@24i.net>
	* change some regular expressions.

2002-05-18 NT <nt@24i.net>
	* remove "," from %Q[<a href="#{url}", title="#{title}">#{str}</a>].

2002-05-16 MUTOH Masao <mutoh@highway.ne.jp>
	* cache mechanism support.
	* code cleanup(remove require 'cgi', 
		getcomment rename to tlink_getcomment).

2002-05-05 NT <nt@24i.net>
	* add URL to User-Agent

2002-04-21 abbey <inlet@cello.no-ip.org>
	* add error shori

2002-04-20 NT <nt@24i.net>
	* change User-Agent
	* modify some regular expressions

2002-04-19 NT <nt@24i.net>
	* modify some regular expressions
	* add User-Agent

2002-04-18 abbey <inlet@cello.no-ip.org>
	* adapt to port numbers except 80
	* adapt to #pXX

2002-04-17 NT <nt@24i.net>
	* create
=end

require 'net/http'
require 'kconv'
require 'pstore'

def tlink_initialize 
  dir = @cache_path + "/tlink"
  @tlink_path = dir + "/tlink.dat"

  Dir.mkdir(dir, 0700) unless FileTest.exist?(dir)
  db = PStore.new(@tlink_path).transaction do |db|
    if (db.root?('tlinkdata')) then
      @tlink_dic = db["tlinkdata"]
    else
      @tlink_dic = Hash.new
    end
  end
end

def tlink_finalize
  db = PStore.new(@tlink_path)
  db.transaction do
    begin
      db["tlinkdata"] = @tlink_dic
    rescue PStore::Error
    end
  end
end

def tlink_getcomment( url )
  result = ""
  ref = base_url
  agent = { "User-Agent" => "DoCoMo (compatible; tDiary plugin; tlink; #{ref})" }
  host, path, frag = url.scan( %r[http://(.*?)/(.*)#((?:p|c)\d\d)] )[0]
  if /p0/ =~ frag
    frag = "(?:" + frag + "|" + frag.sub( /p/, "p#" ).sub( /#0/, "#" ) + ")"
  end
  port = 80
  if /(.*):(\d+)/ =~ host
    host = $1
    port = $2
  end
  hata = 0
  http = Net::HTTP.new( host, port )
  begin
    http.open_timeout = 3
    response , = http.get( "/#{path}", agent )
    response.body.each { |line|
      if %r[<A NAME="#{frag}] =~ line
        if %r[<(?:P|H3)><A NAME="#{frag}">(?:.*?)</A> (.*?)</(?:P|H3)>] =~ line.toutf8
          result = $1
          break
        else
          hata = 1
        end
      elsif hata == 1 && %r[^\t*(.*?)<BR>] =~ line.toutf8
        result = $1
        hata = 0
        break
      end
    }
  rescue
    result = ""
  end

  result = CGI::escapeHTML( result.gsub( %r[</?[aA](.*?)>], "" ) ).gsub( /&amp;nbsp;/, " " )
end

tlink_initialize

def tlink( url, str, title = nil )
  unless title
    if @tlink_dic[url] && %r[#(p|c)\d\d$] =~ url && @tlink_dic[url] != ''
      title = @tlink_dic[url]
    elsif @tlink_dic[url] && %r[#(p|c)\d\d$] !~ url
      title = @tlink_dic[url]
    else
      if /#{url}/ =~ ENV["REDIRECT_URL"] && /#{url}/ =~ @date.strftime('%Y%m%d')
      else
        title = tlink_getcomment( url )
        @tlink_dic[url] = title
        tlink_finalize
      end
    end
  end

  %Q[<a href="#{h url}" title="#{h title}">#{str}</a>]
end


# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End: