optimacms 0.3.23 → 0.3.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/optimacms/application.scss +7 -0
  3. data/app/controllers/optimacms/admin/backup_metadata_controller.rb +4 -1
  4. data/app/controllers/optimacms/admin/pages_controller.rb +1 -0
  5. data/app/controllers/optimacms/application_controller.rb +13 -0
  6. data/app/models/optimacms/cms_admin_user.rb +31 -1
  7. data/app/models/optimacms/page.rb +33 -1
  8. data/app/views/cms_admin_users/sessions/new.html.haml +43 -0
  9. data/app/views/optimacms/admin/appdata/index.html.haml +10 -9
  10. data/app/views/optimacms/admin/layouts/basic.html.haml +1 -1
  11. data/app/views/optimacms/admin/mediafiles/index.html.erb +3 -3
  12. data/app/views/optimacms/admin/pages/_form_folder.html.haml +1 -0
  13. data/config/initializers/devise.rb +4 -0
  14. data/lib/optimacms/appdata/rsync_command.rb +60 -0
  15. data/lib/optimacms/appdata/service.rb +39 -25
  16. data/lib/optimacms/appdata/ssh_command.rb +180 -0
  17. data/lib/optimacms/backup_metadata/backup.rb +5 -3
  18. data/lib/optimacms/backup_metadata/page_import.rb +10 -8
  19. data/lib/optimacms/concerns/admin_menu/admin_menu.rb +3 -3
  20. data/lib/optimacms/devise.rb +3 -0
  21. data/lib/optimacms/mycontroller.rb +1 -1
  22. data/lib/optimacms/version.rb +1 -1
  23. data/spec/dummy/config/initializers/devise.rb +1 -1
  24. data/spec/dummy/config/secrets.yml +2 -2
  25. data/spec/dummy/log/development.log +4944 -0
  26. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0m/0mcAe0Hhx0J17BMXbMxKzwvGiiI_20xASSAITdm1ziU.cache +1 -0
  27. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2z/2zwgrDVnzLZlTx8Memb0gzpf8yagLFZN3JGQAX4OniM.cache +0 -0
  28. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6_/6_y_S8oVqUuB2sc04zlksxKHk9syS6sk5qFUecJ03q8.cache +1 -0
  29. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9k/9kye0L2ZDoq9vTjMGfvwxMIiaSlAqgL7Lp5ctzjx6eE.cache +0 -0
  30. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/E9/E9ZKDOUFr9ts2L-I2rTrunk7Gik_Ft_oQ6IUBRCsVh8.cache +1 -0
  31. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ot/OtR0AxjtDduwkdYgLAyGUSVTmPzqJtZprIGk9dqRoBg.cache +0 -0
  32. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/V5/V5Fc_yYrC6DrvWkqweF4721viJOg6miLaAhoE5wjIQc.cache +0 -0
  33. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/WX/WXJgHWrvkJSuyYyGqt826Ntu2G2WuNxmJbUqO7hH2Qg.cache +0 -0
  34. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/k3/k38_e4uNEpuFVjGD1JEc8a_sEP7Tsrh3s3BSTkPsD-A.cache +0 -0
  35. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pn/pnhFGUpeu-U6-EluSZI82xJzUrxyoM_PzepMONjKKcg.cache +1 -0
  36. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xW/xWA0OS9RacBbkbDr1ge6K_aPjihZEfS90Ctpw-zZq_Y.cache +0 -0
  37. data/spec/dummy/tmp/pids/server.pid +1 -1
  38. metadata +27 -156
  39. data/app/views/cms_admin_users/sessions/new.html.erb +0 -26
  40. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/about.json +0 -21
  41. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/auth.json +0 -21
  42. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/contact_form.json +0 -21
  43. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/contact_form_result.json +0 -21
  44. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/contacts.json +0 -21
  45. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/dev.json +0 -21
  46. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/error403.json +0 -21
  47. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/error404.json +0 -21
  48. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/example.json +0 -21
  49. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/folder-services.json +0 -21
  50. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/folder-system.json +0 -21
  51. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/folder_contact.json +0 -21
  52. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/home.json +0 -21
  53. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/mp1.json +0 -21
  54. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/news-folder.json +0 -21
  55. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/news.json +0 -21
  56. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/news2.json +0 -21
  57. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/news_category.json +0 -21
  58. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/news_country_city.json +0 -21
  59. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/news_item.json +0 -21
  60. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/newsarticle.json +0 -21
  61. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/p1.json +0 -21
  62. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/p3.json +0 -21
  63. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/page1.json +0 -21
  64. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/page4.json +0 -21
  65. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/register.json +0 -21
  66. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/register_result.json +0 -21
  67. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/service.json +0 -21
  68. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/services.json +0 -21
  69. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/sitemap.json +0 -21
  70. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/t1.json +0 -21
  71. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/t2.json +0 -21
  72. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/ta1.json +0 -21
  73. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/text1.json +0 -21
  74. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/textpages.json +0 -21
  75. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/pages/tt1.json +0 -21
  76. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/company--p2.json +0 -14
  77. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/company--p3.json +0 -14
  78. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/company.json +0 -14
  79. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/home--index.json +0 -14
  80. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/home.json +0 -14
  81. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/layouts--application.json +0 -14
  82. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/layouts--home_news_data.json +0 -14
  83. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/layouts--layout2.json +0 -14
  84. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/layouts--main.json +0 -14
  85. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/layouts.json +0 -14
  86. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/news--index.json +0 -14
  87. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/news--show.json +0 -14
  88. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/news.json +0 -14
  89. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/pages--about.json +0 -14
  90. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/pages--text1.json +0 -14
  91. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/services--index.json +0 -14
  92. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/services--index_bottom.json +0 -14
  93. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/services--index_top.json +0 -14
  94. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/services--service.json +0 -14
  95. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/services.json +0 -14
  96. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--b1.json +0 -14
  97. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--h1.json +0 -14
  98. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--home.json +0 -14
  99. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--multi1.json +0 -14
  100. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--multi2.json +0 -14
  101. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--news.json +0 -14
  102. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--news_item.json +0 -14
  103. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--p1.json +0 -14
  104. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--part1.json +0 -14
  105. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--part2.json +0 -14
  106. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--t1.json +0 -14
  107. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--t2.json +0 -14
  108. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--ta1.json +0 -14
  109. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp--workers--index.json +0 -14
  110. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp.json +0 -14
  111. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp9--t2.json +0 -14
  112. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp9--t9.json +0 -14
  113. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/temp9.json +0 -14
  114. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/workers--index.json +0 -14
  115. data/spec/dummy/data/backups/cms/metadata/2017.09.08.14.11.34/templates/workers.json +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 690ee2065fe5506fe47d0d36b7b269f8d5275d1f
4
- data.tar.gz: a271a7b17bc0f75c9a85bbd4487412fd3abcbafa
3
+ metadata.gz: f0b9b2205c8bc82968042a97682ad648e2a08953
4
+ data.tar.gz: 02bd91769a57bae77c8ed131abcbdacf0e1c61fa
5
5
  SHA512:
6
- metadata.gz: 96efee9837fded7f54c673d83868e00c82764c2d4a52fe96a16a1e6350ab846cae24c1266b349741093a6187ac1ca372afe14abd8b1b1656ea6c307449577c32
7
- data.tar.gz: 619dd9d08990cd1b0134b99df617757a63237c1c213b667d09b0be796eb7a7cd0b27e37d9149ec4fb267c07f6476d05ef5a9d4791960cd63d33b8face2126001
6
+ metadata.gz: 13b733bdfcadfe1dcd9eae255cb35668018ef4dff2000d45e05c83b33b670043478017d754b64396139ce1a60ce0d678fc654983d7a4d077d7513f91919d5b8e
7
+ data.tar.gz: f6ac5bae985b6110ebb3630f3c541acb2392f6fc464a21f33051d7e2f37e3bf7df62b890b2f1fdfe075cdbab246c799155ec2f2a76e93e866d0cc8dcd969c9aa
@@ -1,2 +1,9 @@
1
+ // font-awesome
2
+ @import "font_awesome";
1
3
 
4
+ //
5
+ @import "admin_variables";
6
+
7
+ // Bootstrap and its default variables
8
+ @import "bootstrap/scss/bootstrap";
2
9
 
@@ -48,7 +48,10 @@ module Optimacms
48
48
 
49
49
  path = File.join(BackupMetadata::Backup.dir_backups, f)
50
50
 
51
- send_data File.read(path), filename: f
51
+ #data = File.open(path, 'rb') { |f| f.read }
52
+ data = IO.read(path)
53
+ send_data data, filename: f
54
+ #send_file path
52
55
  end
53
56
 
54
57
  def delete
@@ -11,6 +11,7 @@ module Optimacms
11
11
 
12
12
  #
13
13
  @parent_id = @filter.v('parent_id')
14
+ @parent_id = nil if @parent_id && @parent_id==0
14
15
  #@parent_id = (@parent_id || 0).to_i
15
16
  @parent = Page.find(@parent_id) rescue nil
16
17
 
@@ -16,5 +16,18 @@ module Optimacms
16
16
  raise ActionController::RoutingError.new('Not Found')
17
17
  end
18
18
 
19
+
20
+ # devise
21
+ before_action :configure_permitted_parameters, if: :devise_controller?
22
+
23
+
24
+ protected
25
+
26
+ def configure_permitted_parameters
27
+ added_attrs = [:username, :email, :password, :password_confirmation, :remember_me]
28
+ devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
29
+ devise_parameter_sanitizer.permit :account_update, keys: added_attrs
30
+ end
31
+
19
32
  end
20
33
  end
@@ -5,9 +5,11 @@ module Optimacms
5
5
  # Include default devise modules. Others available are:
6
6
  # :confirmable, :lockable, :timeoutable and :omniauthable
7
7
  #devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
8
- devise :database_authenticatable, :recoverable, :rememberable, :trackable
8
+ devise :database_authenticatable, :recoverable, :rememberable, :trackable,
9
+ authentication_keys: [:login]
9
10
  #, :validatable
10
11
 
12
+ attr_accessor :login
11
13
 
12
14
  # search
13
15
  searchable_by_simple_filter
@@ -20,13 +22,24 @@ module Optimacms
20
22
  :length => { :minimum => 6 },
21
23
  :if => :should_validate_password? # only validate if password changed!
22
24
 
25
+ validates :username,
26
+ presence: :true,
27
+ uniqueness: { case_sensitive: false }
28
+
29
+ # Only allow letter, number, underscore and punctuation.
30
+ #validates_format_of :username, with: /^[a-zA-Z0-9_\.]*$/, :multiline => true
31
+
32
+
23
33
  def should_validate_password?
24
34
  x = new_record? || !password.blank?
25
35
  #if: Proc.new{|obj| obj.new_record? || !obj.<attribute>.blank? }
26
36
  end
27
37
 
38
+ ### callbacks
39
+
28
40
  before_destroy :can_destroy?
29
41
 
42
+
30
43
  def can_destroy?
31
44
  !self.is_superadmin
32
45
  end
@@ -37,5 +50,22 @@ module Optimacms
37
50
  def is_superadmin?
38
51
  self.is_superadmin
39
52
  end
53
+
54
+
55
+
56
+
57
+ ### for login auth
58
+
59
+ def self.find_for_database_authentication(warden_conditions)
60
+ conditions = warden_conditions.dup
61
+ conditions[:email].downcase! if conditions[:email]
62
+
63
+ if login = conditions.delete(:login)
64
+ where(conditions.to_hash).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
65
+ elsif conditions.has_key?(:username) || conditions.has_key?(:email)
66
+ where(conditions.to_hash).first
67
+ end
68
+ end
69
+
40
70
  end
41
71
  end
@@ -2,18 +2,37 @@ module Optimacms
2
2
  class Page < ActiveRecord::Base
3
3
  self.table_name = 'cms_pages'
4
4
 
5
+
6
+ # relations
7
+
5
8
  belongs_to :layout, :foreign_key => 'layout_id', :class_name => 'Template'
6
9
  belongs_to :template, :foreign_key => 'template_id', :class_name => 'Template'
7
10
  belongs_to :folder, :foreign_key => 'parent_id', :class_name => 'Page'
8
11
  has_many :translations, :foreign_key => 'item_id', :class_name => 'PageTranslation', :dependent => :destroy
9
12
  accepts_nested_attributes_for :translations
10
-
11
13
  accepts_nested_attributes_for :template
12
14
 
13
15
  #has_many :page_translations
14
16
  #accepts_nested_attributes_for :page_translations
15
17
 
18
+ # validation
19
+ #validates :name, uniqueness: { scope: :w_page}
20
+
21
+ with_options unless: :is_folder? do |m|
22
+ m.validates :name, uniqueness: {
23
+ conditions: -> {
24
+ w_page
25
+ }
26
+ }
27
+ end
28
+
29
+ with_options if: :is_folder? do |m|
30
+ m.validates :name, uniqueness: { scope: :parent_id}
31
+ end
32
+
33
+
16
34
  # callbacks
35
+ before_save :_before_validate
17
36
  before_save :_before_save
18
37
 
19
38
  # modules
@@ -23,6 +42,8 @@ module Optimacms
23
42
 
24
43
  # scopes
25
44
  scope :of_parent, lambda { |parent_id| where_parent(parent_id) }
45
+ scope :w_page, -> { where(is_folder: false) }
46
+ scope :w_folder, -> { where(is_folder: false) }
26
47
 
27
48
  #
28
49
  paginates_per 10
@@ -60,6 +81,17 @@ module Optimacms
60
81
  end
61
82
 
62
83
 
84
+ ### validate
85
+
86
+
87
+ ### callbacks
88
+
89
+
90
+ def _before_validate
91
+ self.parent_id = nil if self.parent_id && self.parent_id==0
92
+ end
93
+
94
+
63
95
  ### content
64
96
 
65
97
  def content(lang='')
@@ -0,0 +1,43 @@
1
+
2
+ .container
3
+ .row.justify-content-center
4
+ .col-xl-4.col-lg-4.col-md-6.col-12
5
+ .card
6
+ .card-body
7
+ %h3.card-title.text-uppercase
8
+ Admin Area
9
+ -#%h6.card-subtitle.mt-2.mb-2.text-muted
10
+ OptimaCMS Admin Area
11
+ -#%p.card-text
12
+
13
+ = form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
14
+ .form-group
15
+ = f.label :login
16
+ %br
17
+ = f.text_field :login, autofocus: true, class: 'form-control'
18
+
19
+ .form-group
20
+ = f.label :password
21
+ %br
22
+ = f.password_field :password, autocomplete: "off", class: 'form-control'
23
+
24
+ - if devise_mapping.rememberable?
25
+ .form-group
26
+ = f.check_box :remember_me
27
+ = f.label :remember_me
28
+
29
+ .actions
30
+ = f.submit "Log in", class: 'btn btn-primary btn-lg'
31
+
32
+ %p.mt-3
33
+ = render "devise/shared/links"
34
+
35
+ %hr.mt-2
36
+ %p
37
+ =link_to 'OptimaCMS', 'https://github.com/maxivak/optimacms'
38
+ v.#{Optimacms::Common::Common.version}
39
+
40
+
41
+
42
+
43
+
@@ -5,7 +5,7 @@
5
5
  - @list.each do |content|
6
6
  %h2 #{content['name']}
7
7
  Storage:<br>
8
- #{content['storage']['type']}
8
+ Type: #{content['storage']['type']}
9
9
  %br
10
10
  Dirs: #{content['dirs'].map{|r| r}.join(", ") }
11
11
  %br
@@ -71,14 +71,17 @@
71
71
  %h1 Help
72
72
 
73
73
  %b Save changes
74
- Save current changes to remote repo
74
+ %br
75
+ Save current changes to remote repo:
76
+ %br
75
77
  * run on server
76
78
  %pre
77
- name=NAME RAILS_ENV=#{Rails.env} rake appdata:save
79
+ RAILS_ENV=#{Rails.env} rake appdata:save['CONTENT_NAME']
78
80
 
79
81
  * run from local project
80
82
  %pre
81
- cap #{Rails.env} deploy:appdata:server_save
83
+ name=CONTENT_NAME cap #{Rails.env} deploy:appdata:server_save
84
+
82
85
 
83
86
  %br
84
87
  %br
@@ -87,15 +90,13 @@ Save current changes to remote repo
87
90
  %b Get changes
88
91
  Get changes from remote repo
89
92
  %br
90
-
91
- or<br>
92
93
  * run on server
93
94
  %pre
94
- name=NAME RAILS_ENV=#{Rails.env} rake appdata:update
95
+ name=CONTENT_NAME RAILS_ENV=#{Rails.env} rake appdata:update
95
96
 
96
- * run from local project
97
+ * or run from local project
97
98
  %pre
98
- cap #{Rails.env} deploy:appdata:server_update
99
+ name=CONTENT_NAME cap #{Rails.env} deploy:appdata:server_update
99
100
 
100
101
 
101
102
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  .container-fluid.p-0.m-0
5
5
  .row.no-gutters
6
- .col-lg-2
6
+ .col-sm-2
7
7
  = render 'optimacms/admin/shared/leftmenu'
8
8
  .col
9
9
  = render 'optimacms/admin/shared/breadcrumbs'
@@ -4,9 +4,9 @@
4
4
  <title>File Manager</title>
5
5
 
6
6
 
7
- <link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/smoothness/jquery-ui.css" />
8
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
9
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
7
+ <link rel="stylesheet" type="text/css" media="screen" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/smoothness/jquery-ui.css" />
8
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
9
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
10
10
 
11
11
 
12
12
  <script type="text/javascript" src="/elfinder/js/elfinder.min.js"></script>
@@ -6,6 +6,7 @@
6
6
  = f.input :parent_id, as: :hidden
7
7
  = f.input :is_folder, as: :hidden
8
8
 
9
+ = f.input :name, label: "Name", hint: 'only English letters'
9
10
  = f.input :title, label: "Title"
10
11
 
11
12
  - if @item.parent_id
@@ -0,0 +1,4 @@
1
+ Devise.setup do |config|
2
+ config.scoped_views = true
3
+ end
4
+
@@ -0,0 +1,60 @@
1
+ module Optimacms
2
+ module Appdata
3
+ class RsyncCommand
4
+
5
+
6
+ def self.build_cmd_with_ssh_save(storage, d_local_full, d_remote)
7
+ s_ssh = " #{storage['ssh_user']}@#{storage['host']}"
8
+ ssh_opts = build_ssh_opts(storage)
9
+
10
+ cmd_rsync = %Q(rsync -Lavrt -e "ssh #{ssh_opts}" #{d_local_full} #{s_ssh}:#{d_remote} --delete)
11
+
12
+ cmd = nil
13
+ if storage['ssh_key'] && storage['ssh_key']!=''
14
+ # use ssh key
15
+ cmd = cmd_rsync
16
+ else
17
+ # use sshpass with password
18
+ cmd = %Q(sshpass -p #{storage['ssh_password']} #{cmd_rsync})
19
+ end
20
+
21
+
22
+ cmd
23
+ end
24
+
25
+ def self.build_cmd_with_ssh_update(storage, d_local_full, d_remote)
26
+ s_ssh = " #{storage['ssh_user']}@#{storage['host']}"
27
+ ssh_opts = build_ssh_opts(storage)
28
+
29
+ cmd_rsync = %Q(rsync -Lavrt -e "ssh #{ssh_opts}" #{s_ssh}:#{d_remote} #{d_local_full} --delete)
30
+
31
+
32
+ cmd = nil
33
+ if storage['ssh_key'] && storage['ssh_key']!=''
34
+ # use ssh key
35
+ cmd = cmd_rsync
36
+ else
37
+ # use sshpass with password
38
+ cmd = %Q(sshpass -p #{storage['ssh_password']} #{cmd_rsync})
39
+ end
40
+
41
+
42
+ cmd
43
+ end
44
+
45
+
46
+ def self.build_ssh_opts(storage)
47
+ ssh_opts = "-p #{storage['ssh_port']||22} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
48
+
49
+ if storage['ssh_key'] && storage['ssh_key']!=''
50
+ ssh_opts << " -i #{storage['ssh_key']}"
51
+ end
52
+
53
+ ssh_opts
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+
60
+
@@ -142,13 +142,19 @@ module Optimacms
142
142
  storage = content['storage']
143
143
 
144
144
  #
145
- s_ssh = " #{storage['ssh_user']}@#{storage['host']}"
146
- ssh_opts = "-p #{storage['ssh_port']||22} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
147
-
148
- if storage['ssh_key'] && storage['ssh_key']!=''
149
- ssh_opts << " -i #{storage['ssh_key']}"
150
- end
151
-
145
+ cmd = SshCommand.new
146
+ ssh_options = {
147
+ port: storage['ssh_port'],
148
+ user: storage['ssh_user'],
149
+ password: storage['ssh_password'],
150
+ key: storage['ssh_key']
151
+ }
152
+
153
+ #s_ssh = " #{storage['ssh_user']}@#{storage['host']}"
154
+ #ssh_opts = "-p #{storage['ssh_port']||22} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
155
+ #if storage['ssh_key'] && storage['ssh_key']!=''
156
+ # ssh_opts << " -i #{storage['ssh_key']}"
157
+ #end
152
158
 
153
159
  # sync dirs
154
160
  content['dirs'].each do |d|
@@ -159,12 +165,19 @@ module Optimacms
159
165
 
160
166
 
161
167
  # create remote dir
162
- %x[ssh -t #{ssh_opts} #{s_ssh} mkdir -p #{d_remote}]
168
+ #%x[ssh -t #{ssh_opts} #{s_ssh} mkdir -p #{d_remote}]
169
+ cmd_create = %Q(mkdir -p #{d_remote})
170
+ res_cmd_create = cmd.run_ssh_cmd(storage['host'], ssh_options, cmd_create)
171
+
172
+ if res_cmd_create[:res]!=1
173
+ raise "Cannot create dir: #{res_cmd_create[:error]}"
174
+ end
175
+
163
176
 
164
177
  # rsync
165
- cmd = %Q(rsync -Lavrt -e "ssh #{ssh_opts}" #{d_local_full} #{s_ssh}:#{d_remote} --delete)
166
- puts "#{cmd}"
167
- %x[#{cmd}]
178
+ cmd_rsync = RsyncCommand.build_cmd_with_ssh_save(storage, d_local_full, d_remote)
179
+ #puts "#{cmd_rsync}"
180
+ output = %x[#{cmd_rsync}]
168
181
 
169
182
  end
170
183
 
@@ -182,16 +195,14 @@ module Optimacms
182
195
 
183
196
  #
184
197
  content = Optimacms::Appdata::Settings.get_content_info(_env, content_name)
185
- #puts "content: #{content}"
186
198
  storage = content['storage']
187
199
 
188
200
  #
189
- s_ssh = " #{storage['ssh_user']}@#{storage['host']}"
190
- ssh_opts = "-p #{storage['ssh_port']||22} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
191
-
192
- if storage['ssh_key'] && storage['ssh_key']!=''
193
- ssh_opts << " -i #{storage['ssh_key']}"
194
- end
201
+ #s_ssh = " #{storage['ssh_user']}@#{storage['host']}"
202
+ #ssh_opts = "-p #{storage['ssh_port']||22} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
203
+ #if storage['ssh_key'] && storage['ssh_key']!=''
204
+ # ssh_opts << " -i #{storage['ssh_key']}"
205
+ #end
195
206
 
196
207
 
197
208
  # sync dirs
@@ -200,13 +211,16 @@ module Optimacms
200
211
  d_local = File.join(File.dirname(d), File.basename(d))+"/"
201
212
  d_local_full = File.join(Rails.root, d_local)
202
213
 
203
- #
214
+ # create local dir
204
215
  %x[mkdir -p #{d_local_full}]
205
216
 
217
+
206
218
  # rsync
207
- cmd = %Q(rsync -Lavrt -e "ssh #{ssh_opts}" #{s_ssh}:#{d_remote} #{d_local_full} --delete)
208
- puts "#{cmd}"
209
- %x[#{cmd}]
219
+ cmd_rsync = RsyncCommand.build_cmd_with_ssh_update(storage, d_local_full, d_remote)
220
+ #puts "#{cmd_rsync}"
221
+ output = %x[#{cmd_rsync}]
222
+
223
+ #cmd = %Q(rsync -Lavrt -e "ssh #{ssh_opts}" #{s_ssh}:#{d_remote} #{d_local_full} --delete)
210
224
 
211
225
  end
212
226
 
@@ -259,18 +273,18 @@ module Optimacms
259
273
  d_to = File.join(repo_local_path, d)
260
274
  d_to_base = File.dirname(d_to)
261
275
 
262
- puts "copy from #{d_from} to #{d_to}"
276
+ #puts "copy from #{d_from} to #{d_to}"
263
277
 
264
278
  FileUtils.mkdir_p d_to
265
279
 
266
280
  # rsync or copy
267
281
  if res_rsync!=""
268
282
  cmd = %Q(rsync -Lavrt #{d_from}/ #{d_to}/)
269
- puts "#{cmd}"
283
+ #puts "#{cmd}"
270
284
  %x(#{cmd})
271
285
  else
272
286
  # no rsync
273
- puts "no rsync. copying..."
287
+ #puts "no rsync. copying..."
274
288
 
275
289
  FileUtils.cp_r d_from, d_to_base
276
290
  end