install-command-builder.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. 'use client';
  2. import { useState } from 'react';
  3. import {
  4. buildScriptCommand,
  5. buildDockerRun,
  6. buildDockerCompose,
  7. type InstallMethod,
  8. type InstallOptions,
  9. } from '@/lib/xray/install';
  10. import { ToolFrame } from './tool-frame';
  11. import { TextField, SelectField, CheckboxField } from './shared/fields';
  12. import { OutputBlock } from './shared/output-block';
  13. export function InstallCommandBuilder() {
  14. const [method, setMethod] = useState<InstallMethod>('script');
  15. const [version, setVersion] = useState('');
  16. const [enableFail2ban, setEnableFail2ban] = useState(true);
  17. const [panelPort, setPanelPort] = useState('');
  18. const [webBasePath, setWebBasePath] = useState('');
  19. const options: InstallOptions = {
  20. method,
  21. version,
  22. enableFail2ban,
  23. panelPort,
  24. webBasePath,
  25. };
  26. return (
  27. <ToolFrame
  28. title="Install command builder"
  29. description="Build the exact install command for your setup. It is assembled in your browser."
  30. >
  31. <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
  32. <SelectField
  33. label="Method"
  34. value={method}
  35. onChange={(v) => setMethod(v as InstallMethod)}
  36. options={['script', 'docker']}
  37. />
  38. <TextField
  39. label="Version"
  40. value={version}
  41. onChange={setVersion}
  42. placeholder="latest"
  43. hint="blank = latest stable · a tag like v3.4.0 · or dev-latest for the rolling dev build"
  44. />
  45. {method === 'docker' ? (
  46. <>
  47. <TextField
  48. label="Panel port"
  49. value={panelPort}
  50. onChange={setPanelPort}
  51. placeholder="2053"
  52. />
  53. <TextField
  54. label="Web base path"
  55. value={webBasePath}
  56. onChange={setWebBasePath}
  57. placeholder="/panel"
  58. />
  59. </>
  60. ) : null}
  61. </div>
  62. <div className="mt-3">
  63. <CheckboxField
  64. label="Enable Fail2ban"
  65. checked={enableFail2ban}
  66. onChange={setEnableFail2ban}
  67. />
  68. </div>
  69. <div className="mt-4 grid grid-cols-1 gap-4">
  70. {method === 'script' ? (
  71. <OutputBlock label="Run on your server" value={buildScriptCommand(options)} />
  72. ) : (
  73. <>
  74. <OutputBlock label="docker run" value={buildDockerRun(options)} />
  75. <OutputBlock label="docker-compose.yml" value={buildDockerCompose(options)} />
  76. </>
  77. )}
  78. </div>
  79. </ToolFrame>
  80. );
  81. }