config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* This is free software, licensed under the Apache License, Version 2.0
  2. *
  3. * Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
  4. */
  5. 'use strict';
  6. 'require form';
  7. 'require rpc';
  8. 'require view';
  9. const callServiceList = rpc.declare({
  10. object: 'service',
  11. method: 'list',
  12. params: ['name'],
  13. expect: { '': {} }
  14. });
  15. function getServiceStatus() {
  16. return L.resolveDefault(callServiceList('cloudflared'), {}).then(function (res) {
  17. var isRunning = false;
  18. try {
  19. isRunning = res['cloudflared']['instances']['cloudflared']['running'];
  20. } catch (ignored) {}
  21. return isRunning;
  22. });
  23. }
  24. return view.extend({
  25. load: function () {
  26. return Promise.all([
  27. getServiceStatus()
  28. ]);
  29. },
  30. render: function (data) {
  31. let isRunning = data[0];
  32. let m, s, o;
  33. m = new form.Map('cloudflared', _('Cloudflare Zero Trust Tunnel'),
  34. _('Cloudflare Zero Trust Security services help you get maximum security both from outside and within the network.') + '<br />' +
  35. _('Create and manage your network on the <a %s>Cloudflare Zero Trust</a> dashboard.')
  36. .format('href="https://one.dash.cloudflare.com" target="_blank"') + '<br />' +
  37. _('See <a %s>documentation</a>.')
  38. .format('href="https://openwrt.org/docs/guide-user/services/vpn/cloudfare_tunnel" target="_blank"')
  39. );
  40. s = m.section(form.NamedSection, 'config', 'cloudflared');
  41. o = s.option(form.DummyValue, '_status', _('Status'));
  42. o.rawhtml = true;
  43. o.cfgvalue = function(section_id) {
  44. var span = '<b><span style="color:%s">%s</span></b>';
  45. var renderHTML = isRunning ?
  46. String.format(span, 'green', _('Running')) :
  47. String.format(span, 'red', _('Not Running'));
  48. return renderHTML;
  49. };
  50. o = s.option(form.Flag, 'enabled', _('Enable'));
  51. o.rmempty = false;
  52. o = s.option(form.TextValue, 'token', _('Token'),
  53. _('The tunnel token is shown in the dashboard once you create a tunnel.')
  54. );
  55. o.optional = true;
  56. o.rmempty = false;
  57. o.monospace = true;
  58. o = s.option(form.FileUpload, 'config', _('Config file path'),
  59. _('See <a %s>documentation</a>.')
  60. .format('href="https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/configure-tunnels/local-management/configuration-file/" target="_blank"')
  61. );
  62. o.default = '/etc/cloudflared/config.yml';
  63. o.root_directory = '/etc/cloudflared/';
  64. o.optional = true;
  65. o = s.option(form.FileUpload, 'origincert', _('Certificate of Origin'),
  66. _('The account certificate for your zones authorizing the client to serve as an Origin for that zone') + '<br />' +
  67. _('Obtain a certificate <a %s>here</a>.')
  68. .format('href="https://dash.cloudflare.com/argotunnel" target="_blank"')
  69. );
  70. o.default = '/etc/cloudflared/cert.pem';
  71. o.root_directory = '/etc/cloudflared/';
  72. o.optional = true;
  73. o = s.option(form.ListValue, 'region', _('Region'),
  74. _('The region to which connections are established.')
  75. );
  76. o.value('us', _('United States'));
  77. o.optional = true;
  78. o = s.option(form.ListValue, 'loglevel', _('Logging level'));
  79. o.value('fatal', _('Fatal'));
  80. o.value('error', _('Error'));
  81. o.value('warn', _('Warning'));
  82. o.value('info', _('Info'));
  83. o.value('debug', _('Debug'));
  84. o.default = 'info';
  85. return m.render();
  86. }
  87. });