chef-server-webui 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +135 -0
  3. data/Rakefile +62 -0
  4. data/app/controllers/application.rb +281 -0
  5. data/app/controllers/clients.rb +120 -0
  6. data/app/controllers/cookbook_attributes.rb +41 -0
  7. data/app/controllers/cookbook_definitions.rb +41 -0
  8. data/app/controllers/cookbook_files.rb +39 -0
  9. data/app/controllers/cookbook_libraries.rb +41 -0
  10. data/app/controllers/cookbook_recipes.rb +40 -0
  11. data/app/controllers/cookbook_templates.rb +57 -0
  12. data/app/controllers/cookbooks.rb +78 -0
  13. data/app/controllers/databag_items.rb +102 -0
  14. data/app/controllers/databags.rb +83 -0
  15. data/app/controllers/exceptions.rb +19 -0
  16. data/app/controllers/main.rb +7 -0
  17. data/app/controllers/nodes.rb +138 -0
  18. data/app/controllers/openid_consumer.rb +154 -0
  19. data/app/controllers/roles.rb +144 -0
  20. data/app/controllers/search.rb +62 -0
  21. data/app/controllers/search_entries.rb +64 -0
  22. data/app/controllers/status.rb +39 -0
  23. data/app/controllers/users.rb +186 -0
  24. data/app/helpers/application_helper.rb +171 -0
  25. data/app/helpers/cookbook_attributes_helper.rb +7 -0
  26. data/app/helpers/cookbook_definitions_helper.rb +8 -0
  27. data/app/helpers/cookbook_files_helper.rb +8 -0
  28. data/app/helpers/cookbook_libraries_helper.rb +7 -0
  29. data/app/helpers/cookbook_recipes_helper.rb +8 -0
  30. data/app/helpers/cookbook_templates_helper.rb +8 -0
  31. data/app/helpers/exceptions_helper.rb +6 -0
  32. data/app/helpers/global_helpers.rb +35 -0
  33. data/app/helpers/nodes_helper.rb +41 -0
  34. data/app/helpers/openid_consumer_helper.rb +8 -0
  35. data/app/helpers/openid_register_helper.rb +8 -0
  36. data/app/helpers/openid_server_helper.rb +6 -0
  37. data/app/helpers/openid_server_helpers.rb +29 -0
  38. data/app/helpers/roles_helper.rb +5 -0
  39. data/app/helpers/search_entries_helper.rb +8 -0
  40. data/app/helpers/search_helper.rb +38 -0
  41. data/app/helpers/status_helper.rb +26 -0
  42. data/app/views/clients/_form.html.haml +22 -0
  43. data/app/views/clients/_navigation.html.haml +9 -0
  44. data/app/views/clients/edit.html.haml +6 -0
  45. data/app/views/clients/index.html.haml +21 -0
  46. data/app/views/clients/new.html.haml +6 -0
  47. data/app/views/clients/show.html.haml +20 -0
  48. data/app/views/cookbooks/index.html.haml +10 -0
  49. data/app/views/cookbooks/show.html.haml +40 -0
  50. data/app/views/databag_items/_form.html.haml +14 -0
  51. data/app/views/databag_items/_navigation.html.haml +9 -0
  52. data/app/views/databag_items/edit.html.haml +6 -0
  53. data/app/views/databag_items/index.html.haml +0 -0
  54. data/app/views/databag_items/new.html.haml +6 -0
  55. data/app/views/databag_items/show.html.haml +9 -0
  56. data/app/views/databags/_form.html.haml +12 -0
  57. data/app/views/databags/_item_navigation.html.haml +8 -0
  58. data/app/views/databags/_navigation.html.haml +9 -0
  59. data/app/views/databags/edit.html.haml +6 -0
  60. data/app/views/databags/index.html.haml +19 -0
  61. data/app/views/databags/new.html.haml +6 -0
  62. data/app/views/databags/show.html.haml +19 -0
  63. data/app/views/exceptions/bad_request.json.erb +1 -0
  64. data/app/views/exceptions/internal_server_error.html.erb +216 -0
  65. data/app/views/exceptions/not_acceptable.html.erb +63 -0
  66. data/app/views/exceptions/not_found.html.erb +47 -0
  67. data/app/views/exceptions/standard_error.html.erb +217 -0
  68. data/app/views/layout/_jsonedit.html.haml +82 -0
  69. data/app/views/layout/chef_server_webui.html.haml +56 -0
  70. data/app/views/layout/login.html.haml +36 -0
  71. data/app/views/main/index.html.erb +1 -0
  72. data/app/views/nodes/_action.html.haml +13 -0
  73. data/app/views/nodes/_form.html.haml +53 -0
  74. data/app/views/nodes/_navigation.html.haml +9 -0
  75. data/app/views/nodes/_resource.html.haml +22 -0
  76. data/app/views/nodes/edit.html.haml +7 -0
  77. data/app/views/nodes/index.html.haml +25 -0
  78. data/app/views/nodes/new.html.haml +6 -0
  79. data/app/views/nodes/show.html.haml +60 -0
  80. data/app/views/openid_consumer/index.html.haml +28 -0
  81. data/app/views/openid_consumer/start.html.haml +4 -0
  82. data/app/views/openid_login/index.html.haml +5 -0
  83. data/app/views/openid_register/index.html.haml +19 -0
  84. data/app/views/openid_register/show.html.haml +7 -0
  85. data/app/views/roles/_form.html.haml +53 -0
  86. data/app/views/roles/_navigation.html.haml +9 -0
  87. data/app/views/roles/edit.html.haml +6 -0
  88. data/app/views/roles/index.html.haml +21 -0
  89. data/app/views/roles/new.html.haml +6 -0
  90. data/app/views/roles/show.html.haml +54 -0
  91. data/app/views/search/_search_form.html.haml +6 -0
  92. data/app/views/search/index.html.haml +8 -0
  93. data/app/views/search/show.html.haml +13 -0
  94. data/app/views/search_entries/index.html.haml +8 -0
  95. data/app/views/search_entries/show.html.haml +7 -0
  96. data/app/views/status/index.html.haml +90 -0
  97. data/app/views/users/_form.html.haml +39 -0
  98. data/app/views/users/_navigation.html.haml +9 -0
  99. data/app/views/users/edit.html.haml +6 -0
  100. data/app/views/users/index.html.haml +20 -0
  101. data/app/views/users/login.html.haml +16 -0
  102. data/app/views/users/new.html.haml +27 -0
  103. data/app/views/users/show.html.haml +13 -0
  104. data/app/views/users/start.html.haml +4 -0
  105. data/config.ru +84 -0
  106. data/config/init.rb +49 -0
  107. data/config/router.rb +6 -0
  108. data/lib/chef-server-webui.rb +155 -0
  109. data/lib/chef-server-webui/merbtasks.rb +103 -0
  110. data/lib/chef-server-webui/slicetasks.rb +20 -0
  111. data/lib/chef-server-webui/spectasks.rb +53 -0
  112. data/public/facebox/README.txt +4 -0
  113. data/public/facebox/b.png +0 -0
  114. data/public/facebox/bl.png +0 -0
  115. data/public/facebox/br.png +0 -0
  116. data/public/facebox/closelabel.gif +0 -0
  117. data/public/facebox/facebox.css +95 -0
  118. data/public/facebox/facebox.js +319 -0
  119. data/public/facebox/loading.gif +0 -0
  120. data/public/facebox/tl.png +0 -0
  121. data/public/facebox/tr.png +0 -0
  122. data/public/images/avatar.png +0 -0
  123. data/public/images/black_big.png +0 -0
  124. data/public/images/indicator.gif +0 -0
  125. data/public/images/jsonedit/add2.png +0 -0
  126. data/public/images/jsonedit/build-button.png +0 -0
  127. data/public/images/jsonedit/bullet.gif +0 -0
  128. data/public/images/jsonedit/bullet_orange.png +0 -0
  129. data/public/images/jsonedit/cross.png +0 -0
  130. data/public/images/jsonedit/delete.png +0 -0
  131. data/public/images/jsonedit/deleted.png +0 -0
  132. data/public/images/jsonedit/json.jpg +0 -0
  133. data/public/images/jsonedit/label.gif +0 -0
  134. data/public/images/jsonedit/minus.gif +0 -0
  135. data/public/images/jsonedit/pixel.gif +0 -0
  136. data/public/images/jsonedit/plus.gif +0 -0
  137. data/public/images/jsonedit/saved.png +0 -0
  138. data/public/images/jsonedit/table_refresh.png +0 -0
  139. data/public/images/jsonedit/value.gif +0 -0
  140. data/public/images/merb.jpg +0 -0
  141. data/public/images/toggle-collapse-dark.png +0 -0
  142. data/public/images/toggle-collapse-light.png +0 -0
  143. data/public/images/toggle-collapse.gif +0 -0
  144. data/public/images/toggle-expand-dark.png +0 -0
  145. data/public/images/toggle-expand-light.png +0 -0
  146. data/public/images/toggle-expand.gif +0 -0
  147. data/public/images/treeBuilderImages/Thumbs.db +0 -0
  148. data/public/images/treeBuilderImages/doc.gif +0 -0
  149. data/public/images/treeBuilderImages/docNode.gif +0 -0
  150. data/public/images/treeBuilderImages/docNodeLast.gif +0 -0
  151. data/public/images/treeBuilderImages/docNodeLastFirst.gif +0 -0
  152. data/public/images/treeBuilderImages/folder.gif +0 -0
  153. data/public/images/treeBuilderImages/folderNode.gif +0 -0
  154. data/public/images/treeBuilderImages/folderNodeFirst.gif +0 -0
  155. data/public/images/treeBuilderImages/folderNodeLast.gif +0 -0
  156. data/public/images/treeBuilderImages/folderNodeLastFirst.gif +0 -0
  157. data/public/images/treeBuilderImages/folderNodeOpen.gif +0 -0
  158. data/public/images/treeBuilderImages/folderNodeOpenFirst.gif +0 -0
  159. data/public/images/treeBuilderImages/folderNodeOpenLast.gif +0 -0
  160. data/public/images/treeBuilderImages/folderNodeOpenLastFirst.gif +0 -0
  161. data/public/images/treeBuilderImages/folderOpen.gif +0 -0
  162. data/public/images/treeBuilderImages/vertLine.gif +0 -0
  163. data/public/javascripts/chef.js +160 -0
  164. data/public/javascripts/jquery-1.3.2.min.js +19 -0
  165. data/public/javascripts/jquery-ui-1.7.1.custom.min.js +65 -0
  166. data/public/javascripts/jquery.editinline.js +108 -0
  167. data/public/javascripts/jquery.jeditable.mini.js +30 -0
  168. data/public/javascripts/jquery.livequery.js +250 -0
  169. data/public/javascripts/jquery.localscroll.js +104 -0
  170. data/public/javascripts/jquery.scrollTo.js +150 -0
  171. data/public/javascripts/jquery.tools.min.js +17 -0
  172. data/public/javascripts/jquery.treeTable.min.js +165 -0
  173. data/public/javascripts/json.js +153 -0
  174. data/public/javascripts/jsonedit_main.js +675 -0
  175. data/public/javascripts/yetii-min.js +1 -0
  176. data/public/stylesheets/base.css +336 -0
  177. data/public/stylesheets/chef.css +157 -0
  178. data/public/stylesheets/images/ui-bg_diagonals-small_0_aaaaaa_40x40.png +0 -0
  179. data/public/stylesheets/images/ui-bg_diagonals-thick_15_444444_40x40.png +0 -0
  180. data/public/stylesheets/images/ui-bg_glass_100_f0f0f0_1x400.png +0 -0
  181. data/public/stylesheets/images/ui-bg_glass_50_99c2ff_1x400.png +0 -0
  182. data/public/stylesheets/images/ui-bg_glass_55_fbf5d0_1x400.png +0 -0
  183. data/public/stylesheets/images/ui-bg_glass_80_e6e6e6_1x400.png +0 -0
  184. data/public/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  185. data/public/stylesheets/images/ui-bg_highlight-hard_100_f9f9f9_1x100.png +0 -0
  186. data/public/stylesheets/images/ui-bg_highlight-soft_100_e7eef3_1x100.png +0 -0
  187. data/public/stylesheets/images/ui-icons_222222_256x240.png +0 -0
  188. data/public/stylesheets/images/ui-icons_2694e8_256x240.png +0 -0
  189. data/public/stylesheets/images/ui-icons_2e83ff_256x240.png +0 -0
  190. data/public/stylesheets/images/ui-icons_72a7cf_256x240.png +0 -0
  191. data/public/stylesheets/images/ui-icons_888888_256x240.png +0 -0
  192. data/public/stylesheets/images/ui-icons_cd0a0a_256x240.png +0 -0
  193. data/public/stylesheets/images/ui-icons_ffffff_256x240.png +0 -0
  194. data/public/stylesheets/jquery-ui-1.7.1.custom.css +404 -0
  195. data/public/stylesheets/jquery.treeTable.css +43 -0
  196. data/public/stylesheets/jsonedit_main.css +280 -0
  197. data/public/stylesheets/themes/bec-green/style.css +290 -0
  198. data/public/stylesheets/themes/bec/style.css +301 -0
  199. data/public/stylesheets/themes/blue/style.css +280 -0
  200. data/public/stylesheets/themes/default/style.css +267 -0
  201. data/public/stylesheets/themes/djime-cerulean/style.css +298 -0
  202. data/public/stylesheets/themes/kathleene/style.css +272 -0
  203. data/public/stylesheets/themes/orange/style.css +263 -0
  204. data/public/stylesheets/themes/reidb-greenish/style.css +301 -0
  205. data/stubs/app/controllers/application.rb +2 -0
  206. data/stubs/app/controllers/main.rb +2 -0
  207. metadata +399 -0
@@ -0,0 +1,144 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Nuo Yan (<nuo@opscode.com>)
4
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'chef/role'
21
+
22
+ class ChefServerWebui::Roles < ChefServerWebui::Application
23
+
24
+ provides :html
25
+ before :login_required
26
+
27
+ # GET /roles
28
+ def index
29
+ @role_list = begin
30
+ Chef::Role.list()
31
+ rescue => e
32
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
33
+ @_message = {:error => "Could not list roles"}
34
+ {}
35
+ end
36
+ render
37
+ end
38
+
39
+ # GET /roles/:id
40
+ def show
41
+ @role = begin
42
+ Chef::Role.load(params[:id])
43
+ rescue => e
44
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
45
+ @_message = {:error => "Could not load role #{params[:id]}"}
46
+ Chef::Role.new
47
+ end
48
+ render
49
+ end
50
+
51
+ # GET /roles/new
52
+ def new
53
+ begin
54
+ @available_recipes = get_available_recipes
55
+ @role = Chef::Role.new
56
+ @available_roles = Chef::Role.list.keys.sort
57
+ @run_list = @role.run_list
58
+ render
59
+ rescue => e
60
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
61
+ @role_list = Chef::Role.list()
62
+ @_message = {:error => "Could not load available recipes, roles, or the run list."}
63
+ render :index
64
+ end
65
+ end
66
+
67
+ # GET /roles/:id/edit
68
+ def edit
69
+ begin
70
+ @role = Chef::Role.load(params[:id])
71
+ @available_recipes = get_available_recipes
72
+ @available_roles = Chef::Role.list.keys.sort
73
+ @run_list = @role.run_list
74
+ rescue => e
75
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
76
+ @role = Chef::Role.new
77
+ @available_recipes = []
78
+ @available_roles = []
79
+ @run_list = []
80
+ @_message = {:error => "Could not load role #{params[:id]}, the available recipes, roles, or the run list"}
81
+ end
82
+ render
83
+ end
84
+
85
+ # POST /roles
86
+ def create
87
+ begin
88
+ @role = Chef::Role.new
89
+ @role.name(params[:name])
90
+ @role.run_list(params[:for_role] ? params[:for_role] : [])
91
+ @role.description(params[:description]) if params[:description] != ''
92
+ @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != ''
93
+ @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != ''
94
+ @role.create
95
+ redirect(slice_url(:roles), :message => { :notice => "Created Role #{@role.name}" })
96
+ rescue => e
97
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
98
+ @available_recipes = get_available_recipes
99
+ @role = Chef::Role.new
100
+ @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != ''
101
+ @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != ''
102
+ @run_list = params[:for_role] ? params[:for_role] : []
103
+ @_message = { :error => "Could not create role" }
104
+ render :new
105
+ end
106
+ end
107
+
108
+ # PUT /roles/:id
109
+ def update
110
+ begin
111
+ @role = Chef::Role.load(params[:id])
112
+ @role.run_list(params[:for_role] ? params[:for_role] : [])
113
+ @role.description(params[:description]) if params[:description] != ''
114
+ @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != ''
115
+ @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != ''
116
+ @role.save
117
+ @_message = { :notice => "Updated Role" }
118
+ render :show
119
+ rescue => e
120
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
121
+ @available_recipes = get_available_recipes
122
+ @run_list = params[:for_role] ? params[:for_role] : []
123
+ @role.default_attributes(JSON.parse(params[:default_attributes])) if params[:default_attributes] != ''
124
+ @role.override_attributes(JSON.parse(params[:override_attributes])) if params[:override_attributes] != ''
125
+ @_message = {:error => "Could not update role #{params[:id]}"}
126
+ render :edit
127
+ end
128
+ end
129
+
130
+ # DELETE /roles/:id
131
+ def destroy
132
+ begin
133
+ @role = Chef::Role.load(params[:id])
134
+ @role.destroy
135
+ redirect(absolute_slice_url(:roles), :message => { :notice => "Role #{@role.name} deleted successfully." }, :permanent => true)
136
+ rescue => e
137
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
138
+ @role_list = Chef::Role.list()
139
+ @_message = {:error => "Could not delete role #{params[:id]}"}
140
+ render :index
141
+ end
142
+ end
143
+
144
+ end
@@ -0,0 +1,62 @@
1
+ #
2
+ # Author:: Nuo Yan (<nuo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2009 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef' / 'search' / 'query'
20
+
21
+ class ChefServerWebui::Search < ChefServerWebui::Application
22
+
23
+ provides :html
24
+ before :login_required
25
+
26
+ def index
27
+ @s = Chef::Search::Query.new
28
+ @search_indexes = begin
29
+ @s.list_indexes
30
+ rescue => e
31
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
32
+ @_message = {:error => "Could not list search indexes"}
33
+ {}
34
+ end
35
+ render
36
+ end
37
+
38
+ def show
39
+ begin
40
+ @s = Chef::Search::Query.new
41
+ query = params[:q].nil? ? "*:*" : (params[:q].empty? ? "*:*" : params[:q])
42
+ @results = @s.search(params[:id], query)
43
+ @type = if params[:id].to_s == "node" || params[:id].to_s == "role" || params[:id].to_s == "client"
44
+ params[:id]
45
+ else
46
+ "databag"
47
+ end
48
+ @results = @results - @results.last(2)
49
+ @results.each do |result|
50
+ result.delete(nil)
51
+ end
52
+ @results
53
+ render
54
+ rescue => e
55
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
56
+ @_message = { :error => "Unable to find the #{params[:id]}. (#{$!})" }
57
+ @search_indexes = @s.list_indexes
58
+ render :index
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Christopher Brown (<cb@opscode.com>)
4
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ #require 'chef' / 'search'
21
+ #require 'chef' / 'queue'
22
+
23
+ class ChefServerWebui::SearchEntries < ChefServerWebui::Application
24
+
25
+ provides :html
26
+ before :login_required
27
+
28
+ def index
29
+ @s = Chef::Search.new
30
+ @entries = @s.search(params[:search_id])
31
+ render
32
+ end
33
+
34
+ def show
35
+ @s = Chef::Search.new
36
+ @entry = @s.search(params[:search_id], "id:'#{params[:search_id]}_#{params[:id]}'").first
37
+ render
38
+ end
39
+
40
+ def create
41
+ @to_index = params
42
+ @to_index.delete(:controller)
43
+ @to_index["index_name"] = params[:search_id]
44
+ @to_index["id"] = "#{params[:search_id]}_#{params[:id]}"
45
+ @to_index.delete(:search_id)
46
+ Chef::Queue.send_msg(:queue, :index, @to_index)
47
+ redirect url(:search)
48
+ end
49
+
50
+ def update
51
+ create
52
+ end
53
+
54
+ def destroy
55
+ @s = Chef::Search.new
56
+ @entries = @s.search(params[:id])
57
+ @entries.each do |entry|
58
+ Chef::Queue.send_msg(:queue, :remove, entry)
59
+ end
60
+ @status = 202
61
+ redirect url(:search)
62
+ end
63
+
64
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: Joe Williams (joe@joetify.com)
3
+ # Author:: Nuo Yan (nuo@opscode.com)
4
+ # Copyright:: Copyright (c) 2009 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'chef' / 'node'
21
+
22
+ class ChefServerWebui::Status < ChefServerWebui::Application
23
+
24
+ provides :html
25
+ before :login_required
26
+
27
+ def index
28
+ begin
29
+ @status = Chef::Node.list(true)
30
+ render
31
+ rescue => e
32
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
33
+ @status = {}
34
+ @_message = {:error => "Could not list status"}
35
+ render
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,186 @@
1
+ #
2
+ # Author:: Nuo Yan (<nuo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef'/'webui_user'
20
+ require 'uri'
21
+ require 'merb-param-protection'
22
+
23
+ class ChefServerWebui::Users < ChefServerWebui::Application
24
+
25
+ provides :html
26
+ before :login_required, :exclude => [:login, :login_exec, :complete]
27
+ log_params_filtered :password, :password2, :new_password, :confirm_new_password
28
+
29
+ # List users, only if the user is admin.
30
+ def index
31
+ begin
32
+ authorized_user
33
+ @users = Chef::WebUIUser.list
34
+ render
35
+ rescue => e
36
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
37
+ set_user_and_redirect
38
+ end
39
+ end
40
+
41
+ # Edit user. Admin can edit everyone, non-admin user can only edit itself.
42
+ def edit
43
+ begin
44
+ raise Forbidden, "The current user is not an Administrator, you can only Show and Edit the user itself. To control other users, login as an Administrator." unless params[:user_id] == session[:user] unless session[:level] == :admin
45
+ @user = Chef::WebUIUser.load(params[:user_id])
46
+ render
47
+ rescue => e
48
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
49
+ set_user_and_redirect
50
+ end
51
+ end
52
+
53
+ # Show the details of a user. If the user is not admin, only able to show itself; otherwise able to show everyone
54
+ def show
55
+ begin
56
+ raise Forbidden, "The current user is not an Administrator, you can only Show and Edit the user itself. To control other users, login as an Administrator." unless params[:user_id] == session[:user] unless session[:level] == :admin
57
+ @user = Chef::WebUIUser.load(params[:user_id])
58
+ render
59
+ rescue => e
60
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
61
+ set_user_and_redirect
62
+ end
63
+ end
64
+
65
+ # PUT to /users/:user_id/update
66
+ def update
67
+ begin
68
+ @user = Chef::WebUIUser.load(params[:user_id])
69
+
70
+ if session[:level] == :admin and ['true','false'].include? params[:admin]
71
+ @user.admin = str_to_bool(params[:admin])
72
+ end
73
+
74
+ if params[:user_id] == session[:user] && params[:admin] == 'false'
75
+ session[:level] = :user
76
+ end
77
+
78
+ if not params[:new_password].nil? and not params[:new_password].length == 0
79
+ @user.set_password(params[:new_password], params[:confirm_new_password])
80
+ end
81
+
82
+ if params[:openid].length == 0 or params[:openid].nil?
83
+ @user.set_openid(nil)
84
+ else
85
+ @user.set_openid(URI.parse(params[:openid]).normalize.to_s)
86
+ end
87
+ @user.save
88
+ @_message = { :notice => "Updated User #{@user.name}" }
89
+ render :show
90
+ rescue => e
91
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
92
+ @_message = { :error => "Could not update user" }
93
+ render :edit
94
+ end
95
+ end
96
+
97
+ def new
98
+ begin
99
+ authorized_user
100
+ @user = Chef::WebUIUser.new
101
+ render
102
+ rescue => e
103
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
104
+ set_user_and_redirect
105
+ end
106
+ end
107
+
108
+ def create
109
+ begin
110
+ authorized_user
111
+ @user = Chef::WebUIUser.new
112
+ @user.name = params[:name]
113
+ @user.set_password(params[:password], params[:password2])
114
+ @user.admin = true if params[:admin]
115
+ (params[:openid].length == 0 || params[:openid].nil?) ? @user.set_openid(nil) : @user.set_openid(URI.parse(params[:openid]).normalize.to_s)
116
+ @user.create
117
+ redirect(slice_url(:users), :message => { :notice => "Created User #{params[:name]}" })
118
+ rescue => e
119
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
120
+ @_message = { :error => "Could not create user" }
121
+ session[:level] != :admin ? set_user_and_redirect : (render :new)
122
+ end
123
+ end
124
+
125
+ def login
126
+ @user = Chef::WebUIUser.new
127
+ session[:user] ? redirect(slice_url(:nodes), :message => { :warning => "You've already logged in with user #{session[:user]}" }) : (render :layout => 'login')
128
+ end
129
+
130
+ def login_exec
131
+ begin
132
+ @user = Chef::WebUIUser.load(params[:name])
133
+ raise(Unauthorized, "Wrong username or password.") unless @user.verify_password(params[:password])
134
+ complete
135
+ rescue => e
136
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
137
+ @user = Chef::WebUIUser.new
138
+ @_message = { :error => "Could not complete logging in." }
139
+ render :login
140
+ end
141
+ end
142
+
143
+ def complete
144
+ session[:user] = params[:name]
145
+ session[:level] = (@user.admin == true ? :admin : :user)
146
+ (@user.name == Chef::Config[:web_ui_admin_user_name] && @user.verify_password(Chef::Config[:web_ui_admin_default_password])) ? redirect(slice_url(:users_edit, :user_id => @user.name), :message => { :warning => "Please change the default password" }) : redirect_back_or_default(absolute_slice_url(:nodes))
147
+ end
148
+
149
+ def logout
150
+ cleanup_session
151
+ redirect slice_url(:top)
152
+ end
153
+
154
+ def destroy
155
+ begin
156
+ raise Forbidden, "The last admin user cannot be deleted" if (is_admin(params[:user_id]) && is_last_admin)
157
+ raise Forbidden, "A non-admin user can only delete itself" if (params[:user_id] != session[:user] && session[:level] != :admin)
158
+ @user = Chef::WebUIUser.load(params[:user_id])
159
+ @user.destroy
160
+ logout if params[:user_id] == session[:user]
161
+ redirect(absolute_slice_url(:users), {:message => { :notice => "User #{params[:user_id]} deleted successfully" }, :permanent => true})
162
+ rescue => e
163
+ Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
164
+ session[:level] != :admin ? set_user_and_redirect : redirect_to_list_users({ :error => $! })
165
+ end
166
+ end
167
+
168
+ private
169
+
170
+ def set_user_and_redirect
171
+ begin
172
+ @user = Chef::WebUIUser.load(session[:user]) rescue (raise NotFound, "Cannot find User #{session[:user]}, maybe it got deleted by an Administrator.")
173
+ rescue
174
+ logout_and_redirect_to_login
175
+ else
176
+ redirect(slice_url(:users_show, :user_id => session[:user]), {:message => { :error => $! }, :permanent => true})
177
+ end
178
+ end
179
+
180
+ def redirect_to_list_users(message)
181
+ @_message = message
182
+ @users = Chef::WebUIUser.list
183
+ render :index
184
+ end
185
+
186
+ end