Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: flomesh-io/ztm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0-rc1
Choose a base ref
...
head repository: flomesh-io/ztm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Dec 2, 2024

  1. Copy the full SHA
    7e9925a View commit details
  2. Copy the full SHA
    e094c81 View commit details
  3. fix cn appstore

    lindongchen committed Dec 2, 2024
    Copy the full SHA
    f57e81b View commit details
  4. Copy the full SHA
    199bd4c View commit details
  5. Copy the full SHA
    aae58c6 View commit details
  6. Copy the full SHA
    eec9043 View commit details
  7. Copy the full SHA
    2473580 View commit details
  8. Delete debugging prints

    pajama-coder committed Dec 2, 2024
    Copy the full SHA
    d537147 View commit details

Commits on Dec 3, 2024

  1. Copy the full SHA
    5588490 View commit details
  2. Copy the full SHA
    584bc5d View commit details
  3. fix chat bug

    lindongchen committed Dec 3, 2024
    Copy the full SHA
    ad0cd5d View commit details
  4. fix chat bug

    lindongchen committed Dec 3, 2024
    Copy the full SHA
    fe346e9 View commit details
  5. fix chat scrollbar bg

    lindongchen committed Dec 3, 2024
    Copy the full SHA
    f56f921 View commit details
  6. add jp timezone

    lindongchen committed Dec 3, 2024
    Copy the full SHA
    f309688 View commit details
  7. fix gui issue

    lindongchen committed Dec 3, 2024
    Copy the full SHA
    6e3b08c View commit details
  8. fix chat bug

    lindongchen committed Dec 3, 2024
    Copy the full SHA
    a3e0697 View commit details

Commits on Dec 6, 2024

  1. fix browser pad oveflow

    lindongchen committed Dec 6, 2024
    Copy the full SHA
    79914f6 View commit details
  2. fix browser pad oveflow

    lindongchen committed Dec 6, 2024
    Copy the full SHA
    fb6241c View commit details
  3. update rs lib name

    lindongchen committed Dec 6, 2024
    Copy the full SHA
    b77b90d View commit details

Commits on Dec 12, 2024

  1. Copy the full SHA
    635ada4 View commit details

Commits on Dec 17, 2024

  1. Bump up Pipy version

    pajama-coder committed Dec 17, 2024
    Copy the full SHA
    c0acf31 View commit details
  2. Copy the full SHA
    d3e1299 View commit details
  3. Update README.md

    lindongchen authored Dec 17, 2024
    Copy the full SHA
    2d98732 View commit details
  4. Update README.md

    lindongchen authored Dec 17, 2024
    Copy the full SHA
    5675ba3 View commit details
  5. Update README.md

    lindongchen authored Dec 17, 2024
    Copy the full SHA
    8d2f708 View commit details
  6. Update README.md

    lindongchen authored Dec 17, 2024
    Copy the full SHA
    e7c6774 View commit details
  7. Update README.md

    lindongchen authored Dec 17, 2024
    Copy the full SHA
    1dfb75b View commit details
  8. Update README.md

    lindongchen authored Dec 17, 2024
    Copy the full SHA
    2dc7691 View commit details
  9. Copy the full SHA
    af7c037 View commit details

Commits on Dec 23, 2024

  1. Copy the full SHA
    b165b20 View commit details

Commits on Dec 30, 2024

  1. Copy the full SHA
    3342aeb View commit details

Commits on Dec 31, 2024

  1. add dynamic svg menu

    lindongchen committed Dec 31, 2024
    Copy the full SHA
    5925ef7 View commit details

Commits on Jan 2, 2025

  1. Copy the full SHA
    ebd30a6 View commit details

Commits on Jan 5, 2025

  1. fix msg bug

    lindongchen committed Jan 5, 2025
    Copy the full SHA
    39d7e31 View commit details

Commits on Jan 7, 2025

  1. add i18n

    lindongchen committed Jan 7, 2025
    Copy the full SHA
    4a66b7a View commit details
  2. update i18n

    lindongchen committed Jan 7, 2025
    Copy the full SHA
    5661416 View commit details
  3. update i18n

    lindongchen committed Jan 7, 2025
    Copy the full SHA
    f55181d View commit details
  4. add cloud i18n

    lindongchen committed Jan 7, 2025
    Copy the full SHA
    12aac09 View commit details

Commits on Jan 8, 2025

  1. Copy the full SHA
    82efc2f View commit details
  2. Copy the full SHA
    f857097 View commit details
  3. Copy the full SHA
    0d64b58 View commit details
  4. Copy the full SHA
    14dd0e6 View commit details
  5. update child app i18n

    lindongchen committed Jan 8, 2025
    Copy the full SHA
    69ab3a8 View commit details
  6. Copy the full SHA
    da7303c View commit details
  7. Update ios-build.yml

    lindongchen authored Jan 8, 2025
    Copy the full SHA
    7c64e06 View commit details
  8. Update linux-build.yml

    lindongchen authored Jan 8, 2025
    Copy the full SHA
    b7b757a View commit details
  9. Copy the full SHA
    f2baf67 View commit details
  10. Copy the full SHA
    d5ac010 View commit details
  11. Copy the full SHA
    1d4f7b7 View commit details
  12. Copy the full SHA
    e19e86c View commit details
Showing with 2,604 additions and 817 deletions.
  1. +3 −3 .github/workflows/android-build.yml
  2. +2 −2 .github/workflows/ios-build.yml
  3. +3 −7 .github/workflows/linux-build.yml
  4. +2 −2 .github/workflows/macos-m1-build-sign.yml
  5. +2 −2 .github/workflows/macos-m1-build.yml
  6. +2 −2 .github/workflows/macos-m1-debug.yml
  7. +2 −2 .github/workflows/macos-x64-build.yml
  8. +2 −2 .github/workflows/windows-build.yml
  9. +2 −2 .github/workflows/windows-debug.yml
  10. +2 −0 .gitignore
  11. +22 −0 README.md
  12. +33 −4 agent/api.js
  13. +53 −43 agent/apps/ztm/file/cli.js
  14. +237 −0 agent/apps/ztm/port/api.js
  15. +339 −0 agent/apps/ztm/port/cli.js
  16. +93 −0 agent/apps/ztm/port/main.js
  17. +0 −2 agent/apps/ztm/proxy/api.js
  18. +2 −2 agent/apps/ztm/terminal/api.js
  19. +1 −8 agent/apps/ztm/terminal/cli.js
  20. +2 −2 agent/apps/ztm/tunnel/api.js
  21. +23 −22 agent/apps/ztm/tunnel/cli.js
  22. +62 −2 agent/main.js
  23. +185 −28 agent/mesh.js
  24. +69 −18 cli/main.js
  25. +2 −0 gui/.env
  26. +2 −1 gui/.env.development
  27. +2 −0 gui/apps/ztm/cloud/main.js
  28. +31 −29 gui/apps/ztm/cloud/views/Config.vue
  29. +26 −24 gui/apps/ztm/cloud/views/Files.vue
  30. +3 −2 gui/apps/ztm/cloud/views/Preview.vue
  31. +5 −3 gui/apps/ztm/cloud/views/Queue.vue
  32. +5 −0 gui/apps/ztm/cloud/vite.config.js
  33. +2 −0 gui/apps/ztm/proxy/main.js
  34. +15 −14 gui/apps/ztm/proxy/views/Editor.vue
  35. +15 −13 gui/apps/ztm/proxy/views/Main.vue
  36. +5 −0 gui/apps/ztm/proxy/vite.config.js
  37. +2 −0 gui/apps/ztm/script/main.js
  38. +9 −7 gui/apps/ztm/script/views/Editor.vue
  39. +7 −5 gui/apps/ztm/script/views/Result.vue
  40. +4 −2 gui/apps/ztm/script/views/Scripts.vue
  41. +9 −6 gui/apps/ztm/script/vite.config.js
  42. +2 −0 gui/apps/ztm/tunnel/main.js
  43. +44 −42 gui/apps/ztm/tunnel/views/TunnelEditor.vue
  44. +15 −13 gui/apps/ztm/tunnel/views/Tunnels.vue
  45. +5 −0 gui/apps/ztm/tunnel/vite.config.js
  46. +21 −20 gui/package.json
  47. +0 −72 gui/src-android/app/build.gradle.kts
  48. +2 −0 gui/src-android/app/src/main/AndroidManifest.xml
  49. +3 −0 gui/src-android/app/src/main/java/com/flomesh/ztm/CopyBinaryActivity.kt
  50. +19 −19 gui/src-android/app/src/main/java/com/flomesh/ztm/FileHelper.kt
  51. +32 −2 gui/src-android/app/src/main/java/com/flomesh/ztm/MainActivity.kt
  52. +7 −0 gui/src-android/app/src/main/res/xml/network_security_config.xml
  53. +0 −30 gui/src-ios/apple/LaunchScreen.storyboard
  54. BIN gui/src-ios/apple/Logo.png
  55. +0 −1 gui/src-ios/apple/project.yml
  56. +12 −9 gui/src-ios/apple/ztm.xcodeproj/project.pbxproj
  57. +35 −28 gui/src-ios/apple/ztm_iOS/Info.plist
  58. +45 −0 gui/src-ios/bak/LaunchScreen.storyboard
  59. +14 −15 gui/src-tauri/Cargo.toml
  60. +2 −2 gui/src-tauri/src/{broswer.rs → browser.rs}
  61. +3 −3 gui/src-tauri/src/lib.rs
  62. +1 −1 gui/src-tauri/tauri.conf.json
  63. +9 −0 gui/src/App.vue
  64. +0 −1 gui/src/assets/broswer.scss
  65. +17 −2 gui/src/assets/styles.scss
  66. +23 −0 gui/src/assets/svg.css
  67. +1 −0 gui/src/assets/svg/apps.svg
  68. +1 −0 gui/src/assets/svg/back.svg
  69. +1 −0 gui/src/assets/svg/endpoint.svg
  70. +1 −0 gui/src/assets/svg/grid.svg
  71. +1 −0 gui/src/assets/svg/home.svg
  72. +1 −0 gui/src/assets/svg/log.svg
  73. +1 −0 gui/src/assets/svg/mesh.svg
  74. +1 −0 gui/src/assets/svg/network.svg
  75. +2 −0 gui/src/components.js
  76. +5 −1 gui/src/components/common/AppHeader.vue
  77. +67 −0 gui/src/components/common/Avatar.vue
  78. +20 −11 gui/src/components/common/CertificateUploder.vue
  79. +1 −1 gui/src/components/common/DrawMenu.vue
  80. +4 −2 gui/src/components/common/Empty.vue
  81. +3 −0 gui/src/i18n/en.json
  82. +26 −0 gui/src/i18n/index.js
  83. +195 −0 gui/src/i18n/zh.json
  84. +8 −5 gui/src/layout/AppBottombar.vue
  85. +20 −16 gui/src/layout/AppRoot.vue
  86. +12 −5 gui/src/layout/AppTopbar.vue
  87. +7 −7 gui/src/layout/menu.js
  88. +3 −0 gui/src/main.js
  89. +13 −7 gui/src/service/ZtmService.js
  90. +1 −1 gui/src/service/common/request.js
  91. +10 −0 gui/src/store/modules/account.js
  92. +19 −1 gui/src/utils/dayjs.js
  93. +30 −30 gui/src/utils/style.js
  94. +67 −0 gui/src/utils/svgAvatar.js
  95. +9 −8 gui/src/views/apps/AppManage.vue
  96. +10 −8 gui/src/views/apps/Apps.vue
  97. +2 −3 gui/src/views/apps/core/Browser.vue
  98. +20 −6 gui/src/views/apps/core/Setting.vue
  99. +41 −12 gui/src/views/chat/Chat.vue
  100. +3 −1 gui/src/views/chat/History.vue
  101. +19 −14 gui/src/views/chat/Main.vue
  102. +5 −5 gui/src/views/chat/Setting.vue
  103. +5 −4 gui/src/views/log/EpLog.vue
  104. +8 −6 gui/src/views/log/Log.vue
  105. +6 −4 gui/src/views/mesh/EndpointDetail.vue
  106. +10 −9 gui/src/views/mesh/EndpointInfo.vue
  107. +14 −12 gui/src/views/mesh/Endpoints.vue
  108. +101 −42 gui/src/views/mesh/MeshJoin.vue
  109. +46 −41 gui/src/views/mesh/Meshes.vue
  110. +8 −1 gui/vite.config.js
  111. +177 −32 hub/main.js
  112. +1 −1 pipy
6 changes: 3 additions & 3 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- name: Setup Java JDK
uses: actions/setup-java@v4
with:
@@ -93,12 +93,12 @@ jobs:
export JAVA_HOME='/opt/hostedtoolcache/Java_Adopt_jdk/17.0.10-7/x64'
export ANDROID_HOME='/usr/local/lib/android/sdk'
$ANDROID_HOME/build-tools/31.0.0/apksigner verify ./gui/src-tauri/gen/android/app/build/outputs/apk/universal/release/ztm-app-v${{ vars.APP_VERSION }}-android.apk
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ztm-app-v${{ vars.APP_VERSION }}-android
path: ./gui/src-tauri/gen/android/app/build/outputs/apk/universal/release/ztm-app-v${{ vars.APP_VERSION }}-android.apk

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ztm-lib-v${{ vars.APP_VERSION }}-android
path: |
4 changes: 2 additions & 2 deletions .github/workflows/ios-build.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- name: Decode and import certificate
env:
MACOS_BASE64: ${{ secrets.MACOS_BASE64 }}
@@ -43,7 +43,7 @@ jobs:
cd gui
src-ios/sign.sh src-tauri/gen/apple/build/arm64/ztm.ipa $APPLE_ID $APPLE_PASSWORD
timeout-minutes: 120
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: release
path: ./gui/src-tauri/gen/apple/build/arm64/ztm.ipa
10 changes: 3 additions & 7 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- name: Install dependencies
run: |
sudo apt-get update
@@ -39,18 +39,14 @@ jobs:
- name: Rename deb
run: mv ./gui/src-tauri/target/release/bundle/deb/ztm_${{ vars.APP_VERSION }}_amd64.deb ./gui/src-tauri/target/release/bundle/deb/ztm-app-v${{ vars.APP_VERSION }}-generic_linux.deb

- name: Rename appimage
run: mv ./gui/src-tauri/target/release/bundle/appimage/ztm_${{ vars.APP_VERSION }}_amd64.AppImage ./gui/src-tauri/target/release/bundle/appimage/ztm-app-v${{ vars.APP_VERSION }}-generic_linux.AppImage

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ztm-app-v${{ vars.APP_VERSION }}-generic_linux
path: |
./gui/src-tauri/target/release/bundle/rpm/ztm-app-v${{ vars.APP_VERSION }}-generic_linux.rpm
./gui/src-tauri/target/release/bundle/deb/ztm-app-v${{ vars.APP_VERSION }}-generic_linux.deb
./gui/src-tauri/target/release/bundle/appimage/ztm-app-v${{ vars.APP_VERSION }}-generic_linux.AppImage
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ztm-lib-v${{ vars.APP_VERSION }}-generic_linux
path: |
4 changes: 2 additions & 2 deletions .github/workflows/macos-m1-build-sign.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- name: Decode and import certificate
env:
MACOS_BASE64: ${{ secrets.MACOS_BASE64 }}
@@ -36,7 +36,7 @@ jobs:
cd gui
src-ios/sign.sh src-tauri/target/release/bundle/dmg/ztm_${{ vars.APP_VERSION }}_aarch64.dmg $APPLE_ID $APPLE_PASSWORD
timeout-minutes: 120
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: release
path: ./gui/src-tauri/target/release/bundle/dmg/ztm_${{ vars.APP_VERSION }}_aarch64_signed.dmg
4 changes: 2 additions & 2 deletions .github/workflows/macos-m1-build.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- name: build app
run: |
cd gui
@@ -22,7 +22,7 @@ jobs:
- name: Rename
run: mv ./gui/src-tauri/target/release/bundle/dmg/ztm_${{ vars.APP_VERSION }}_aarch64.dmg ./gui/src-tauri/target/release/bundle/dmg/ztm-app-v${{ vars.APP_VERSION }}-macos-arm64.dmg

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ztm-app-v${{ vars.APP_VERSION }}-macos-arm64
path: ./gui/src-tauri/target/release/bundle/dmg/ztm-app-v${{ vars.APP_VERSION }}-macos-arm64.dmg
4 changes: 2 additions & 2 deletions .github/workflows/macos-m1-debug.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- name: build app
run: |
cd gui
@@ -22,7 +22,7 @@ jobs:
- name: Rename
run: mv ./gui/src-tauri/target/debug/bundle/dmg/ztm_${{ vars.APP_VERSION }}_aarch64.dmg ./gui/src-tauri/target/debug/bundle/dmg/ztm-app-v${{ vars.APP_VERSION }}-macos-arm64.dmg

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ztm-app-v${{ vars.APP_VERSION }}-macos-arm64
path: ./gui/src-tauri/target/debug/bundle/dmg/ztm-app-v${{ vars.APP_VERSION }}-macos-arm64.dmg
4 changes: 2 additions & 2 deletions .github/workflows/macos-x64-build.yml
Original file line number Diff line number Diff line change
@@ -9,15 +9,15 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- name: build app
run: |
cd gui
yarn install
NODE_OPTIONS="--max-old-space-size=4096" yarn build:apps
yarn build-ztm-macos-x64
NODE_OPTIONS="--max-old-space-size=4096" yarn build:base
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: release
path: ./gui/src-tauri/target/release/bundle/dmg/ztm_${{ vars.APP_VERSION }}_x64.dmg
4 changes: 2 additions & 2 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
ninjaVersion: "^1.11.1"
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- run: npm install -g win-node-env
- name: Install NASM
uses: ilammy/setup-nasm@v1
@@ -38,7 +38,7 @@ jobs:
- name: Rename
run: Rename-Item -Path './gui/src-tauri/target/release/bundle/nsis/ztm_${{ vars.APP_VERSION }}_x64-setup.exe' -NewName 'ztm-app-v${{ vars.APP_VERSION }}-win_x86_64.exe'

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ztm-app-v${{ vars.APP_VERSION }}-win_x86_64
path: ./gui/src-tauri/target/release/bundle/nsis/ztm-app-v${{ vars.APP_VERSION }}-win_x86_64.exe
4 changes: 2 additions & 2 deletions .github/workflows/windows-debug.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
ninjaVersion: "^1.11.1"
- uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'
- run: npm install -g win-node-env
- name: Install NASM
uses: ilammy/setup-nasm@v1
@@ -34,7 +34,7 @@ jobs:
run: |
cd gui
set NODE_OPTIONS=--max_old_space_size=4096 && yarn build:debug
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: release
path: ./gui/src-tauri/target/debug/bundle/nsis/ztm_${{ vars.APP_VERSION }}_x64-setup.exe
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -8,3 +8,5 @@ agent/gui
agent/apps/*/*/gui
version.env
usr/
data
config.json
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
<p align="center">
<img width="150px" height="150px" src="https://flomesh.io/img/ztm.png" />
</p>

<div align="center">
<a href="https://github.com/flomesh-io/pipy"><img src="https://flomesh.io/img/favicon.ico" width="20px" height="20px" alt=""></a>
<img src="https://img.shields.io/badge/PipyJS-00adef">
<img src="https://img.shields.io/badge/C++-green">
<img src="https://img.shields.io/badge/Tauri-24C8DB?logo=tauri&logoColor=FFC131">
<img src="https://img.shields.io/badge/Rust-c57c54?logo=rust&logoColor=E34F26">
<img src="https://img.shields.io/badge/Vite5-35495E?logo=vite&logoColor=41D1FF">
<a href="https://gitee.com/link?target=https://github.com/flomesh-io/ztm/stargazers"><img src="https://img.shields.io/github/stars/flomesh-io/ztm" alt="star"></a>
</div>

<p align="center">
<img src="https://img.shields.io/badge/Web-green">
<img src="https://img.shields.io/badge/macOS-gray">
<img src="https://img.shields.io/badge/Windows-blue">
<img src="https://img.shields.io/badge/Linux-orange">
<img src="https://img.shields.io/badge/iOS-Android-blue">
</p>

# ZTM (Zero Trust Mesh)

ZTM is an open source network infrastructure software for running a ***decentralized*** network. It is built upon ***HTTP/2 tunnels*** and can run on ***any sort of IP networks*** such as LANs, containerized networks and the Internet, etc.
37 changes: 33 additions & 4 deletions agent/api.js
Original file line number Diff line number Diff line change
@@ -93,12 +93,12 @@ function delPermit(mesh, username) {
return m.revokePermit(username)
}

function allEndpoints(mesh) {
function allEndpoints(mesh, id, name, keyword, offset, limit) {
var m = meshes[mesh]
if (!m) return Promise.resolve([])
var id = m.config.agent.id
return m.discoverEndpoints().then(
list => list.map(ep => ({ ...ep, isLocal: (ep.id === id) }))
var idLocal = m.config.agent.id
return m.discoverEndpoints(id, name, keyword, offset, limit).then(
list => list.map(ep => ({ ...ep, isLocal: (ep.id === idLocal) }))
)
}

@@ -110,6 +110,26 @@ function getEndpoint(mesh, ep) {
)
}

function getEndpointLabels(mesh, ep) {
var m = meshes[mesh]
if (!m) return Promise.resolve(null)
if (!ep || ep === m.config.agent.id) {
return Promise.resolve(m.getLabels())
} else {
return m.remoteGetLabels(ep)
}
}

function setEndpointLabels(mesh, ep, labels) {
var m = meshes[mesh]
if (!m) return Promise.resolve(null)
if (!ep || ep === m.config.agent.id) {
return Promise.resolve(m.setLabels(labels))
} else {
return m.remoteSetLabels(ep, labels)
}
}

function getEndpointLog(mesh, ep) {
var m = meshes[mesh]
if (!m) return Promise.resolve(null)
@@ -120,6 +140,12 @@ function getEndpointLog(mesh, ep) {
}
}

function allUsers(mesh, name, keyword, offset, limit) {
var m = meshes[mesh]
if (!m) return Promise.resolve([])
return m.discoverUsers(name, keyword, offset, limit)
}

function allFiles(mesh, since) {
var m = meshes[mesh]
if (!m) return Promise.resolve(null)
@@ -234,7 +260,10 @@ export default {
delPermit,
allEndpoints,
getEndpoint,
getEndpointLabels,
setEndpointLabels,
getEndpointLog,
allUsers,
allFiles,
getFileInfo,
delFileInfo,
96 changes: 53 additions & 43 deletions agent/apps/ztm/file/cli.js
Original file line number Diff line number Diff line change
@@ -56,52 +56,62 @@ export default function ({ app, mesh, api, utils }) {
title: 'Copy files or directories',
usage: 'cp <[src-ep:]pathname> <[dst-ep:]pathname>',
action: (args) => {
var src = args['<[src-ep:]pathname>']
var dst = args['<[dst-ep:]pathname>']
return mesh.discover().then(endpoints => {
function resolvePathname(pathname) {
var i = pathname.indexOf(':')
var epID = pathname.substring(0,i)
pathname = pathname.substring(i+1)
if (epID) {
var list = endpoints.filter(ep => ep.name === epID)
if (list.length === 0) list = endpoints.filter(ep => ep.id === epID)
if (list.length > 1) throw 'Ambiguous endpoint name: ' + epID
if (list.length < 1) throw 'Endpoint not found: ' + epID
epID = list[0].id
} else {
epID = app.endpoint.id
pathname = os.path.resolve(cwd, pathname)
}
return { ep: epID, pathname }
}
src = resolvePathname(src)
dst = resolvePathname(dst)
}).then(() => {
return api.startTransfer(
dst.ep, dst.pathname,
src.ep, src.pathname,
app.username
).then(ret => {
if (!ret) throw 'Cannot copy files'
function wait() {
return new Timeout(1).wait().then(
() => api.getTransfer(dst.ep, dst.pathname, app.username)
).then(transfer => {
var state = transfer?.state
if (state === 'working') return wait()
api.abortTransfer(dst.ep, dst.pathname, app.username)
if (state === 'error') throw 'Failed to copy files'
transfer?.copied?.forEach?.(filename => output(filename + '\n'))
switch (state) {
case 'done': output('Done\n'); break
case 'abort': output('Aborted\n'); break
var pair = [
args['<[src-ep:]pathname>'],
args['<[dst-ep:]pathname>'],
].map(pathname => {
var i = pathname.indexOf(':')
var host = pathname.substring(0,i)
pathname = pathname.substring(i+1)
return { host, pathname }
})
return Promise.all(pair.map(
({ host, pathname }) => {
if (host) {
return mesh.discover(host, host).then(endpoints => {
var list = endpoints.filter(ep => ep.name === host)
if (list.length === 0) list = endpoints.filter(ep => ep.id === host)
if (list.length > 1) throw 'Ambiguous endpoint name: ' + host
if (list.length < 1) throw 'Endpoint not found: ' + host
return {
host: list[0].id,
pathname,
}
})
} else {
return Promise.resolve({
host: app.endpoint.id,
pathname: os.path.resolve(cwd, pathname),
})
}
return wait()
})
})
}
)).then(
([src, dst]) => (
api.startTransfer(
dst.host, dst.pathname,
src.host, src.pathname,
app.username
).then(ret => {
if (!ret) throw 'Cannot copy files'
function wait() {
return new Timeout(1).wait().then(
() => api.getTransfer(dst.host, dst.pathname, app.username)
).then(transfer => {
var state = transfer?.state
if (state === 'working') return wait()
api.abortTransfer(dst.host, dst.pathname, app.username)
if (state === 'error') throw 'Failed to copy files'
transfer?.copied?.forEach?.(filename => output(filename + '\n'))
switch (state) {
case 'done': output('Done\n'); break
case 'abort': output('Aborted\n'); break
}
})
}
return wait()
})
)
)
}
},
]
Loading