controller.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. let 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. let 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. let 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. let 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. let 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 SSL Passthrough Hosts
  203. */
  204. showNginxSslPassthrough: function () {
  205. if (Cache.User.isAdmin() || Cache.User.canView('ssl_passthrough_hosts')) {
  206. let controller = this;
  207. require(['./main', './nginx/ssl-passthrough/main'], (App, View) => {
  208. controller.navigate('/nginx/ssl-passthrough');
  209. App.UI.showAppContent(new View());
  210. });
  211. }
  212. },
  213. /**
  214. * SSL Passthrough Hosts Form
  215. *
  216. * @param [model]
  217. */
  218. showNginxSslPassthroughForm: function (model) {
  219. if (Cache.User.isAdmin() || Cache.User.canManage('ssl_passthrough_hosts')) {
  220. require(['./main', './nginx/ssl-passthrough/form'], function (App, View) {
  221. App.UI.showModalDialog(new View({model: model}));
  222. });
  223. }
  224. },
  225. /**
  226. * SSL Passthrough Hosts Delete Confirm
  227. *
  228. * @param model
  229. */
  230. showNginxSslPassthroughConfirm: function (model) {
  231. if (Cache.User.isAdmin() || Cache.User.canManage('ssl_passthrough_hosts')) {
  232. require(['./main', './nginx/ssl-passthrough/delete'], function (App, View) {
  233. App.UI.showModalDialog(new View({model: model}));
  234. });
  235. }
  236. },
  237. /**
  238. * Nginx Dead Hosts
  239. */
  240. showNginxDead: function () {
  241. if (Cache.User.isAdmin() || Cache.User.canView('dead_hosts')) {
  242. let controller = this;
  243. require(['./main', './nginx/dead/main'], (App, View) => {
  244. controller.navigate('/nginx/404');
  245. App.UI.showAppContent(new View());
  246. });
  247. }
  248. },
  249. /**
  250. * Dead Host Form
  251. *
  252. * @param [model]
  253. */
  254. showNginxDeadForm: function (model) {
  255. if (Cache.User.isAdmin() || Cache.User.canManage('dead_hosts')) {
  256. require(['./main', './nginx/dead/form'], function (App, View) {
  257. App.UI.showModalDialog(new View({model: model}));
  258. });
  259. }
  260. },
  261. /**
  262. * Dead Host Delete Confirm
  263. *
  264. * @param model
  265. */
  266. showNginxDeadDeleteConfirm: function (model) {
  267. if (Cache.User.isAdmin() || Cache.User.canManage('dead_hosts')) {
  268. require(['./main', './nginx/dead/delete'], function (App, View) {
  269. App.UI.showModalDialog(new View({model: model}));
  270. });
  271. }
  272. },
  273. /**
  274. * Help Dialog
  275. *
  276. * @param {String} title
  277. * @param {String} content
  278. */
  279. showHelp: function (title, content) {
  280. require(['./main', './help/main'], function (App, View) {
  281. App.UI.showModalDialog(new View({title: title, content: content}));
  282. });
  283. },
  284. /**
  285. * Nginx Access
  286. */
  287. showNginxAccess: function () {
  288. if (Cache.User.isAdmin() || Cache.User.canView('access_lists')) {
  289. let controller = this;
  290. require(['./main', './nginx/access/main'], (App, View) => {
  291. controller.navigate('/nginx/access');
  292. App.UI.showAppContent(new View());
  293. });
  294. }
  295. },
  296. /**
  297. * Nginx Access List Form
  298. *
  299. * @param [model]
  300. */
  301. showNginxAccessListForm: function (model) {
  302. if (Cache.User.isAdmin() || Cache.User.canManage('access_lists')) {
  303. require(['./main', './nginx/access/form'], function (App, View) {
  304. App.UI.showModalDialog(new View({model: model}));
  305. });
  306. }
  307. },
  308. /**
  309. * Access List Delete Confirm
  310. *
  311. * @param model
  312. */
  313. showNginxAccessListDeleteConfirm: function (model) {
  314. if (Cache.User.isAdmin() || Cache.User.canManage('access_lists')) {
  315. require(['./main', './nginx/access/delete'], function (App, View) {
  316. App.UI.showModalDialog(new View({model: model}));
  317. });
  318. }
  319. },
  320. /**
  321. * Nginx Certificates
  322. */
  323. showNginxCertificates: function () {
  324. if (Cache.User.isAdmin() || Cache.User.canView('certificates')) {
  325. let controller = this;
  326. require(['./main', './nginx/certificates/main'], (App, View) => {
  327. controller.navigate('/nginx/certificates');
  328. App.UI.showAppContent(new View());
  329. });
  330. }
  331. },
  332. /**
  333. * Nginx Certificate Form
  334. *
  335. * @param [model]
  336. */
  337. showNginxCertificateForm: function (model) {
  338. if (Cache.User.isAdmin() || Cache.User.canManage('certificates')) {
  339. require(['./main', './nginx/certificates/form'], function (App, View) {
  340. App.UI.showModalDialog(new View({model: model}));
  341. });
  342. }
  343. },
  344. /**
  345. * Certificate Renew
  346. *
  347. * @param model
  348. */
  349. showNginxCertificateRenew: function (model) {
  350. if (Cache.User.isAdmin() || Cache.User.canManage('certificates')) {
  351. require(['./main', './nginx/certificates/renew'], function (App, View) {
  352. App.UI.showModalDialog(new View({model: model}));
  353. });
  354. }
  355. },
  356. /**
  357. * Certificate Delete Confirm
  358. *
  359. * @param model
  360. */
  361. showNginxCertificateDeleteConfirm: function (model) {
  362. if (Cache.User.isAdmin() || Cache.User.canManage('certificates')) {
  363. require(['./main', './nginx/certificates/delete'], function (App, View) {
  364. App.UI.showModalDialog(new View({model: model}));
  365. });
  366. }
  367. },
  368. /**
  369. * Audit Log
  370. */
  371. showAuditLog: function () {
  372. let controller = this;
  373. if (Cache.User.isAdmin()) {
  374. require(['./main', './audit-log/main'], (App, View) => {
  375. controller.navigate('/audit-log');
  376. App.UI.showAppContent(new View());
  377. });
  378. } else {
  379. this.showDashboard();
  380. }
  381. },
  382. /**
  383. * Audit Log Metadata
  384. *
  385. * @param model
  386. */
  387. showAuditMeta: function (model) {
  388. if (Cache.User.isAdmin()) {
  389. require(['./main', './audit-log/meta'], function (App, View) {
  390. App.UI.showModalDialog(new View({model: model}));
  391. });
  392. }
  393. },
  394. /**
  395. * Settings
  396. */
  397. showSettings: function () {
  398. let controller = this;
  399. if (Cache.User.isAdmin()) {
  400. require(['./main', './settings/main'], (App, View) => {
  401. controller.navigate('/settings');
  402. App.UI.showAppContent(new View());
  403. });
  404. } else {
  405. this.showDashboard();
  406. }
  407. },
  408. /**
  409. * Settings Item Form
  410. *
  411. * @param model
  412. */
  413. showSettingForm: function (model) {
  414. if (Cache.User.isAdmin()) {
  415. if (model.get('id') === 'default-site') {
  416. require(['./main', './settings/default-site/main'], function (App, View) {
  417. App.UI.showModalDialog(new View({model: model}));
  418. });
  419. }
  420. }
  421. },
  422. /**
  423. * Logout
  424. */
  425. logout: function () {
  426. Tokens.dropTopToken();
  427. this.showLogin();
  428. }
  429. };