Wiki2Go 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/Wiki2GoServer.rb +11 -0
- data/bin/Wiki2Go_make_site.rb +10 -0
- data/bin/Wiki2Go_make_wiki.rb +10 -0
- data/bin/Wiki2Go_update_site.rb +10 -0
- data/lib/Web2Go/CGIRequest.rb +99 -0
- data/lib/Web2Go/CGIResponse.rb +64 -0
- data/lib/Web2Go/ERB_Interpreter.rb +47 -0
- data/lib/Web2Go/MockCookie.rb +17 -0
- data/lib/Web2Go/MockRequest.rb +131 -0
- data/lib/Web2Go/MockResponse.rb +35 -0
- data/lib/Web2Go/Web2Go.rb +0 -0
- data/lib/Web2Go/WebrickRequest.rb +124 -0
- data/lib/Web2Go/WebrickResponse.rb +50 -0
- data/lib/Wiki2Go.rb +2 -0
- data/lib/Wiki2Go/BlackList.rb +52 -0
- data/lib/Wiki2Go/DotGraphics.rb +69 -0
- data/lib/Wiki2Go/FileStorage.rb +267 -0
- data/lib/Wiki2Go/GreyList.rb +88 -0
- data/lib/Wiki2Go/Install/config/chonqed_blacklist.txt +4743 -0
- data/lib/Wiki2Go/Install/config/passwords +1 -0
- data/lib/Wiki2Go/Install/make_site.rb +515 -0
- data/lib/Wiki2Go/Install/site/error.html +77 -0
- data/lib/Wiki2Go/Install/site/html/admin.css +135 -0
- data/lib/Wiki2Go/Install/site/html/xml.gif +0 -0
- data/lib/Wiki2Go/Install/site/robots.txt +13 -0
- data/lib/Wiki2Go/Install/site/style.css +135 -0
- data/lib/Wiki2Go/Install/templates/admin.htm +48 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/admin.txt +1 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/greylist.txt +72 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/passwords.txt +67 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/regenerate.txt +26 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/removespam.txt +19 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/update.txt +13 -0
- data/lib/Wiki2Go/Install/templates/edit.htm +74 -0
- data/lib/Wiki2Go/Install/templates/pagelist.htm +82 -0
- data/lib/Wiki2Go/Install/templates/rss.xml +11 -0
- data/lib/Wiki2Go/Install/templates/versionlist.htm +84 -0
- data/lib/Wiki2Go/Install/templates/view.htm +72 -0
- data/lib/Wiki2Go/Install/wiki/style.css +135 -0
- data/lib/Wiki2Go/Page.rb +69 -0
- data/lib/Wiki2Go/PrivateWikiConfig.rb +27 -0
- data/lib/Wiki2Go/PublicWikiConfig.rb +52 -0
- data/lib/Wiki2Go/ReadWriteWikiConfig.rb +23 -0
- data/lib/Wiki2Go/Server.rb +94 -0
- data/lib/Wiki2Go/SpamFilter.rb +95 -0
- data/lib/Wiki2Go/UrlFinder.rb +26 -0
- data/lib/Wiki2Go/Web.rb +185 -0
- data/lib/Wiki2Go/WebrickServlet.rb +211 -0
- data/lib/Wiki2Go/WhiteList.rb +29 -0
- data/lib/Wiki2Go/Wiki2Go.rb +274 -0
- data/lib/Wiki2Go/Wiki2GoConfig.rb +144 -0
- data/lib/Wiki2Go/Wiki2GoServlet.rb +197 -0
- data/lib/Wiki2Go/WikiFormatter.rb +597 -0
- data/lib/Wiki2Go/WikiLogFile.rb +43 -0
- data/lib/Wiki2Go/cgi/changes.rb +20 -0
- data/lib/Wiki2Go/cgi/display.rb +20 -0
- data/lib/Wiki2Go/cgi/edit.rb +20 -0
- data/lib/Wiki2Go/cgi/redirect.rb +20 -0
- data/lib/Wiki2Go/cgi/save.rb +20 -0
- data/lib/Wiki2Go/cgi/search.rb +20 -0
- data/lib/Wiki2Go/cgi/secure/admin.rb +20 -0
- data/lib/Wiki2Go/cgi/secure/generate_static.rb +20 -0
- data/lib/Wiki2Go/cgi/secure/removespam.rb +20 -0
- data/lib/Wiki2Go/cgi/upload.rb +20 -0
- data/lib/Wiki2Go/cgi/versions.rb +20 -0
- data/lib/Wiki2Go/cgi/view.rb +20 -0
- metadata +113 -0
@@ -0,0 +1,274 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "Wiki2Go/WikiFormatter"
|
4
|
+
|
5
|
+
require 'Web2Go/ERB_Interpreter'
|
6
|
+
|
7
|
+
module Wiki2Go
|
8
|
+
|
9
|
+
class Wiki
|
10
|
+
def initialize(config)
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def view(web)
|
15
|
+
html = @config.redirect_to_html?(web)
|
16
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
17
|
+
|
18
|
+
text = @config.storage.load_page(web.name,web.current_page)
|
19
|
+
template = @config.storage.load_template(web.name,"view.htm")
|
20
|
+
|
21
|
+
return formatter.format_page_in_template(template,text)
|
22
|
+
end
|
23
|
+
|
24
|
+
def versions(web)
|
25
|
+
html = @config.redirect_to_html?(web)
|
26
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
27
|
+
|
28
|
+
topics = @config.storage.all_versions_of(web.name,web.current_page)
|
29
|
+
template = @config.storage.load_template(web.name,"versionlist.htm")
|
30
|
+
|
31
|
+
return formatter.format_pagelist_in_template(template,topics,"","Versions of '#{web.current_page}'")
|
32
|
+
end
|
33
|
+
|
34
|
+
def view_dynamic(web)
|
35
|
+
html = false
|
36
|
+
editable = @config.editable?(web)
|
37
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,editable)
|
38
|
+
|
39
|
+
text = @config.storage.load_page(web.name,web.current_page)
|
40
|
+
template = @config.storage.load_template(web.name,"view.htm")
|
41
|
+
|
42
|
+
return formatter.format_page_in_template(template,text)
|
43
|
+
end
|
44
|
+
|
45
|
+
def view_html(web)
|
46
|
+
html = true
|
47
|
+
editable = @config.editable?(web)
|
48
|
+
web = @config.static_web(web)
|
49
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,editable)
|
50
|
+
|
51
|
+
text = @config.storage.load_page(web.name,web.current_page)
|
52
|
+
template = @config.storage.load_template(web.name,"view.htm")
|
53
|
+
|
54
|
+
return formatter.format_page_in_template(template,text)
|
55
|
+
end
|
56
|
+
|
57
|
+
def generate_rss(web,changes)
|
58
|
+
html = @config.generate_html
|
59
|
+
editable = false
|
60
|
+
web = @config.static_web(web)
|
61
|
+
template = @config.storage.load_template(web.name,"rss.xml")
|
62
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,editable)
|
63
|
+
rss = formatter.generate_rss(template,changes)
|
64
|
+
return rss
|
65
|
+
end
|
66
|
+
|
67
|
+
def edit(web)
|
68
|
+
html = @config.redirect_to_html?(web)
|
69
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
70
|
+
|
71
|
+
text = @config.storage.load_page(web.name,web.current_page)
|
72
|
+
template = @config.storage.load_template(web.name,"edit.htm")
|
73
|
+
|
74
|
+
return formatter.put_page_in_template(template,text)
|
75
|
+
end
|
76
|
+
|
77
|
+
def save(web,new_content)
|
78
|
+
new_content = new_content.join('\r\n') if new_content.kind_of? Array
|
79
|
+
new_content.gsub!(/\t/,' ')
|
80
|
+
|
81
|
+
name ||= web.current_page
|
82
|
+
changed = true
|
83
|
+
newfile = !@config.storage.exists(web.path)
|
84
|
+
if !newfile then
|
85
|
+
current = @config.storage.load_page(web.name,web.current_page)
|
86
|
+
changed = (current.content != new_content) || name != current.name
|
87
|
+
end
|
88
|
+
|
89
|
+
if changed then
|
90
|
+
if @config.accept_page?(web,new_content) then
|
91
|
+
@config.save(web,new_content)
|
92
|
+
changes = @config.storage.read_changes_in(web.name,20,true)
|
93
|
+
save_rss(web,changes)
|
94
|
+
if @config.generate_html then
|
95
|
+
if newfile then
|
96
|
+
generate_html_for_page(web,web.current_page)
|
97
|
+
else
|
98
|
+
save_html(web)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
else
|
102
|
+
@config.storage.save_spam(web.name,web.current_page,new_content,web.user)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
html = @config.redirect_to_html?(web)
|
106
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
107
|
+
return formatter.absolute_url
|
108
|
+
end
|
109
|
+
|
110
|
+
def upload(web,name,content)
|
111
|
+
if name.empty? || content.nil? then
|
112
|
+
view(web)
|
113
|
+
else
|
114
|
+
@config.storage.store_web_file(web.name,name,content)
|
115
|
+
page = @config.storage.load_page(web.name,web.current_page)
|
116
|
+
text = page.content
|
117
|
+
text += "\n---\n{#{name}}"
|
118
|
+
save(web,text)
|
119
|
+
view(web)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def changes(web)
|
124
|
+
html = @config.redirect_to_html?(web)
|
125
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
126
|
+
|
127
|
+
topics = @config.storage.read_changes_in(web.name,20,false)
|
128
|
+
template = @config.storage.load_template(web.name,"pagelist.htm")
|
129
|
+
|
130
|
+
return formatter.format_pagelist_in_template(template,topics,"","Recent Changes")
|
131
|
+
end
|
132
|
+
|
133
|
+
def search(web,searchtopic)
|
134
|
+
searchtopic ||= ''
|
135
|
+
html = @config.redirect_to_html?(web)
|
136
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
137
|
+
|
138
|
+
topics = @config.storage.search(web.name,searchtopic)
|
139
|
+
template = @config.storage.load_template(web.name,"pagelist.htm")
|
140
|
+
|
141
|
+
return formatter.format_pagelist_in_template(template,topics,searchtopic,"Search for '#{searchtopic}'")
|
142
|
+
end
|
143
|
+
|
144
|
+
def remove_spam(web)
|
145
|
+
any_changes = false
|
146
|
+
files = @config.storage.all_pages_in(web.name)
|
147
|
+
blacklist = @config.storage.load_blacklist
|
148
|
+
files.each do |topic|
|
149
|
+
page = @config.storage.load_page(web.name,topic)
|
150
|
+
if blacklist.contains(page.author) then
|
151
|
+
restore_last_good_version(web,topic,blacklist)
|
152
|
+
any_changes = true
|
153
|
+
end
|
154
|
+
end
|
155
|
+
if any_changes then
|
156
|
+
changes = @config.storage.read_changes_in(web.name,20,true)
|
157
|
+
save_rss(web,changes)
|
158
|
+
end
|
159
|
+
return changes(web)
|
160
|
+
end
|
161
|
+
|
162
|
+
def blacklist(user)
|
163
|
+
@config.log("Adding #{user} to blacklist")
|
164
|
+
list = @config.storage.load_blacklist
|
165
|
+
list.add(user)
|
166
|
+
@config.storage.save_list(list)
|
167
|
+
end
|
168
|
+
|
169
|
+
def log(msg)
|
170
|
+
@config.log(msg)
|
171
|
+
end
|
172
|
+
|
173
|
+
def generate_html(web)
|
174
|
+
report = ["Generating HTML\r\n" , "<ul>"]
|
175
|
+
files = @config.storage.all_pages_in(web.name)
|
176
|
+
files.each do |file|
|
177
|
+
@config.log("Generating file #{file}")
|
178
|
+
report << "<li>#{file}</li>\r\n"
|
179
|
+
pageweb = Wiki2Go::Web.new(web.server,web.port,web.script_prefix,"view",web.name,file)
|
180
|
+
save_html(pageweb)
|
181
|
+
end
|
182
|
+
changes = @config.storage.read_changes_in(web.name,20,true)
|
183
|
+
save_rss(web,changes)
|
184
|
+
report << "</ul>\r\n"
|
185
|
+
return report
|
186
|
+
end
|
187
|
+
|
188
|
+
def admin(request)
|
189
|
+
|
190
|
+
wikiweb = Wiki2Go::Web.from_request(request,false)
|
191
|
+
|
192
|
+
template_name = wikiweb.current_page
|
193
|
+
if template_name.nil? || template_name.empty?
|
194
|
+
template_name = 'admin'
|
195
|
+
end
|
196
|
+
master = @config.storage.load_template(wikiweb.name,'admin.htm')
|
197
|
+
template = @config.storage.load_template(wikiweb.name,File.join('admin_pages',template_name+'.txt'))
|
198
|
+
|
199
|
+
master = master.gsub(/\$BODY\$/,template)
|
200
|
+
|
201
|
+
erb = Web2Go::ERB_Interpreter.new
|
202
|
+
erb.add_field(:@request,request)
|
203
|
+
erb.add_field(:@config,@config)
|
204
|
+
erb.add_field(:@web,wikiweb)
|
205
|
+
result = erb.execute master
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
private
|
210
|
+
|
211
|
+
def save_rss(web,changes)
|
212
|
+
rss = generate_rss(web,changes)
|
213
|
+
@config.storage.store_web_file(web.name,"rss.xml",rss)
|
214
|
+
end
|
215
|
+
|
216
|
+
def save_html(web)
|
217
|
+
if @config.generate_html then
|
218
|
+
static_web = @config.static_web(web)
|
219
|
+
@config.storage.save_html(static_web.name,static_web.current_page, view_html(static_web))
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# Optimized method of regenerating only the HTML of pages that are affected by a new page
|
224
|
+
# Search for all pages containing the title of the new page and render those + the new page
|
225
|
+
def generate_html_for_page(web,pagename)
|
226
|
+
files = @config.storage.search(web.name,pagename)
|
227
|
+
files << @config.storage.load_page(web.name,pagename)
|
228
|
+
files.each do |file|
|
229
|
+
@config.log("Generating HTML for #{file.title}")
|
230
|
+
pageweb = Wiki2Go::Web.new(web.server,web.port,web.script_prefix,"view",web.name,file.title)
|
231
|
+
static_web = @config.static_web(pageweb)
|
232
|
+
@config.storage.save_html(static_web.name,static_web.current_page, view_html_of_page(static_web,file))
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def view_html_of_page(web,text)
|
237
|
+
html = true
|
238
|
+
editable = @config.editable?(web)
|
239
|
+
web = @config.static_web(web)
|
240
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,editable)
|
241
|
+
|
242
|
+
template = @config.storage.load_template(web.name,"view.htm")
|
243
|
+
|
244
|
+
return formatter.format_page_in_template(template,text)
|
245
|
+
end
|
246
|
+
|
247
|
+
def view_text(web,text)
|
248
|
+
html = @config.generate_html && !web.secure
|
249
|
+
formatter = Wiki2Go::Formatter.new(web,@config.storage,@config,html,@config.editable?(web))
|
250
|
+
|
251
|
+
template = @config.storage.load_template(web.name,"view.htm")
|
252
|
+
|
253
|
+
page = Wiki2Go::Page.new("Report",text,"system",Time.now,"Report")
|
254
|
+
return formatter.format_page_in_template(template,page)
|
255
|
+
end
|
256
|
+
|
257
|
+
def restore_last_good_version(web,topic,blacklist)
|
258
|
+
versions = @config.storage.all_versions_of(web.name,topic)
|
259
|
+
first_good_version = versions.find do |v|
|
260
|
+
not blacklist.contains(v.author)
|
261
|
+
end
|
262
|
+
if first_good_version.nil? then
|
263
|
+
@config.errorlog("NO GOOD VERSION FOUND. Delete #{topic}!")
|
264
|
+
elsif first_good_version.equal?(versions[0]) then
|
265
|
+
else
|
266
|
+
@config.errorlog("#{topic} must be replaced by version by #{first_good_version.author}")
|
267
|
+
@config.storage.store_page(web.name,first_good_version)
|
268
|
+
thispage = web.dup
|
269
|
+
thispage.current_page = topic
|
270
|
+
save_html(thispage)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
|
4
|
+
require "Wiki2Go/FileStorage.rb"
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
module Wiki2Go
|
8
|
+
class Config
|
9
|
+
|
10
|
+
attr_accessor :server
|
11
|
+
attr_accessor :port
|
12
|
+
attr_accessor :default_web
|
13
|
+
attr_accessor :default_page
|
14
|
+
|
15
|
+
attr_accessor :root_directory
|
16
|
+
attr_accessor :site_directory
|
17
|
+
|
18
|
+
attr_accessor :generate_html
|
19
|
+
attr_accessor :debug
|
20
|
+
attr_accessor :multi_wiki
|
21
|
+
attr_accessor :site_admin
|
22
|
+
|
23
|
+
def initialize(directory=nil)
|
24
|
+
directory ||= Dir.getwd
|
25
|
+
|
26
|
+
@root_directory = directory
|
27
|
+
@site_directory = File.join(directory,'site')
|
28
|
+
|
29
|
+
@server = 'localhost'
|
30
|
+
@port = 8081
|
31
|
+
@default_web = 'Wiki2go'
|
32
|
+
@default_page = 'FrontPage'
|
33
|
+
@generate_html = true
|
34
|
+
@storage = nil
|
35
|
+
@processors = { }
|
36
|
+
@debug = false
|
37
|
+
@multi_wiki = true
|
38
|
+
@site_admin = 'wiki2go@nayima.be'
|
39
|
+
end
|
40
|
+
|
41
|
+
def storage
|
42
|
+
@storage ||= make_storage
|
43
|
+
@storage
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_storage
|
47
|
+
return Wiki2Go::FileStorage.new(@root_directory,@site_directory)
|
48
|
+
end
|
49
|
+
|
50
|
+
def log(msg)
|
51
|
+
Config.log(logfile,msg) if @debug
|
52
|
+
end
|
53
|
+
|
54
|
+
def errorlog(msg)
|
55
|
+
Config.log(logfile,msg)
|
56
|
+
end
|
57
|
+
|
58
|
+
def Config.log(logfile,msg)
|
59
|
+
dir = File.dirname(logfile)
|
60
|
+
FileUtils::mkdir_p(dir, { :mode => 0775 }) unless File.exists?(dir)
|
61
|
+
File.open(logfile ,File::APPEND | File::CREAT | File::WRONLY) do |f|
|
62
|
+
f.puts msg
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def logfile
|
67
|
+
File.join( @root_directory,'wiki.log')
|
68
|
+
end
|
69
|
+
|
70
|
+
def default_wiki
|
71
|
+
return Wiki2Go::Web.new(@server,@port.to_s,"","view",(@multi_wiki ? @default_web : ''),@default_page)
|
72
|
+
end
|
73
|
+
|
74
|
+
def editable?(web)
|
75
|
+
true
|
76
|
+
end
|
77
|
+
|
78
|
+
def redirect_url?(web,url)
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
82
|
+
def static_web(web)
|
83
|
+
server = web.server.gsub(/^edit\./,"www.")
|
84
|
+
script_prefix = web.script_prefix.gsub(/\/secure/,"")
|
85
|
+
return Wiki2Go::Web.new(server,web.port,script_prefix,web.verb,web.name,web.current_page)
|
86
|
+
end
|
87
|
+
|
88
|
+
def accept_page?(web,content)
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
def redirect_to_html?(web)
|
93
|
+
@generate_html && !web.secure
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_processor(type,proc)
|
97
|
+
@processors[type] = proc
|
98
|
+
end
|
99
|
+
|
100
|
+
def preprocess(web,content)
|
101
|
+
if content =~ /^<!--([^:]+):(.*)-->$/m then
|
102
|
+
type = $1
|
103
|
+
value = $2
|
104
|
+
processor = @processors[type]
|
105
|
+
if !processor.nil? then
|
106
|
+
content += processor.process(self,web,value)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
content
|
110
|
+
end
|
111
|
+
|
112
|
+
def save(web,new_content)
|
113
|
+
process_comment(web,new_content)
|
114
|
+
|
115
|
+
page = Page.new(web.current_page,new_content,web.user,Time.now,web.title,web.alias)
|
116
|
+
|
117
|
+
storage.save_page(web.name,page)
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def process_comment(web,content)
|
123
|
+
if content =~ /^(.*)(<!--(.*)-->)(.*)$/m then
|
124
|
+
before,match,after = $1,$3,$4
|
125
|
+
process_comment(web,before)
|
126
|
+
log("Matched #{match}")
|
127
|
+
if match =~ /^([^:]+):(.*)$/m then
|
128
|
+
type = $1
|
129
|
+
value = $2
|
130
|
+
log( "type = #{type} value= #{value}")
|
131
|
+
processor = @processors[type]
|
132
|
+
if !processor.nil? then
|
133
|
+
processor.save(self,web,value)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
process_comment(web,after)
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'Wiki2Go/Web'
|
4
|
+
require 'Wiki2Go/Wiki2Go'
|
5
|
+
|
6
|
+
require 'webrick/httpstatus'
|
7
|
+
|
8
|
+
module Wiki2Go
|
9
|
+
class Servlet
|
10
|
+
|
11
|
+
USER_COOKIE = 'Wiki2Go_user'
|
12
|
+
|
13
|
+
def initialize(config)
|
14
|
+
@config = config
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(request,response)
|
18
|
+
@config.log("Request cookies = #{request.cookies}")
|
19
|
+
response.add_cookies(request.cookies)
|
20
|
+
result = execute_command(request,response)
|
21
|
+
@config.log("Response cookies = #{response.cookies}")
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def perform_view(req,res,wikiweb)
|
26
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
27
|
+
|
28
|
+
res.content_type = 'text/html'
|
29
|
+
res.body = wiki.view(wikiweb)
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def perform_save(req,res,wikiweb)
|
34
|
+
|
35
|
+
content = req.parameter('text')
|
36
|
+
name = req.parameter('title',wikiweb.current_page)
|
37
|
+
author = req.parameter('author')
|
38
|
+
remember_me = req.parameter('remember_me')
|
39
|
+
@config.log("Author = #{author}, remember = #{remember_me}")
|
40
|
+
|
41
|
+
|
42
|
+
if !author.nil? && author.length > 0 then # !wikiweb.secure &&
|
43
|
+
wikiweb.alias = author
|
44
|
+
timeout = Time.now + 7 * 24 * 3600
|
45
|
+
res.add_cookie(USER_COOKIE,author,nil,nil,timeout) unless remember_me.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
49
|
+
|
50
|
+
wikiweb.title = name
|
51
|
+
|
52
|
+
redirect_to = wiki.save(wikiweb,content)
|
53
|
+
res.redirect_to = redirect_to
|
54
|
+
res.content_type = "text/html"
|
55
|
+
res.body = "Redirect to #{redirect_to}"
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def perform_changes(req,res,wikiweb)
|
60
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
61
|
+
|
62
|
+
res.content_type = "text/html"
|
63
|
+
res.body = wiki.changes(wikiweb)
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
def perform_search(req,res,wikiweb)
|
68
|
+
topic = req.parameter('text')
|
69
|
+
|
70
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
71
|
+
|
72
|
+
res.content_type = "text/html"
|
73
|
+
res.body = wiki.search(wikiweb,topic)
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
def perform_versions(req,res,wikiweb)
|
78
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
79
|
+
|
80
|
+
res.content_type = "text/html"
|
81
|
+
res.body = wiki.versions(wikiweb)
|
82
|
+
true
|
83
|
+
end
|
84
|
+
|
85
|
+
def perform_edit(req,res,wikiweb)
|
86
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
87
|
+
|
88
|
+
res.content_type = "text/html"
|
89
|
+
res.body = wiki.edit(wikiweb)
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
def perform_redirect(req,res,wikiweb)
|
94
|
+
redirect_to = req.parameter('url')
|
95
|
+
|
96
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
97
|
+
|
98
|
+
res.redirect_to = redirect_to
|
99
|
+
res.content_type = "text/html"
|
100
|
+
res.body = "Redirect to #{redirect_to}"
|
101
|
+
true
|
102
|
+
end
|
103
|
+
|
104
|
+
def perform_admin(req,res,wikiweb)
|
105
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
106
|
+
result = wiki.admin(req)
|
107
|
+
|
108
|
+
res.content_type = "text/html"
|
109
|
+
res.body = result
|
110
|
+
true
|
111
|
+
end
|
112
|
+
|
113
|
+
def perform_removespam(req,res,wikiweb)
|
114
|
+
|
115
|
+
user = req.parameter('user')
|
116
|
+
|
117
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
118
|
+
|
119
|
+
if !user.nil? && !user.empty? then
|
120
|
+
wiki.blacklist(user)
|
121
|
+
end
|
122
|
+
|
123
|
+
res.content_type = "text/html"
|
124
|
+
res.body = wiki.remove_spam(wikiweb)
|
125
|
+
true
|
126
|
+
end
|
127
|
+
|
128
|
+
def perform_generate_static(req,res,wikiweb)
|
129
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
130
|
+
|
131
|
+
res.content_type = "text/html"
|
132
|
+
res.body = wiki.generate_html(wikiweb)
|
133
|
+
true
|
134
|
+
end
|
135
|
+
|
136
|
+
def perform_upload(req,res,wikiweb)
|
137
|
+
|
138
|
+
uploaded_file = req.uploaded_file('FILE')
|
139
|
+
wiki = Wiki2Go::Wiki.new(@config)
|
140
|
+
|
141
|
+
res.content_type = "text/html"
|
142
|
+
res.body = wiki.upload(wikiweb,uploaded_file.filename,uploaded_file.content)
|
143
|
+
true
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
def execute_command(req,res)
|
149
|
+
wikiweb = Wiki2Go::Web.from_request(req,@config.multi_wiki)
|
150
|
+
@config.log("WIKI Web = #{wikiweb.inspect}")
|
151
|
+
command = wikiweb.verb
|
152
|
+
if command =~ /^([^\.]+)\./ then
|
153
|
+
command = $1
|
154
|
+
end
|
155
|
+
if (command == "" || command.nil?) && (req.path == "" || req.path == "/") then
|
156
|
+
wikiweb = @config.default_wiki
|
157
|
+
perform('perform_view',req,res,wikiweb)
|
158
|
+
return true
|
159
|
+
else
|
160
|
+
method = 'perform_' + command
|
161
|
+
if self.methods.include?(method) || self.private_methods.include?(method) then
|
162
|
+
return perform(method,req,res,wikiweb)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
return false
|
166
|
+
end
|
167
|
+
|
168
|
+
def perform(method,req,res,wikiweb)
|
169
|
+
begin
|
170
|
+
@config.log("==> Cookies for #{method}: #{req.cookies.inspect}")
|
171
|
+
cookie = req.cookie(USER_COOKIE)
|
172
|
+
@config.log("User Cookie = #{cookie.inspect}") unless cookie.nil?
|
173
|
+
|
174
|
+
author = cookie.value unless cookie.nil?
|
175
|
+
|
176
|
+
if !author.nil? && author.length > 0 then # !wikiweb.secure &&
|
177
|
+
wikiweb.alias = author
|
178
|
+
end
|
179
|
+
|
180
|
+
result = self.send(method,req,res,wikiweb)
|
181
|
+
@config.log("<== Cookies for #{method}: #{res.cookies.inspect}")
|
182
|
+
return result
|
183
|
+
rescue WEBrick::HTTPStatus::Redirect => redirect then
|
184
|
+
raise redirect
|
185
|
+
rescue Exception => e then
|
186
|
+
@config.errorlog("Caught exception in #{method}: #{e.inspect}")
|
187
|
+
@config.errorlog("Stack: #{$@}")
|
188
|
+
redirect_url = "#{wikiweb.base_url}error.html"
|
189
|
+
|
190
|
+
res.redirect_to = redirect_url
|
191
|
+
res.body = "redirect to view <a href=\"#{redirect_url}\">view</a><br>"
|
192
|
+
end
|
193
|
+
return false
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
end
|