Wiki2Go 1.14.4 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/Wiki2Go_make_repository.rb +10 -0
- data/bin/Wiki2Go_make_site.rb +1 -1
- data/lib/Web2Go/ERB_Interpreter.rb +6 -1
- data/lib/Wiki2Go/FileStorage.rb +28 -12
- data/lib/Wiki2Go/Install/make_repository.rb +140 -0
- data/lib/Wiki2Go/Install/make_site.rb +98 -16
- data/lib/Wiki2Go/Install/site/html/admin.css +197 -101
- data/lib/Wiki2Go/Install/site/html/rssLogo.png +0 -0
- data/lib/Wiki2Go/Install/site/html/valid-html401.png +0 -0
- data/lib/Wiki2Go/Install/templates/admin.htm +51 -47
- data/lib/Wiki2Go/Install/templates/admin_pages/update_blacklist.txt +17 -0
- data/lib/Wiki2Go/Install/templates/edit.htm +9 -28
- data/lib/Wiki2Go/Install/templates/full_footer.htm +35 -0
- data/lib/Wiki2Go/Install/templates/header.htm +7 -0
- data/lib/Wiki2Go/Install/templates/pagelist.htm +2 -24
- data/lib/Wiki2Go/Install/templates/simple_footer.htm +17 -0
- data/lib/Wiki2Go/Install/templates/versionlist.htm +2 -24
- data/lib/Wiki2Go/Install/templates/view.htm +2 -42
- data/lib/Wiki2Go/Install/wiki/style.css +65 -67
- data/lib/Wiki2Go/Page.rb +14 -2
- data/lib/Wiki2Go/PrivateWikiConfig.rb +34 -19
- data/lib/Wiki2Go/PublicWikiConfig.rb +59 -41
- data/lib/Wiki2Go/ReadWriteWikiConfig.rb +24 -13
- data/lib/Wiki2Go/Server.rb +19 -18
- data/lib/Wiki2Go/SpamFilter.rb +31 -18
- data/lib/Wiki2Go/Web.rb +31 -17
- data/lib/Wiki2Go/Wiki2Go.rb +59 -15
- data/lib/Wiki2Go/Wiki2GoConfig.rb +10 -4
- data/lib/Wiki2Go/Wiki2GoServlet.rb +18 -4
- data/lib/Wiki2Go/WikiFormatter.rb +82 -26
- metadata +13 -4
- data/lib/Wiki2Go/cgi/display.rb +0 -20
data/lib/Wiki2Go/Page.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
module Wiki2Go
|
2
2
|
|
3
|
+
# Represents one page in the Wiki
|
3
4
|
class Page
|
4
5
|
|
6
|
+
# Name of the file
|
5
7
|
attr_reader :title
|
8
|
+
# Descriptive name given by author
|
6
9
|
attr_reader :name
|
10
|
+
# Real author (if authenticated) or IP/DNS address
|
7
11
|
attr_accessor :author
|
12
|
+
# Authorname given by author
|
8
13
|
attr_reader :alias
|
9
|
-
|
14
|
+
# Array of Strings containing the page text
|
15
|
+
attr_accessor :lines
|
16
|
+
# Date and time last modified
|
10
17
|
attr_reader :lastmodified
|
11
18
|
|
12
19
|
def initialize(title,lines, author, time,name,aliasname=nil)
|
@@ -21,7 +28,7 @@ module Wiki2Go
|
|
21
28
|
def Page.make_page(title, lines,default_time)
|
22
29
|
author = "unknown"
|
23
30
|
lastmodified = default_time
|
24
|
-
name = File.basename(title)
|
31
|
+
name = File.basename(title,'.rbl')
|
25
32
|
|
26
33
|
last = lines.last
|
27
34
|
while !last.nil? and last =~ /\$([^:]+):(.*)\$/ do
|
@@ -52,6 +59,7 @@ module Wiki2Go
|
|
52
59
|
file.puts "$AUTHOR:#{@author}$"
|
53
60
|
end
|
54
61
|
|
62
|
+
|
55
63
|
def length
|
56
64
|
return @lines.length
|
57
65
|
end
|
@@ -65,5 +73,9 @@ module Wiki2Go
|
|
65
73
|
@lastmodified = date
|
66
74
|
end
|
67
75
|
|
76
|
+
def Page.is_dynamic?(pagename)
|
77
|
+
pagename =~ /\.rbl$/
|
78
|
+
end
|
79
|
+
|
68
80
|
end
|
69
81
|
end
|
@@ -3,30 +3,45 @@
|
|
3
3
|
require "Wiki2Go/FileStorage.rb"
|
4
4
|
require "Wiki2Go/Wiki2GoConfig.rb"
|
5
5
|
|
6
|
-
|
6
|
+
module Wiki2Go
|
7
|
+
# The base class for configurations files of private wikis
|
8
|
+
class PrivateWikiConfig < Wiki2Go::Config
|
9
|
+
|
10
|
+
# Initialize with root directory of wiki
|
11
|
+
# By default generate HTML
|
12
|
+
def initialize(directory)
|
13
|
+
super(directory)
|
14
|
+
@generate_html = true
|
15
|
+
end
|
16
|
+
|
17
|
+
# A private wiki is always editable
|
18
|
+
def editable?(web)
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
# Never redirect URLs
|
23
|
+
def redirect_url?(web,url)
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
# Redirect to the .HTML version after a Save, if site generates HTML
|
28
|
+
def redirect_to_html?(web)
|
29
|
+
@generate_html
|
30
|
+
end
|
31
|
+
|
32
|
+
# The configuration to generate a static HTML page is identical to the current one
|
33
|
+
def static_web(web)
|
34
|
+
web.clone
|
35
|
+
end
|
7
36
|
|
8
|
-
def initialize(directory)
|
9
|
-
super(directory)
|
10
|
-
@generate_html = true
|
11
|
-
end
|
12
|
-
|
13
|
-
def editable?(web)
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
def redirect_url?(web,url)
|
18
|
-
false
|
19
|
-
end
|
20
37
|
|
21
|
-
def redirect_to_html?(web)
|
22
|
-
@generate_html
|
23
38
|
end
|
39
|
+
end
|
24
40
|
|
25
|
-
|
26
|
-
|
41
|
+
class PrivateWikiConfig < Wiki2Go::PrivateWikiConfig
|
42
|
+
def initialize(directory)
|
43
|
+
super(directory)
|
27
44
|
end
|
28
|
-
|
29
|
-
|
30
45
|
end
|
31
46
|
|
32
47
|
|
@@ -5,48 +5,66 @@ require "Wiki2Go/Wiki2GoConfig.rb"
|
|
5
5
|
|
6
6
|
require 'Wiki2Go/SpamFilter'
|
7
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
|
-
|
8
|
+
module Wiki2Go
|
9
|
+
# Base class for public wiki
|
10
|
+
class PublicWikiConfig < Wiki2Go::Config
|
11
|
+
|
12
|
+
# Initialize with root directory of wiki
|
13
|
+
# By default, generates HTML
|
14
|
+
def initialize(directory)
|
15
|
+
super(directory)
|
16
|
+
@generate_html = true
|
17
|
+
end
|
18
|
+
|
19
|
+
# Accept a page save if
|
20
|
+
# * The edit is by an authenticated user
|
21
|
+
# * OR the user is not on the blacklist and none of the URLs on the page are on the blacklist
|
22
|
+
def accept_page?(web,content)
|
23
|
+
|
24
|
+
return true if web.secure
|
25
|
+
|
26
|
+
author = web.user
|
27
|
+
filter = Wiki2Go::SpamFilter.new(self)
|
28
|
+
|
29
|
+
if filter.edit_by_banned_user?(author) ||
|
30
|
+
filter.edit_contains_banned_url?(content) then
|
31
|
+
|
32
|
+
current_page = storage.load_page(web.name,web.current_page)
|
33
|
+
filter.blacklist_user_and_urls_added(author,current_page.content,content)
|
34
|
+
|
35
|
+
tarpit
|
36
|
+
false
|
37
|
+
else
|
38
|
+
current_page = storage.load_page(web.name,web.current_page)
|
39
|
+
filter.greylist_new_urls(author,current_page.content,content)
|
40
|
+
return true
|
41
|
+
end
|
34
42
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
43
|
+
|
44
|
+
# What to do when we encounter a spammer? Delay him for 60 seconds
|
45
|
+
def tarpit
|
38
46
|
sleep(60)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
end
|
48
|
+
|
49
|
+
# A public wiki is always editable
|
50
|
+
def editable?(web)
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
# Redirect if the url is on the greylist, unless the user is authenticated
|
55
|
+
def redirect_url?(web,url)
|
56
|
+
return false if web.secure
|
57
|
+
|
58
|
+
greylist = storage.load_greylist
|
59
|
+
greylist.contains_url(url)
|
60
|
+
end
|
51
61
|
|
62
|
+
end
|
52
63
|
end
|
64
|
+
|
65
|
+
class PublicWikiConfig < Wiki2Go::PublicWikiConfig
|
66
|
+
|
67
|
+
def initialize(directory)
|
68
|
+
super(directory)
|
69
|
+
end
|
70
|
+
end
|
@@ -3,21 +3,32 @@
|
|
3
3
|
require "Wiki2Go/FileStorage.rb"
|
4
4
|
require "Wiki2Go/Wiki2GoConfig.rb"
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module Wiki2Go
|
7
|
+
# Base class for read/write wikis (authenticated users can write, everybody can read)
|
8
|
+
class ReadWriteWikiConfig < Wiki2Go::Config
|
9
|
+
|
10
|
+
def initialize(directory)
|
11
|
+
super(directory)
|
12
|
+
@generate_html = true
|
13
|
+
end
|
14
|
+
|
15
|
+
# Wiki is editable if user is authenticated
|
16
|
+
def editable?(web)
|
17
|
+
web.secure
|
18
|
+
end
|
19
|
+
|
20
|
+
# Never redirect URLs, we trust our authenticated writers
|
21
|
+
def redirect_url?(web,url)
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ReadWriteWikiConfig < Wiki2Go::ReadWriteWikiConfig
|
29
|
+
|
8
30
|
def initialize(directory)
|
9
31
|
super(directory)
|
10
|
-
@generate_html = true
|
11
32
|
end
|
12
|
-
|
13
|
-
def editable?(web)
|
14
|
-
web.secure
|
15
|
-
end
|
16
|
-
|
17
|
-
def redirect_url?(web,url)
|
18
|
-
false
|
19
|
-
end
|
20
|
-
|
21
33
|
end
|
22
34
|
|
23
|
-
|
data/lib/Wiki2Go/Server.rb
CHANGED
@@ -15,9 +15,9 @@ require 'Wiki2Go/DotGraphics'
|
|
15
15
|
require 'optparse'
|
16
16
|
|
17
17
|
module Wiki2Go
|
18
|
-
|
18
|
+
|
19
19
|
class LocalConfig < PublicWikiConfig
|
20
|
-
|
20
|
+
|
21
21
|
def initialize(dir)
|
22
22
|
super(dir)
|
23
23
|
@generate_html = false
|
@@ -25,17 +25,17 @@ module Wiki2Go
|
|
25
25
|
@debug = true
|
26
26
|
add_processor('GRAPH',Wiki2Go::DotGraphics.new('c:/Program Files/ATT/Graphviz/bin/'))
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def redirect_url?(web,url)
|
30
30
|
result = super(web,url)
|
31
31
|
return result
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
end
|
35
|
-
|
36
|
-
|
35
|
+
|
36
|
+
|
37
37
|
class Server
|
38
|
-
|
38
|
+
|
39
39
|
def initialize(args)
|
40
40
|
puts "Args = #{args.inspect}"
|
41
41
|
opts = OptionParser.new
|
@@ -43,37 +43,38 @@ module Wiki2Go
|
|
43
43
|
port = 8081
|
44
44
|
wiki = 'Wiki2Go'
|
45
45
|
single = false
|
46
|
+
allow_dynamic = false
|
47
|
+
|
46
48
|
opts.on("-d",'--dir <directory>','(default is current directory)',String) { |val| dir = val }
|
47
49
|
opts.on("-p",'--port <nb>',"(default is port 8081)",String) { |val| port = val }
|
48
50
|
opts.on("-w",'--wiki <wikiname>',"(default is 'Wiki2Go')",String) { |val| wiki = val }
|
49
|
-
opts.on("-s","--single","Single or multi-wiki (default)") { |val|
|
50
|
-
|
51
|
-
single = true
|
52
|
-
}
|
51
|
+
opts.on("-s","--single","Single or multi-wiki (default)") { |val| single = true }
|
52
|
+
opts.on('-r','--rublets','Allow dynamic pages') { |val| allow_dynamic = true }
|
53
53
|
opts.on_tail("-h", "--help", "Show this message") do
|
54
54
|
puts opts
|
55
55
|
exit
|
56
56
|
end
|
57
57
|
opts.parse(args)
|
58
|
-
|
58
|
+
|
59
59
|
@config = LocalConfig.new(dir)
|
60
|
+
@config.allow_dynamic_pages = allow_dynamic
|
60
61
|
@config.port = port
|
61
62
|
@config.default_web = wiki
|
62
63
|
@config.generate_html = false
|
63
64
|
@config.multi_wiki = !single
|
64
65
|
puts "Multi wiki = #{@config.multi_wiki}"
|
65
66
|
end
|
66
|
-
|
67
|
+
|
67
68
|
def start
|
68
69
|
begin
|
69
|
-
|
70
|
+
|
70
71
|
yield @config if block_given?
|
71
|
-
|
72
|
+
|
72
73
|
web_thread = Thread.new(@config) do |config|
|
73
74
|
s = WEBrick::HTTPServer.new( :Port => config.port)
|
74
|
-
|
75
|
+
|
75
76
|
s.mount("/", WikiServlet,config)
|
76
|
-
|
77
|
+
|
77
78
|
trap("INT"){ s.shutdown }
|
78
79
|
s.start
|
79
80
|
end
|
@@ -83,7 +84,7 @@ module Wiki2Go
|
|
83
84
|
puts $@
|
84
85
|
end
|
85
86
|
end
|
86
|
-
|
87
|
+
|
87
88
|
def stop
|
88
89
|
Net::HTTP.start( @config.server, @config.port) { |http|
|
89
90
|
response = http.get('/stop/' + @config.default_web + '/')
|
data/lib/Wiki2Go/SpamFilter.rb
CHANGED
@@ -1,59 +1,60 @@
|
|
1
1
|
require 'Wiki2Go/UrlFinder'
|
2
2
|
|
3
3
|
require "uri"
|
4
|
+
require 'net/http'
|
4
5
|
|
5
6
|
module Wiki2Go
|
6
7
|
class SpamFilter
|
7
|
-
|
8
|
+
|
8
9
|
def initialize(config)
|
9
10
|
@config = config
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
def edit_by_banned_user?(author)
|
13
14
|
banned_users.contains(author)
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
def edit_contains_banned_url?(content)
|
17
18
|
banned_urls.found_in(content) || chonqed_urls.found_in(content)
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
def too_many_new_urls?(original_content, modified_content,max_new_urls)
|
21
22
|
return added_urls(original_content,modified_content).size > max_new_urls
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
def added_urls(original_content, modified_content)
|
25
26
|
url_finder = Wiki2Go::UrlFinder.new
|
26
|
-
|
27
|
+
|
27
28
|
old_urls = url_finder.urls_in(original_content)
|
28
29
|
new_urls = url_finder.urls_in(modified_content)
|
29
30
|
urls = new_urls - old_urls
|
30
31
|
urls
|
31
32
|
end
|
32
|
-
|
33
|
+
|
33
34
|
def blacklist_user(author)
|
34
35
|
bad_users = banned_users
|
35
36
|
bad_users.add(author)
|
36
37
|
@config.storage.save_list(bad_users)
|
37
38
|
end
|
38
|
-
|
39
|
+
|
39
40
|
def blacklist_url(url)
|
40
41
|
banned_urls.add(host_of(url))
|
41
42
|
@config.storage.save_list(banned_urls)
|
42
43
|
end
|
43
|
-
|
44
|
+
|
44
45
|
def blacklist_urls(urls)
|
45
46
|
urls.each do |url|
|
46
47
|
banned_urls.add(url)
|
47
48
|
end
|
48
49
|
@config.storage.save_list(banned_urls)
|
49
50
|
end
|
50
|
-
|
51
|
+
|
51
52
|
def blacklist_user_and_urls_added(author,original,new_content)
|
52
53
|
blacklist_user(author)
|
53
54
|
new_urls = added_urls(original,new_content)
|
54
55
|
blacklist_urls(new_urls)
|
55
56
|
end
|
56
|
-
|
57
|
+
|
57
58
|
def greylist_new_urls(author,original,new_content)
|
58
59
|
new_urls = added_urls(original,new_content)
|
59
60
|
if new_urls.length > 0 then
|
@@ -64,32 +65,44 @@ module Wiki2Go
|
|
64
65
|
@config.storage.save_list(list)
|
65
66
|
end
|
66
67
|
end
|
67
|
-
|
68
|
+
|
69
|
+
def update_chongqed
|
70
|
+
output = 'Updating blacklist'
|
71
|
+
response = Net::HTTP.get_response('blacklist.chongqed.org','/index.html')
|
72
|
+
if response.code == '200' then
|
73
|
+
output = response.body
|
74
|
+
@config.storage.update_chongqed_spamlist(output)
|
75
|
+
else
|
76
|
+
output = "Error code #{response.code}: #{response.message}"
|
77
|
+
end
|
78
|
+
output
|
79
|
+
end
|
80
|
+
|
68
81
|
private
|
69
|
-
|
82
|
+
|
70
83
|
def host_of(url)
|
71
84
|
return '://' + URI::parse(url).host
|
72
85
|
end
|
73
|
-
|
86
|
+
|
74
87
|
def banned_users
|
75
88
|
@banned_users ||= @config.storage.load_blacklist('user')
|
76
89
|
@banned_users
|
77
90
|
end
|
78
|
-
|
91
|
+
|
79
92
|
def banned_urls
|
80
93
|
@banned_urls ||= @config.storage.load_blacklist('url')
|
81
94
|
@banned_urls
|
82
95
|
end
|
83
|
-
|
96
|
+
|
84
97
|
def chonqed_urls
|
85
98
|
@chonqed_urls ||= @config.storage.load_blacklist('chonqed')
|
86
99
|
@chonqed_urls
|
87
100
|
end
|
88
|
-
|
101
|
+
|
89
102
|
def greylist
|
90
103
|
@greylist ||= @config.storage.load_greylist
|
91
104
|
@greylist
|
92
105
|
end
|
93
|
-
|
106
|
+
|
94
107
|
end
|
95
108
|
end
|