camaleon_cms 2.7.5 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of camaleon_cms might be problematic. Click here for more details.

Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -27
  3. data/app/apps/plugins/attack/config/config.json +2 -2
  4. data/app/apps/plugins/front_cache/admin_controller.rb +4 -6
  5. data/app/apps/plugins/front_cache/config/config.json +1 -1
  6. data/app/apps/plugins/front_cache/config/locales/translation.yml +1 -1
  7. data/app/apps/plugins/front_cache/front_cache_helper.rb +3 -3
  8. data/app/apps/plugins/visibility_post/config/config.json +2 -2
  9. data/app/apps/themes/camaleon_first/assets/js/main.js +1 -1
  10. data/app/apps/themes/camaleon_first/views/index.html.erb +1 -1
  11. data/app/apps/themes/default/assets/js/main.js +1 -1
  12. data/app/apps/themes/new/assets/js/main.js +1 -1
  13. data/app/apps/themes/new/views/index.html.erb +4 -4
  14. data/app/apps/themes/new/views/layouts/_footer.html.erb +2 -2
  15. data/app/assets/javascripts/camaleon_cms/admin/admin-basic-manifest.js +2 -2
  16. data/app/assets/javascripts/camaleon_cms/admin/admin-manifest.js +1 -1
  17. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/de.js +2 -2
  18. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/en.js +2 -2
  19. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/fr.js +2 -2
  20. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/it.js +2 -2
  21. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/nl.js +1 -1
  22. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/pt-BR.js +2 -2
  23. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/ru.js +2 -2
  24. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/uk.js +2 -2
  25. data/app/assets/javascripts/camaleon_cms/admin/tinymce/langs/zh-CN.js +1 -1
  26. data/app/assets/javascripts/camaleon_cms/admin/uploader/_media_manager.js +2 -2
  27. data/app/assets/stylesheets/camaleon_cms/admin/admin-manifest.css +2 -1
  28. data/app/assets/stylesheets/camaleon_cms/admin/{colorpicker.css.scss → colorpicker.css} +5 -5
  29. data/app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb +15 -10
  30. data/app/controllers/camaleon_cms/admin/installers_controller.rb +1 -1
  31. data/app/controllers/camaleon_cms/admin/media_controller.rb +12 -9
  32. data/app/controllers/camaleon_cms/admin/settings_controller.rb +1 -1
  33. data/app/controllers/camaleon_cms/camaleon_controller.rb +8 -2
  34. data/app/decorators/camaleon_cms/application_decorator.rb +8 -0
  35. data/app/decorators/camaleon_cms/category_decorator.rb +1 -1
  36. data/app/decorators/camaleon_cms/post_decorator.rb +5 -5
  37. data/app/decorators/camaleon_cms/post_type_decorator.rb +3 -3
  38. data/app/decorators/camaleon_cms/term_taxonomy_decorator.rb +1 -1
  39. data/app/helpers/camaleon_cms/admin/category_helper.rb +1 -1
  40. data/app/helpers/camaleon_cms/frontend/nav_menu_helper.rb +12 -11
  41. data/app/helpers/camaleon_cms/html_helper.rb +7 -7
  42. data/app/helpers/camaleon_cms/plugins_helper.rb +1 -1
  43. data/app/helpers/camaleon_cms/session_helper.rb +1 -1
  44. data/app/helpers/camaleon_cms/short_code_helper.rb +1 -1
  45. data/app/helpers/camaleon_cms/site_helper.rb +1 -1
  46. data/app/helpers/camaleon_cms/theme_helper.rb +1 -1
  47. data/app/helpers/camaleon_cms/uploader_helper.rb +60 -17
  48. data/app/models/camaleon_cms/ability.rb +1 -1
  49. data/app/models/camaleon_cms/custom_field_group.rb +3 -6
  50. data/app/models/camaleon_cms/nav_menu.rb +1 -1
  51. data/app/models/camaleon_cms/post.rb +1 -1
  52. data/app/models/camaleon_cms/post_default.rb +1 -1
  53. data/app/models/camaleon_cms/post_type.rb +8 -8
  54. data/app/models/camaleon_cms/site.rb +1 -1
  55. data/app/models/camaleon_cms/term_taxonomy.rb +13 -0
  56. data/app/models/concerns/camaleon_cms/custom_fields_read.rb +11 -22
  57. data/app/models/concerns/camaleon_cms/site_default_settings.rb +1 -1
  58. data/app/uploaders/camaleon_cms_aws_uploader.rb +3 -3
  59. data/app/uploaders/camaleon_cms_local_uploader.rb +10 -4
  60. data/app/uploaders/camaleon_cms_uploader.rb +13 -0
  61. data/app/validators/camaleon_cms/post_uniq_validator.rb +11 -12
  62. data/app/validators/camaleon_cms/uniq_validator.rb +9 -3
  63. data/app/views/camaleon_cms/admin/media/index.html.erb +1 -1
  64. data/app/views/camaleon_cms/admin/settings/_email_settings.html.erb +2 -2
  65. data/app/views/camaleon_cms/admin/settings/custom_fields/_get_items.html.erb +1 -2
  66. data/app/views/camaleon_cms/admin/settings/custom_fields/_render.html.erb +2 -2
  67. data/app/views/camaleon_cms/default_theme/index.html.erb +4 -4
  68. data/app/views/camaleon_cms/default_theme/sitemap.xml.builder +3 -3
  69. data/app/views/layouts/camaleon_cms/admin/_footer.html.erb +1 -1
  70. data/config/initializers/custom_initializers.rb +14 -0
  71. data/config/initializers/sass.rb +12 -16
  72. data/lib/camaleon_cms/engine.rb +2 -2
  73. data/lib/camaleon_cms/version.rb +1 -1
  74. data/lib/ext/hash.rb +1 -1
  75. data/lib/ext/string.rb +2 -2
  76. data/lib/generators/camaleon_cms/theme_template/assets/js/main.js +1 -1
  77. metadata +53 -39
@@ -30,6 +30,8 @@ module CamaleonCms
30
30
 
31
31
  file = cama_uploader.fetch_file("private/#{params[:file]}")
32
32
 
33
+ return render plain: helpers.sanitize(file[:error]) if file.is_a?(Hash) && file[:error].present?
34
+
33
35
  send_file file, disposition: 'inline'
34
36
  end
35
37
 
@@ -51,16 +53,15 @@ module CamaleonCms
51
53
  def actions
52
54
  authorize! :manage, :media if params[:media_action] != 'crop_url'
53
55
  params[:folder] = params[:folder].gsub('//', '/') if params[:folder].present?
56
+
54
57
  case params[:media_action]
55
58
  when 'new_folder'
56
59
  params[:folder] = slugify_folder(params[:folder])
57
- render partial: 'render_file_item', locals: { files: [cama_uploader.add_folder(params[:folder])] }
60
+ return render partial: 'render_file_item', locals: { files: [cama_uploader.add_folder(params[:folder])] }
58
61
  when 'del_folder'
59
- cama_uploader.delete_folder(params[:folder])
60
- render plain: ''
62
+ r = cama_uploader.delete_folder(params[:folder])
61
63
  when 'del_file'
62
- cama_uploader.delete_file(params[:folder].gsub('//', '/'))
63
- render plain: ''
64
+ r = cama_uploader.delete_file(params[:folder].gsub('//', '/'))
64
65
  when 'crop_url'
65
66
  user_url = params[:url].to_s
66
67
  user_url = "#{current_site.the_url(locale: nil)}#{user_url}" unless user_url.start_with?('data:', 'http')
@@ -70,16 +71,18 @@ module CamaleonCms
70
71
  else
71
72
  cama_tmp_upload(user_url, formats: params[:formats], name: params[:name])
72
73
  end
73
- if r[:error].present?
74
- render plain: helpers.sanitize(r[:error])
75
- else
74
+ if r[:error].blank?
76
75
  params[:file_upload] = r[:file_path]
77
76
  sett = { remove_source: true }
78
77
  sett[:same_name] = true if params[:same_name].present?
79
78
  sett[:name] = params[:name] if params[:name].present?
80
- upload(sett)
79
+ return upload(sett)
81
80
  end
82
81
  end
82
+
83
+ return render plain: helpers.sanitize(r[:error]) if r[:error].present?
84
+
85
+ render plain: ''
83
86
  end
84
87
 
85
88
  # upload files from media uploader
@@ -26,7 +26,7 @@ module CamaleonCms
26
26
  flash[:notice] = t('camaleon_cms.admin.settings.message.site_updated')
27
27
  args = { action: :site }
28
28
  args[:host], args[:port] = @site.get_domain.to_s.split(':') if cache_slug != @site.slug
29
- redirect_to(args)
29
+ redirect_to(args, allow_other_host: true)
30
30
  else
31
31
  render 'site'
32
32
  end
@@ -51,7 +51,7 @@ module CamaleonCms
51
51
  # generate captcha image
52
52
  def captcha
53
53
  image = cama_captcha_build(params[:len])
54
- send_data image.to_blob, type: image.mime_type, disposition: 'inline'
54
+ send_data image.to_blob, type: MiniMime.lookup_by_extension(image.type).content_type, disposition: 'inline'
55
55
  end
56
56
 
57
57
  private
@@ -103,7 +103,13 @@ module CamaleonCms
103
103
  def cama_site_check_existence
104
104
  if !current_site.present?
105
105
  if Cama::Site.main_site.present?
106
- redirect_to Cama::Site.main_site.decorate.the_url
106
+ url = Cama::Site.main_site.decorate.the_url
107
+ # TODO: Remove this condition when Rails 6.x won't be supported
108
+ if Rails.gem_version >= Gem::Version.new('7.0.0')
109
+ redirect_to url, allow_other_host: true
110
+ else
111
+ redirect_to url
112
+ end
107
113
  else
108
114
  redirect_to cama_admin_installers_path
109
115
  end
@@ -4,6 +4,14 @@ module CamaleonCms
4
4
  @_deco_locale = nil
5
5
  include CamaleonCms::MetasDecoratorMethods
6
6
 
7
+ def marshal_dump
8
+ @object
9
+ end
10
+
11
+ def marshal_load(obj)
12
+ @object = obj
13
+ end
14
+
7
15
  # return the keywords for this model
8
16
  def the_keywords
9
17
  k = object.get_option('keywords', '')
@@ -21,7 +21,7 @@ module CamaleonCms
21
21
 
22
22
  # return all children categories for the current category (active_record) filtered by permissions + hidden posts + roles + etc...
23
23
  # in return object, you can add custom where's or pagination like here:
24
- # http://edgeguides.rubyonrails.org/active_record_querying.html
24
+ # https://edgeguides.rubyonrails.org/active_record_querying.html
25
25
  def the_categories
26
26
  object.children
27
27
  end
@@ -41,8 +41,8 @@ module CamaleonCms
41
41
  if th.present?
42
42
  th
43
43
  else
44
- (default || object.post_type.get_option('default_thumb',
45
- nil) || h.asset_url('camaleon_cms/image-not-found.png'))
44
+ default || object.post_type.get_option('default_thumb',
45
+ nil) || h.asset_url('camaleon_cms/image-not-found.png')
46
46
  end
47
47
  end
48
48
  alias the_image_url the_thumb_url
@@ -61,12 +61,12 @@ module CamaleonCms
61
61
  end
62
62
 
63
63
  # return front url for this post
64
- # sample: http://localhost.com/my-page.html
64
+ # sample: https://localhost.com/my-page.html
65
65
  # args:
66
66
  # locale: language (default current language)
67
67
  # as_path: return the path instead of full url, sample: /my-page.html
68
68
  # Also, you can pass extra attributes as params for the url, sample: page.the_url(my_param: 'value', other: "asd")
69
- # => http://localhost.com/my-page.html?my_param=value&other=asd
69
+ # => https://localhost.com/my-page.html?my_param=value&other=asd
70
70
  # Return String URL
71
71
  def the_url(*args)
72
72
  args = args.extract_options!
@@ -127,7 +127,7 @@ module CamaleonCms
127
127
  end
128
128
 
129
129
  # return a hash of frontend urls for this post
130
- # sample: {es: 'http://mydomain.com/es/articulo-3.html', en: 'http://mydomain.com/en/post-3.html'}
130
+ # sample: {es: 'https://mydomain.com/es/articulo-3.html', en: 'https://mydomain.com/en/post-3.html'}
131
131
  def the_urls(*args)
132
132
  args = args.extract_options!
133
133
  res = {}
@@ -55,14 +55,14 @@ module CamaleonCms
55
55
 
56
56
  # return main categories (first level) for the post_type (active_record) filtered by permissions
57
57
  # in return object, you can add custom where's or pagination like here:
58
- # http://edgeguides.rubyonrails.org/active_record_querying.html
58
+ # https://edgeguides.rubyonrails.org/active_record_querying.html
59
59
  def the_categories
60
60
  object.categories
61
61
  end
62
62
 
63
63
  # return full categories (all levels) for the post_type (active_record) filtered by permissions
64
64
  # in return object, you can add custom where's or pagination like here:
65
- # http://edgeguides.rubyonrails.org/active_record_querying.html
65
+ # https://edgeguides.rubyonrails.org/active_record_querying.html
66
66
  def the_full_categories
67
67
  object.full_categories
68
68
  end
@@ -76,7 +76,7 @@ module CamaleonCms
76
76
 
77
77
  # return all post_tags for the post_type (active_record) filtered by permissions + hidden posts + roles + etc...
78
78
  # in return object, you can add custom where's or pagination like here:
79
- # http://edgeguides.rubyonrails.org/active_record_querying.html
79
+ # https://edgeguides.rubyonrails.org/active_record_querying.html
80
80
  def the_post_tags
81
81
  object.post_tags
82
82
  end
@@ -48,7 +48,7 @@ module CamaleonCms
48
48
  # ---------------------- filters
49
49
  # return all posts for this model (active_record) filtered by permissions + hidden posts + roles + etc...
50
50
  # in return object, you can add custom where's or pagination like here:
51
- # http://edgeguides.rubyonrails.org/active_record_querying.html
51
+ # https://edgeguides.rubyonrails.org/active_record_querying.html
52
52
  def the_posts
53
53
  h.verify_front_visibility(object.posts)
54
54
  end
@@ -17,7 +17,7 @@ module CamaleonCms
17
17
  options << [('—' * level) + category.the_title, category.id]
18
18
  children = attrs[:max_level] < level ? [] : category.children
19
19
  children = [] if attrs[:until_cats].include?(category.id)
20
- options += cama_category_get_options_html(children, level + 1, attrs) if children.size.positive?
20
+ options += cama_category_get_options_html(children, level + 1, attrs) unless children.empty?
21
21
  end
22
22
  options
23
23
  end
@@ -23,7 +23,7 @@ module CamaleonCms
23
23
  item_class_parent: 'dropdown', # class for all menu items that contain sub items
24
24
  sub_container: 'ul', # type of container for sub items
25
25
  sub_class: 'dropdown-menu', # class for sub container
26
- callback_item: ->(args) {},
26
+ callback_item: ->(args) {}, # rubocop:disable Lint/ShadowingOuterLocalVariable
27
27
  # callback executed for each item (args = { menu_item, link, level, settings, has_children, link_attrs = "", index}).
28
28
  # menu_item: (Object) Menu object
29
29
  # link: (Hash) link data: {link: '', name: ''}
@@ -48,10 +48,11 @@ module CamaleonCms
48
48
  container_append: '' # content append for menu container
49
49
  }
50
50
 
51
- args = args_def.merge(args)
51
+ args = args_def.merge!(args)
52
52
  nav_menu = current_site.nav_menus.find_by_slug(args[:menu_slug])
53
- nav_menu = current_site.nav_menus.first unless nav_menu.present?
54
- html = "<#{args[:container]} class='#{args[:container_class]}' id='#{args[:container_id]}'>#{args[:container_prepend]}{__}#{args[:container_append]}</#{args[:container]}>"
53
+ nav_menu ||= current_site.nav_menus.first
54
+ html = "<#{args[:container]} class='#{args[:container_class]}' "\
55
+ "id='#{args[:container_id]}'>#{args[:container_prepend]}{__}#{args[:container_append]}</#{args[:container]}>"
55
56
  if nav_menu.present?
56
57
  html.sub('{__}', cama_menu_draw_items(args, nav_menu.children.reorder(:term_order)))
57
58
  else
@@ -69,10 +70,10 @@ module CamaleonCms
69
70
  data_nav_item = cama_parse_menu_item(nav_menu_item)
70
71
  next if data_nav_item == false
71
72
 
72
- _is_current = data_nav_item[:current] || site_current_path == data_nav_item[:link] || site_current_path == data_nav_item[:link].sub(
73
- '.html', ''
74
- )
75
- has_children = nav_menu_item.have_children? && (args[:levels] == -1 || (args[:levels] != -1 && level <= args[:levels]))
73
+ _is_current = data_nav_item[:current] || site_current_path == data_nav_item[:link] ||
74
+ site_current_path == data_nav_item[:link].sub('.html', '')
75
+ has_children = nav_menu_item.have_children? && (args[:levels] == -1 ||
76
+ (args[:levels] != -1 && level <= args[:levels]))
76
77
  r = {
77
78
  menu_item: nav_menu_item.decorate,
78
79
  link: data_nav_item,
@@ -116,7 +117,7 @@ module CamaleonCms
116
117
  index += 1
117
118
  end
118
119
 
119
- if level.zero?
120
+ if level == 0
120
121
  html
121
122
  else
122
123
  html = "<#{args[:sub_container]} class='#{args[:sub_class]} #{if parent_current
@@ -142,7 +143,7 @@ module CamaleonCms
142
143
  '.html', ''
143
144
  )
144
145
  has_children = nav_menu_item.have_children?
145
- has_children = false if max_levels.positive? && max_levels == internal_level
146
+ has_children = false if max_levels > 0 && max_levels == internal_level
146
147
  data_nav_item[:label] = data_nav_item[:name]
147
148
  data_nav_item[:url] = data_nav_item[:link]
148
149
  r = {
@@ -169,7 +170,7 @@ module CamaleonCms
169
170
  res << r
170
171
  end
171
172
 
172
- if internal_level.zero?
173
+ if internal_level == 0
173
174
  res
174
175
  else
175
176
  [res, is_current_parent, levels.max]
@@ -72,14 +72,14 @@ module CamaleonCms
72
72
  def cama_draw_custom_assets
73
73
  cama_html_helpers_init unless @_assets_libraries.present?
74
74
  libs = []
75
- @_assets_libraries.each do |_key, assets|
75
+ @_assets_libraries.each_value do |assets|
76
76
  libs += assets[:css] if assets[:css].present?
77
77
  end
78
78
  stylesheets = libs.uniq
79
79
  css = stylesheet_link_tag(*stylesheets, media: 'all')
80
80
 
81
81
  libs = []
82
- @_assets_libraries.each do |_key, assets|
82
+ @_assets_libraries.each_value do |assets|
83
83
  libs += assets[:js] if assets[:js].present?
84
84
  end
85
85
  javascripts = libs.uniq
@@ -98,7 +98,7 @@ module CamaleonCms
98
98
  terms.all.each do |term|
99
99
  options << [('—' * level) + term.name, term.id] unless @term.id == term.id
100
100
  children = term.children
101
- options += cama_get_options_html_from_items(children, level + 1) if children.size.positive?
101
+ options += cama_get_options_html_from_items(children, level + 1) unless children.empty?
102
102
  end
103
103
  options
104
104
  end
@@ -117,22 +117,22 @@ module CamaleonCms
117
117
 
118
118
  libs = {}
119
119
  libs[:colorpicker] =
120
- { js: ['camaleon_cms/admin/bootstrap-colorpicker'], css: ['camaleon_cms/admin/colorpicker.css'] }
120
+ { js: ['camaleon_cms/admin/bootstrap-colorpicker'], css: ['camaleon_cms/admin/colorpicker'] }
121
121
  libs[:datepicker] = { js: [] }
122
122
  libs[:datetimepicker] = { js: [], css: [] }
123
123
  libs[:tinymce] =
124
- { js: ['camaleon_cms/admin/tinymce/tinymce.min', 'camaleon_cms/admin/tinymce/plugins/filemanager/plugin.min'],
124
+ { js: %w[camaleon_cms/admin/tinymce/tinymce.min camaleon_cms/admin/tinymce/plugins/filemanager/plugin.min],
125
125
  css: ['camaleon_cms/admin/tinymce/skins/lightgray/content.min'] }
126
126
  libs[:form_ajax] = { js: ['camaleon_cms/admin/form/jquery.form'] }
127
127
  libs[:cropper] = {} # loaded by default
128
128
  libs[:post] =
129
- { js: ['camaleon_cms/admin/jquery.tagsinput.min', 'camaleon_cms/admin/post'],
129
+ { js: %w[camaleon_cms/admin/jquery.tagsinput.min camaleon_cms/admin/post],
130
130
  css: ['camaleon_cms/admin/jquery.tagsinput'] }
131
131
  libs[:multiselect] = { js: ['camaleon_cms/admin/bootstrap-select.js'] }
132
132
  libs[:validate] = { js: ['camaleon_cms/admin/jquery.validate'] }
133
133
  libs[:nav_menu] =
134
134
  { css: ['camaleon_cms/admin/nestable/jquery.nestable'],
135
- js: ['camaleon_cms/admin/jquery.nestable', 'camaleon_cms/admin/nav_menu'] }
135
+ js: %w[camaleon_cms/admin/jquery.nestable camaleon_cms/admin/nav_menu] }
136
136
  libs[:admin_intro] =
137
137
  { js: ['camaleon_cms/admin/introjs/intro.min'], css: ['camaleon_cms/admin/introjs/introjs.min'] }
138
138
  @_cama_assets_libraries = libs
@@ -127,7 +127,7 @@ module CamaleonCms
127
127
  # asset: (String) asset name
128
128
  # plugin_key: (optional) plugin name, default (current plugin caller to this function)
129
129
  # sample:
130
- # plugin_asset_url("css/main.css") => return: http://myhost.com/assets/plugins/my_plugin/assets/css/main-54505620f.css
130
+ # plugin_asset_url("css/main.css") => return: https://myhost.com/assets/plugins/my_plugin/assets/css/main-54505620f.css
131
131
  def plugin_asset_url(asset, plugin_key = nil)
132
132
  key = plugin_key || self_plugin_key(1)
133
133
  p = PluginRoutes.plugin_info(key)['gem_mode'] ? "plugins/#{key}/#{asset}" : "plugins/#{key}/assets/#{asset}"
@@ -6,7 +6,7 @@ module CamaleonCms
6
6
  # redirect_url (default nil): after initialized the session, this will be redirected to
7
7
  # "redirect_url" if defined
8
8
  # it doesn't redirect if redirect_url === false
9
- # return to previous page if defined the cookie['return_to'] or login url received extra param: return_to=http://mysite.com
9
+ # return to previous page if defined the cookie['return_to'] or login url received extra param: return_to=https://mysite.com
10
10
  def login_user(user, remember_me = false, redirect_url = nil)
11
11
  c = { value: [user.auth_token, request.user_agent, request.ip], expires: 24.hours.from_now }
12
12
  c[:domain] = :all if PluginRoutes.system_info['users_share_sites'].present? && CamaleonCms::Site.count > 1
@@ -15,7 +15,7 @@ module CamaleonCms
15
15
  return args[:shortcode] unless attrs.present?
16
16
 
17
17
  cama_load_libraries(*attrs['data'].to_s.split(','))
18
- return ''
18
+ ''
19
19
  },
20
20
  "Permit to load libraries on demand, sample: [load_libraries data='datepicker,tinymce']")
21
21
 
@@ -32,7 +32,7 @@ module CamaleonCms
32
32
  nil
33
33
  end
34
34
  unless r[:site].present?
35
- Rails.logger.error 'Camaleon CMS - Please define your current site: $current_site = CamaleonCms::Site.first.decorate or map your domains: http://camaleon.tuzitio.com/documentation/category/139779-examples/how.html'.cama_log_style(:red)
35
+ Rails.logger.error 'Camaleon CMS - Please define your current site: $current_site = CamaleonCms::Site.first.decorate or map your domains: https://camaleon.website/documentation/category/139779-examples/how.html'.cama_log_style(:red)
36
36
  end
37
37
  @current_site = r[:site]
38
38
  end
@@ -26,7 +26,7 @@ module CamaleonCms
26
26
  # asset: (String) asset name
27
27
  # theme_name: (optional) theme name, default (current theme caller to this function)
28
28
  # sample:
29
- # theme_asset_url("css/main.css") => return: http://myhost.com/assets/themes/my_theme/assets/css/main-54505620f.css
29
+ # theme_asset_url("css/main.css") => return: https://myhost.com/assets/themes/my_theme/assets/css/main-54505620f.css
30
30
  def theme_asset_url(asset, theme_name = nil)
31
31
  p = theme_asset_path(asset, theme_name)
32
32
  begin
@@ -1,7 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CamaleonCms
2
4
  module UploaderHelper
5
+ SUSPICIOUS_PATTERNS = [
6
+ /<script[\s>]/i, # Script tags
7
+ /on\w{3,}\s*=/i, # Inline event handlers like oncut, onload, onclick, etc.
8
+ /javascript:/i, # JavaScript in href/src attributes
9
+ /<iframe[\s>]/i, # Iframes
10
+ /<object[\s>]/i, # Object tags
11
+ /<embed[\s>]/i, # Embed tags
12
+ /<base[\s>]/i, # Base tags (can be used to manipulate URLs)
13
+ /data:/i # data: URLs (which can include scripts)
14
+ ].freeze
15
+
3
16
  include ActionView::Helpers::NumberHelper
4
17
  include CamaleonCms::CamaleonHelper
18
+
5
19
  # upload a file into server
6
20
  # settings:
7
21
  # folder: Directory where the file will be saved (default: "")
@@ -12,11 +26,12 @@ module CamaleonCms
12
26
  # formats: extensions permitted, sample: jpg,png,... or generic: images | videos | audios | documents (default *)
13
27
  # remove_source: Boolean (delete source file after saved if this is true, default false)
14
28
  # same_name: Boolean (save the file with the same name if defined true, else search for a non used name)
15
- # versions: (String) Create addtional multiple versions of the image uploaded, sample: '300x300,505x350' ==> Will create two extra images with these dimensions
16
- # sample "test.png", versions: '200x200,450x450' will generate: thumb/test-png_200x200.png, test-png_450x450.png
29
+ # versions: (String) Create additional multiple versions of the image uploaded,
30
+ # sample: '300x300,505x350' ==> Will create two extra images with these dimensions
31
+ # sample "test.png", versions: '200x200,450x450' will generate: thumb/test-png_200x200.png, test-png_450x450.png
17
32
  # thumb_size: String (redefine the dimensions of the thumbnail, sample: '100x100' ==> only for images)
18
33
  # temporal_time: if great than 0 seconds, then this file will expire (removed) in that time (default: 0)
19
- # To manage jobs, please check http://edgeguides.rubyonrails.org/active_job_basics.html
34
+ # To manage jobs, please check https://edgeguides.rubyonrails.org/active_job_basics.html
20
35
  # Note: if you are using temporal_time, you will need to copy the file to another directory later
21
36
  # sample: upload_file(params[:my_file], {formats: "images", folder: "temporal"})
22
37
  # sample: upload_file(params[:my_file], {formats: "jpg,png,gif,mp3,mp4", temporal_time: 10.minutes, maximum: 10.megabytes})
@@ -36,6 +51,8 @@ module CamaleonCms
36
51
  uploaded_io = File.open(cama_resize_upload(uploaded_io.path, settings[:dimension]))
37
52
  end
38
53
 
54
+ return { error: 'Potentially malicious content found!' } if file_content_unsafe?(uploaded_io)
55
+
39
56
  settings = settings.to_sym
40
57
  settings[:uploaded_io] = uploaded_io
41
58
  settings = {
@@ -45,7 +62,7 @@ module CamaleonCms
45
62
  generate_thumb: true,
46
63
  temporal_time: 0,
47
64
  filename: begin
48
- (cached_name || uploaded_io.original_filename)
65
+ cached_name || uploaded_io.original_filename
49
66
  rescue StandardError
50
67
  uploaded_io.path.split('/').last
51
68
  end.cama_fix_filename,
@@ -54,10 +71,13 @@ module CamaleonCms
54
71
  same_name: false,
55
72
  versions: '',
56
73
  thumb_size: nil
57
- }.merge(settings)
74
+ }.merge!(settings)
58
75
  hooks_run('before_upload', settings)
59
76
  res = { error: nil }
60
77
 
78
+ # guard against path traversal
79
+ return { error: 'Invalid file path' } unless cama_uploader.class.valid_folder_path?(settings[:folder])
80
+
61
81
  # formats validations
62
82
  return { error: "#{ct('file_format_error')} (#{settings[:formats]})" } unless cama_uploader.class.validate_file_format(
63
83
  uploaded_io.path, settings[:formats]
@@ -72,7 +92,6 @@ module CamaleonCms
72
92
  # save file
73
93
  key = File.join(settings[:folder], settings[:filename]).to_s.cama_fix_slash
74
94
  res = cama_uploader.add_file(settings[:uploaded_io], key, { same_name: settings[:same_name] })
75
- {} if (settings[:temporal_time]).positive?
76
95
 
77
96
  # generate image versions
78
97
  if res['file_type'] == 'image'
@@ -92,6 +111,12 @@ module CamaleonCms
92
111
  FileUtils.rm_f(uploaded_io.path) if settings[:remove_source] && File.exist?(uploaded_io.path)
93
112
 
94
113
  hooks_run('after_upload', settings)
114
+
115
+ # temporal file upload (always put as local for temporal files)
116
+ if settings[:temporal_time] > 0
117
+ CamaleonCmsUploader.delete_block.call(settings, cama_uploader, key)
118
+ end
119
+
95
120
  res
96
121
  end
97
122
 
@@ -189,7 +214,7 @@ module CamaleonCms
189
214
  # Return: (String) file path where saved this cropped
190
215
  # sample: cama_resize_and_crop(my_file, 200, 200, {gravity: :north_east, overwrite: false})
191
216
  def cama_resize_and_crop(file, w, h, settings = {})
192
- settings = { gravity: :north_east, overwrite: true, output_name: '' }.merge(settings)
217
+ settings = { gravity: :north_east, overwrite: true, output_name: +'' }.merge!(settings)
193
218
  img = MiniMagick::Image.open(file)
194
219
  if file.end_with? '.svg'
195
220
  img.format 'jpg'
@@ -237,7 +262,7 @@ module CamaleonCms
237
262
  # upload tmp file
238
263
  # support for url and local path
239
264
  # sample:
240
- # cama_tmp_upload('http://camaleon.tuzitio.com/media/132/logo2.png') ==> /var/rails/my_project/public/tmp/1/logo2.png
265
+ # cama_tmp_upload('https://camaleon.website/media/132/logo2.png') ==> /var/rails/my_project/public/tmp/1/logo2.png
241
266
  # cama_tmp_upload('/var/www/media/132/logo 2.png') ==> /var/rails/my_project/public/tmp/1/logo-2.png
242
267
  # accept args:
243
268
  # name: to indicate the name to use, sample: cama_tmp_upload('/var/www/media/132/logo 2.png', {name: 'owen.png', formats: 'images'})
@@ -295,10 +320,11 @@ module CamaleonCms
295
320
 
296
321
  # resize image if the format is correct
297
322
  # return resized file path
298
- def cama_resize_upload(image_path, dimesion, args = {})
299
- if cama_uploader.class.validate_file_format(image_path, 'image') && dimesion.present?
300
- r = { file: image_path, w: dimesion.split('x')[0], h: dimesion.split('x')[1], w_offset: 0, h_offset: 0,
301
- resize: !dimesion.split('x')[2] || dimesion.split('x')[2] == 'resize', replace: true, gravity: :north_east }.merge(args)
323
+ def cama_resize_upload(image_path, dimension, args = {})
324
+ if cama_uploader.class.validate_file_format(image_path, 'image') && dimension.present?
325
+ r = { file: image_path, w: dimension.split('x')[0], h: dimension.split('x')[1], w_offset: 0, h_offset: 0,
326
+ resize: !dimension.split('x')[2] || dimension.split('x')[2] == 'resize',
327
+ replace: true, gravity: :north_east }.merge!(args)
302
328
  hooks_run('on_uploader_resize', r)
303
329
  image_path = if r[:w].present? && r[:h].present?
304
330
  cama_resize_and_crop(r[:file], r[:w], r[:h], { overwrite: r[:replace], gravity: r[:gravity] })
@@ -324,12 +350,12 @@ module CamaleonCms
324
350
  cloud_front: current_site.get_option('filesystem_s3_cloudfront'),
325
351
  aws_file_upload_settings: lambda { |settings|
326
352
  settings
327
- }, # permit to add your custom attributes for file_upload http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html#upload_file-instance_method
353
+ }, # permit to add your custom attributes for file_upload https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html#upload_file-instance_method
328
354
  aws_file_read_settings: lambda { |data, _s3_file|
329
355
  data
330
356
  } # permit to read custom attributes from aws file and add to file parsed object
331
357
  },
332
- custom_uploader: nil # posibility to use custom file uploader
358
+ custom_uploader: nil # possibility to use custom file uploader
333
359
  }
334
360
  hooks_run('on_uploader', args)
335
361
  return args[:custom_uploader] if args[:custom_uploader].present?
@@ -350,13 +376,30 @@ module CamaleonCms
350
376
  end
351
377
 
352
378
  def slugify_folder(val)
353
- splitted_folder = val.split('/')
354
- splitted_folder[-1] = slugify(splitted_folder.last)
355
- splitted_folder.join('/')
379
+ split_folder = val.split('/')
380
+ split_folder[-1] = slugify(split_folder.last)
381
+ split_folder.join('/')
356
382
  end
357
383
 
358
384
  private
359
385
 
386
+ def file_content_unsafe?(uploaded_io)
387
+ file = uploaded_io.is_a?(ActionDispatch::Http::UploadedFile) ? uploaded_io.tempfile : uploaded_io
388
+ file_content_unsafe = nil
389
+
390
+ file.set_encoding(Encoding::BINARY) if file.respond_to?(:binmode) && file.respond_to?(:set_encoding)
391
+
392
+ file_content = file.read
393
+ SUSPICIOUS_PATTERNS.each do |pattern|
394
+ if file_content =~ pattern
395
+ Rails.logger.info { "Potentially malicious content found: #{pattern.inspect}" }
396
+ break file_content_unsafe = pattern.inspect
397
+ end
398
+ end
399
+
400
+ file_content_unsafe
401
+ end
402
+
360
403
  # helper for resize and crop method
361
404
  def cama_crop_offsets_by_gravity(gravity, original_dimensions, cropped_dimensions)
362
405
  original_width, original_height = original_dimensions
@@ -105,7 +105,7 @@ module CamaleonCms
105
105
  end
106
106
 
107
107
  # support for custom abilities for each posttype
108
- # sample: http://camaleon.tuzitio.com/documentation/category/40756-uncategorized/custom-models.html
108
+ # sample: https://camaleon.website/documentation/category/40756-uncategorized/custom-models.html
109
109
  @roles_post_type.each do |k, v|
110
110
  next if %w[edit edit_other edit_publish publish manage_categories].include?(k.to_s)
111
111
 
@@ -5,8 +5,8 @@ module CamaleonCms
5
5
  alias_attribute :site_id, :parent_id
6
6
 
7
7
  default_scope do
8
- where.not(object_class: '_fields')
9
- .reorder("#{CamaleonCms::CustomField.table_name}.field_order ASC")
8
+ where("object_class != '_fields'")
9
+ .reorder("#{CamaleonCms::CustomField.table_name}.field_order ASC")
10
10
  end
11
11
 
12
12
  has_many :metas, -> { where(object_class: 'CustomFieldGroup') }, foreign_key: :objectid, dependent: :destroy
@@ -24,12 +24,9 @@ module CamaleonCms
24
24
  # - options (textbox sample): {"field_key":"text_box","multiple":"1","required":"1",
25
25
  # "translate":"1"}
26
26
  # * field_key (string) | translate (boolean) | default_value (unique value) |
27
- # default_values (array - multiple values for this field) | label_eval (boolean) |
28
- # multiple_options (array)
27
+ # default_values (array - multiple values for this field) | multiple_options (array)
29
28
  # * multiple_options (used for select, radio and checkboxes ): [{"title"=>"Option Title",
30
29
  # "value"=>"2", "default"=>"1"}, {"title"=>"abcde", "value"=>"3"}]
31
- # * label_eval: (Boolean, default false), true => will evaluate the label and description of
32
- # current field using (eval('my_label')) to have translatable|dynamic labels
33
30
  # ****** check all options for each case in Admin::CustomFieldsHelper ****
34
31
  # SAMPLE: my_model.add_field({"name"=>"Sub Title", "slug"=>"subtitle"}, {"field_key"=>"text_box",
35
32
  # "translate"=>true, default_value: "Get in Touch"})
@@ -10,7 +10,7 @@ module CamaleonCms
10
10
  # add menu item for current menu
11
11
  # value: (Hash) is a hash object that contains label, type, link
12
12
  # options for type: post | category | post_type | post_tag | external
13
- # sample: {label: "my label", type: "external", link: "http://camaleon.tuzitio.com", target: '_blank'}
13
+ # sample: {label: "my label", type: "external", link: "https://camaleon.website", target: '_blank'}
14
14
  # sample: {label: "my label", type: "post", link: 10}
15
15
  # sample: {label: "my label", type: "category", link: 12}
16
16
  # return item created
@@ -42,7 +42,7 @@ module CamaleonCms
42
42
  validates_with CamaleonCms::PostUniqValidator
43
43
  attr_accessor :show_title_with_parent
44
44
 
45
- before_create :fix_post_order, if: ->(p) { !p.post_order.present? || p.post_order.zero? }
45
+ before_create :fix_post_order, if: ->(p) { !p.post_order.present? || p.post_order == 0 }
46
46
 
47
47
  # return all parents for current page hierarchy ordered bottom to top
48
48
  def parents
@@ -42,7 +42,7 @@ module CamaleonCms
42
42
  res = where("#{CamaleonCms::Post.table_name}.slug = ? OR #{CamaleonCms::Post.table_name}.slug LIKE ? ", slug,
43
43
  "%-->#{slug}<!--%")
44
44
  # end
45
- res.reorder('').first
45
+ res.take
46
46
  end
47
47
 
48
48
  # return the parent of a post (support for sub contents or tree of posts)