2007-01-22 14:43:50 +01:00
|
|
|
class AdminController < ApplicationController
|
|
|
|
|
|
|
|
layout 'default'
|
|
|
|
cache_sweeper :web_sweeper
|
2008-12-16 07:40:30 +01:00
|
|
|
before_filter :dnsbl_check
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
def create_system
|
|
|
|
if @wiki.setup?
|
|
|
|
flash[:error] =
|
|
|
|
"Wiki has already been created in '#{@wiki.storage_path}'. " +
|
|
|
|
"Shut down Instiki and delete this directory if you want to recreate it from scratch." +
|
|
|
|
"\n\n" +
|
|
|
|
"(WARNING: this will destroy content of your current wiki)."
|
|
|
|
redirect_home(@wiki.webs.keys.first)
|
2007-05-11 18:47:38 +02:00
|
|
|
elsif params['web_name']
|
2007-01-22 14:43:50 +01:00
|
|
|
# form submitted -> create a wiki
|
2007-05-11 18:47:38 +02:00
|
|
|
@wiki.setup(params['password'], params['web_name'], params['web_address'])
|
|
|
|
flash[:info] = "Your new wiki '#{params['web_name']}' is created!\n" +
|
2007-01-22 14:43:50 +01:00
|
|
|
"Please edit its home page and press Submit when finished."
|
2007-05-11 18:47:38 +02:00
|
|
|
redirect_to :web => params['web_address'], :controller => 'wiki', :action => 'new',
|
2007-01-22 14:43:50 +01:00
|
|
|
:id => 'HomePage'
|
|
|
|
else
|
|
|
|
# no form submitted -> go to template
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_web
|
2007-05-11 18:47:38 +02:00
|
|
|
if params['address']
|
2008-12-15 06:29:40 +01:00
|
|
|
return unless is_post
|
2007-01-22 14:43:50 +01:00
|
|
|
# form submitted
|
2007-05-11 18:47:38 +02:00
|
|
|
if @wiki.authenticate(params['system_password'])
|
2007-01-22 14:43:50 +01:00
|
|
|
begin
|
2007-05-11 18:47:38 +02:00
|
|
|
@wiki.create_web(params['name'], params['address'])
|
|
|
|
flash[:info] = "New web '#{params['name']}' successfully created."
|
|
|
|
redirect_to :web => params['address'], :controller => 'wiki', :action => 'new',
|
2007-01-22 14:43:50 +01:00
|
|
|
:id => 'HomePage'
|
|
|
|
rescue Instiki::ValidationError => e
|
|
|
|
@error = e.message
|
|
|
|
# and re-render the form again
|
|
|
|
end
|
2008-12-21 22:41:35 +01:00
|
|
|
else
|
|
|
|
flash[:error] = "System Password incorrect. Try again."
|
|
|
|
redirect_to :controller => 'admin', :action => 'create_web'
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
# no form submitted -> render template
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit_web
|
2007-05-11 18:47:38 +02:00
|
|
|
system_password = params['system_password']
|
2007-01-22 14:43:50 +01:00
|
|
|
if system_password
|
2008-12-15 06:29:40 +01:00
|
|
|
return unless is_post
|
2007-01-22 14:43:50 +01:00
|
|
|
# form submitted
|
|
|
|
if wiki.authenticate(system_password)
|
|
|
|
begin
|
2008-12-21 00:54:54 +01:00
|
|
|
raise Instiki::ValidationError.new("Password for this Web didn't match") unless
|
|
|
|
(params['password'].empty? or params['password'] == params['password_check'])
|
2007-01-22 14:43:50 +01:00
|
|
|
wiki.edit_web(
|
2007-05-11 18:47:38 +02:00
|
|
|
@web.address, params['address'], params['name'],
|
|
|
|
params['markup'].intern,
|
|
|
|
params['color'], params['additional_style'],
|
|
|
|
params['safe_mode'] ? true : false,
|
|
|
|
params['password'].empty? ? nil : params['password'],
|
|
|
|
params['published'] ? true : false,
|
|
|
|
params['brackets_only'] ? true : false,
|
|
|
|
params['count_pages'] ? true : false,
|
|
|
|
params['allow_uploads'] ? true : false,
|
|
|
|
params['max_upload_size']
|
2007-01-22 14:43:50 +01:00
|
|
|
)
|
2007-05-11 18:47:38 +02:00
|
|
|
flash[:info] = "Web '#{params['address']}' was successfully updated"
|
|
|
|
redirect_home(params['address'])
|
2007-01-22 14:43:50 +01:00
|
|
|
rescue Instiki::ValidationError => e
|
|
|
|
logger.warn e.message
|
|
|
|
@error = e.message
|
|
|
|
# and re-render the same template again
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@error = password_error(system_password)
|
|
|
|
# and re-render the same template again
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# no form submitted - go to template
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_orphaned_pages
|
2008-12-15 06:29:40 +01:00
|
|
|
return unless is_post
|
2007-05-11 18:47:38 +02:00
|
|
|
if wiki.authenticate(params['system_password_orphaned'])
|
2007-01-22 14:43:50 +01:00
|
|
|
wiki.remove_orphaned_pages(@web_name)
|
|
|
|
flash[:info] = 'Orphaned pages removed'
|
|
|
|
redirect_to :controller => 'wiki', :web => @web_name, :action => 'list'
|
|
|
|
else
|
2007-05-11 18:47:38 +02:00
|
|
|
flash[:error] = password_error(params['system_password_orphaned'])
|
2007-01-22 14:43:50 +01:00
|
|
|
redirect_to :controller => 'admin', :web => @web_name, :action => 'edit_web'
|
|
|
|
end
|
|
|
|
end
|
2008-12-06 13:06:46 +01:00
|
|
|
|
2008-12-06 23:11:47 +01:00
|
|
|
def remove_orphaned_pages_in_category
|
2008-12-15 06:29:40 +01:00
|
|
|
return unless is_post
|
2008-12-06 23:11:47 +01:00
|
|
|
if wiki.authenticate(params['system_password_orphaned_in_category'])
|
|
|
|
category = params['category']
|
|
|
|
wiki.remove_orphaned_pages_in_category(@web_name, category)
|
|
|
|
flash[:info] = "Orphaned pages in category \"#{category}\" removed"
|
|
|
|
redirect_to :controller => 'wiki', :web => @web_name, :action => 'list'
|
|
|
|
else
|
|
|
|
flash[:error] = password_error(params['system_password_orphaned_in_category'])
|
|
|
|
redirect_to :controller => 'admin', :web => @web_name, :action => 'edit_web'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-12-06 13:06:46 +01:00
|
|
|
def delete_web
|
2008-12-15 06:29:40 +01:00
|
|
|
return unless is_post
|
2008-12-06 13:06:46 +01:00
|
|
|
if wiki.authenticate(params['system_password_delete_web'])
|
|
|
|
wiki.delete_web(@web_name)
|
|
|
|
flash[:info] = "Web \"#{@web_name}\" has been deleted."
|
|
|
|
redirect_to :controller => 'wiki', :action => 'web_list'
|
|
|
|
else
|
|
|
|
flash[:error] = password_error(params['system_password_delete_web'])
|
|
|
|
redirect_to :controller => 'admin', :web => @web_name, :action => 'edit_web'
|
|
|
|
end
|
|
|
|
end
|
2008-12-31 10:54:23 +01:00
|
|
|
|
|
|
|
def delete_files
|
|
|
|
return unless is_post
|
|
|
|
some_deleted = false
|
|
|
|
if wiki.authenticate(params['system_password'])
|
|
|
|
params.each do |file, p|
|
|
|
|
if p == 'delete'
|
|
|
|
WikiFile.find_by_file_name(file).destroy
|
|
|
|
some_deleted = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
flash[:info] = "File(s) successfully deleted." if some_deleted
|
|
|
|
else
|
|
|
|
flash[:error] = password_error(params['system_password'])
|
2008-12-31 18:30:33 +01:00
|
|
|
end
|
|
|
|
redirect_to :back
|
2008-12-31 10:54:23 +01:00
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
|
2008-12-15 06:29:40 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def is_post
|
2010-05-26 21:16:34 +02:00
|
|
|
unless (request.post? || Rails.env.test?)
|
2008-12-15 06:29:40 +01:00
|
|
|
headers['Allow'] = 'POST'
|
|
|
|
render(:status => 405, :text => 'You must use an HTTP POST', :layout => 'error')
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|