controller.js 9.8 KB

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