From a3a567b3d8a7d52dbf95c81f0ac9f8ec492a0458 Mon Sep 17 00:00:00 2001
From: snltty <1069410172@qq.com>
Date: Tue, 19 Sep 2023 10:01:42 +0800
Subject: [PATCH] init
---
.dockerignore | 25 +++++++++++
.github/workflows/docker.yml | 41 +++++++++++++++++++
README.md | 6 +--
cmonitor/Dockerfile-alpine | 19 +++++++++
cmonitor/Program.cs | 6 +--
cmonitor/Properties/launchSettings.json | 10 +++++
cmonitor/cmonitor.csproj | 2 +
cmonitor/cmonitor.csproj.user | 1 +
.../client/reports/share/ShareReport.cs | 8 ++--
publish-docker.sh | 29 +++++++++++++
10 files changed, 136 insertions(+), 11 deletions(-)
create mode 100644 .dockerignore
create mode 100644 .github/workflows/docker.yml
create mode 100644 cmonitor/Dockerfile-alpine
create mode 100644 cmonitor/Properties/launchSettings.json
create mode 100644 publish-docker.sh
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..3729ff0c
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,25 @@
+**/.classpath
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/azds.yaml
+**/bin
+**/charts
+**/docker-compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md
\ No newline at end of file
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
new file mode 100644
index 00000000..4e8d4511
--- /dev/null
+++ b/.github/workflows/docker.yml
@@ -0,0 +1,41 @@
+name: Docker
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+jobs:
+
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: setup dotnet7
+ uses: actions/setup-dotnet@v2
+ env:
+ GITHUB_TOKEN: '${{ secrets.ACTIONS_TOKEN }}'
+ with:
+ dotnet-version: 7.0.x
+
+ - name: restore projects
+ run:
+ dotnet restore ./cmonitor
+
+ - name: docker login
+ uses: docker/login-action@v2.1.0
+ with:
+ username: '${{secrets.DOCKER_USERNAME}}'
+ password: '${{secrets.DOCKER_PASSWORD}}'
+
+ - name: docker buildx
+ uses: docker/setup-buildx-action@v2.5.0
+
+ - name: chmod shell
+ run: chmod +x publish-docker.sh
+ - name: publish projects
+ run: ./publish-docker.sh
\ No newline at end of file
diff --git a/README.md b/README.md
index 55823f0b..fa64ca26 100644
--- a/README.md
+++ b/README.md
@@ -41,9 +41,9 @@
##### 2、客户端
- [x] **【--server】** 服务器ip **192.168.1.18**
-- [x] **【--service** 服务端口 **1802**
+- [x] **【--service】** 服务端口 **1802**
- [x] **【--share-key】** 自定数据共享 **cmonitor/share**,每项数据长度255
-- [x] **【--share-len】** 长度 **2550**,默认预留10项位置,0键盘KeyBoard、1用户名UserName、2解锁Lock、3壁纸Wallpaper、4锁屏LLock
+- [x] **【--share-len】** 长度 **2550**,默认预留10项位置,0键盘KeyBoard、1壁纸Wallpaper、2锁屏LLock
##### 3、服务端
- [x] **【--web】** 管理UI端口 **1800**
@@ -60,7 +60,7 @@ params += " --share-key cmonitor/share --share-len 2550";
//server
params = " --mode server --web 1800 --api 1801 --service 1802";
-schtasks.exe /create /tn "cmonitor" /rl highest /sc ONLOGON /delay 0000:30 /tr "\\"{exePath}\\"{params}" /f
+schtasks.exe /create /tn "cmonitor" /rl highest /sc ONLOGON /delay 0000:30 /tr "\"{exePath}\"{params}" /f
```
##### linux服务端
```
diff --git a/cmonitor/Dockerfile-alpine b/cmonitor/Dockerfile-alpine
new file mode 100644
index 00000000..e0112b16
--- /dev/null
+++ b/cmonitor/Dockerfile-alpine
@@ -0,0 +1,19 @@
+FROM alpine:latest
+
+ENV TZ=Asia/Shanghai DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
+RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/main/" > /etc/apk/repositories \
+ && apk add --no-cache libstdc++ libintl tzdata zeromq bash \
+ && ln -snf /usr/share/zoneinfo/$clTZ /etc/localtime \
+ && echo $TZ > /etc/timezone
+
+EXPOSE 1800/tcp
+EXPOSE 1801/tcp
+EXPOSE 1802/tcp
+EXPOSE 1802/udp
+
+WORKDIR /app
+COPY . .
+
+
+
+ENTRYPOINT ["./cmonitor.run"]
\ No newline at end of file
diff --git a/cmonitor/Program.cs b/cmonitor/Program.cs
index 3d47e630..ded111ac 100644
--- a/cmonitor/Program.cs
+++ b/cmonitor/Program.cs
@@ -257,10 +257,8 @@ namespace cmonitor
public const int ShareMemoryItemLength = 255;
public const int ShareMemoryKeyBoardIndex = 0;
- public const int ShareMemoryUserNameIndex = 1;
- public const int ShareMemoryLockIndex = 2;
- public const int ShareMemoryWallpaperIndex = 3;
- public const int ShareMemoryLLockIndex = 4;
+ public const int ShareMemoryWallpaperIndex = 1;
+ public const int ShareMemoryLLockIndex = 2;
public const int ReportTime = 30;
public const int ScreenTime = 200;
diff --git a/cmonitor/Properties/launchSettings.json b/cmonitor/Properties/launchSettings.json
new file mode 100644
index 00000000..1c376aac
--- /dev/null
+++ b/cmonitor/Properties/launchSettings.json
@@ -0,0 +1,10 @@
+{
+ "profiles": {
+ "cmonitor": {
+ "commandName": "Project"
+ },
+ "Docker": {
+ "commandName": "Docker"
+ }
+ }
+}
\ No newline at end of file
diff --git a/cmonitor/cmonitor.csproj b/cmonitor/cmonitor.csproj
index de87fbee..ce966b86 100644
--- a/cmonitor/cmonitor.csproj
+++ b/cmonitor/cmonitor.csproj
@@ -10,6 +10,7 @@
favicon.ico
true
Debug;Release;ReleaseLinux
+ Linux
@@ -63,6 +64,7 @@
+
diff --git a/cmonitor/cmonitor.csproj.user b/cmonitor/cmonitor.csproj.user
index 91f3e8c4..f302d508 100644
--- a/cmonitor/cmonitor.csproj.user
+++ b/cmonitor/cmonitor.csproj.user
@@ -2,5 +2,6 @@
<_LastSelectedProfileId>D:\desktop\cmonitor\cmonitor\Properties\PublishProfiles\FolderProfile.pubxml
+ Docker
\ No newline at end of file
diff --git a/cmonitor/server/client/reports/share/ShareReport.cs b/cmonitor/server/client/reports/share/ShareReport.cs
index 5d5e6e87..65147e9d 100644
--- a/cmonitor/server/client/reports/share/ShareReport.cs
+++ b/cmonitor/server/client/reports/share/ShareReport.cs
@@ -23,11 +23,11 @@ namespace cmonitor.server.client.reports.share
GetShare();
return dic;
}
- public bool GetShare(string key,out ShareItemInfo item)
+ public bool GetShare(string key, out ShareItemInfo item)
{
return dic.TryGetValue(key, out item);
}
-
+
MemoryMappedFile mmf3;
MemoryMappedViewAccessor accessor3;
@@ -56,12 +56,12 @@ namespace cmonitor.server.client.reports.share
while (span.Length > 0)
{
byte keyLen = span[0];
- if (keyLen > 0)
+ if (keyLen > 0 && keyLen <= Config.ShareMemoryItemLength - 2)
{
string key = Encoding.UTF8.GetString(span.Slice(1, keyLen));
string val = string.Empty;
byte valLen = span[1 + keyLen];
- if (valLen > 0)
+ if (valLen > 0 && valLen <= Config.ShareMemoryItemLength - 2 - keyLen)
{
val = Encoding.UTF8.GetString(span.Slice(2 + keyLen, valLen));
}
diff --git a/publish-docker.sh b/publish-docker.sh
new file mode 100644
index 00000000..66da15a6
--- /dev/null
+++ b/publish-docker.sh
@@ -0,0 +1,29 @@
+target=$(cd $(dirname $0); pwd)
+image="snltty/cmonitor"
+
+
+fs=('cmonitor')
+ps=('alpine')
+rs=('x64' 'arm64')
+
+for f in ${fs[@]}
+do
+ for p in ${ps[@]}
+ do
+ for r in ${rs[@]}
+ do
+ dotnet publish ./${f} -c release -f net7.0 -o ./public/publish/docker/linux-${p}-${r}/${f} -r ${p}-${r} --self-contained true -p:TieredPGO=true -p:DebugType=none -p:DebugSymbols=false -p:PublishSingleFile=true -p:PublishTrimmed=true -p:EnableCompressionInSingleFile=true -p:DebuggerSupport=false -p:EnableUnsafeBinaryFormatterSerialization=false -p:EnableUnsafeUTF7Encoding=false -p:HttpActivityPropagationSupport=false -p:InvariantGlobalization=true -p:MetadataUpdaterSupport=false -p:UseSystemResourceKeys=true -p:TrimMode=partial
+ cp -rf public/publish/docker/linux-${p}-${r}/${f}/${f} public/publish/docker/linux-${p}-${r}/${f}/${f}.run
+ rm -rf public/publish/docker/linux-${p}-${r}/${f}/${f}
+ cp -rf smash.proxy/Dockerfile-${p} public/publish/docker/linux-${p}-${r}/${f}/Dockerfile-${p}
+ done
+
+ cd public/publish/docker/linux-${p}-x64/${f}
+ docker buildx build -f ${target}/public/publish/docker/linux-${p}-x64/${f}/Dockerfile-${p} --platform="linux/x86_64" --force-rm -t "${image}-${p}-x64" . --push
+ cd ../../../../../
+
+ cd public/publish/docker/linux-${p}-arm64/${f}
+ docker buildx build -f ${target}/public/publish/docker/linux-${p}-arm64/${f}/Dockerfile-${p} --platform="linux/arm64" --force-rm -t "${image}-${p}-arm64" . --push
+ cd ../../../../../
+ done
+done
\ No newline at end of file