controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. 'use strict';
  2. const Backbone = require('backbone');
  3. const Cache = require('./cache');
  4. const Tokens = require('./tokens');
  5. module.exports = {
  6. /**
  7. * @param {String} route
  8. * @param {Object} [options]
  9. * @returns {Boolean}
  10. */
  11. navigate: function (route, options) {
  12. options = options || {};
  13. Backbone.history.navigate(route.toString(), options);
  14. return true;
  15. },
  16. /**
  17. * Login
  18. */
  19. showLogin: function () {
  20. window.location = '/login';
  21. },
  22. /**
  23. * Users
  24. */
  25. showUsers: function () {
  26. let controller = this;
  27. if (Cache.User.isAdmin()) {
  28. require(['./main', './users/main'], (App, View) => {
  29. controller.navigate('/users');
  30. App.UI.showAppContent(new View());
  31. });
  32. } else {
  33. this.showDashboard();
  34. }
  35. },
  36. /**
  37. * User Form
  38. *
  39. * @param [model]
  40. */
  41. showUserForm: function (model) {
  42. if (Cache.User.isAdmin()) {
  43. require(['./main', './user/form'], function (App, View) {
  44. App.UI.showModalDialog(new View({model: model}));
  45. });
  46. }
  47. },
  48. /**
  49. * User Permissions Form
  50. *
  51. * @param model
  52. */
  53. showUserPermissions: function (model) {
  54. if (Cache.User.isAdmin()) {
  55. require(['./main', './user/permissions'], function (App, View) {
  56. App.UI.showModalDialog(new View({model: model}));
  57. });
  58. }
  59. },
  60. /**
  61. * User Password Form
  62. *
  63. * @param model
  64. */
  65. showUserPasswordForm: function (model) {
  66. if (Cache.User.isAdmin() || model.get('id') === Cache.User.get('id')) {
  67. require(['./main', './user/password'], function (App, View) {
  68. App.UI.showModalDialog(new View({model: model}));
  69. });
  70. }
  71. },
  72. /**
  73. * User Delete Confirm
  74. *
  75. * @param model
  76. */
  77. showUserDeleteConfirm: function (model) {
  78. if (Cache.User.isAdmin() && model.get('id') !== Cache.User.get('id')) {
  79. require(['./main', './user/delete'], function (App, View) {
  80. App.UI.showModalDialog(new View({model: model}));
  81. });
  82. }
  83. },
  84. /**
  85. * Error
  86. *
  87. * @param {Error} err
  88. * @param {String} nice_msg
  89. */
  90. /*
  91. showError: function (err, nice_msg) {
  92. require(['./main', './error/main'], (App, View) => {
  93. App.UI.showAppContent(new View({
  94. err: err,
  95. nice_msg: nice_msg
  96. }));
  97. });
  98. },
  99. */
  100. /**
  101. * Dashboard
  102. */
  103. showDashboard: function () {
  104. let controller = this;
  105. require(['./main', './dashboard/main'], (App, View) => {
  106. controller.navigate('/');
  107. App.UI.showAppContent(new View());
  108. });
  109. },
  110. /**
  111. * Nginx Proxy Hosts
  112. */
  113. showNginxProxy: function () {
  114. if (Cache.User.isAdmin() || Cache.User.canView('proxy_hosts')) {
  115. let controller = this;
  116. require(['./main', './nginx/proxy/main'], (App, View) => {
  117. controller.navigate('/nginx/proxy');
  118. App.UI.showAppContent(new View());
  119. });
  120. }
  121. },
  122. /**
  123. * Nginx Proxy Host Form
  124. *
  125. * @param [model]
  126. */
  127. showNginxProxyForm: function (model) {
  128. if (Cache.User.isAdmin() || Cache.User.canManage('proxy_hosts')) {
  129. require(['./main', './nginx/proxy/form'], function (App, View) {
  130. App.UI.showModalDialog(new View({model: model}));
  131. });
  132. }
  133. },
  134. /**
  135. * Proxy Host Delete Confirm
  136. *
  137. * @param model
  138. */
  139. showNginxProxyDeleteConfirm: function (model) {
  140. if (Cache.User.isAdmin() || Cache.User.canManage('proxy_hosts')) {
  141. require(['./main', './nginx/proxy/delete'], function (App, View) {
  142. App.UI.showModalDialog(new View({model: model}));
  143. });
  144. }
  145. },
  146. /**
  147. * Nginx Redirection Hosts
  148. */
  149. showNginxRedirection: function () {
  150. if (Cache.User.isAdmin() || Cache.User.canView('redirection_hosts')) {
  151. let controller = this;
  152. require(['./main', './nginx/redirection/main'], (App, View) => {
  153. controller.navigate('/nginx/redirection');
  154. App.UI.showAppContent(new View());
  155. });
  156. }
  157. },
  158. /**
  159. * Nginx Redirection Host Form
  160. *
  161. * @param [model]
  162. */
  163. showNginxRedirectionForm: function (model) {
  164. if (Cache.User.isAdmin() || Cache.User.canManage('redirection_hosts')) {
  165. require(['./main', './nginx/redirection/form'], function (App, View) {
  166. App.UI.showModalDialog(new View({model: model}));
  167. });
  168. }
  169. },
  170. /**
  171. * Proxy Redirection Delete Confirm
  172. *
  173. * @param model
  174. */
  175. showNginxRedirectionDeleteConfirm: function (model) {
  176. if (Cache.User.isAdmin() || Cache.User.canManage('redirection_hosts')) {
  177. require(['./main', './nginx/redirection/delete'], function (App, View) {
  178. App.UI.showModalDialog(new View({model: model}));
  179. });
  180. }
  181. },
  182. /**
  183. * Nginx Stream Hosts
  184. */
  185. showNginxStream: function () {
  186. if (Cache.User.isAdmin() || Cache.User.canView('streams')) {
  187. let controller = this;
  188. require(['./main', './nginx/stream/main'], (App, View) => {
  189. controller.navigate('/nginx/stream');
  190. App.UI.showAppContent(new View());
  191. });
  192. }
  193. },
  194. /**
  195. * Stream Form
  196. *
  197. * @param [model]
  198. */
  199. showNginxStreamForm: function (model) {
  200. if (Cache.User.isAdmin() || Cache.User.canManage('streams')) {
  201. require(['./main', './nginx/stream/form'], function (App, View) {
  202. App.UI.showModalDialog(new View({model: model}));
  203. });
  204. }
  205. },
  206. /**
  207. * Stream Delete Confirm
  208. *
  209. * @param model
  210. */
  211. showNginxStreamDeleteConfirm: function (model) {
  212. if (Cache.User.isAdmin() || Cache.User.canManage('streams')) {
  213. require(['./main', './nginx/stream/delete'], function (App, View) {
  214. App.UI.showModalDialog(new View({model: model}));
  215. });
  216. }
  217. },
  218. /**
  219. * Nginx Dead Hosts
  220. */
  221. showNginxDead: function () {
  222. if (Cache.User.isAdmin() || Cache.User.canView('dead_hosts')) {
  223. let controller = this;
  224. require(['./main', './nginx/dead/main'], (App, View) => {
  225. controller.navigate('/nginx/404');
  226. App.UI.showAppContent(new View());
  227. });
  228. }
  229. },
  230. /**
  231. * Dead Host Form
  232. *
  233. * @param [model]
  234. */
  235. showNginxDeadForm: function (model) {
  236. if (Cache.User.isAdmin() || Cache.User.canManage('dead_hosts')) {
  237. require(['./main', './nginx/dead/form'], function (App, View) {
  238. App.UI.showModalDialog(new View({model: model}));
  239. });
  240. }
  241. },
  242. /**
  243. * Dead Host Delete Confirm
  244. *
  245. * @param model
  246. */
  247. showNginxDeadDeleteConfirm: function (model) {
  248. if (Cache.User.isAdmin() || Cache.User.canManage('dead_hosts')) {
  249. require(['./main', './nginx/dead/delete'], function (App, View) {
  250. App.UI.showModalDialog(new View({model: model}));
  251. });
  252. }
  253. },
  254. /**
  255. * Help Dialog
  256. *
  257. * @param {String} title
  258. * @param {String} content
  259. */
  260. showHelp: function (title, content) {
  261. require(['./main', './help/main'], function (App, View) {
  262. App.UI.showModalDialog(new View({title: title, content: content}));
  263. });
  264. },
  265. /**
  266. * Nginx Access
  267. */
  268. showNginxAccess: function () {
  269. if (Cache.User.isAdmin() || Cache.User.canView('access_lists')) {
  270. let controller = this;
  271. require(['./main', './nginx/access/main'], (App, View) => {
  272. controller.navigate('/nginx/access');
  273. App.UI.showAppContent(new View());
  274. });
  275. }
  276. },
  277. /**
  278. * Nginx Access List Form
  279. *
  280. * @param [model]
  281. */
  282. showNginxAccessListForm: function (model) {
  283. if (Cache.User.isAdmin() || Cache.User.canManage('access_lists')) {
  284. require(['./main', './nginx/access/form'], function (App, View) {
  285. App.UI.showModalDialog(new View({model: model}));
  286. });
  287. }
  288. },
  289. /**
  290. * Nginx Certificates
  291. */
  292. showNginxCertificates: function () {
  293. if (Cache.User.isAdmin() || Cache.User.canView('certificates')) {
  294. let controller = this;
  295. require(['./main', './nginx/certificates/main'], (App, View) => {
  296. controller.navigate('/nginx/certificates');
  297. App.UI.showAppContent(new View());
  298. });
  299. }
  300. },
  301. /**
  302. * Nginx Certificate Form
  303. *
  304. * @param [model]
  305. */
  306. showNginxCertificateForm: function (model) {
  307. if (Cache.User.isAdmin() || Cache.User.canManage('certificates')) {
  308. require(['./main', './nginx/certificates/form'], function (App, View) {
  309. App.UI.showModalDialog(new View({model: model}));
  310. });
  311. }
  312. },
  313. /**
  314. * Certificate Delete Confirm
  315. *
  316. * @param model
  317. */
  318. showNginxCertificateDeleteConfirm: function (model) {
  319. if (Cache.User.isAdmin() || Cache.User.canManage('certificates')) {
  320. require(['./main', './nginx/certificates/delete'], function (App, View) {
  321. App.UI.showModalDialog(new View({model: model}));
  322. });
  323. }
  324. },
  325. /**
  326. * Audit Log
  327. */
  328. showAuditLog: function () {
  329. let controller = this;
  330. if (Cache.User.isAdmin()) {
  331. require(['./main', './audit-log/main'], (App, View) => {
  332. controller.navigate('/audit-log');
  333. App.UI.showAppContent(new View());
  334. });
  335. } else {
  336. this.showDashboard();
  337. }
  338. },
  339. /**
  340. * Audit Log Metadata
  341. *
  342. * @param model
  343. */
  344. showAuditMeta: function (model) {
  345. if (Cache.User.isAdmin()) {
  346. require(['./main', './audit-log/meta'], function (App, View) {
  347. App.UI.showModalDialog(new View({model: model}));
  348. });
  349. }
  350. },
  351. /**
  352. * Logout
  353. */
  354. logout: function () {
  355. Tokens.dropTopToken();
  356. this.showLogin();
  357. }
  358. };