rhoconnect 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. data/CHANGELOG +208 -0
  2. data/CREDITS +38 -0
  3. data/Gemfile +18 -0
  4. data/Gemfile.lock +97 -0
  5. data/LICENSE +75 -0
  6. data/README.md +10 -0
  7. data/Rakefile +82 -0
  8. data/bench/bench +7 -0
  9. data/bench/bench_runner.rb +112 -0
  10. data/bench/benchapp/Gemfile +21 -0
  11. data/bench/benchapp/Gemfile.lock +76 -0
  12. data/bench/benchapp/Rakefile +22 -0
  13. data/bench/benchapp/application.rb +39 -0
  14. data/bench/benchapp/config.ru +36 -0
  15. data/bench/benchapp/settings/license.key +1 -0
  16. data/bench/benchapp/settings/settings.yml +20 -0
  17. data/bench/benchapp/sources/mock_adapter.rb +55 -0
  18. data/bench/benchapp/sources/queue_mock_adapter.rb +2 -0
  19. data/bench/benchapp/spec/sources/mock_adapter_spec.rb +25 -0
  20. data/bench/benchapp/spec/sources/queue_mock_adapter_spec.rb +25 -0
  21. data/bench/benchapp/spec/spec_helper.rb +42 -0
  22. data/bench/blobapp/Gemfile +31 -0
  23. data/bench/blobapp/Gemfile.lock +103 -0
  24. data/bench/blobapp/Rakefile +25 -0
  25. data/bench/blobapp/application.rb +44 -0
  26. data/bench/blobapp/config.ru +36 -0
  27. data/bench/blobapp/settings/license.key +1 -0
  28. data/bench/blobapp/settings/settings.yml +16 -0
  29. data/bench/blobapp/sources/blob_adapter.rb +71 -0
  30. data/bench/blobapp/spec/sources/blob_adapter_spec.rb +25 -0
  31. data/bench/blobapp/spec/spec_helper.rb +42 -0
  32. data/bench/lib/bench/cli.rb +16 -0
  33. data/bench/lib/bench/logging.rb +13 -0
  34. data/bench/lib/bench/mock_client.rb +41 -0
  35. data/bench/lib/bench/result.rb +50 -0
  36. data/bench/lib/bench/runner.rb +107 -0
  37. data/bench/lib/bench/session.rb +67 -0
  38. data/bench/lib/bench/statistics.rb +56 -0
  39. data/bench/lib/bench/test_data.rb +98 -0
  40. data/bench/lib/bench/timer.rb +10 -0
  41. data/bench/lib/bench/utils.rb +49 -0
  42. data/bench/lib/bench.rb +129 -0
  43. data/bench/lib/testdata/100-data.txt +148 -0
  44. data/bench/lib/testdata/5-data.txt +9 -0
  45. data/bench/lib/testdata/images/icon.ico +0 -0
  46. data/bench/lib/testdata/images/icon.png +0 -0
  47. data/bench/lib/testdata/images/loading-Landscape.png +0 -0
  48. data/bench/lib/testdata/images/loading-LandscapeLeft.png +0 -0
  49. data/bench/lib/testdata/images/loading-LandscapeRight.png +0 -0
  50. data/bench/lib/testdata/images/loading-Portrait.png +0 -0
  51. data/bench/lib/testdata/images/loading-PortraitUpsideDown.png +0 -0
  52. data/bench/lib/testdata/images/loading.png +0 -0
  53. data/bench/lib/testdata/images/loading@2x.png +0 -0
  54. data/bench/run_bench.sh +42 -0
  55. data/bench/run_blob_script.sh +3 -0
  56. data/bench/run_cud_script.sh +3 -0
  57. data/bench/run_query_md_script.sh +3 -0
  58. data/bench/run_query_only_script.sh +3 -0
  59. data/bench/run_query_script.sh +3 -0
  60. data/bench/scripts/blob_cud_script.rb +98 -0
  61. data/bench/scripts/cud_script.rb +92 -0
  62. data/bench/scripts/helpers.rb +101 -0
  63. data/bench/scripts/query_md_script.rb +45 -0
  64. data/bench/scripts/query_only_script.rb +51 -0
  65. data/bench/scripts/query_script.rb +45 -0
  66. data/bench/spec/bench_spec_helper.rb +33 -0
  67. data/bench/spec/logging_spec.rb +15 -0
  68. data/bench/spec/mock_adapter_spec.rb +61 -0
  69. data/bench/spec/mock_client_spec.rb +65 -0
  70. data/bench/spec/result_spec.rb +61 -0
  71. data/bench/spec/utils_spec.rb +36 -0
  72. data/bin/rhoconnect +34 -0
  73. data/bin/rhoconnect-setup +84 -0
  74. data/doc/async-jobs.txt +69 -0
  75. data/doc/authentication.txt +76 -0
  76. data/doc/benchmarks.txt +168 -0
  77. data/doc/blob-sync.txt +130 -0
  78. data/doc/bulk-sync.txt +102 -0
  79. data/doc/client.txt +432 -0
  80. data/doc/command-line.txt +210 -0
  81. data/doc/contributing.txt +60 -0
  82. data/doc/deploying.txt +82 -0
  83. data/doc/install.txt +28 -0
  84. data/doc/introduction.txt +20 -0
  85. data/doc/licensing.txt +18 -0
  86. data/doc/metadata.txt +458 -0
  87. data/doc/migration.txt +182 -0
  88. data/doc/public/css/print.css +29 -0
  89. data/doc/public/css/screen.css +257 -0
  90. data/doc/public/css/style.css +20 -0
  91. data/doc/push.txt +135 -0
  92. data/doc/release.txt +41 -0
  93. data/doc/rest-api.txt +367 -0
  94. data/doc/source-adapters.txt +325 -0
  95. data/doc/stats-middleware.txt +69 -0
  96. data/doc/testing.txt +222 -0
  97. data/doc/tutorial.txt +315 -0
  98. data/doc/web-console.txt +35 -0
  99. data/examples/simple/Rakefile +14 -0
  100. data/examples/simple/application.rb +27 -0
  101. data/examples/simple/config.ru +49 -0
  102. data/examples/simple/settings/license.key +1 -0
  103. data/examples/simple/settings/settings.yml +23 -0
  104. data/examples/simple/sources/sample_adapter.rb +5 -0
  105. data/examples/simple/sources/simple_adapter.rb +5 -0
  106. data/generators/rhoconnect.rb +119 -0
  107. data/generators/templates/application/Gemfile +21 -0
  108. data/generators/templates/application/Rakefile +22 -0
  109. data/generators/templates/application/application.rb +39 -0
  110. data/generators/templates/application/config.ru +36 -0
  111. data/generators/templates/application/settings/license.key +1 -0
  112. data/generators/templates/application/settings/settings.yml +14 -0
  113. data/generators/templates/application/spec/spec_helper.rb +42 -0
  114. data/generators/templates/source/source_adapter.rb +47 -0
  115. data/generators/templates/source/source_spec.rb +25 -0
  116. data/install.sh +408 -0
  117. data/installer/unix-like/rho_connect_install_checkers.rb +140 -0
  118. data/installer/unix-like/rho_connect_install_constants.rb +51 -0
  119. data/installer/unix-like/rho_connect_install_debian.rb +63 -0
  120. data/installer/unix-like/rho_connect_install_dnd.rb +58 -0
  121. data/installer/unix-like/rho_connect_install_get_params.rb +30 -0
  122. data/installer/unix-like/rho_connect_install_installers.rb +142 -0
  123. data/installer/unix-like/rho_connect_install_utilities.rb +85 -0
  124. data/installer/unix-like/rho_connect_install_yum.rb +63 -0
  125. data/installer/unix-like/rhoinstaller.rb +89 -0
  126. data/installer/utils/create_texts.rb +366 -0
  127. data/installer/utils/install_test.rb +140 -0
  128. data/installer/windows/EnvVarUpdate.nsh +328 -0
  129. data/installer/windows/ServiceLib.nsh +369 -0
  130. data/installer/windows/configUi.ini +44 -0
  131. data/installer/windows/icon.ico +0 -0
  132. data/installer/windows/rhosync.nsi +418 -0
  133. data/installer/windows/uninstall.bat +7 -0
  134. data/lib/rhoconnect/api/admin/get_api_token.rb +14 -0
  135. data/lib/rhoconnect/api/admin/get_license_info.rb +8 -0
  136. data/lib/rhoconnect/api/admin/login.rb +6 -0
  137. data/lib/rhoconnect/api/admin/reset.rb +10 -0
  138. data/lib/rhoconnect/api/admin/stats.rb +21 -0
  139. data/lib/rhoconnect/api/application/bulk_data.rb +7 -0
  140. data/lib/rhoconnect/api/application/clientcreate.rb +8 -0
  141. data/lib/rhoconnect/api/application/clientlogin.rb +6 -0
  142. data/lib/rhoconnect/api/application/clientregister.rb +6 -0
  143. data/lib/rhoconnect/api/application/clientreset.rb +6 -0
  144. data/lib/rhoconnect/api/application/query.rb +7 -0
  145. data/lib/rhoconnect/api/application/queue_updates.rb +6 -0
  146. data/lib/rhoconnect/api/application/search.rb +6 -0
  147. data/lib/rhoconnect/api/client/create_client.rb +3 -0
  148. data/lib/rhoconnect/api/client/delete_client.rb +5 -0
  149. data/lib/rhoconnect/api/client/get_client_params.rb +3 -0
  150. data/lib/rhoconnect/api/client/list_client_docs.rb +12 -0
  151. data/lib/rhoconnect/api/client/list_clients.rb +3 -0
  152. data/lib/rhoconnect/api/client/ping.rb +7 -0
  153. data/lib/rhoconnect/api/source/get_adapter.rb +3 -0
  154. data/lib/rhoconnect/api/source/get_db_doc.rb +7 -0
  155. data/lib/rhoconnect/api/source/get_source_params.rb +3 -0
  156. data/lib/rhoconnect/api/source/list_source_docs.rb +10 -0
  157. data/lib/rhoconnect/api/source/list_sources.rb +15 -0
  158. data/lib/rhoconnect/api/source/push_deletes.rb +8 -0
  159. data/lib/rhoconnect/api/source/push_objects.rb +8 -0
  160. data/lib/rhoconnect/api/source/save_adapter.rb +3 -0
  161. data/lib/rhoconnect/api/source/set_db_doc.rb +8 -0
  162. data/lib/rhoconnect/api/source/set_refresh_time.rb +8 -0
  163. data/lib/rhoconnect/api/source/upload_file.rb +4 -0
  164. data/lib/rhoconnect/api/user/create_user.rb +7 -0
  165. data/lib/rhoconnect/api/user/delete_user.rb +9 -0
  166. data/lib/rhoconnect/api/user/list_users.rb +3 -0
  167. data/lib/rhoconnect/api/user/update_user.rb +4 -0
  168. data/lib/rhoconnect/api_token.rb +19 -0
  169. data/lib/rhoconnect/app.rb +76 -0
  170. data/lib/rhoconnect/bulk_data/bulk_data.rb +88 -0
  171. data/lib/rhoconnect/bulk_data/syncdb.index.schema +4 -0
  172. data/lib/rhoconnect/bulk_data/syncdb.schema +41 -0
  173. data/lib/rhoconnect/bulk_data.rb +2 -0
  174. data/lib/rhoconnect/client.rb +96 -0
  175. data/lib/rhoconnect/client_sync.rb +412 -0
  176. data/lib/rhoconnect/console/app/helpers/auth_helper.rb +22 -0
  177. data/lib/rhoconnect/console/app/helpers/extensions.rb +19 -0
  178. data/lib/rhoconnect/console/app/helpers/helpers.rb +57 -0
  179. data/lib/rhoconnect/console/app/public/ThickBox.css +649 -0
  180. data/lib/rhoconnect/console/app/public/home.css +438 -0
  181. data/lib/rhoconnect/console/app/public/images/foot_logo_rhoconnect.png +0 -0
  182. data/lib/rhoconnect/console/app/public/images/header_halo.jpg +0 -0
  183. data/lib/rhoconnect/console/app/public/images/land_separator.gif +0 -0
  184. data/lib/rhoconnect/console/app/public/images/landing_header.jpg +0 -0
  185. data/lib/rhoconnect/console/app/public/images/logo_rhoconnect.png +0 -0
  186. data/lib/rhoconnect/console/app/public/images/rhomobile_rhohub_logo.png +0 -0
  187. data/lib/rhoconnect/console/app/public/images/tabs_separator.png +0 -0
  188. data/lib/rhoconnect/console/app/public/jqplot/excanvas.min.js +35 -0
  189. data/lib/rhoconnect/console/app/public/jqplot/jqplot.barRenderer.min.js +34 -0
  190. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisLabelRenderer.js +187 -0
  191. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisTickRenderer.js +226 -0
  192. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasTextRenderer.js +408 -0
  193. data/lib/rhoconnect/console/app/public/jqplot/jqplot.categoryAxisRenderer.min.js +34 -0
  194. data/lib/rhoconnect/console/app/public/jqplot/jqplot.cursor.js +952 -0
  195. data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.js +313 -0
  196. data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.min.js +34 -0
  197. data/lib/rhoconnect/console/app/public/jqplot/jqplot.pointLabels.min.js +34 -0
  198. data/lib/rhoconnect/console/app/public/jqplot/jquery-1.4.2.min.js +154 -0
  199. data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.css +1 -0
  200. data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.js +34 -0
  201. data/lib/rhoconnect/console/app/public/main.css +7 -0
  202. data/lib/rhoconnect/console/app/public/reset.css +76 -0
  203. data/lib/rhoconnect/console/app/public/style.css +2201 -0
  204. data/lib/rhoconnect/console/app/public/text.txt +0 -0
  205. data/lib/rhoconnect/console/app/routes/adapter.rb +28 -0
  206. data/lib/rhoconnect/console/app/routes/auth.rb +29 -0
  207. data/lib/rhoconnect/console/app/routes/client.rb +31 -0
  208. data/lib/rhoconnect/console/app/routes/docs.rb +145 -0
  209. data/lib/rhoconnect/console/app/routes/heroku.rb +19 -0
  210. data/lib/rhoconnect/console/app/routes/home.rb +63 -0
  211. data/lib/rhoconnect/console/app/routes/timing.rb +242 -0
  212. data/lib/rhoconnect/console/app/routes/user.rb +117 -0
  213. data/lib/rhoconnect/console/app/views/adapter.erb +16 -0
  214. data/lib/rhoconnect/console/app/views/client.erb +30 -0
  215. data/lib/rhoconnect/console/app/views/content.erb +14 -0
  216. data/lib/rhoconnect/console/app/views/doc.erb +8 -0
  217. data/lib/rhoconnect/console/app/views/docdata.erb +28 -0
  218. data/lib/rhoconnect/console/app/views/docs.erb +30 -0
  219. data/lib/rhoconnect/console/app/views/edituser.erb +13 -0
  220. data/lib/rhoconnect/console/app/views/headermenu.erb +40 -0
  221. data/lib/rhoconnect/console/app/views/home.erb +24 -0
  222. data/lib/rhoconnect/console/app/views/index.erb +58 -0
  223. data/lib/rhoconnect/console/app/views/jqplot.erb +52 -0
  224. data/lib/rhoconnect/console/app/views/layout.erb +165 -0
  225. data/lib/rhoconnect/console/app/views/login.erb +26 -0
  226. data/lib/rhoconnect/console/app/views/newuser.erb +17 -0
  227. data/lib/rhoconnect/console/app/views/ping.erb +28 -0
  228. data/lib/rhoconnect/console/app/views/result.erb +11 -0
  229. data/lib/rhoconnect/console/app/views/rightboxlinks.erb +15 -0
  230. data/lib/rhoconnect/console/app/views/select_doc.erb +17 -0
  231. data/lib/rhoconnect/console/app/views/upload_doc.erb +23 -0
  232. data/lib/rhoconnect/console/app/views/user.erb +29 -0
  233. data/lib/rhoconnect/console/app/views/users.erb +12 -0
  234. data/lib/rhoconnect/console/rhoconnect_api.rb +245 -0
  235. data/lib/rhoconnect/console/server.rb +32 -0
  236. data/lib/rhoconnect/console.rb +3 -0
  237. data/lib/rhoconnect/cors.rb +229 -0
  238. data/lib/rhoconnect/credential.rb +9 -0
  239. data/lib/rhoconnect/db_adapter.rb +46 -0
  240. data/lib/rhoconnect/document.rb +49 -0
  241. data/lib/rhoconnect/dynamic_adapter.rb +91 -0
  242. data/lib/rhoconnect/generator.rb +1 -0
  243. data/lib/rhoconnect/jobs/bulk_data_job.rb +203 -0
  244. data/lib/rhoconnect/jobs/ping_job.rb +46 -0
  245. data/lib/rhoconnect/jobs/source_job.rb +16 -0
  246. data/lib/rhoconnect/license.rb +86 -0
  247. data/lib/rhoconnect/lock_ops.rb +11 -0
  248. data/lib/rhoconnect/model.rb +414 -0
  249. data/lib/rhoconnect/ping/android.rb +56 -0
  250. data/lib/rhoconnect/ping/apple.rb +52 -0
  251. data/lib/rhoconnect/ping/blackberry.rb +56 -0
  252. data/lib/rhoconnect/ping.rb +3 -0
  253. data/lib/rhoconnect/read_state.rb +31 -0
  254. data/lib/rhoconnect/rho_indifferent_access.rb +88 -0
  255. data/lib/rhoconnect/server/views/index.erb +13 -0
  256. data/lib/rhoconnect/server.rb +286 -0
  257. data/lib/rhoconnect/source.rb +289 -0
  258. data/lib/rhoconnect/source_adapter.rb +123 -0
  259. data/lib/rhoconnect/source_sync.rb +302 -0
  260. data/lib/rhoconnect/stats/middleware.rb +20 -0
  261. data/lib/rhoconnect/stats/record.rb +108 -0
  262. data/lib/rhoconnect/store.rb +232 -0
  263. data/lib/rhoconnect/tasks.rb +350 -0
  264. data/lib/rhoconnect/test_methods.rb +220 -0
  265. data/lib/rhoconnect/user.rb +95 -0
  266. data/lib/rhoconnect/version.rb +3 -0
  267. data/lib/rhoconnect/x_domain_session_wrapper.rb +53 -0
  268. data/lib/rhoconnect.rb +285 -0
  269. data/rhoconnect.gemspec +67 -0
  270. data/spec/api/admin/api_token_spec.rb +14 -0
  271. data/spec/api/admin/get_api_token_spec.rb +36 -0
  272. data/spec/api/admin/get_license_info_spec.rb +38 -0
  273. data/spec/api/admin/reset_spec.rb +22 -0
  274. data/spec/api/admin/stats_spec.rb +66 -0
  275. data/spec/api/api_helper.rb +21 -0
  276. data/spec/api/application/rhoconnect_api_spec.rb +548 -0
  277. data/spec/api/client/create_client_spec.rb +13 -0
  278. data/spec/api/client/delete_client_spec.rb +13 -0
  279. data/spec/api/client/get_client_params_spec.rb +18 -0
  280. data/spec/api/client/list_client_docs_spec.rb +32 -0
  281. data/spec/api/client/list_clients_spec.rb +22 -0
  282. data/spec/api/client/ping_spec.rb +23 -0
  283. data/spec/api/rhosync_api_spec.rb.orig +606 -0
  284. data/spec/api/source/adapter_spec.rb +29 -0
  285. data/spec/api/source/get_db_doc_spec.rb +21 -0
  286. data/spec/api/source/get_source_params_spec.rb +32 -0
  287. data/spec/api/source/list_source_docs_spec.rb +25 -0
  288. data/spec/api/source/list_sources_spec.rb +26 -0
  289. data/spec/api/source/push_deletes_spec.rb +18 -0
  290. data/spec/api/source/push_objects_spec.rb +27 -0
  291. data/spec/api/source/set_db_doc_spec.rb +19 -0
  292. data/spec/api/source/set_refresh_time_spec.rb +43 -0
  293. data/spec/api/source/upload_file_spec.rb +26 -0
  294. data/spec/api/user/create_user_spec.rb +16 -0
  295. data/spec/api/user/delete_user_spec.rb +36 -0
  296. data/spec/api/user/list_users_spec.rb +30 -0
  297. data/spec/api/user/update_user_spec.rb +31 -0
  298. data/spec/api_token_spec.rb +14 -0
  299. data/spec/app_spec.rb +18 -0
  300. data/spec/apps/emptyapp/application.rb +27 -0
  301. data/spec/apps/emptyapp/settings/license.key +1 -0
  302. data/spec/apps/emptyapp/settings/settings.yml +14 -0
  303. data/spec/apps/rhotestapp/Rakefile +1 -0
  304. data/spec/apps/rhotestapp/application.rb +19 -0
  305. data/spec/apps/rhotestapp/config.ru +1 -0
  306. data/spec/apps/rhotestapp/settings/apple_fake_cert.pem +1 -0
  307. data/spec/apps/rhotestapp/settings/license.key +1 -0
  308. data/spec/apps/rhotestapp/settings/settings.yml +36 -0
  309. data/spec/apps/rhotestapp/sources/base_adapter.rb +9 -0
  310. data/spec/apps/rhotestapp/sources/fixed_schema_adapter.rb +28 -0
  311. data/spec/apps/rhotestapp/sources/sample_adapter.rb +71 -0
  312. data/spec/apps/rhotestapp/sources/simple_adapter.rb +41 -0
  313. data/spec/apps/rhotestapp/sources/sub_adapter.rb +7 -0
  314. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem/mygem.rb +8 -0
  315. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem.rb +1 -0
  316. data/spec/bulk_data/bulk_data_spec.rb +97 -0
  317. data/spec/client_spec.rb +124 -0
  318. data/spec/client_sync_spec.rb +774 -0
  319. data/spec/doc/base.html +72 -0
  320. data/spec/doc/doc_spec.rb +376 -0
  321. data/spec/doc/footer.html +4 -0
  322. data/spec/doc/header.html +30 -0
  323. data/spec/document_spec.rb +31 -0
  324. data/spec/dynamic_adapter_spec.rb +43 -0
  325. data/spec/factories/factories.rb +17 -0
  326. data/spec/generator/generator_spec.rb +58 -0
  327. data/spec/generator/generator_spec_helper.rb +9 -0
  328. data/spec/jobs/bulk_data_job_spec.rb +125 -0
  329. data/spec/jobs/ping_job_spec.rb +102 -0
  330. data/spec/jobs/source_job_spec.rb +29 -0
  331. data/spec/license_spec.rb +66 -0
  332. data/spec/model_spec.rb +273 -0
  333. data/spec/perf/bulk_data_perf_spec.rb +32 -0
  334. data/spec/perf/perf_spec_helper.rb +50 -0
  335. data/spec/perf/store_perf_spec.rb +27 -0
  336. data/spec/ping/android_spec.rb +91 -0
  337. data/spec/ping/apple_spec.rb +70 -0
  338. data/spec/ping/blackberry_spec.rb +62 -0
  339. data/spec/read_state_spec.rb +35 -0
  340. data/spec/rhosync_spec.rb +75 -0
  341. data/spec/server/cors_spec.rb +287 -0
  342. data/spec/server/server_spec.rb +470 -0
  343. data/spec/server/x_domain_session_wrapper_spec.rb +150 -0
  344. data/spec/source_adapter_spec.rb +125 -0
  345. data/spec/source_spec.rb +114 -0
  346. data/spec/source_sync_spec.rb +328 -0
  347. data/spec/spec.opts +4 -0
  348. data/spec/spec_helper.rb +231 -0
  349. data/spec/stats/middleware_spec.rb +53 -0
  350. data/spec/stats/record_spec.rb +92 -0
  351. data/spec/store_spec.rb +251 -0
  352. data/spec/support/shared_examples.rb +168 -0
  353. data/spec/sync_states_spec.rb +72 -0
  354. data/spec/test_methods_spec.rb +134 -0
  355. data/spec/testdata/1000-data.txt +1414 -0
  356. data/spec/testdata/compressed/compress-data.txt +1 -0
  357. data/spec/testdata/upload1.txt +1 -0
  358. data/spec/testdata/upload2.txt +1 -0
  359. data/spec/user_spec.rb +139 -0
  360. data/tasks/redis.rake +206 -0
  361. metadata +706 -0
File without changes
@@ -0,0 +1,28 @@
1
+ class RhoconnectConsole::Server
2
+
3
+ get '/adapter' do
4
+ if params[:xhr] or request.xhr?
5
+ @adapter = nil
6
+ handle_api_error("Can't load adapter url") do
7
+ @adapter = RhoconnectApi::get_adapter(session[:server],session[:token])['adapter_url']
8
+ @domain = ENV['RHODES_URL'] || request.session[:server_url] + "/application"
9
+ end
10
+ erb :adapter, :layout => false
11
+ else
12
+ render_page url_path("/adapter")
13
+ end
14
+ end
15
+
16
+ post '/adapter/create' do
17
+ session[:errors] = nil
18
+ verify_format_of :adapter_url, "url must start with http(s)"
19
+ unless session[:errors]
20
+ handle_api_error("Can't save adapter url") do
21
+ RhoconnectApi::save_adapter(session[:server],
22
+ session[:token],params[:adapter_url])
23
+ end
24
+ end
25
+ redirect url_path( '/adapter'), 303
26
+ end
27
+
28
+ end
@@ -0,0 +1,29 @@
1
+ class RhoconnectConsole::Server
2
+ post '/login' do
3
+ begin
4
+ session[:errors] = nil
5
+ session[:login] = params[:login]
6
+ session[:connect] = params[:connect]
7
+ session[:server_url] = params[:server]
8
+ session[:server] = params[:connect] == 'direct' ? nil : params[:server]
9
+
10
+ #verify_presence_of :server, "Server is not provaided."
11
+ verify_presence_of :login, "Login is not provided."
12
+
13
+ unless session[:errors]
14
+ session[:token] = RhoconnectApi::get_token(session[:server],params[:login],params[:password])
15
+ end
16
+ rescue Exception => e
17
+ session[:token] = nil
18
+ report_error("Can't login to Rhoconnect server.")
19
+ #puts e.message + "\n" + e.backtrace.join("\n")
20
+ end
21
+ redirect url_path('/'), 303
22
+ end
23
+
24
+ get '/logout' do
25
+ session[:token] = nil
26
+ redirect url_path('/'), 303
27
+ end
28
+
29
+ end
@@ -0,0 +1,31 @@
1
+ class RhoconnectConsole::Server
2
+
3
+ get '/device/create' do
4
+ session[:errors] = nil
5
+ handle_api_error("Can't create new device") do
6
+ RhoconnectApi::create_client(session[:server],session[:token],params[:user_id])
7
+ end
8
+ redirect url_path("/user?user_id=#{CGI.escape(params[:user_id])}"), 303
9
+ end
10
+
11
+ get '/device' do
12
+ @attributes = []
13
+ handle_api_error("Can't load list of device attributes") do
14
+ @attributes = RhoconnectApi::get_client_params(session[:server],session[:token],params[:device_id])
15
+ end
16
+ @sources = []
17
+ handle_api_error("Can't load list of sources") do
18
+ @sources = RhoconnectApi::list_sources(session[:server],session[:token],:all)
19
+ end
20
+ erb :client, :layout => false
21
+ end
22
+
23
+ get '/device/delete' do
24
+ handle_api_error("Can't delete device #{params[:device_id]}") do
25
+ RhoconnectApi::delete_client(session[:server],session[:token],
26
+ params[:user_id],params[:device_id])
27
+ end
28
+ redirect url_path(session[:errors] ? "/device?user_id=#{CGI.escape(params[:user_id])}&device_id=#{CGI.escape(params[:device_id])}" :
29
+ "/user?user_id=#{CGI.escape(params[:user_id])}"), 303
30
+ end
31
+ end
@@ -0,0 +1,145 @@
1
+ class RhoconnectConsole::Server
2
+ def docs_render_page(contenturl)
3
+ @currentpage = "Console"
4
+ @initialcontent = contenturl
5
+ @pagetitle = "Rhoconnect Console" #H1 title
6
+ @locals = {
7
+ :div => "main_box",
8
+ :links => [
9
+ { :url => url_path('/homepage'), :title => 'Info' },
10
+ { :url => url_path('/doc/select'), :selected => true, :title => 'Server Document' },
11
+ { :url => url_path('/users'), :title => 'Users' }
12
+ ]
13
+ }
14
+ erb :content
15
+ end
16
+
17
+ def hash_to_params(inhash)
18
+ outstring = "?"
19
+ inhash.each do |k,v|
20
+ outstring << "#{k}=#{CGI.escape(v)}&"
21
+ end
22
+ outstring
23
+ end
24
+
25
+ get '/docs' do
26
+ if params[:xhr] or request.xhr?
27
+
28
+ @src_params = []
29
+ handle_api_error("Can't load list of source attributes") do
30
+ @src_params = RhoconnectApi::get_source_params(
31
+ session[:server],session[:token],params[:source_id])
32
+ end
33
+ @docs = []
34
+ @docs_name = ''
35
+ @back_href = ''
36
+ @doc_params = doc_params
37
+ handle_api_error("Can't load list of the documents") do
38
+ if params[:device_id]
39
+ @docs_name = "device #{params[:device_id]}"
40
+ @back_href = url_path("device?user_id=#{CGI.escape(params[:user_id])}&device_id=#{CGI.escape(params[:device_id])}")
41
+ @docs = RhoconnectApi::list_client_docs(session[:server],session[:token],params[:source_id],params[:device_id])
42
+ else
43
+ if params[:user_id]=='*'
44
+ @docs_name = "app partition"
45
+ @back_href = url_path('/')
46
+ else
47
+ @docs_name = "user #{params[:user_id]} partition"
48
+ @back_href = url_path("user?user_id=#{CGI.escape(params[:user_id])}")
49
+ end
50
+ @docs = RhoconnectApi::list_source_docs(session[:server],
51
+ session[:token],params[:source_id],params[:user_id])
52
+ end
53
+ end
54
+ erb :docs, :layout => false
55
+ else
56
+ docs_render_page url_path("/docs" + hash_to_params(params))
57
+
58
+ end
59
+ end
60
+
61
+ get '/doc/select' do
62
+ if params[:xhr] or request.xhr?
63
+ if params[:dbkey].nil?
64
+ @dbkey = ''
65
+ @data = {}
66
+ else
67
+ @dbkey = params[:dbkey]
68
+ @is_string = doc_is_string
69
+ handle_api_error("Can't load document") do
70
+ @data = RhoconnectApi::get_db_doc(session[:server],
71
+ session[:token],params[:dbkey],@is_string ? :string : '')
72
+ end
73
+ end
74
+ erb :select_doc, :layout => false
75
+ else
76
+ docs_render_page url_path("/doc/select" + hash_to_params(params))
77
+ end
78
+ end
79
+
80
+ get '/doc' do
81
+ if params[:xhr] or request.xhr?
82
+
83
+ @data = {}
84
+ @is_string = doc_is_string
85
+ handle_api_error("Can't load document") do
86
+ @data = RhoconnectApi::get_db_doc(session[:server],
87
+ session[:token],params[:dbkey],@is_string ? :string : '')
88
+ end
89
+ @back_params = "source_id=#{CGI.escape(params[:source_id])}&user_id=#{CGI.escape(params[:user_id])}"
90
+ @back_params += "&device_id=#{CGI.escape(params[:device_id])}" if params[:device_id]
91
+ @back_href = url_path("docs?#{doc_params}")
92
+ erb :doc, :layout => false
93
+ else
94
+ docs_render_page url_path("/doc" + hash_to_params(params))
95
+ end
96
+
97
+ end
98
+
99
+ get '/doc/clear' do
100
+ if params[:xhr] or request.xhr?
101
+ is_string = doc_is_string
102
+ handle_api_error("Can't clear document") do
103
+ RhoconnectApi::set_db_doc(session[:server],session[:token],params[:dbkey],
104
+ is_string ? '' : {}, is_string ? :string : '')
105
+ end
106
+ @result_name = "Clear result"
107
+ @status = "Successfully cleared: [#{CGI.unescape(params[:dbkey])}]"
108
+ @back_href = params[:user_id] ?
109
+ url_path("doc?#{doc_params}&dbkey=#{CGI.escape(params[:dbkey])}") :
110
+ url_path("doc/select?dbkey=#{CGI.escape(params[:dbkey])}")
111
+ erb :result, :layout => false
112
+ else
113
+ docs_render_page url_path("/doc/clear" + hash_to_params(params))
114
+ end
115
+ end
116
+
117
+ post '/doc/upload' do
118
+ if params[:string]
119
+ handle_api_error("Can't upload document") do
120
+ RhoconnectApi::set_db_doc(session[:server],session[:token],CGI.unescape(params[:doc]),params[:string],:string)
121
+ end
122
+ else
123
+ unless params[:file] &&
124
+ (tmpfile = params[:file][:tempfile]) &&
125
+ (name = params[:file][:filename])
126
+ report_error "No file selected"
127
+ else
128
+ data = []
129
+ while blk = tmpfile.read(65536)
130
+ data << blk
131
+ end
132
+ handle_api_error("Can't upload document #{name.inspect}") do
133
+ RhoconnectApi::set_db_doc(session[:server],session[:token],CGI.unescape(params[:doc]),JSON.parse(data.join))
134
+ end
135
+ end
136
+ end
137
+ @result_name = "Upload result"
138
+ @status = "Successfully uploadad data to: [#{CGI.unescape(params[:doc])}]"
139
+ @back_href = params[:user_id] ?
140
+ url_path("doc?#{doc_params}&dbkey=#{params[:doc]}") :
141
+ url_path("doc/select?dbkey=#{params[:doc]}")
142
+ erb :result
143
+ end
144
+
145
+ end
@@ -0,0 +1,19 @@
1
+ class RhoconnectConsole::Server
2
+
3
+ get "/heroku/resources/:id" do
4
+ begin
5
+ # check heroku addon started app
6
+ halt 403 unless ENV['INSTANCE_ID'] == params[:id] && params[:token] == ENV['API_TOKEN']
7
+ # rhoconnect authentication
8
+ session[:login] = 'rhoadmin'
9
+ session[:connect] = 'direct'
10
+ session[:token] = RhoconnectApi::get_token(session[:server],session[:login],ENV['PSWRD'])
11
+ rescue Exception => e
12
+ session[:token] = nil
13
+ halt 403
14
+ end
15
+ response.set_cookie('heroku-nav-data', :value => params[:nav], :path => '/')
16
+ redirect url_path('/'), 303
17
+ end
18
+
19
+ end
@@ -0,0 +1,63 @@
1
+ class RhoconnectConsole::Server
2
+ get '/' do
3
+ if params[:xhr] or request.xhr?
4
+ if login_required
5
+ redirect url_path('/loginpage')
6
+ else
7
+ redirect url_path('/homepage')
8
+ end
9
+ else
10
+ @currentpage = "Console" #which page in menu
11
+ if login_required
12
+ @pagetitle = "Login" #H1 title
13
+ @initialcontent = url_path('/loginpage')
14
+
15
+ @locals = {
16
+ :div => "main_box",
17
+ :links => [
18
+ # { :url => url_path('/timing/bydevice'), :selected => true, :title => 'By Device' },
19
+ # { :url => url_path('/timing/bysource'), :title => 'By Source' }
20
+ ]
21
+ }
22
+ else
23
+ @pagetitle = "Rhoconnect Console" #H1 title
24
+ @initialcontent = url_path('/homepage')
25
+
26
+ @locals = {
27
+ :div => "main_box",
28
+ :links => [
29
+ { :url => url_path('/homepage'), :selected => true, :title => 'Info' },
30
+ { :url => url_path('/doc/select'), :title => 'Server Document' },
31
+ { :url => url_path('/adapter'), :title => 'Adapter URL' },
32
+ { :url => url_path('/users'), :title => 'Users' }
33
+ ]
34
+ }
35
+ end
36
+ erb :content
37
+ end
38
+ end
39
+
40
+ get '/loginpage' do
41
+ halt 401 if ENV['INSTANCE_ID']
42
+ erb :login, :layout => false
43
+ end
44
+
45
+ get '/homepage' do
46
+ @license = nil
47
+ handle_api_error("Can't get license information") do
48
+ @license = RhoconnectApi::get_license_info(session[:server],session[:token])
49
+ end
50
+ @sources = nil
51
+ handle_api_error("Can't load list of application partition sources") do
52
+ @sources = RhoconnectApi::list_sources(session[:server],session[:token],:app)
53
+ end
54
+ erb :home, :layout => false
55
+ end
56
+
57
+ get '/reset' do
58
+ handle_api_error("Can't reset server") do
59
+ RhoconnectApi::reset(session[:server],session[:token])
60
+ end
61
+ redirect url_path('/'), 303
62
+ end
63
+ end
@@ -0,0 +1,242 @@
1
+ require 'json'
2
+
3
+ class RhoconnectConsole::Server
4
+ get '/timing' do
5
+ if login_required
6
+ redirect url_path('/')
7
+ return
8
+ end
9
+ @currentpage = "Statistics"
10
+ @pagetitle = "Statistics" #H1 title
11
+
12
+ @initialcontent = url_path('/timing/usercount')
13
+
14
+ @locals = {
15
+ :div => "main_box",
16
+ :links => [
17
+ { :url => url_path('/timing/usercount'), :selected => true, :title => 'User Count' },
18
+ { :url => url_path('/timing/devicecount'), :title => 'Device Count' },
19
+ { :url => url_path('/timing/httptiming'), :title => 'HTTP Timing' },
20
+ { :url => url_path('/timing/bysource'), :title => 'Source Timing' }
21
+ ]
22
+ }
23
+
24
+ erb :content
25
+ end
26
+
27
+
28
+ get '/timing/bydevice' do
29
+ '<div id="chartdiv" style="height:400px;width:300px; "></div> '
30
+ end
31
+
32
+ def count_graph(uri,title,name,metric)
33
+ @uri = 'uri'
34
+
35
+ start = 0
36
+ finish = -1
37
+ now = Time.now.to_i
38
+ format = "%m/%d/%y %H:%M:%S"
39
+
40
+ thisdata = []
41
+ series = []
42
+ series <<
43
+ options = { :legend => { :show => false }, :title => title }
44
+ @sources = []
45
+
46
+ s = {}
47
+ usercount = []
48
+
49
+ begin
50
+ usercount = JSON.parse RhoconnectApi::stats(session[:server],session[:token], {:metric => metric, :start => start, :finish => finish})
51
+ rescue Exception => e
52
+ usercount = ["0:#{Time.now.to_i}"]
53
+ end
54
+ usercount.each do |count|
55
+ user,timestamp = count.split(':')
56
+ user = user.to_i
57
+ timestamp = timestamp.to_i * 1000
58
+ thisdata << [timestamp,user]
59
+ end
60
+
61
+ options[:axes] = {
62
+ :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer',
63
+ :tickOptions => {:formatString => format}},
64
+ :yaxis => {:label => name, :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer'}
65
+ }
66
+
67
+ options[:cursor] = {:zoom => true, :showTooltip => true}
68
+ s['name'] = name
69
+ s['data'] = [thisdata]
70
+ s['options'] = options
71
+ @sources << s
72
+ erb :jqplot, :layout => false
73
+ end
74
+
75
+ get '/timing/usercount' do
76
+ count_graph('timing/usercount', "User Count", "Users", "users")
77
+ end
78
+
79
+ get '/timing/devicecount' do
80
+ count_graph('timing/devicecount', "Device Count", "Devices", "clients")
81
+ end
82
+
83
+
84
+
85
+ get '/timing/bysource' do
86
+ @uri = 'timing/bysource'
87
+
88
+ #name,data,options
89
+ @displayname = params['display']
90
+ names = []
91
+ handle_api_error("Can't load list of sources") do
92
+ names = RhoconnectApi::list_sources(session[:server],session[:token],:all)
93
+ end
94
+ @sources = []
95
+
96
+ names.each do |name|
97
+ s = {}
98
+ data = []
99
+ series = []
100
+ options = { :legend => { :show => true }, :title => name }
101
+ s['name'] = name
102
+
103
+ keys = JSON.parse RhoconnectApi::stats(session[:server],session[:token], :names => "source:*:#{name}")
104
+
105
+ xmin = 9999999999999999
106
+ xmax = -1
107
+ ymin = 9999999999999999
108
+ ymax = -1
109
+ keys.each do |key|
110
+ method = key.gsub(/source:/,"").gsub(/:.*/,"")
111
+ series << {:showLabel => true, :label => method }
112
+ #range = r.zrange(key,0,-1)
113
+ range = JSON.parse RhoconnectApi::stats(session[:server],session[:token], {:metric => key, :start => 0, :finish => -1})
114
+ thisdata = []
115
+ range.each do |value|
116
+ count = value.split(',')[0]
117
+ value.gsub!(/.*,/,"")
118
+ thisdata << value.split(":").reverse
119
+ thisdata[-1][0] = thisdata[-1][0].to_i * 1000
120
+ thisdata[-1][1] = thisdata[-1][1].to_f
121
+ thisdata[-1][1] /= count.to_f
122
+
123
+ ymin = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f < ymin
124
+ ymax = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f > ymax
125
+
126
+ end
127
+ data << thisdata
128
+ xmin = thisdata[0][0].to_i if thisdata[0] && thisdata[0][0].to_i < xmin
129
+ xmax = thisdata[-1][0].to_i if thisdata[-1] && thisdata[-1][0].to_i > xmax
130
+ end
131
+ #ticks = []
132
+ #xmin..xmax.step(60) {|x| ticks << x }
133
+
134
+ options[:axes] = {
135
+ :yaxis => { :tickOptions => { :formatString =>'%.3f'}, :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05), :label => 'Seconds', :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer' },
136
+ :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer',
137
+ :tickOptions => {:formatString => '%m/%d/%y %H:%M:%S'}}
138
+ }
139
+
140
+
141
+ # options[:axes] = {
142
+ # :yaxis => { :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05) },
143
+ # :xaxis => { :autoscale => true, :min => xmin - 60, :max => xmax + 60, :renderer=>'$.jqplot.DateAxisRenderer',
144
+ # :tickOptions => {:formatString => '%m/%d/%y %H:%M:%S'}}
145
+ # }
146
+
147
+ s['data'] = data
148
+ options[:series] = series
149
+ options[:cursor] = {:zoom => true, :showTooltip => true}
150
+
151
+ # options[:seriesDefaults] = { :showMarker => false}
152
+ # options[:seriesDefaults] = { :renderer => '$.jqplot.BarRenderer', :rendererOptions => {:barPadding => 8, :barMargin => 20}}
153
+ s['options'] = options
154
+
155
+ @sources << s
156
+ end
157
+
158
+ @data = [[[1,2],[3,4],[5,6]]].to_json
159
+ erb :jqplot, :layout => false
160
+ end
161
+
162
+
163
+ get '/timing/httptiming' do
164
+ @uri = 'timing/httptiming'
165
+
166
+ #name,data,options
167
+ @displayname = params['display']
168
+ names = ["GET","POST"]
169
+ handle_api_error("Can't load list of sources") do
170
+ names = RhoconnectApi::list_sources(session[:server],session[:token],:all)
171
+ end
172
+ names << "ALL"
173
+ @sources = []
174
+
175
+ names.each do |name|
176
+ s = {}
177
+ data = []
178
+ series = []
179
+ options = { :legend => { :show => true }, :title => name }
180
+ s['name'] = name
181
+
182
+ name = "*" if name == "ALL"
183
+ keys = JSON.parse RhoconnectApi::stats(session[:server],session[:token], :names => "http:*:#{name}")
184
+
185
+ xmin = 9999999999999999
186
+ xmax = -1
187
+ ymin = 9999999999999999
188
+ ymax = -1
189
+ keys.each do |key|
190
+ method = key.gsub(/http:.*?:/,"")
191
+ method.gsub!(/:.*/,"") unless name == "*"
192
+ series << {:showLabel => true, :label => method }
193
+ #range = r.zrange(key,0,-1)
194
+ range = JSON.parse RhoconnectApi::stats(session[:server],session[:token], {:metric => key, :start => 0, :finish => -1})
195
+ thisdata = []
196
+ range.each do |value|
197
+ count = value.split(',')[0]
198
+ value.gsub!(/.*,/,"")
199
+ thisdata << value.split(":").reverse
200
+ thisdata[-1][0] = thisdata[-1][0].to_i * 1000
201
+ thisdata[-1][1] = thisdata[-1][1].to_f
202
+ thisdata[-1][1] /= count.to_f
203
+
204
+ ymin = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f < ymin
205
+ ymax = thisdata[-1][1].to_f if thisdata[-1][1] && thisdata[-1][1].to_f > ymax
206
+
207
+ end
208
+ data << thisdata
209
+ xmin = thisdata[0][0].to_i if thisdata[0] && thisdata[0][0].to_i < xmin
210
+ xmax = thisdata[-1][0].to_i if thisdata[-1] && thisdata[-1][0].to_i > xmax
211
+ end
212
+ #ticks = []
213
+ #xmin..xmax.step(60) {|x| ticks << x }
214
+
215
+ options[:axes] = {
216
+ :yaxis => { :tickOptions => { :formatString =>'%.3f'}, :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05), :label => 'Seconds', :labelRenderer => '$.jqplot.CanvasAxisLabelRenderer' },
217
+ :xaxis => { :autoscale => true, :renderer=>'$.jqplot.DateAxisRenderer',
218
+ :tickOptions => {:formatString => '%m/%d/%y %H:%M:%S'}}
219
+ }
220
+
221
+
222
+ # options[:axes] = {
223
+ # :yaxis => { :autoscale => true, :min => 0, :max => ymax + (ymax * 0.05) },
224
+ # :xaxis => { :autoscale => true, :min => xmin - 60, :max => xmax + 60, :renderer=>'$.jqplot.DateAxisRenderer',
225
+ # :tickOptions => {:formatString => '%m/%d/%y %H:%M:%S'}}
226
+ # }
227
+
228
+ s['data'] = data
229
+ options[:series] = series
230
+ options[:cursor] = {:zoom => true, :showTooltip => true}
231
+
232
+ # options[:seriesDefaults] = { :showMarker => false}
233
+ # options[:seriesDefaults] = { :renderer => '$.jqplot.BarRenderer', :rendererOptions => {:barPadding => 8, :barMargin => 20}}
234
+ s['options'] = options
235
+
236
+ @sources << s
237
+ end
238
+
239
+ @data = [[[1,2],[3,4],[5,6]]].to_json
240
+ erb :jqplot, :layout => false
241
+ end
242
+ end
@@ -0,0 +1,117 @@
1
+ class RhoconnectConsole::Server
2
+ def render_page(contenturl)
3
+ @currentpage = "Console"
4
+ @initialcontent = contenturl
5
+ @pagetitle = "Rhoconnect Console" #H1 title
6
+ @locals = {
7
+ :div => "main_box",
8
+ :links => [
9
+ { :url => url_path('/homepage'), :title => 'Info' },
10
+ { :url => url_path('/doc/select'), :title => 'Server Document' },
11
+ { :url => url_path('/adapter'), :title => 'Adapter URL' },
12
+ { :url => url_path('/users'), :selected => true, :title => 'Users' }
13
+ ]
14
+ }
15
+ erb :content
16
+ end
17
+
18
+ get '/users' do
19
+ if params[:xhr] or request.xhr?
20
+ @users = []
21
+ handle_api_error("Can't load list of users") do
22
+ @users = RhoconnectApi::list_users(session[:server],session[:token])
23
+ end
24
+ erb :users, :layout => false
25
+
26
+ else
27
+ render_page url_path("/users")
28
+ end
29
+ end
30
+
31
+ get '/user/new' do
32
+ if params[:xhr] or request.xhr?
33
+ erb :newuser, :layout => false
34
+ else
35
+ render_page url_path("/user/new")
36
+ end
37
+
38
+ end
39
+
40
+ get '/user/edit' do
41
+ if params[:xhr] or request.xhr?
42
+ erb :edituser, :layout => false
43
+ else
44
+ render_page url_path("/user/edit")
45
+ end
46
+ end
47
+
48
+ post '/user/update' do
49
+ params.merge!({:login => 'rhoadmin'})
50
+ handle_api_error("Can't update admin password") do
51
+ RhoconnectApi::update_user(session[:server],
52
+ session[:token],params)
53
+ end
54
+ redirect url_path(session[:errors] ? '/user/edit' : '/users'), 303
55
+ end
56
+
57
+ post '/user/create' do
58
+ session[:errors] = nil
59
+ verify_presence_of :login, "Login is not provided."
60
+ unless session[:errors]
61
+ handle_api_error("Can't create new user") do
62
+ RhoconnectApi::create_user(session[:server],
63
+ session[:token],params[:login],params[:password])
64
+ end
65
+ end
66
+ redirect url_path(session[:errors] ? '/user/new' : '/users'), 303
67
+ end
68
+
69
+ get '/user' do
70
+ if params[:xhr] or request.xhr?
71
+
72
+ @devices = []
73
+ handle_api_error("Can't load list of devices") do
74
+ @devices = RhoconnectApi::list_clients(
75
+ session[:server],session[:token],params[:user_id])
76
+ end
77
+ @sources = []
78
+ handle_api_error("Can't load list of user partition sources") do
79
+ @sources = RhoconnectApi::list_sources(session[:server],session[:token],:user)
80
+ end
81
+ erb :user, :layout => false
82
+ else
83
+ params[:user_id] = CGI::escape(params[:user_id]) if params[:user_id]
84
+ render_page url_path("/user?user_id=#{params[:user_id]}")
85
+ end
86
+ end
87
+
88
+ get '/user/delete' do
89
+ handle_api_error("Can't delete user #{params[:user_id]}") do
90
+ RhoconnectApi::delete_user(session[:server],session[:token],params[:user_id])
91
+ end
92
+ redirect url_path(session[:errors] ? "/user?user_id=#{CGI.escape(params[:user_id])}" : '/users'), 303
93
+ end
94
+
95
+ get '/user/ping' do
96
+ if params[:xhr] or request.xhr?
97
+
98
+ @sources = []
99
+ handle_api_error("Can't load list of user partition sources") do
100
+ @sources = RhoconnectApi::list_sources(session[:server],session[:token],:all)
101
+ end
102
+ erb :ping, :layout => false
103
+ else
104
+ render_page url_path("/user/ping?user_id=#{CGI.escape(params[:user_id])}")
105
+ end
106
+
107
+ end
108
+
109
+ post '/user/ping' do
110
+ params['sources'] = params['sources'].split(',')
111
+ handle_api_error("Error while pinging") do
112
+ RhoconnectApi::ping(session[:server],session[:token],params[:user_id],params)
113
+ end
114
+ user = CGI.escape(params[:user_id])
115
+ redirect url_path(session[:errors] ? "/user/ping?user_id=#{user}" : "/user?user_id=#{user}"), 303
116
+ end
117
+ end