2
0

xfrpc.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. 'use strict';
  2. 'require view';
  3. 'require ui';
  4. 'require form';
  5. 'require rpc';
  6. 'require tools.widgets as widgets';
  7. var callServiceList = rpc.declare({
  8. object: 'service',
  9. method: 'list',
  10. params: ['name'],
  11. expect: { '': {} }
  12. });
  13. function getServiceStatus() {
  14. return L.resolveDefault(callServiceList('xfrpc'), {}).then(function (res) {
  15. var isRunning = false;
  16. try {
  17. isRunning = res['xfrpc']['instances']['instance1']['running'];
  18. } catch (e) { }
  19. return isRunning;
  20. });
  21. }
  22. function renderStatus(isRunning) {
  23. var renderHTML = "";
  24. var spanTemp = '<em><span style="color:%s"><strong>%s %s</strong></span></em>';
  25. if (isRunning) {
  26. renderHTML += String.format(spanTemp, 'green', _("x-frp Client "), _("RUNNING"));
  27. } else {
  28. renderHTML += String.format(spanTemp, 'red', _("x-frp Client "), _("NOT RUNNING"));
  29. }
  30. return renderHTML;
  31. }
  32. return view.extend({
  33. render: function() {
  34. var m, s, o;
  35. m = new form.Map('xfrpc', _('xfrpc'));
  36. m.description = _("xfrpc is a c language frp client for frps.");
  37. s = m.section(form.NamedSection, '_status');
  38. s.anonymous = true;
  39. s.render = function (section_id) {
  40. L.Poll.add(function () {
  41. return L.resolveDefault(getServiceStatus()).then(function(res) {
  42. var view = document.getElementById("service_status");
  43. view.innerHTML = renderStatus(res);
  44. });
  45. });
  46. return E('div', { class: 'cbi-map' },
  47. E('fieldset', { class: 'cbi-section'}, [
  48. E('p', { id: 'service_status' },
  49. _('Collecting data ...'))
  50. ])
  51. );
  52. }
  53. s = m.section(form.NamedSection, 'common', 'xfrpc');
  54. s.dynamic = true;
  55. s.tab('common', _('Common Settings'));
  56. s.tab('init', _('Startup Settings'));
  57. o = s.taboption('common', form.Value, 'server_addr', _('Server address'),
  58. '%s <br /> %s'.format(_('Server address specifies the address of the server to connect to.'),
  59. _('By default, this value is "0.0.0.0".')));
  60. o.datatype = 'host';
  61. o = s.taboption('common', form.Value, 'server_port', _('Server port'),
  62. '%s <br /> %s'.format(_('Server port specifies the port to connect to the server on.'),
  63. _('By default, this value is 7000.')));
  64. o.datatype = 'port';
  65. o = s.taboption('common', form.Value, 'token', _('Token'),
  66. '%s <br /> %s'.format(_('Token specifies the authorization token used to create keys to be \
  67. sent to the server. The server must have a matching token for authorization to succeed.'),
  68. _('By default, this value is "".')));
  69. o = s.taboption('init', form.SectionValue, 'init', form.TypedSection,
  70. 'xfrp', _('Startup Settings'));
  71. s = o.subsection;
  72. s.anonymous = true;
  73. s.dynamic = true;
  74. o = s.option(form.Flag, 'disabled', _('Disabled xfrpc service'));
  75. o.datatype = 'bool';
  76. o.optional = true;
  77. o = s.option(form.ListValue, 'loglevel', _('Log level'),
  78. '%s <br /> %s'.format(_('LogLevel specifies the minimum log level. Valid values are "Debug", "Info", \
  79. "Notice", "Warning", "Error", "Critical", "Alert" and "Emergency".'),
  80. _('By default, this value is "Info".')));
  81. o.value(8, _('Debug'))
  82. o.value(7, _('Info'))
  83. o.value(6, _('Notice'))
  84. o.value(5, _('Warning'))
  85. o.value(4, _('Error'))
  86. o.value(3, _('Critical'))
  87. o.value(2, _('Alert'))
  88. o.value(1, _('Emergency'))
  89. s = m.section(form.GridSection, 'xfrpc', _('Proxy Settings'));
  90. s.addremove = true;
  91. s.filter = function(s) { return s !== 'common'; };
  92. s.renderSectionAdd = function(extra_class) {
  93. var el = form.GridSection.prototype.renderSectionAdd.apply(this, arguments),
  94. nameEl = el.querySelector('.cbi-section-create-name');
  95. ui.addValidator(nameEl, 'uciname', true, function(v) {
  96. if (v === 'common') return _('Name can not be "common"');
  97. return true;
  98. }, 'blur', 'keyup');
  99. return el;
  100. }
  101. s.tab('general', _('General Settings'));
  102. s.tab('http', _('HTTP Settings'));
  103. s.option(form.Value, 'type', _('Proxy type'));
  104. s.option(form.Value, 'local_ip', _('Local IP'));
  105. s.option(form.Value, 'local_port', _('Local port'));
  106. o = s.taboption('general', form.ListValue, 'type', _('Proxy type'),
  107. '%s <br /> %s'.format(_('ProxyType specifies the type of this proxy. Valid values include "tcp", "http", "https".'),
  108. _('By default, this value is "tcp".')));
  109. o.value('tcp');
  110. o.value('http');
  111. o.value('https');
  112. o.modalonly = true;
  113. o = s.taboption('general', form.Value, 'local_ip', _('Local IP'),
  114. _('LocalIp specifies the IP address or host name to proxy to.'));
  115. o.modalonly = true;
  116. o.datatype = 'ip4addr';
  117. o = s.taboption('general', form.Value, 'local_port', _('Local port'),
  118. _('LocalPort specifies the port to proxy to.'));
  119. o.modalonly = true;
  120. o.datatype = 'port';
  121. // TCP
  122. o = s.taboption('general', form.Value, 'remote_port', _('Remote port'),
  123. _('If remote_port is 0, frps will assign a random port for you'));
  124. o.depends.apply(o, [{type: 'tcp'}]);
  125. o.optional = true;
  126. o.modalonly = true;
  127. o.datatype = 'port';
  128. // HTTP and HTTPS
  129. o = s.taboption('http', form.Value, 'custom_domains', _('Custom domains'));
  130. o.depends.apply(o, [{type: 'http'}]);
  131. o.depends.apply(o, [{type: 'https'}]);
  132. o.optional = true;
  133. o.modalonly = true;
  134. o = s.taboption('http', form.Value, 'subdomain', _('Subdomain'));
  135. o.depends.apply(o, [{type: 'http'}]);
  136. o.depends.apply(o, [{type: 'https'}]);
  137. o.optional = true;
  138. o.modalonly = true;
  139. return m.render();
  140. }
  141. });