diff options
22 files changed, 373 insertions, 22 deletions
diff --git a/app/controllers/restore_jobs_controller.rb b/app/controllers/restore_jobs_controller.rb new file mode 100644 index 0000000..bfecc33 --- /dev/null +++ b/app/controllers/restore_jobs_controller.rb @@ -0,0 +1,25 @@ +class RestoreJobsController < ApplicationController + skip_before_filter :start_setup_if_new_installation, :only => [:new, :create, :show, :index] + + load_and_authorize_resource :restore_job + + def index + end + + def show + end + + def new + end + + def create + @restore_job.state = 'new' + + if @restore_job.save + session[:user_id] = nil + redirect_to @restore_job, :notice => t('restore_jobs.controller.successfuly_created') + else + render :new + end + end +end diff --git a/app/helpers/restore_jobs_helper.rb b/app/helpers/restore_jobs_helper.rb new file mode 100644 index 0000000..9a5d120 --- /dev/null +++ b/app/helpers/restore_jobs_helper.rb @@ -0,0 +1,2 @@ +module RestoreJobsHelper +end diff --git a/app/models/ability.rb b/app/models/ability.rb index d886d53..690ee76 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -176,6 +176,7 @@ class Ability # can :create, GemeinschaftSetup can :manage, SipDomain + can [:create, :new, :show, :index], RestoreJob end end diff --git a/app/models/restore_job.rb b/app/models/restore_job.rb new file mode 100644 index 0000000..2c2da54 --- /dev/null +++ b/app/models/restore_job.rb @@ -0,0 +1,13 @@ +class RestoreJob < ActiveRecord::Base + attr_accessible :state, :backup_file + + mount_uploader :backup_file, BackupFileUploader + + def to_s + if self.backup_file? + File.basename(self.backup_file.to_s) + else + "RestoreJob ID #{self.id}" + end + end +end diff --git a/app/uploaders/backup_file_uploader.rb b/app/uploaders/backup_file_uploader.rb index 8b126a9..0244ba5 100644 --- a/app/uploaders/backup_file_uploader.rb +++ b/app/uploaders/backup_file_uploader.rb @@ -42,9 +42,9 @@ class BackupFileUploader < CarrierWave::Uploader::Base # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: - # def extension_white_list - # %w(jpg jpeg gif png) - # end + def extension_white_list + %w(tar.gz) + end # Override the filename of the uploaded files: # Avoid using model.id or version_name here, see uploader/store.rb for details. diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml index 6fcb1dc..ddc4766 100644 --- a/app/views/backup_jobs/show.html.haml +++ b/app/views/backup_jobs/show.html.haml @@ -1,22 +1,34 @@ - content_for :title, t("backup_jobs.show.page_title") -%p - %strong= t('backup_jobs.show.started_at') + ":" - = @backup_job.started_at -%p - %strong= t('backup_jobs.show.finished_at') + ":" - = @backup_job.finished_at -%p - %strong= t('backup_jobs.show.state') + ":" - = @backup_job.state -%p - %strong= t('backup_jobs.show.directory') + ":" - = @backup_job.directory -%p - %strong= t('backup_jobs.show.size_of_the_backup') + ":" - - if @backup_job.backup_file? - %a{:href => backup_job.backup_file.url} - %i{:class => 'icon-download'} - = number_to_human_size(backup_job.backup_file.size, :precision => 2) +%table.table.table-striped + %tbody + %tr + %td + %strong= t('backup_jobs.show.started_at') + ":" + %td + = @backup_job.started_at + %tr + %td + %strong= t('backup_jobs.show.finished_at') + ":" + %td + = @backup_job.finished_at + %tr + %td + %strong= t('backup_jobs.show.state') + ":" + %td + = @backup_job.state + %tr + %td + %strong= t('backup_jobs.show.directory') + ":" + %td + = @backup_job.directory + %tr + %td + %strong= t('backup_jobs.show.size_of_the_backup') + ":" + %td + - if @backup_job.backup_file? + %a{:href => backup_job.backup_file.url} + %i{:class => 'icon-download'} + = number_to_human_size(backup_job.backup_file.size, :precision => 2) = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @backup_job }
\ No newline at end of file diff --git a/app/views/restore_jobs/_form.html.haml b/app/views/restore_jobs/_form.html.haml new file mode 100644 index 0000000..43ced9a --- /dev/null +++ b/app/views/restore_jobs/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for(@restore_job) do |f| + = f.error_notification + + = render "form_core", :f => f + + .form-actions + = f.button :submit, conditional_t('restore_jobs.form.submit') diff --git a/app/views/restore_jobs/_form_core.html.haml b/app/views/restore_jobs/_form_core.html.haml new file mode 100644 index 0000000..017c124 --- /dev/null +++ b/app/views/restore_jobs/_form_core.html.haml @@ -0,0 +1,2 @@ +.inputs + = f.input :backup_file, :label => t('restore_jobs.form.backup_file.label'), :hint => conditional_hint('restore_jobs.form.backup_file.hint') diff --git a/app/views/restore_jobs/_index_core.html.haml b/app/views/restore_jobs/_index_core.html.haml new file mode 100644 index 0000000..f6127ba --- /dev/null +++ b/app/views/restore_jobs/_index_core.html.haml @@ -0,0 +1,12 @@ +%table.table.table-striped + %tr + %th= t('restore_jobs.index.state') + %th= t('restore_jobs.index.backup_file') + %th + + + - for restore_job in restore_jobs + %tr + %td= restore_job.state + %td= restore_job.to_s + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => restore_job}
\ No newline at end of file diff --git a/app/views/restore_jobs/index.html.haml b/app/views/restore_jobs/index.html.haml new file mode 100644 index 0000000..b8aa74e --- /dev/null +++ b/app/views/restore_jobs/index.html.haml @@ -0,0 +1,6 @@ +- content_for :title, t("restore_jobs.index.page_title") + +- if @restore_jobs && @restore_jobs.count > 0 + = render "index_core", :restore_jobs => @restore_jobs + += render :partial => 'shared/create_link', :locals => {:child_class => RestoreJob}
\ No newline at end of file diff --git a/app/views/restore_jobs/new.html.haml b/app/views/restore_jobs/new.html.haml new file mode 100644 index 0000000..ffae792 --- /dev/null +++ b/app/views/restore_jobs/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("restore_jobs.new.page_title") + += render "form"
\ No newline at end of file diff --git a/app/views/restore_jobs/show.html.haml b/app/views/restore_jobs/show.html.haml new file mode 100644 index 0000000..5993872 --- /dev/null +++ b/app/views/restore_jobs/show.html.haml @@ -0,0 +1,22 @@ +- content_for :title, t("restore_jobs.show.page_title") + +%table.table.table-striped + %tbody + %tr + %td + %strong= t('restore_jobs.show.state') + ":" + %td + = @restore_job.state + %tr + %td + %strong= t('restore_jobs.show.backup_file') + ":" + %td + = @restore_job.to_s + %tr + %td + %strong= t('backup_jobs.show.size_of_the_backup') + ":" + %td + - if @restore_job.backup_file? + = number_to_human_size(@restore_job.backup_file.size, :precision => 2) + += render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @restore_job }
\ No newline at end of file diff --git a/config/backup.rb b/config/backup.rb index aa8ade3..1c79c04 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -24,6 +24,7 @@ Backup::Model.new(:GS5, 'GS5 backup') do db.host = "localhost" db.port = 3306 db.socket = "/var/run/mysqld/mysqld.sock" + db.skip_tables = ["backup_jobs", "restore_jobs"] end ## diff --git a/config/locales/views/restore_jobs/de.yml b/config/locales/views/restore_jobs/de.yml new file mode 100644 index 0000000..18ee349 --- /dev/null +++ b/config/locales/views/restore_jobs/de.yml @@ -0,0 +1,45 @@ +de: + restore_jobs: + name: 'Restore Auftrag' + controller: + successfuly_created: 'Restore Auftrag wurde angelegt.' + successfuly_updated: 'Restore Auftrag wurde aktualisiert.' + successfuly_destroyed: 'Restore Auftrag wurde gelöscht.' + index: + page_title: 'Liste Restore Aufträge' + state: 'Status' + backup_file: 'Backup Datei' + actions: + confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Restore Auftrag' + destroy: 'Löschen' + edit: 'Bearbeiten' + show: 'Anzeigen' + create: 'Neu anlegen' + create_for: 'Restore Auftrag neu anlegen für %{resource}' + show: + page_title: 'Restore Auftrag bearbeiten' + state: 'Status' + backup_file: 'Backup Datei' + actions: + confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?' + destroy: 'Löschen' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + new: + page_title: 'Restore Auftrag neu anlegen' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: + page_title: 'Restore Auftrag bearbeiten' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + form: + state: + label: 'Status' + hint: '' + backup_file: + label: 'Backup Datei' + hint: '' + submit: 'Absenden'
\ No newline at end of file diff --git a/config/locales/views/restore_jobs/en.yml b/config/locales/views/restore_jobs/en.yml new file mode 100644 index 0000000..d75de95 --- /dev/null +++ b/config/locales/views/restore_jobs/en.yml @@ -0,0 +1,45 @@ +en: + restore_jobs: + name: 'Restorejob' + controller: + successfuly_created: 'Successfully created Restorejob.' + successfuly_updated: 'Successfully updated Restorejob.' + successfuly_destroyed: 'Successfully destroyed Restorejob.' + index: + page_title: 'Listing Restorejob' + state: 'State' + backup_file: 'Backup file' + actions: + confirm_destroy: 'Are you sure you want to delete this Restorejob?' + destroy: 'Delete' + edit: 'Edit' + show: 'View' + create: 'New' + create_for: 'New Restorejob for %{resource}' + show: + page_title: 'Show Restorejob' + state: 'State' + backup_file: 'Backup file' + actions: + confirm_destroy: 'Are you sure you want to delete this element?' + destroy: 'Delete' + edit: 'Edit' + view_all: 'View All' + new: + page_title: 'New Restorejob' + actions: + back_to_list: 'Back to Index' + edit: + page_title: 'Editing Restorejob' + actions: + back_to_list: 'Back to Index' + edit: 'Edit' + view_all: 'View All' + form: + state: + label: 'State' + hint: '' + backup_file: + label: 'Backup file' + hint: '' + submit: 'Submit'
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 16133d2..adff556 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Gemeinschaft42c::Application.routes.draw do + resources :restore_jobs + resources :groups do resources :group_memberships resources :group_permissions diff --git a/db/migrate/20130225160423_create_restore_jobs.rb b/db/migrate/20130225160423_create_restore_jobs.rb new file mode 100644 index 0000000..9f83791 --- /dev/null +++ b/db/migrate/20130225160423_create_restore_jobs.rb @@ -0,0 +1,13 @@ +class CreateRestoreJobs < ActiveRecord::Migration + def self.up + create_table :restore_jobs do |t| + t.string :state + t.string :backup_file + t.timestamps + end + end + + def self.down + drop_table :restore_jobs + end +end diff --git a/db/schema.rb b/db/schema.rb index df55604..60bc7f5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130215133749) do +ActiveRecord::Schema.define(:version => 20130225160423) do create_table "access_authorizations", :force => true do |t| t.string "access_authorizationable_type" @@ -554,6 +554,30 @@ ActiveRecord::Schema.define(:version => 20130215133749) do t.string "trunk_access_code" end + create_table "group_memberships", :force => true do |t| + t.integer "group_id" + t.string "item_type" + t.integer "item_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "group_permissions", :force => true do |t| + t.integer "group_id" + t.string "permission" + t.integer "target_group_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "groups", :force => true do |t| + t.string "name" + t.boolean "active" + t.string "comment" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "gs_cluster_sync_log_entries", :force => true do |t| t.integer "gs_node_id" t.string "class_name" @@ -854,6 +878,13 @@ ActiveRecord::Schema.define(:version => 20130215133749) do add_index "registrations", ["reg_user", "realm", "hostname"], :name => "regindex1" + create_table "restore_jobs", :force => true do |t| + t.string "state" + t.string "backup_file" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "ringtones", :force => true do |t| t.string "ringtoneable_type" t.integer "ringtoneable_id" diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake index c285e1f..d12bf5e 100644 --- a/lib/tasks/backup.rake +++ b/lib/tasks/backup.rake @@ -3,4 +3,41 @@ namespace :backup do task :daily_backup => :environment do # This would be the daily backup. end + + desc "Restore the system" + task :restore => :environment do + # This task takes the first RestoreJob to restore the system. + # + if RestoreJob.where(:state => 'new').any? + restore_job = RestoreJob.where(:state => 'new').order(:created_at).last + tmp_dir = "/tmp/gs5_restore_directory" + FileUtils.rm_rf tmp_dir + FileUtils.mkdir_p tmp_dir + system "cd #{tmp_dir} && tar xzf #{restore_job.backup_file.path}" + system "cd /tmp/gs5_restore_directory/*/ && tar xf GS5.tar && rm GS5.tar" + + # Restore faxes + # + system "cd / && tar xzfP /tmp/gs5_restore_directory/*/GS5/archives/faxes.tar.gz" + + # Restore voicemails + # + # system "cd / && tar xzfP /tmp/gs5_restore_directory/*/GS5/archives/voicemails.tar.gz" + + # Restore the database + # + system_odbc_ini_file = '/var/lib/freeswitch/.odbc.ini' + system_odbc_configuration = IniFile.load(system_odbc_ini_file) + database = system_odbc_configuration['gemeinschaft']['DATABASE'] + db_user = system_odbc_configuration['gemeinschaft']['USER'] + db_password = system_odbc_configuration['gemeinschaft']['PASSWORD'] + + system "gunzip < /tmp/gs5_restore_directory/*/GS5/databases/MySQL/gemeinschaft.sql.gz | mysql -u #{db_user} -p#{db_password} #{database}" + + FileUtils.rm_rf tmp_dir + + system "cd /opt/gemeinschaft && rake db:migrate" + end + end + end
\ No newline at end of file diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 4969b07..f72651f 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -27,6 +27,14 @@ </match> </input> </macro> + <macro name="voicemail_change_pass_success"> + <input pattern="(.*)"> + <match> + <action function="play-file" data="voicemail/vm-password_has_been_changed.wav"/> + <action function="say" data="$1" method="pronounced" type="name_spelled"/> + </match> + </input> + </macro> <macro name="voicemail_fail_auth"> <input pattern="(.*)"> <match> @@ -536,6 +544,14 @@ </match> </input> </macro> + <macro name="voicemail_change_pass_success"> + <input pattern="(.*)"> + <match> + <action function="play-file" data="voicemail/vm-password_has_been_changed.wav"/> + <action function="say" data="$1" method="pronounced" type="name_spelled"/> + </match> + </input> + </macro> <macro name="voicemail_fail_auth"> <input pattern="(.*)"> <match> diff --git a/test/functional/restore_jobs_controller_test.rb b/test/functional/restore_jobs_controller_test.rb new file mode 100644 index 0000000..bd06b25 --- /dev/null +++ b/test/functional/restore_jobs_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class RestoreJobsControllerTest < ActionController::TestCase + setup do + @restore_job = restore_jobs(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:restore_jobs) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create restore_job" do + assert_difference('RestoreJob.count') do + post :create, restore_job: @restore_job.attributes + end + + assert_redirected_to restore_job_path(assigns(:restore_job)) + end + + test "should show restore_job" do + get :show, id: @restore_job.to_param + assert_response :success + end + + test "should get edit" do + get :edit, id: @restore_job.to_param + assert_response :success + end + + test "should update restore_job" do + put :update, id: @restore_job.to_param, restore_job: @restore_job.attributes + assert_redirected_to restore_job_path(assigns(:restore_job)) + end + + test "should destroy restore_job" do + assert_difference('RestoreJob.count', -1) do + delete :destroy, id: @restore_job.to_param + end + + assert_redirected_to restore_jobs_path + end +end diff --git a/test/unit/restore_job_test.rb b/test/unit/restore_job_test.rb new file mode 100644 index 0000000..ce69ced --- /dev/null +++ b/test/unit/restore_job_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RestoreJobTest < ActiveSupport::TestCase + def test_should_be_valid + assert RestoreJob.new.valid? + end +end |