Skip to content

Commit

Permalink
master
Browse files Browse the repository at this point in the history
  • Loading branch information
tongchong committed Mar 21, 2023
2 parents 657ea36 + 5a06987 commit 8f36afe
Show file tree
Hide file tree
Showing 15 changed files with 680 additions and 758 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-bags-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/portal-server": patch
---

portal-server 启动时在/etc/profile.d 配置 shell 打开文件所需功能
4 changes: 2 additions & 2 deletions apps/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"@fastify/formbody": "7.4.0",
"@fastify/static": "6.9.0",
"@fastify/view": "7.4.1",
"liquidjs": "10.6.1",
"liquidjs": "10.6.2",
"@scow/config": "workspace:*",
"@scow/lib-config": "workspace:*",
"@scow/lib-ssh": "workspace:*",
"@scow/utils": "workspace:*",
"@sinclair/typebox": "0.25.24",
"asn1": "0.2.6",
"fastify": "4.14.1",
"fastify": "4.15.0",
"fastify-graceful-shutdown": "3.4.0",
"fastify-plugin": "4.5.0",
"ioredis": "5.3.1",
Expand Down
12 changes: 6 additions & 6 deletions apps/mis-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"@ddadaal/tsgrpc-server": "0.19.0",
"@ddadaal/tsgrpc-common": "0.2.1",
"@grpc/grpc-js": "1.8.12",
"@mikro-orm/cli": "5.6.14",
"@mikro-orm/core": "5.6.14",
"@mikro-orm/mariadb": "5.6.14",
"@mikro-orm/migrations": "5.6.14",
"@mikro-orm/mysql": "5.6.14",
"@mikro-orm/seeder": "5.6.14",
"@mikro-orm/cli": "5.6.15",
"@mikro-orm/core": "5.6.15",
"@mikro-orm/mariadb": "5.6.15",
"@mikro-orm/migrations": "5.6.15",
"@mikro-orm/mysql": "5.6.15",
"@mikro-orm/seeder": "5.6.15",
"@scow/config": "workspace:*",
"@scow/lib-decimal": "workspace:*",
"@scow/lib-slurm": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions apps/mis-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@scow/lib-web": "workspace:*",
"@scow/utils": "workspace:*",
"@sinclair/typebox": "0.25.24",
"antd": "5.3.0",
"antd": "5.3.2",
"dayjs": "1.11.7",
"google-protobuf": "3.21.2",
"less": "4.1.3",
Expand All @@ -52,7 +52,7 @@
"react-dom": "18.2.0",
"react-is": "18.2.0",
"simstate": "3.0.1",
"styled-components": "5.3.8",
"styled-components": "5.3.9",
"tslib": "2.5.0",
"typescript": "5.0.2"
},
Expand All @@ -61,14 +61,14 @@
"@next/bundle-analyzer": "13.2.4",
"@types/google-protobuf": "3.15.6",
"@types/mime-types": "2.1.1",
"@types/node": "18.15.1",
"@types/node": "18.15.5",
"@types/nprogress": "0.2.0",
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
"@types/styled-components": "5.1.26",
"babel-plugin-import": "1.13.6",
"postcss": "8.4.21",
"webpack": "5.76.1"
"webpack": "5.76.2"
},
"browserslist": {
"production": [
Expand Down
36 changes: 36 additions & 0 deletions apps/portal-server/assets/scow-shell-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
sdown () {
if [ "$1" == "-h" ]; then
echo "Usage: sdown [-h] [FILE]"
echo "Downloading the specified file (only valid in SCOW)."
return 0
fi
if [ $# -eq 0 ];then
echo "Please enter the file name you want to download."
return 0
fi
if [ $# -gt 1 ];then
echo "Please enter only one file name. Multiple file names are not supported."
return 0
fi
result=$(echo $@ | grep "/")
if [[ "$result" != "" ]]
then
echo "sdown does not support relative paths. Please enter the file name."
return 0
fi
if [ ! -f "$@" ]; then
echo "File $@ does not exist."
return 0
fi
echo "SCOW is downloading file $@ in directory `pwd`"
echo "This command is only valid for SCOW web shells."
}
sopen () {
if [ "$1" == "-h" ]; then
echo "Usage: sopen [-h]"
echo "Open file explorer (only valid in SCOW)."
return 0
fi
echo "SCOW is opening the file system `pwd`"
echo "This command is only valid for SCOW web shells."
}
2 changes: 1 addition & 1 deletion apps/portal-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@types/wait-on": "5.3.1",
"@types/shell-quote": "1.7.1",
"form-data": "4.0.0",
"@types/ssh2": "1.11.7"
"@types/ssh2": "1.11.8"
},
"volta": {
"extends": "../../package.json"
Expand Down
7 changes: 7 additions & 0 deletions apps/portal-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import { Server } from "@ddadaal/tsgrpc-server";
import { omitConfigSpec } from "@scow/lib-config";
import { readVersionFile } from "@scow/utils/build/version";
import { clusters } from "src/config/clusters";
import { config } from "src/config/env";
import { plugins } from "src/plugins";
import { appServiceServer } from "src/services/app";
import { desktopServiceServer } from "src/services/desktop";
import { fileServiceServer } from "src/services/file";
import { jobServiceServer } from "src/services/job";
import { shellServiceServer } from "src/services/shell";
import { initShellFile } from "src/utils/shell";
import { checkClustersRootUserLogin } from "src/utils/ssh";

export async function createServer() {
Expand Down Expand Up @@ -50,7 +52,12 @@ export async function createServer() {

if (process.env.NODE_ENV === "production") {
await checkClustersRootUserLogin(server.logger);
await Promise.all(Object.entries(clusters).map(async ([id]) => {
await initShellFile(id, server.logger);
}));
}



return server;
}
37 changes: 37 additions & 0 deletions apps/portal-server/src/utils/shell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { sftpChmod } from "@scow/lib-ssh";
import { getClusterLoginNode, sshConnect } from "src/utils/ssh";
import { Logger } from "ts-log";


const SHELL_FILE_LOCAL = "assets/scow-shell-file.sh";
const PROFILE_DIRECTORY = "/etc/profile.d";
const SHELL_FILE_REMOTE = "/etc/profile.d/scow-shell-file.sh";


export async function initShellFile(cluster: string, logger: Logger) {

const host = getClusterLoginNode(cluster);
if (!host) { throw new Error(`Cluster ${cluster} has no login node`); }

return await sshConnect(host, "root", logger, async (ssh) => {
// make sure directory /etc/profile.d exists.
await ssh.mkdir(PROFILE_DIRECTORY);
const sftp = await ssh.requestSFTP();

await ssh.putFile(SHELL_FILE_LOCAL, SHELL_FILE_REMOTE);
await sftpChmod(sftp)(SHELL_FILE_REMOTE, "755");
logger.info(`Copy scow-shell-file.sh to the ${SHELL_FILE_REMOTE} of the login node of cluster ${cluster}.`);
});
}
36 changes: 36 additions & 0 deletions apps/portal-server/tests/shell/initShellFile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { sftpExists, sftpStat, sshConnect } from "@scow/lib-ssh";
import { rootKeyPair } from "src/config/env";
import { initShellFile } from "src/utils/shell";
import { getClusterLoginNode } from "src/utils/ssh";

const SHELL_FILE_REMOTE = "/etc/profile.d/scow-shell-file.sh";

it("To test whether the scow-shell-file.sh is automatically copied", async () => {
const cluster = "hpc01";

await initShellFile(cluster, console);
const host = getClusterLoginNode(cluster);
if (!host) { throw new Error(`Cluster ${cluster} has no login node`); }

await sshConnect(host, "test", rootKeyPair, console, async (ssh) => {
const sftp = await ssh.requestSFTP();
const result = await sftpExists(sftp, SHELL_FILE_REMOTE);
expect(result).toEqual(true);
const stats = await sftpStat(sftp)(SHELL_FILE_REMOTE);
const testNumberPermission = (stats.mode & parseInt("777", 8)).toString(8);
expect(testNumberPermission).toEqual("755");
});
});

12 changes: 6 additions & 6 deletions apps/portal-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@uiw/react-codemirror": "4.19.9",
"@codemirror/view": "6.9.2",
"@codemirror/language": "6.6.0",
"@codemirror/legacy-modes": "6.3.1",
"@codemirror/legacy-modes": "6.3.2",
"@uiw/codemirror-theme-github": "4.19.9",
"@ddadaal/next-typed-api-routes-runtime": "0.5.2",
"@ddadaal/tsgrpc-client": "0.17.3",
Expand All @@ -44,7 +44,7 @@
"@scow/lib-web": "workspace:*",
"@sinclair/typebox": "0.25.24",
"@scow/protos": "workspace:*",
"antd": "5.3.0",
"antd": "5.3.2",
"busboy": "1.6.0",
"google-protobuf": "3.21.2",
"less": "4.1.3",
Expand All @@ -61,7 +61,7 @@
"react-dom": "18.2.0",
"react-is": "18.2.0",
"simstate": "3.0.1",
"styled-components": "5.3.8",
"styled-components": "5.3.9",
"tslib": "2.5.0",
"typescript": "5.0.2",
"xterm": "5.1.0",
Expand All @@ -77,17 +77,17 @@
"@types/busboy": "1.5.0",
"@types/google-protobuf": "3.15.6",
"@types/mime-types": "2.1.1",
"@types/node": "18.15.1",
"@types/node": "18.15.5",
"@types/nprogress": "0.2.0",
"@types/random-words": "1.1.2",
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
"@types/styled-components": "5.1.26",
"@types/url-join": "4.0.1",
"jest-environment-jsdom": "29.5.0",
"node-mocks-http": "1.12.1",
"node-mocks-http": "1.12.2",
"postcss": "8.4.21",
"webpack": "5.76.1",
"webpack": "5.76.2",
"ts-log": "2.2.5",
"@types/ws": "8.5.4"
},
Expand Down
52 changes: 3 additions & 49 deletions docs/docs/deploy/config/portal/shell.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
sidebar_position: 5
title: 配置Shell终端文件传输功能
title: Shell终端文件传输功能
---

# 配置Shell终端文件传输功能
# Shell终端文件传输功能

Shell终端支持输入命令跳转到文件系统,进行文件的上传和下载;支持下载指定文件。

Expand All @@ -22,52 +22,6 @@ sdown hello.txt
2. 也可以`sopen`进入文件系统以后,在图形界面切换到A目录选择文件进行下载。



`sopen``sdown [文件名]`这两个命令仅在SCOW的Shell终端中使用有效。

该功能需要在登录节点需要修改`/etc/bashrc`,插入以下函数:

```bash
sdown () {
if [ "$1" == "-h" ]; then
echo "Usage: sdown [-h] [FILE]"
echo "Downloading the specified file (only valid in SCOW)."
return 0
fi
if [ $# -eq 0 ];then
echo "Please enter the file name you want to download."
return 0
fi

if [ $# -gt 1 ];then
echo "Please enter only one file name. Multiple file names are not supported."
return 0
fi


result=$(echo $@ | grep "/")
if [[ "$result" != "" ]]
then
echo "sdown does not support relative paths. Please enter the file name."
return 0
fi

if [ ! -f "$@" ]; then
echo "File $@ does not exist."
return 0
fi

echo "SCOW is downloading file $@ in directory `pwd`"
echo "This command is only valid for SCOW web shells."
}

sopen () {
if [ "$1" == "-h" ]; then
echo "Usage: sopen [-h]"
echo "Open file explorer (only valid in SCOW)."
return 0
fi
echo "SCOW is opening the file system `pwd`"
echo "This command is only valid for SCOW web shells."
}
```
在系统启动时,系统会自动上传到登录节点的`/etc/profile.d/`目录下一个`scow-shell-file.sh`脚本,用于在Shell终端中进行文件系统的跳转和文件的下载。如果`/etc/profile.d/`目录不存在会创建该目录。
2 changes: 1 addition & 1 deletion libs/ssh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"devDependencies": {
"@types/shell-quote": "1.7.1",
"@types/ssh2": "1.11.7",
"@types/ssh2": "1.11.8",
"ts-log": "2.2.5"
},
"author": "PKUHPC (https://github.com/PKUHPC)",
Expand Down
8 changes: 4 additions & 4 deletions libs/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"mime-types": "2.1.35"
},
"peerDependencies": {
"antd": "5.3.0",
"antd": "5.3.2",
"next": "13.2.4",
"styled-components": "5.3.8",
"styled-components": "5.3.9",
"@ant-design/icons": "5.0.1",
"dayjs": "1.11.7"
},
"devDependencies": {
"antd": "5.3.0",
"antd": "5.3.2",
"next": "13.2.4",
"styled-components": "5.3.8",
"styled-components": "5.3.9",
"@types/mime-types": "2.1.1",
"react": "18.2.0",
"@types/react": "18.0.28",
Expand Down
Loading

0 comments on commit 8f36afe

Please sign in to comment.