rxcms-dbms_plugin 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/alliance_dbms_plugin/configure.js +555 -0
- data/app/assets/javascripts/alliance_dbms_plugin/index.js +7 -0
- data/app/assets/javascripts/alliance_dbms_plugin/installer.js +101 -0
- data/app/assets/stylesheets/dbms_engine.css +4 -0
- data/app/assets/stylesheets/dbms_installer.css +4 -0
- data/app/controllers/dbms_connection_controller.rb +291 -0
- data/app/controllers/dbms_engine_controller.rb +70 -0
- data/app/controllers/dbms_installer_controller.rb +138 -0
- data/app/controllers/dbms_services_controller.rb +33 -0
- data/app/helpers/dbms_engine_helper.rb +49 -0
- data/app/helpers/dbms_installer_helper.rb +2 -0
- data/app/helpers/dbms_plugin_helper.rb +30 -0
- data/app/models/database.rb +47 -0
- data/app/views/dbms_engine/configure.html.erb +165 -0
- data/app/views/dbms_engine/index.html.erb +1 -0
- data/app/views/dbms_engine/installer.html.erb +55 -0
- data/config/dbms/dbms_config.yml +8 -0
- data/config/routes.rb +25 -0
- data/db/migrate/20130828071533_create_databases.rb +8 -0
- data/lib/rxcms-dbms_plugin/classes/executor.rb +153 -0
- data/lib/rxcms-dbms_plugin/engine.rb +14 -0
- data/lib/rxcms-dbms_plugin/version.rb +3 -0
- data/lib/rxcms-dbms_plugin.rb +5 -0
- data/lib/tasks/rxcms-dbms_plugin_tasks.rake +4 -0
- metadata +174 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
$(function(){
|
2
|
+
|
3
|
+
Messenger.options = {
|
4
|
+
extraClasses: 'messenger-fixed messenger-on-bottom messenger-on-right',
|
5
|
+
theme: 'air'
|
6
|
+
};
|
7
|
+
|
8
|
+
$("#dbmsTypeSelect").on("change", function(){
|
9
|
+
$(".connectorContainer").fadeOut("fast");
|
10
|
+
switch($(this).val())
|
11
|
+
{
|
12
|
+
case "mysql2":
|
13
|
+
$("#sql").fadeIn("fast");
|
14
|
+
$("#portTxt").val("3306");
|
15
|
+
break;
|
16
|
+
case "sqlite":
|
17
|
+
$("#sqlite").fadeIn("fast");
|
18
|
+
break;
|
19
|
+
case "postgresql":
|
20
|
+
$("#sql").fadeIn("fast");
|
21
|
+
$("#portTxt").val("5432");
|
22
|
+
break;
|
23
|
+
default:
|
24
|
+
}
|
25
|
+
});
|
26
|
+
|
27
|
+
$(".sqlProceedBtn").on("click", function(){
|
28
|
+
|
29
|
+
if ($("#dbmsTypeSelect").val() == "sqlite")
|
30
|
+
{
|
31
|
+
if ($("#dbTxtSqlite").val().length == 0)
|
32
|
+
{
|
33
|
+
Messenger().post("Path to database is required");
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
else
|
38
|
+
{
|
39
|
+
var errors = "";
|
40
|
+
if ($("#hostTxt").val().length == 0) errors += "Host is required.<br />"
|
41
|
+
if ($("#portTxt").val().length == 0) errors += "Port is required.<br />"
|
42
|
+
if ($("#dbTxt").val().length == 0) errors += "Database is required.<br />"
|
43
|
+
if ($("#userTxt").val().length == 0) errors += "User is required.<br />"
|
44
|
+
|
45
|
+
if (errors.length > 0)
|
46
|
+
{
|
47
|
+
Messenger().post(errors);
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
$("#sqlProceedBtn").attr("disabled","disabled");
|
53
|
+
|
54
|
+
$.post("/dbms/connection/make", {
|
55
|
+
"type" : $("#dbmsTypeSelect").val(),
|
56
|
+
"host" : $("#hostTxt").val(),
|
57
|
+
"port" : $("#portTxt").val(),
|
58
|
+
"database": $("#dbmsTypeSelect").val() == "sqlite" ? $("#dbTxtSqlite").val() : $("#dbTxt").val(),
|
59
|
+
"user" : $("#userTxt").val(),
|
60
|
+
"password" : $("#passwordTxt").val()
|
61
|
+
}, function(response){
|
62
|
+
if (response.status == "success")
|
63
|
+
{
|
64
|
+
Messenger().post("Connection to database server was established, creating persistent database records...");
|
65
|
+
|
66
|
+
$.post("/dbms/installer/before_process", {
|
67
|
+
"dbmsAdapter" : $("#dbmsTypeSelect").val(),
|
68
|
+
"dbmsHost" : $("#hostTxt").val(),
|
69
|
+
"dbmsPort" : $("#portTxt").val(),
|
70
|
+
"dbmsDatabase" : $("#dbmsTypeSelect").val() == "sqlite" ? $("#dbTxtSqlite").val() : $("#dbTxt").val(),
|
71
|
+
"dbmsUser" : $("#userTxt").val(),
|
72
|
+
"dbmsPassword" : $("#passwordTxt").val()
|
73
|
+
}, function(response){
|
74
|
+
if (response.status == "success")
|
75
|
+
{
|
76
|
+
Messenger().post("All done, redirecting...");
|
77
|
+
location.reload();
|
78
|
+
}
|
79
|
+
else
|
80
|
+
{
|
81
|
+
$("#sqlProceedBtn").removeAttr("disabled");
|
82
|
+
Messenger().post("There was a problem while doing initial processing");
|
83
|
+
}
|
84
|
+
}).error(function(){
|
85
|
+
{
|
86
|
+
$("#sqlProceedBtn").removeAttr("disabled");
|
87
|
+
Messenger().post("Unable to do initial processing");
|
88
|
+
}
|
89
|
+
})
|
90
|
+
} else
|
91
|
+
{
|
92
|
+
$("#sqlProceedBtn").removeAttr("disabled");
|
93
|
+
Messenger().post("Connection cannot be established due to either wrong login information or server unavailability");
|
94
|
+
}
|
95
|
+
}).error(function(){
|
96
|
+
$("#sqlProceedBtn").removeAttr("disabled");
|
97
|
+
Messenger().post("Unable to contact server");
|
98
|
+
});
|
99
|
+
|
100
|
+
});
|
101
|
+
});
|
@@ -0,0 +1,291 @@
|
|
1
|
+
class DbmsConnectionController < ApplicationController
|
2
|
+
include DbmsPluginHelper
|
3
|
+
|
4
|
+
# Only allow admin and developer
|
5
|
+
before_filter :get_current_user_role
|
6
|
+
|
7
|
+
# Load configuration items (MANDATORY, must be included)
|
8
|
+
APP_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../config/dbms/dbms_config.yml', __FILE__))))
|
9
|
+
|
10
|
+
# Controller Actions
|
11
|
+
def makeNewConnection
|
12
|
+
SymmetricEncryption.load!
|
13
|
+
|
14
|
+
begin
|
15
|
+
|
16
|
+
# Check access
|
17
|
+
if (@curUserRole == 'contentadmin' ||
|
18
|
+
@curUserRole == 'user' ||
|
19
|
+
@curUserRole == 'loggedin' ||
|
20
|
+
@curUserRole == 'anonymous')
|
21
|
+
raise 'unauthorized access'
|
22
|
+
end
|
23
|
+
|
24
|
+
connectionResult = false
|
25
|
+
|
26
|
+
if (params[:type] == "sqlite")
|
27
|
+
connectionResult = Database.connect_sqlite(params[:database])
|
28
|
+
else
|
29
|
+
connectionResult = Database.connect_sql(params[:type], params[:host], params[:port], params[:user], SymmetricEncryption.encrypt(params[:password]), params[:database])
|
30
|
+
end
|
31
|
+
|
32
|
+
if (connectionResult)
|
33
|
+
render :json => {:status => "success"}
|
34
|
+
else
|
35
|
+
render :json => {:status => "failure"}
|
36
|
+
end
|
37
|
+
rescue Exception => ex
|
38
|
+
render :json => {:status => "failure", :message => ex.message}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def getConnectionStatus
|
43
|
+
begin
|
44
|
+
|
45
|
+
# Check access
|
46
|
+
if (@curUserRole == 'contentadmin' ||
|
47
|
+
@curUserRole == 'user' ||
|
48
|
+
@curUserRole == 'loggedin' ||
|
49
|
+
@curUserRole == 'anonymous')
|
50
|
+
raise 'unauthorized access'
|
51
|
+
end
|
52
|
+
|
53
|
+
if (ActiveRecord::Base.connection != Database.connection)
|
54
|
+
status = Database.connection.active?
|
55
|
+
|
56
|
+
if (status)
|
57
|
+
render :json => {:status => "success", :data => Database.connection.current_database}
|
58
|
+
else
|
59
|
+
render :json => {:status => "failure", :message => "database unavailable"}
|
60
|
+
end
|
61
|
+
else
|
62
|
+
render :json => {:status => "failure", :message => "connection unavailable"}
|
63
|
+
end
|
64
|
+
rescue Exception => ex
|
65
|
+
render :json => {:status => "failure", :message => ex.message}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def getListOfTables
|
70
|
+
begin
|
71
|
+
|
72
|
+
# Check access
|
73
|
+
if (@curUserRole == 'contentadmin' ||
|
74
|
+
@curUserRole == 'user' ||
|
75
|
+
@curUserRole == 'loggedin' ||
|
76
|
+
@curUserRole == 'anonymous')
|
77
|
+
raise 'unauthorized access'
|
78
|
+
end
|
79
|
+
|
80
|
+
if (ActiveRecord::Base.connection != Database.connection)
|
81
|
+
tables = Database.connection.tables
|
82
|
+
render :json => {:status => "success", :data => tables}
|
83
|
+
else
|
84
|
+
render :json => {:status => "success", :message => []}
|
85
|
+
end
|
86
|
+
rescue Exception => ex
|
87
|
+
render :json => {:status => "failure", :message => ex.message}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def executeSQL
|
92
|
+
begin
|
93
|
+
|
94
|
+
# Check access
|
95
|
+
if (@curUserRole == 'contentadmin' ||
|
96
|
+
@curUserRole == 'user' ||
|
97
|
+
@curUserRole == 'loggedin' ||
|
98
|
+
@curUserRole == 'anonymous')
|
99
|
+
raise 'unauthorized access'
|
100
|
+
end
|
101
|
+
|
102
|
+
if (ActiveRecord::Base.connection != Database.connection)
|
103
|
+
|
104
|
+
resultSet = []
|
105
|
+
begin
|
106
|
+
Database.connection.execute("BEGIN")
|
107
|
+
resultSet = Database.connection.select_all(params[:sql])
|
108
|
+
# Must put ROLLBACK here because Postgres adapter doesn't throw any exception when update or delete commands are executed
|
109
|
+
Database.connection.execute("ROLLBACK")
|
110
|
+
|
111
|
+
# Parse columns
|
112
|
+
columns = Array.new
|
113
|
+
if resultSet.length > 0
|
114
|
+
# Take this first one
|
115
|
+
firstResult = resultSet.first
|
116
|
+
columns = firstResult.keys
|
117
|
+
end
|
118
|
+
|
119
|
+
render :json => {:status => "success", :data => {:columns => columns, :result => resultSet}}
|
120
|
+
rescue NoMethodError
|
121
|
+
Database.connection.execute("ROLLBACK")
|
122
|
+
render :json => {:status => "success", :data => {:columns => [], :result => []}}
|
123
|
+
rescue ActiveRecord::StatementInvalid => dberr
|
124
|
+
render :json => { :status => "failure", :data => {:columns => [], :result => []}, :message => dberr.message }
|
125
|
+
end
|
126
|
+
|
127
|
+
else
|
128
|
+
render :json => {:status => "failure", :data => {:columns => [], :result => []}, :message => "connect not established"}
|
129
|
+
end
|
130
|
+
rescue Exception => ex
|
131
|
+
render :json => {:status => "failure", :data => {:columns => [], :result => []}, :message => "command executed, no result set returned"}
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def getListOfStoredQueries
|
136
|
+
begin
|
137
|
+
|
138
|
+
# Check access
|
139
|
+
if (@curUserRole == 'contentadmin' ||
|
140
|
+
@curUserRole == 'user' ||
|
141
|
+
@curUserRole == 'loggedin' ||
|
142
|
+
@curUserRole == 'anonymous')
|
143
|
+
raise 'unauthorized access'
|
144
|
+
end
|
145
|
+
|
146
|
+
storedQueries = Metadata.all({ :conditions => ['cat = ? and sites_id = ?', APP_CONFIG[:DBMS_CAT_STORED_QUERY], session[:accessible_appid]] })
|
147
|
+
|
148
|
+
tArray = Array.new
|
149
|
+
storedQueries.each do |t|
|
150
|
+
tHash = Hash.new
|
151
|
+
|
152
|
+
tHash[:id] = t.id
|
153
|
+
tHash[:key] = t.key
|
154
|
+
tHash[:value] = SymmetricEncryption.decrypt(t.value)
|
155
|
+
|
156
|
+
tArray << tHash
|
157
|
+
end
|
158
|
+
|
159
|
+
render :json => {:status => "success", :data => tArray}
|
160
|
+
rescue Exception => ex
|
161
|
+
render :json => {:status => "failure", :message => ex.message}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def getOneStoredQueryInfos
|
166
|
+
SymmetricEncryption.load!
|
167
|
+
|
168
|
+
begin
|
169
|
+
|
170
|
+
# Check access
|
171
|
+
if (@curUserRole == 'contentadmin' ||
|
172
|
+
@curUserRole == 'user' ||
|
173
|
+
@curUserRole == 'loggedin' ||
|
174
|
+
@curUserRole == 'anonymous')
|
175
|
+
raise 'unauthorized access'
|
176
|
+
end
|
177
|
+
|
178
|
+
storedQuery = Metadata.first({ :conditions => [ 'id = ? and cat = ? and sites_id = ?', params[:id], params[:cat], session[:accessible_appid] ]})
|
179
|
+
|
180
|
+
render :json => {:status => "success", :data => {:id => storedQuery.id ,:key => storedQuery.key, :value => SymmetricEncryption.decrypt(storedQuery.value)}}
|
181
|
+
rescue Exception => ex
|
182
|
+
render :json => {:status => "failure", :message => ex.message}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def addStoredQuery
|
187
|
+
SymmetricEncryption.load!
|
188
|
+
|
189
|
+
begin
|
190
|
+
|
191
|
+
# Check access
|
192
|
+
if (@curUserRole == 'contentadmin' ||
|
193
|
+
@curUserRole == 'user' ||
|
194
|
+
@curUserRole == 'loggedin' ||
|
195
|
+
@curUserRole == 'anonymous')
|
196
|
+
raise 'unauthorized access'
|
197
|
+
end
|
198
|
+
|
199
|
+
# if (Metadata.all(:conditions => ["key = ?", params[:key]]).length > 0)
|
200
|
+
# raise "key is duplicated"
|
201
|
+
# end
|
202
|
+
|
203
|
+
# Check for value duplications
|
204
|
+
storedQueryValues = Metadata.all(:conditions => ["cat = ? and sites_id = ?", APP_CONFIG[:DBMS_CAT_STORED_QUERY], session[:accessible_appid]])
|
205
|
+
storedQueryValues.each do |t|
|
206
|
+
valueJsonObject = ActiveSupport::JSON.decode(SymmetricEncryption.decrypt(t.value))
|
207
|
+
|
208
|
+
if valueJsonObject['sql'] == params[:value]
|
209
|
+
raise "value is duplicated"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# If all is fine, create the stored query
|
214
|
+
Metadata.create({
|
215
|
+
:key => params[:key],
|
216
|
+
:value => SymmetricEncryption.encrypt({ :sql => params[:value], :enabled => false, :language => 'none' }.to_json),
|
217
|
+
:cat => APP_CONFIG[:DBMS_CAT_STORED_QUERY],
|
218
|
+
:mime => "text/sql",
|
219
|
+
:sites_id => session[:accessible_appid]
|
220
|
+
})
|
221
|
+
|
222
|
+
render :json => {:status => "success"}
|
223
|
+
rescue Exception => ex
|
224
|
+
render :json => {:status => "failure", :message => ex.message}
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def updateStoredQuery
|
229
|
+
SymmetricEncryption.load!
|
230
|
+
|
231
|
+
begin
|
232
|
+
|
233
|
+
# Check access
|
234
|
+
if (@curUserRole == 'contentadmin' ||
|
235
|
+
@curUserRole == 'user' ||
|
236
|
+
@curUserRole == 'loggedin' ||
|
237
|
+
@curUserRole == 'anonymous')
|
238
|
+
raise 'unauthorized access'
|
239
|
+
end
|
240
|
+
|
241
|
+
# select that id first
|
242
|
+
updateObj = Metadata.find(params[:id])
|
243
|
+
|
244
|
+
if (!updateObj.nil?)
|
245
|
+
updateObjData = ActiveSupport::JSON.decode(SymmetricEncryption.decrypt(updateObj.value))
|
246
|
+
if (!params[:value].nil? && params[:enabled].nil? && params[:language].nil?)
|
247
|
+
Metadata.update(params[:id], {
|
248
|
+
:value => SymmetricEncryption.encrypt({ :sql => params[:value], :enabled => updateObjData['enabled'], :language => updateObjData['language'] }.to_json)
|
249
|
+
});
|
250
|
+
elsif (params[:value].nil? && !params[:enabled].nil? && params[:language].nil?)
|
251
|
+
Metadata.update(params[:id], {
|
252
|
+
:value => SymmetricEncryption.encrypt({ :sql => updateObjData['sql'] , :enabled => params[:enabled] == "true" ? true : false, :language => updateObjData['language'] }.to_json)
|
253
|
+
});
|
254
|
+
elsif (params[:value].nil? && params[:enabled].nil? && !params[:language].nil?)
|
255
|
+
Metadata.update(params[:id], {
|
256
|
+
:value => SymmetricEncryption.encrypt({ :sql => updateObjData['sql'] , :enabled => updateObjData['enabled'], :language => params[:language] }.to_json)
|
257
|
+
});
|
258
|
+
else
|
259
|
+
# Unimplemented
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
render :json => {:status => "success"}
|
264
|
+
rescue Exception => ex
|
265
|
+
render :json => {:status => "failure", :message => ex.message}
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def deleteStoredQuery
|
270
|
+
begin
|
271
|
+
|
272
|
+
# Check access
|
273
|
+
if (@curUserRole == 'contentadmin' ||
|
274
|
+
@curUserRole == 'user' ||
|
275
|
+
@curUserRole == 'loggedin' ||
|
276
|
+
@curUserRole == 'anonymous')
|
277
|
+
raise 'unauthorized access'
|
278
|
+
end
|
279
|
+
|
280
|
+
Metadata.find_by_id(params[:id]).destroy
|
281
|
+
|
282
|
+
render :json => {:status => "success"}
|
283
|
+
rescue Exception => ex
|
284
|
+
render :json => {:status => "failure", :message => ex.message}
|
285
|
+
end
|
286
|
+
end
|
287
|
+
# END
|
288
|
+
|
289
|
+
private
|
290
|
+
|
291
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class DbmsEngineController < ApplicationController
|
2
|
+
include DbmsPluginHelper, DbmsEngineHelper
|
3
|
+
|
4
|
+
layout false
|
5
|
+
|
6
|
+
before_filter :get_current_user_role
|
7
|
+
|
8
|
+
# Load configuration items (MANDATORY, must be included)
|
9
|
+
APP_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../config/dbms/dbms_config.yml', __FILE__))))
|
10
|
+
|
11
|
+
# Allow all to access index
|
12
|
+
# Disallow all to access configure and installer, except for admin
|
13
|
+
|
14
|
+
# Write your readme here
|
15
|
+
def index
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure
|
20
|
+
|
21
|
+
# Check access
|
22
|
+
if (@curUserRole == 'contentadmin' ||
|
23
|
+
@curUserRole == 'user' ||
|
24
|
+
@curUserRole == 'loggedin' ||
|
25
|
+
@curUserRole == 'anonymous')
|
26
|
+
raise 'unauthorized access'
|
27
|
+
end
|
28
|
+
|
29
|
+
if request.xhr?
|
30
|
+
if Metadata.first({ :conditions => [ 'key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_DATABASE], session[:accessible_appid]] }).nil?
|
31
|
+
raise "setup required"
|
32
|
+
else
|
33
|
+
if Metadata.first({ :conditions => [ 'key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_DATABASE], session[:accessible_appid]] }).value.empty?
|
34
|
+
raise "setup required"
|
35
|
+
else
|
36
|
+
# Perform connection persisting if necessary
|
37
|
+
persist_connection
|
38
|
+
|
39
|
+
respond_to do |t|
|
40
|
+
t.html
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
raise 'unauthorized access'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def installer
|
50
|
+
|
51
|
+
# Check access
|
52
|
+
if (@curUserRole == 'contentadmin' ||
|
53
|
+
@curUserRole == 'user' ||
|
54
|
+
@curUserRole == 'loggedin' ||
|
55
|
+
@curUserRole == 'anonymous')
|
56
|
+
raise 'unauthorized access'
|
57
|
+
end
|
58
|
+
|
59
|
+
if request.xhr?
|
60
|
+
respond_to do |t|
|
61
|
+
t.html
|
62
|
+
end
|
63
|
+
else
|
64
|
+
raise 'unauthorized access'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
class DbmsInstallerController < ApplicationController
|
2
|
+
include DbmsPluginHelper
|
3
|
+
|
4
|
+
layout false
|
5
|
+
|
6
|
+
before_filter :get_current_user_role
|
7
|
+
|
8
|
+
# Load configuration items (MANDATORY, must be included)
|
9
|
+
APP_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../config/dbms/dbms_config.yml', __FILE__))))
|
10
|
+
|
11
|
+
# Each step should return JSON status "success", "failure" or "unimplemented"
|
12
|
+
|
13
|
+
# Used for initializing and creating database entries
|
14
|
+
def before_process
|
15
|
+
SymmetricEncryption.load!
|
16
|
+
|
17
|
+
begin
|
18
|
+
|
19
|
+
# Check access
|
20
|
+
if (@curUserRole == 'contentadmin' ||
|
21
|
+
@curUserRole == 'user' ||
|
22
|
+
@curUserRole == 'loggedin' ||
|
23
|
+
@curUserRole == 'anonymous')
|
24
|
+
raise 'unauthorized access'
|
25
|
+
end
|
26
|
+
|
27
|
+
if !Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_ADAPTER], session[:accessible_appid]] }).nil?
|
28
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_ADAPTER], session[:accessible_appid]] }).destroy
|
29
|
+
end
|
30
|
+
if !Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_HOST], session[:accessible_appid]] }).nil?
|
31
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_HOST], session[:accessible_appid]] }).destroy
|
32
|
+
end
|
33
|
+
if !Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_PORT], session[:accessible_appid]] }).nil?
|
34
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_PORT], session[:accessible_appid]] }).destroy
|
35
|
+
end
|
36
|
+
if !Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_DATABASE], session[:accessible_appid]] }).nil?
|
37
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_DATABASE], session[:accessible_appid]] }).destroy
|
38
|
+
end
|
39
|
+
if !Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_USER], session[:accessible_appid]] }).nil?
|
40
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_USER], session[:accessible_appid]] }).destroy
|
41
|
+
end
|
42
|
+
if !Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_PASSWORD], session[:accessible_appid]] }).nil?
|
43
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_PASSWORD], session[:accessible_appid]] }).destroy
|
44
|
+
end
|
45
|
+
|
46
|
+
Metadata.create!({
|
47
|
+
:key => APP_CONFIG[:DBMS_CURRENT_ADAPTER],
|
48
|
+
:value => params[:dbmsAdapter].nil? ? '' : params[:dbmsAdapter],
|
49
|
+
:cat => APP_CONFIG[:DBMS_CAT_CONFIG],
|
50
|
+
:mime => "text/plain",
|
51
|
+
:sites_id => session[:accessible_appid]
|
52
|
+
})
|
53
|
+
Metadata.create!({
|
54
|
+
:key => APP_CONFIG[:DBMS_CURRENT_HOST],
|
55
|
+
:value => params[:dbmsHost].nil? ? '' : params[:dbmsHost],
|
56
|
+
:cat => APP_CONFIG[:DBMS_CAT_CONFIG],
|
57
|
+
:mime => "text/plain",
|
58
|
+
:sites_id => session[:accessible_appid]
|
59
|
+
})
|
60
|
+
Metadata.create!({
|
61
|
+
:key => APP_CONFIG[:DBMS_CURRENT_PORT],
|
62
|
+
:value => params[:dbmsPort].nil? ? '' : params[:dbmsPort],
|
63
|
+
:cat => APP_CONFIG[:DBMS_CAT_CONFIG],
|
64
|
+
:mime => "text/plain",
|
65
|
+
:sites_id => session[:accessible_appid]
|
66
|
+
})
|
67
|
+
Metadata.create!({
|
68
|
+
:key => APP_CONFIG[:DBMS_CURRENT_DATABASE],
|
69
|
+
:value => params[:dbmsDatabase].nil? ? '' : params[:dbmsDatabase],
|
70
|
+
:cat => APP_CONFIG[:DBMS_CAT_CONFIG],
|
71
|
+
:mime => "text/plain",
|
72
|
+
:sites_id => session[:accessible_appid]
|
73
|
+
})
|
74
|
+
Metadata.create!({
|
75
|
+
:key => APP_CONFIG[:DBMS_CURRENT_USER],
|
76
|
+
:value => params[:dbmsUser].nil? ? '' : params[:dbmsUser],
|
77
|
+
:cat => APP_CONFIG[:DBMS_CAT_CONFIG],
|
78
|
+
:mime => "text/plain",
|
79
|
+
:sites_id => session[:accessible_appid]
|
80
|
+
})
|
81
|
+
Metadata.create!({
|
82
|
+
:key => APP_CONFIG[:DBMS_CURRENT_PASSWORD],
|
83
|
+
:value => SymmetricEncryption.encrypt(params[:dbmsPassword].nil? ? '' : params[:dbmsPassword]),
|
84
|
+
:cat => APP_CONFIG[:DBMS_CAT_CONFIG],
|
85
|
+
:mime => "text/plain",
|
86
|
+
:sites_id => session[:accessible_appid]
|
87
|
+
})
|
88
|
+
|
89
|
+
render :json => { :status => 'success' }
|
90
|
+
rescue Exception => ex
|
91
|
+
render :json => { :status => 'failure', :message => ex.message }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Used for logical processing
|
96
|
+
def core_process
|
97
|
+
render :json => { :status => 'unimplemented' }
|
98
|
+
end
|
99
|
+
|
100
|
+
# Used for configuring data
|
101
|
+
def post_process
|
102
|
+
render :json => { :status => 'unimplemented' }
|
103
|
+
end
|
104
|
+
|
105
|
+
# Uninstaller
|
106
|
+
def uninstall
|
107
|
+
begin
|
108
|
+
|
109
|
+
# Check access
|
110
|
+
if (@curUserRole == 'contentadmin' ||
|
111
|
+
@curUserRole == 'user' ||
|
112
|
+
@curUserRole == 'loggedin' ||
|
113
|
+
@curUserRole == 'anonymous')
|
114
|
+
raise 'unauthorized access'
|
115
|
+
end
|
116
|
+
|
117
|
+
# Delete all configuration items
|
118
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_ADAPTER], session[:accessible_appid]] }).destroy
|
119
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_HOST], session[:accessible_appid]] }).destroy
|
120
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_PORT], session[:accessible_appid]] }).destroy
|
121
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_DATABASE], session[:accessible_appid]] }).destroy
|
122
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_USER], session[:accessible_appid]] }).destroy
|
123
|
+
Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:DBMS_CURRENT_PASSWORD], session[:accessible_appid]] }).destroy
|
124
|
+
|
125
|
+
# Delete all stored queries
|
126
|
+
Metadata.all({ :conditions => ['cat = ? and sites_id = ?', APP_CONFIG[:DBMS_CAT_STORED_QUERY], session[:accessible_appid]] }).each do |t|
|
127
|
+
t.destroy
|
128
|
+
end
|
129
|
+
|
130
|
+
render :json => { :status => 'success' }
|
131
|
+
rescue
|
132
|
+
render :json => { :status => 'failure' }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class DbmsServicesController < ApplicationController
|
2
|
+
|
3
|
+
# Load configuration items (MANDATORY, must be included)
|
4
|
+
APP_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../config/dbms/dbms_config.yml', __FILE__))))
|
5
|
+
|
6
|
+
# Controller Actions
|
7
|
+
def execute
|
8
|
+
SymmetricEncryption.load!
|
9
|
+
|
10
|
+
begin
|
11
|
+
serviceObj = Metadata.find_by_key(params[:key])
|
12
|
+
|
13
|
+
if (!serviceObj.nil?)
|
14
|
+
serviceValueObj = ActiveSupport::JSON.decode(SymmetricEncryption.decrypt(serviceObj.value))
|
15
|
+
|
16
|
+
if (serviceValueObj['enabled'] == true)
|
17
|
+
resultSet = Database.connection.select_all(serviceValueObj['sql'])
|
18
|
+
|
19
|
+
render :json => {:status => "success", :data => resultSet}
|
20
|
+
else
|
21
|
+
raise "service unavailable"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
raise "data unavailable"
|
25
|
+
end
|
26
|
+
|
27
|
+
rescue Exception => ex
|
28
|
+
render :json => {:status => "failure", :message => ex.message, :data => []}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
# END
|
32
|
+
|
33
|
+
end
|