mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-12-23 21:14:41 +00:00
Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3aa22605d | ||
|
|
39ccbe251f | ||
|
|
8a28d3c589 | ||
|
|
fb15695dab | ||
|
|
5f5091f1e2 | ||
|
|
df92766c74 | ||
|
|
cc8b3e8f06 | ||
|
|
a116db8dbd | ||
|
|
d697547cb7 | ||
|
|
01960c0391 | ||
|
|
953c393e71 | ||
|
|
0873f7dd46 | ||
|
|
8d93a7f320 | ||
|
|
801eca0a14 | ||
|
|
a3ec7b70c9 | ||
|
|
4a77548b23 | ||
|
|
15ccade3d3 | ||
|
|
587fb6fb8a | ||
|
|
5bcb663ac8 | ||
|
|
cbd945536d | ||
|
|
081e9213c2 | ||
|
|
966fae2d4c | ||
|
|
dc4f9ea990 | ||
|
|
05b9c75714 | ||
|
|
4aeeea2325 | ||
|
|
72531cf6c2 | ||
|
|
9ad9be8c61 | ||
|
|
1aa15932a0 | ||
|
|
dbc6a4265a | ||
|
|
edea1f144a | ||
|
|
85c59c03cf | ||
|
|
a1f57bf1d1 | ||
|
|
e6f2c46c28 | ||
|
|
55c6c21aa3 | ||
|
|
40617185e9 | ||
|
|
c3dba45e17 | ||
|
|
83f58366a6 | ||
|
|
3fa09dad8e | ||
|
|
f0f0eb2ef0 | ||
|
|
436b87f8a8 | ||
|
|
f0888ef2ac | ||
|
|
03e23ec203 | ||
|
|
3e1d24624a | ||
|
|
1e3585d47c | ||
|
|
db7fe3781e | ||
|
|
c2ad576cd9 | ||
|
|
5c8d4b4b94 | ||
|
|
88f0cdf738 | ||
|
|
b759585d20 | ||
|
|
183bc211cd | ||
|
|
9bce06d171 | ||
|
|
2491a03d4b | ||
|
|
4b02ad914d | ||
|
|
a1b876d088 | ||
|
|
2cb16144ca | ||
|
|
93b1b618d2 | ||
|
|
97e88f595a | ||
|
|
2448173f44 | ||
|
|
191aaff575 |
148
.github/workflows/casa.yml
vendored
Normal file
148
.github/workflows/casa.yml
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
# This is a basic workflow to help you get started with Actions
|
||||
|
||||
name: Build CasaOS
|
||||
|
||||
on:
|
||||
repository_dispatch:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
ssh:
|
||||
description: 'SSH connection to Actions'
|
||||
required: false
|
||||
default: 'false'
|
||||
|
||||
#on:
|
||||
# push:
|
||||
# branches:
|
||||
# - 'main'
|
||||
# tags:
|
||||
# - 'v*'
|
||||
env:
|
||||
REPO_URL: https://github.com/IceWhaleTech/CasaOS.git
|
||||
REPO_BRANCH: main
|
||||
PACK_SH_URL: https://raw.githubusercontent.com/jerrykuku/actions-casa/main/pack.sh
|
||||
PACK_SH: pack.sh
|
||||
TZ: Asia/Shanghai
|
||||
|
||||
jobs:
|
||||
xgo:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
go_version:
|
||||
- 1.17.1
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
# - name: Get release
|
||||
# id: get_release
|
||||
# uses: bruceadams/get-release@v1.2.3
|
||||
# env:
|
||||
# GITHUB_TOKEN: ${{ github.token }}
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
# - name: Initialization environment
|
||||
# env:
|
||||
# DEBIAN_FRONTEND: noninteractive
|
||||
# run: |
|
||||
# sudo timedatectl set-timezone "$TZ"
|
||||
# sudo mkdir -p /workdir
|
||||
# sudo chown $USER:$GROUPS /workdir
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# - name: Clone source code
|
||||
# working-directory: /workdir
|
||||
# run: |
|
||||
# df -hT $PWD
|
||||
# git clone $REPO_URL -b $REPO_BRANCH --recursive casa
|
||||
# ln -sf /workdir/casa $GITHUB_WORKSPACE/casa
|
||||
# ls
|
||||
|
||||
|
||||
- name: Set enviroment for github-release
|
||||
run: |
|
||||
echo "VERSION=$(cat types/system.go | grep CURRENTVERSION | awk '$2 == "CURRENTVERSION"{print $4}' | sed 's/"//g')" >>$GITHUB_ENV
|
||||
echo "BODY=$(cat types/system.go | grep BODY | awk -F= '{print $2}' | sed 's/"//g')" >>$GITHUB_ENV
|
||||
|
||||
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
|
||||
- name: Build frontend with nodejs and yarn
|
||||
run: |
|
||||
cd UI
|
||||
ls
|
||||
yarn install
|
||||
yarn build
|
||||
|
||||
- name: list work
|
||||
run: pwd
|
||||
|
||||
- name: Build with xgo
|
||||
uses: crazy-max/ghaction-xgo@v1
|
||||
with:
|
||||
xgo_version: latest
|
||||
go_version: ${{ matrix.go_version }}
|
||||
dest: build
|
||||
prefix: casa
|
||||
targets: linux/amd64,linux/arm64,linux/arm-7
|
||||
v: true
|
||||
x: false
|
||||
race: false
|
||||
ldflags: -s -w
|
||||
buildmode: default
|
||||
#
|
||||
# - name: List Files
|
||||
# run: |
|
||||
# ls
|
||||
# mkdir build
|
||||
# ls
|
||||
# echo "::set-output name=status::success"
|
||||
|
||||
- name: Pack builds
|
||||
run: |
|
||||
wget $PACK_SH_URL
|
||||
chmod +x $PACK_SH
|
||||
./$PACK_SH
|
||||
echo "::set-output name=status::success"
|
||||
- name: list work
|
||||
run: ls
|
||||
|
||||
|
||||
- name: Update release
|
||||
uses: meeDamian/github-release@2.0
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
files: >
|
||||
linux-amd64-casaos.tar.gz
|
||||
linux-arm64-casaos.tar.gz
|
||||
linux-arm-7-casaos.tar.gz
|
||||
tag: v${{ env.VERSION }}
|
||||
body: >
|
||||
${{ env.BODY }}
|
||||
name: v${{ env.VERSION }}
|
||||
gzip: false
|
||||
allow_override: false
|
||||
prerelease: true
|
||||
# - name: Upload linux-amd64-casaos.tar.gz
|
||||
# id: upload_assets_amd64
|
||||
# uses: shogo82148/actions-upload-release-asset@v1
|
||||
# with:
|
||||
# upload_url: ${{ steps.get_release.outputs.upload_url }}
|
||||
# asset_path: /workdir/casa/upload/linux-amd64-casaos.tar.gz
|
||||
#
|
||||
# - name: Upload linux-arm64-casaos.tar.gz
|
||||
# id: upload_assets_arm64
|
||||
# uses: shogo82148/actions-upload-release-asset@v1
|
||||
# with:
|
||||
# upload_url: ${{ steps.get_release.outputs.upload_url }}
|
||||
# asset_path: /workdir/casa/upload/linux-arm64-casaos.tar.gz
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -20,6 +20,7 @@
|
||||
|
||||
# IntelliJ project files
|
||||
.idea
|
||||
.vscode
|
||||
*.iml
|
||||
out
|
||||
gen
|
||||
@@ -28,3 +29,5 @@ gen
|
||||
/out/
|
||||
/db/
|
||||
/docs/
|
||||
/conf/conf.ini
|
||||
__debug_bin
|
||||
|
||||
5
.gitmodules
vendored
5
.gitmodules
vendored
@@ -1,3 +1,4 @@
|
||||
[submodule "CasaOS-UI"]
|
||||
path = CasaOS-UI
|
||||
[submodule "UI"]
|
||||
path = UI
|
||||
url = https://github.com/IceWhaleTech/CasaOS-UI.git
|
||||
branch = main
|
||||
Submodule CasaOS-UI deleted from 6139d87e80
2
Makefile
2
Makefile
@@ -4,7 +4,7 @@ build: build-ui build-backend
|
||||
|
||||
|
||||
build-ui:
|
||||
cd UI && yarn install && yarn build
|
||||
cd CasaOS-UI && yarn install && yarn build
|
||||
|
||||
build-backend:
|
||||
export CGO_ENABLED=1;export CGO_LDFLAGS=-static;go build -o ./casa main.go;upx --lzma --best casa
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
## 目录结构
|
||||
|
||||
- conf 配置文件
|
||||
- route 路由
|
||||
- service 方法的具体实现
|
||||
- utils 工具
|
||||
- main.go 入口
|
||||
69
README.md
69
README.md
@@ -1,42 +1,40 @@
|
||||
# CasaOS - A simple, easy to use, beautiful open source home server system.
|
||||
# CasaOS - A simple, easy-to-use, elegant open-source home server system.
|
||||
|
||||

|
||||

|
||||
|
||||
[](https://github.com/IceWhaleTech/CasaOS)
|
||||
[](https://github.com/IceWhaleTech/CasaOS)
|
||||
[](https://github.com/IceWhaleTech/CasaOS/pulls)
|
||||
[](https://github.com/IceWhaleTech/CasaOS/issues)
|
||||
[](https://github.com/IceWhaleTech/CasaOS/stargazers)
|
||||
[](https://github.com/IceWhaleTech/CasaOS/stargazers)
|
||||
[](https://discord.gg/Gx4BCEtHjx)
|
||||
|
||||
CasaOS is an open source home server system based on Docker ecology and designed for home scenarios. It is committed to building the world's most simple, easy-to-use and beautiful home intelligence hub system.
|
||||
CasaOS is an open-source home server system based on the Docker ecosystem and designed for home scenarios. It is committed to building the world's most simple, easy-to-use, and elegant home server system.
|
||||
|
||||
The team promotes a community-driven collaborative innovation model to create a home intelligence hub through open communication with global enthusiasts and developers.
|
||||
IceWhale team believes that through community-driven collaborative innovation and open communication with global developers, we can reshape the digital home experience like never before.
|
||||
|
||||
|
||||
## Features
|
||||
## Key Features
|
||||
|
||||
- UI Designed for home scenarios - simple, beautiful and easy to use
|
||||
- Custom Docker app installation in 3 steps
|
||||
- Automatic Docker application management
|
||||
- Private Cloud App Store 🚧
|
||||
- Home file data/digital asset management 🚧
|
||||
- Smart Home Device Management 🚧
|
||||
- UI designed for home scenarios - simple, elegant, and easy-to-use
|
||||
- Quick Docker app installation with only three steps, plus automatic management
|
||||
- App Store for private cloud 🚧
|
||||
- Home data/digital asset management 🚧
|
||||
- Smart home manager 🚧
|
||||
|
||||
🚧 is under development...
|
||||
🚧 is under development.
|
||||
|
||||
We are actively moving forward with development and welcome you to discuss ideas with us in [Discord](https://discord.gg/Gx4BCEtHjx)!
|
||||
We are actively moving forward with development, and you are more than welcome to share any idea with us!
|
||||
|
||||
|
||||
## Comunity
|
||||
## Community
|
||||
|
||||
Casa is derived from the Spanish word for "home".
|
||||
The CasaOS project originated as a pre-installed system for IceWhale's hardware product ZimaBoard.
|
||||
The word Casa comes from the Spanish word for "home". Project CasaOS originated as a pre-installed system for crowdfunded product [ZimaBoard](https://www.zimaboard.com) on Kickstarter.
|
||||
|
||||
After researching a large number of operating systems and software on the market, the team found that there was no server system designed for home scenarios.
|
||||
After looking at many systems and software on the market, the team found no server system designed for home scenarios, sadly true.
|
||||
|
||||
So, we chose to launch this open source project to develop CasaOS with our friends in the community and you.
|
||||
So, we set out to build this open source project to develop CasaOS with our own hands, everyone in the community, and you.
|
||||
|
||||
> Sincerely welcome you to propose and discuss your great ideas in [Discord](https://discord.gg/Gx4BCEtHjx)!
|
||||
> A warm welcome for you to share and discuss your great ideas in the [Discord server](https://discord.gg/Gx4BCEtHjx)!
|
||||
|
||||
[](https://discord.gg/Gx4BCEtHjx)
|
||||
|
||||
@@ -45,31 +43,32 @@ So, we chose to launch this open source project to develop CasaOS with our frien
|
||||
|
||||
> ⚠️ Note:
|
||||
>
|
||||
> CasaOS is still in a very early version and may be very different from the final release. Feel free to experience and discuss with us in the [Discord](https://discord.gg/Gx4BCEtHjx)!
|
||||
> CasaOS is still in the early development stage and may vary significantly with the final release. Feel free to test run and share your feedback in the [Discord server](https://discord.gg/Gx4BCEtHjx)!
|
||||
|
||||
### System Compatibility
|
||||
|
||||
- Ubuntu Server 20.04 amd64 (✅ Recommend, Tested)
|
||||
- Debian 11 amd64 (⚠️ Not fully tested yet)
|
||||
- OpenWrt 21.02 amd64 (⚠️ Not fully tested yet)
|
||||
- Debian 11 amd64 (⚠️ Not Fully Tested Yet)
|
||||
- OpenWrt 21.02 amd64 (⚠️ Not Fully Tested Yet)
|
||||
- Raspberry Pi OS aarch64/arm64 (🚧 Under Planning)
|
||||
- OpenWrt 21.02 aarch64/arm64 (🚧 Under Planning)
|
||||
|
||||
### Quick Setup CasaOS
|
||||
|
||||
Install a fresh system from the above list and run this command:
|
||||
Fresh install a system from the above list and run the below command:
|
||||
|
||||
```sh
|
||||
curl -fsSL https://get.icewhale.io/casaos.sh | bash
|
||||
```
|
||||
|
||||
|
||||
## To Do
|
||||
|
||||
**v 0.1.x**
|
||||
|
||||
- [x] A beautiful UI for home
|
||||
- [x] An elegant UI for home scenarios
|
||||
- [x] Custom installation of Docker Apps
|
||||
- [x] Docker Apps update, stop, uninstall, restart, etc.
|
||||
- [x] Update, stop, uninstall, restart, etc. of Docker apps
|
||||
- [x] Docker CLI parser
|
||||
- [x] System Update
|
||||
- [ ] Getting Started tutorial
|
||||
@@ -77,13 +76,11 @@ curl -fsSL https://get.icewhale.io/casaos.sh | bash
|
||||
- [ ] App config file import and export
|
||||
- [ ] macvlan network mode
|
||||
|
||||
## Contributors
|
||||
|
||||
- Icewhale Technology
|
||||
- Jerry Liu
|
||||
- Link Liang
|
||||
- Ober Zhang
|
||||
- Zyaiire Ann
|
||||
- John Guan
|
||||
- CasaOS Community
|
||||
- Waiting for you
|
||||
## Maintainers
|
||||
- Jerry Liu
|
||||
- Link Liang
|
||||
- Ober Zhang
|
||||
- Zyaire Ann
|
||||
- John Guan
|
||||
- Right here, waiting for YOU!
|
||||
1
UI
Submodule
1
UI
Submodule
Submodule UI added at 60d08a6b73
@@ -1,11 +1,9 @@
|
||||
[app]
|
||||
PAGE_SIZE = 10
|
||||
RuntimeRootPath = runtime/
|
||||
;LogSavePath = /casaOS/logs/server/
|
||||
LogSavePath = /oasis/logs/server/
|
||||
LogSavePath = /casaOS/logs/server/
|
||||
LogSaveName = log
|
||||
LogFileExt = log
|
||||
; 必须的格式
|
||||
DateStrFormat = 20060102
|
||||
DateTimeFormat = 2006-01-02 15:04:05
|
||||
TimeFormat = 15:04:05
|
||||
@@ -15,37 +13,29 @@ ProjectPath = /casaOS/server
|
||||
|
||||
[server]
|
||||
HttpPort = 8089
|
||||
RunMode = debug
|
||||
;ServerApi = http://113.52.135.30:8090
|
||||
;ServerApi = https://casaos.zimaboard.com
|
||||
;ServerApi = http://192.168.2.167:8090
|
||||
ServerApi = http://192.168.2.142:8090
|
||||
RunMode = release
|
||||
ServerApi = https://api.casaos.zimaboard.com
|
||||
|
||||
[user]
|
||||
UserName = admin
|
||||
PWD = zimaboard
|
||||
Email = aaa@222.ddd
|
||||
Description = ddddddd
|
||||
Email = user@gmail.com
|
||||
Description = description
|
||||
Token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImVyZXJlIiwicGFzc3dvcmQiOiJhZHNmZGYiLCJleHAiOjE2MjQwMDU0ODEsImlzcyI6Imdpbi1ibG9nIn0.JNsCccZuFCwlSMLJg62iOIB2xymk_k7xGa11xhZ07bc
|
||||
|
||||
[zerotier]
|
||||
UserName = ddddd
|
||||
PWD =
|
||||
UserName = user
|
||||
PWD = pwd
|
||||
Token = yBKYyavr2RdFAIVN7iTpzlsB1o6CqTgm
|
||||
|
||||
[redis]
|
||||
Host = 192.168.2.167:6379
|
||||
Host = 127.0.0.1:6379
|
||||
Password =
|
||||
MaxIdle = 30
|
||||
MaxActive = 30
|
||||
IdleTimeout = 200
|
||||
|
||||
[system]
|
||||
AutoUpdate = true
|
||||
SearchSwitch = true
|
||||
WidgetsSwitch = false
|
||||
ShortcutsSwitch = true
|
||||
SearchEngine = baidu
|
||||
Background = http://baidu.com1
|
||||
BackgroundType = d
|
||||
ConfigStr =
|
||||
WidgetList =
|
||||
|
||||
2901
docs/docs.go
2901
docs/docs.go
File diff suppressed because it is too large
Load Diff
2839
docs/swagger.json
2839
docs/swagger.json
File diff suppressed because it is too large
Load Diff
1753
docs/swagger.yaml
1753
docs/swagger.yaml
File diff suppressed because it is too large
Load Diff
57
go.mod
57
go.mod
@@ -3,54 +3,85 @@ module github.com/IceWhaleTech/CasaOS
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.5.0 // indirect
|
||||
github.com/Microsoft/hcsshim v0.8.22 // indirect
|
||||
github.com/PuerkitoBio/goquery v1.7.0
|
||||
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
|
||||
github.com/containerd/containerd v1.5.2
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/aquasecurity/libbpfgo v0.2.1-libbpf-0.4.0 // indirect
|
||||
github.com/bits-and-blooms/bitset v1.2.1 // indirect
|
||||
github.com/containerd/containerd v1.5.7
|
||||
github.com/containerd/continuity v0.2.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
|
||||
github.com/docker/docker v20.10.7+incompatible
|
||||
github.com/docker/go-connections v0.4.0
|
||||
github.com/forease/gotld v0.0.0-20190808124948-c50ff635576b
|
||||
github.com/gin-contrib/gzip v0.0.2 // indirect
|
||||
github.com/gin-gonic/gin v1.7.2
|
||||
github.com/go-delve/delve v1.7.2 // indirect
|
||||
github.com/go-ini/ini v1.62.0
|
||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.19.6 // indirect
|
||||
github.com/go-openapi/spec v0.20.3 // indirect
|
||||
github.com/go-openapi/spec v0.20.4 // indirect
|
||||
github.com/go-openapi/swag v0.19.15 // indirect
|
||||
github.com/go-playground/validator/v10 v10.6.1 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/gogo/googleapis v1.4.1 // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/gomodule/redigo v1.8.5
|
||||
github.com/google/go-dap v0.6.0 // indirect
|
||||
github.com/google/go-github/v36 v36.0.0
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/jinzhu/copier v0.3.2
|
||||
github.com/json-iterator/go v1.1.11 // indirect
|
||||
github.com/klauspost/compress v1.13.6 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||
github.com/mattn/go-colorable v0.1.11 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
|
||||
github.com/morikuni/aec v1.0.0 // indirect
|
||||
github.com/opencontainers/runc v1.0.2 // indirect
|
||||
github.com/opencontainers/selinux v1.8.5 // indirect
|
||||
github.com/peterh/liner v1.2.1 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prestonTao/upnp v0.0.0-20150206124352-f4370df5e109
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
github.com/robfig/cron v1.2.0
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/shirou/gopsutil/v3 v3.21.5
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/smartystreets/assertions v1.2.0 // indirect
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
github.com/spf13/cobra v1.2.1 // indirect
|
||||
github.com/swaggo/gin-swagger v1.3.0
|
||||
github.com/swaggo/swag v1.7.0
|
||||
github.com/swaggo/swag v1.7.3
|
||||
github.com/tidwall/gjson v1.8.0
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
||||
github.com/ugorji/go v1.2.6 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
||||
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
|
||||
golang.org/x/tools v0.1.3 // indirect
|
||||
google.golang.org/grpc v1.39.0 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
go.starlark.net v0.0.0-20210901212718-87f333178d59 // indirect
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
|
||||
golang.org/x/mod v0.5.0 // indirect
|
||||
golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
|
||||
golang.org/x/sys v0.0.0-20211020174200-9d6173849985 // indirect
|
||||
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
|
||||
golang.org/x/tools v0.1.7 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0 // indirect
|
||||
google.golang.org/grpc v1.41.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
gorm.io/driver/sqlite v1.1.5
|
||||
gorm.io/gorm v1.21.15
|
||||
src.techknowlogick.com/xgo v1.4.1-0.20210909190026-ce016894db20 // indirect
|
||||
src.techknowlogick.com/xgo v1.4.1-0.20211007230901-4fb1c2d7b2ab // indirect
|
||||
)
|
||||
|
||||
28
main.go
28
main.go
@@ -3,53 +3,61 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
|
||||
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"github.com/IceWhaleTech/CasaOS/route"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/robfig/cron"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var sqliteDB *gorm.DB
|
||||
|
||||
var swagHandler gin.HandlerFunc
|
||||
var configFlag = flag.String("c", "", "config address")
|
||||
|
||||
var showUserInfo = flag.Bool("show-user-info", false, "show user info")
|
||||
|
||||
func init() {
|
||||
flag.Parse()
|
||||
config.InitSetup(*configFlag)
|
||||
config.UpdateSetup()
|
||||
loger2.LogSetup()
|
||||
sqliteDB = sqlite.GetDb(config.AppInfo.ProjectPath)
|
||||
//gredis.GetRedisConn(config.RedisInfo),
|
||||
service.MyService = service.NewService(sqliteDB, loger2.NewOLoger())
|
||||
}
|
||||
|
||||
// @title Oasis API
|
||||
// @title casaOS API
|
||||
// @version 1.0.0
|
||||
// @contact.name lauren.pan
|
||||
// @contact.url https://www.zimaboard.com
|
||||
// @contact.email lauren.pan@icewhale.org
|
||||
// @description Oasis v1版本api
|
||||
// @host 192.168.2.114:8089
|
||||
// @description casaOS v1版本api
|
||||
// @host 192.168.2.217:8089
|
||||
// @securityDefinitions.apikey ApiKeyAuth
|
||||
// @in header
|
||||
// @name Authorization
|
||||
// @BasePath /v1
|
||||
func main() {
|
||||
if *showUserInfo {
|
||||
fmt.Println("CasaOS User Info")
|
||||
fmt.Println("UserName:" + config.UserInfo.UserName)
|
||||
fmt.Println("Password:" + config.UserInfo.PWD)
|
||||
return
|
||||
}
|
||||
//model.Setup()
|
||||
//gredis.Setup()
|
||||
r := route.InitRouter(swagHandler)
|
||||
service.SyncTask(sqliteDB)
|
||||
r := route.InitRouter()
|
||||
//service.SyncTask(sqliteDB)
|
||||
cron2 := cron.New() //创建一个cron实例
|
||||
//执行定时任务(每5秒执行一次)
|
||||
err := cron2.AddFunc("0 0 0 1/1 * *", func() {
|
||||
//service.UpdataDDNSList(mysqldb)
|
||||
service.SyncTask(sqliteDB)
|
||||
//service.SyncTask(sqliteDB)
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
7
model/search.go
Normal file
7
model/search.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
type SearchFileInfo struct {
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Type int `json:"type"`
|
||||
}
|
||||
@@ -60,11 +60,7 @@ type RedisModel struct {
|
||||
}
|
||||
|
||||
type SystemConfig struct {
|
||||
SearchSwitch bool `json:"search_switch"` //搜索开关
|
||||
SearchEngine string `json:"search_engine"` //搜索引擎
|
||||
ShortcutsSwitch bool `json:"shortcuts_switch"`
|
||||
WidgetsSwitch bool `json:"widgets_switch"`
|
||||
BackgroundType string `json:"background_type"`
|
||||
Background string `json:"background"`
|
||||
AutoUpdate bool `json:"auto_update"`
|
||||
ConfigStr string `json:"config_str"`
|
||||
WidgetList string `json:"widget_list"`
|
||||
ConfigPath string `json:"config_path"`
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
type Path struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
IsDir bool `json:"is_dir"`
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/go-ini/ini"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/go-ini/ini"
|
||||
)
|
||||
|
||||
//系统配置
|
||||
@@ -55,6 +56,7 @@ func InitSetup(config string) {
|
||||
mapTo("redis", RedisInfo)
|
||||
mapTo("server", ServerInfo)
|
||||
mapTo("system", SystemConfigInfo)
|
||||
SystemConfigInfo.ConfigPath = configDir
|
||||
// AppInfo.ProjectPath = getCurrentDirectory() //os.Getwd()
|
||||
|
||||
}
|
||||
|
||||
15
pkg/config/update.go
Normal file
15
pkg/config/update.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package config
|
||||
|
||||
import "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
|
||||
//检查目录是否存在
|
||||
func mkdirDATAAll() {
|
||||
dirArray := [7]string{"/DATA/AppData", "/DATA/Documents", "/DATA/Downloads", "/DATA/Gallery", "/DATA/Media/Movies", "/DATA/Media/TV Shows", "/DATA/Media/Music"}
|
||||
for _, v := range dirArray {
|
||||
file.IsNotExistMkDir(v)
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateSetup() {
|
||||
mkdirDATAAll()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package github
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetRepos(t *testing.T) {
|
||||
GetRepos()
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package gredis
|
||||
|
||||
import (
|
||||
"github.com/gomodule/redigo/redis"
|
||||
"oasis/model"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/gomodule/redigo/redis"
|
||||
)
|
||||
|
||||
func GetRedisConn(m *model.RedisModel) *redis.Pool {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package upnp
|
||||
|
||||
import (
|
||||
ip_helper2 "oasis/pkg/utils/ip_helper"
|
||||
"testing"
|
||||
|
||||
ip_helper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/ip_helper"
|
||||
)
|
||||
|
||||
func TestGetCtrlUrl(t *testing.T) {
|
||||
|
||||
@@ -100,10 +100,9 @@ func MustOpen(fileName, filePath string) (*os.File, error) {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
|
||||
// 判断所给路径文件/文件夹是否存在
|
||||
func Exists(path string) bool {
|
||||
_, err := os.Stat(path) //os.Stat获取文件信息
|
||||
_, err := os.Stat(path) //os.Stat获取文件信息
|
||||
if err != nil {
|
||||
if os.IsExist(err) {
|
||||
return true
|
||||
@@ -126,3 +125,23 @@ func IsDir(path string) bool {
|
||||
func IsFile(path string) bool {
|
||||
return !IsDir(path)
|
||||
}
|
||||
|
||||
func CreateFile(path string) error {
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsNotExistMkDir create a directory if it does not exist
|
||||
func IsNotExistCreateFile(src string) error {
|
||||
if notExist := CheckNotExist(src); notExist == true {
|
||||
if err := CreateFile(src); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"time"
|
||||
|
||||
jwt "github.com/golang-jwt/jwt"
|
||||
)
|
||||
|
||||
type Claims struct {
|
||||
@@ -15,8 +16,7 @@ var jwtSecret []byte
|
||||
|
||||
//创建token
|
||||
func GenerateToken(username, password string) (string, error) {
|
||||
nowTime := time.Now()
|
||||
expireTime := nowTime.Add(3 * time.Hour)
|
||||
expireTime := time.Now().AddDate(999, 0, 0)
|
||||
clims := Claims{
|
||||
username,
|
||||
password,
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func JWT(swagHandler gin.HandlerFunc) gin.HandlerFunc {
|
||||
@@ -22,13 +21,15 @@ func JWT(swagHandler gin.HandlerFunc) gin.HandlerFunc {
|
||||
code = oasis_err2.INVALID_PARAMS
|
||||
}
|
||||
if swagHandler == nil {
|
||||
claims, err := ParseToken(token)
|
||||
//claims, err := ParseToken(token)
|
||||
_, err := ParseToken(token)
|
||||
if err != nil {
|
||||
code = oasis_err2.ERROR_AUTH_TOKEN
|
||||
|
||||
} else if time.Now().Unix() > claims.ExpiresAt {
|
||||
code = oasis_err2.ERROR_AUTH_TOKEN
|
||||
}
|
||||
//else if time.Now().Unix() > claims.ExpiresAt {
|
||||
// code = oasis_err2.ERROR_AUTH_TOKEN
|
||||
//}
|
||||
}
|
||||
|
||||
if code != oasis_err2.SUCCESS {
|
||||
|
||||
@@ -10,7 +10,9 @@ const (
|
||||
PWD_INVALID = 10001
|
||||
|
||||
//system
|
||||
DIR_ALREADY_EXISTS = 20001
|
||||
DIR_ALREADY_EXISTS = 20001
|
||||
FILE_ALREADY_EXISTS = 20002
|
||||
FILE_OR_DIR_EXISTS = 20003
|
||||
|
||||
//zerotier
|
||||
GET_TOKEN_ERROR = 30001
|
||||
@@ -38,8 +40,9 @@ var MsgFlags = map[int]string{
|
||||
PWD_INVALID: "Password invalid",
|
||||
|
||||
//system
|
||||
DIR_ALREADY_EXISTS: "Directory already exists",
|
||||
|
||||
DIR_ALREADY_EXISTS: "Directory already exists",
|
||||
FILE_ALREADY_EXISTS: "File already exists",
|
||||
FILE_OR_DIR_EXISTS: "File or directory already exists",
|
||||
|
||||
//zerotier
|
||||
GET_TOKEN_ERROR: "Get token error,Please log in to zerotier's official website to confirm whether the account is available",
|
||||
|
||||
@@ -2,13 +2,14 @@ package version
|
||||
|
||||
import (
|
||||
json2 "encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
|
||||
"github.com/IceWhaleTech/CasaOS/types"
|
||||
"github.com/tidwall/gjson"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func IsNeedUpdate() (bool, model.Version) {
|
||||
@@ -35,3 +36,23 @@ func IsNeedUpdate() (bool, model.Version) {
|
||||
}
|
||||
return false, version
|
||||
}
|
||||
|
||||
//a版本大于b版本
|
||||
func VersionCompared(a string, b string) bool {
|
||||
v1 := strings.Split(a, ".")
|
||||
v2 := strings.Split(b, ".")
|
||||
for len(v1) < len(v2) {
|
||||
v1 = append(v1, "0")
|
||||
}
|
||||
for len(v2) < len(v1) {
|
||||
v2 = append(v2, "0")
|
||||
}
|
||||
for i := 0; i < len(v1); i++ {
|
||||
a, _ := strconv.Atoi(v1[i])
|
||||
b, _ := strconv.Atoi(v2[i])
|
||||
if a > b {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
//go:build doc
|
||||
// +build doc
|
||||
|
||||
package route
|
||||
|
||||
import (
|
||||
_ "github.com/IceWhaleTech/CasaOS/docs"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
swaggerFiles "github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// swagHandler = ginSwagger.WrapHandler(swaggerFiles.Handler)
|
||||
swagHandler = ginSwagger.WrapHandler(swaggerFiles.Handler)
|
||||
}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
_ "github.com/IceWhaleTech/CasaOS/docs"
|
||||
"github.com/IceWhaleTech/CasaOS/middleware"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
jwt2 "github.com/IceWhaleTech/CasaOS/pkg/utils/jwt"
|
||||
v1 "github.com/IceWhaleTech/CasaOS/route/v1"
|
||||
"github.com/IceWhaleTech/CasaOS/web"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var swagHandler gin.HandlerFunc
|
||||
|
||||
func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
|
||||
func InitRouter() *gin.Engine {
|
||||
|
||||
r := gin.Default()
|
||||
r.Use(middleware.Cors())
|
||||
@@ -29,8 +31,11 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
|
||||
//登录
|
||||
r.POST("/v1/user/login", v1.Login)
|
||||
|
||||
r.GET("/debug", v1.GetSystemConfigDebug)
|
||||
r.GET("/v1/guide/check", v1.GetGuideCheck)
|
||||
|
||||
r.GET("/debug", v1.GetSystemConfigDebug)
|
||||
//设置用户
|
||||
r.POST("/v1/user/setusernamepwd", v1.Set_Name_Pwd)
|
||||
v1Group := r.Group("/v1")
|
||||
|
||||
v1Group.Use(jwt2.JWT(swagHandler))
|
||||
@@ -38,8 +43,7 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
|
||||
v1UserGroup := v1Group.Group("/user")
|
||||
v1UserGroup.Use()
|
||||
{
|
||||
//设置用户
|
||||
v1UserGroup.POST("/setusernamepwd", v1.Set_Name_Pwd)
|
||||
|
||||
//chang head
|
||||
v1UserGroup.POST("/changhead", v1.Up_Load_Head)
|
||||
//chang user name
|
||||
@@ -183,6 +187,8 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
|
||||
v1SysGroup.GET("/wsssh", v1.WsSsh)
|
||||
v1SysGroup.GET("/config", v1.GetSystemConfig)
|
||||
v1SysGroup.POST("/config", v1.PostSetSystemConfig)
|
||||
v1SysGroup.GET("/widget/config", v1.GetWidgetConfig)
|
||||
v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig)
|
||||
}
|
||||
v1FileGroup := v1Group.Group("/file")
|
||||
v1FileGroup.Use()
|
||||
@@ -194,6 +200,7 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
|
||||
v1FileGroup.GET("/dirpath", v1.DirPath)
|
||||
//创建目录
|
||||
v1FileGroup.POST("/mkdir", v1.MkdirAll)
|
||||
v1FileGroup.POST("/create", v1.PostCreateFile)
|
||||
|
||||
v1FileGroup.GET("/download", v1.GetDownloadFile)
|
||||
//v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
|
||||
@@ -252,6 +259,11 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
|
||||
v1NotifyGroup.GET("/ws", v1.NotifyWS)
|
||||
v1NotifyGroup.PUT("/read/:id", v1.PutNotifyRead)
|
||||
}
|
||||
v1SearchGroup := v1Group.Group("/search")
|
||||
v1SearchGroup.Use()
|
||||
{
|
||||
v1SearchGroup.GET("/search", v1.GetSearchList)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -3,6 +3,12 @@ package v1
|
||||
import (
|
||||
"bytes"
|
||||
json2 "encoding/json"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/docker"
|
||||
upnp2 "github.com/IceWhaleTech/CasaOS/pkg/upnp"
|
||||
@@ -19,11 +25,6 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/jinzhu/copier"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
@@ -283,6 +284,16 @@ func InstallApp(c *gin.Context) {
|
||||
//}
|
||||
|
||||
//step:创建容器
|
||||
// networkName, err := service.MyService.Docker().GetNetWorkNameByNetWorkID(appInfo.NetworkModel)
|
||||
// if err != nil {
|
||||
// //service.MyService.Redis().Set(id, "{\"id\"\""+id+"\",\"state\":false,\"message\":\""+err.Error()+"\",\"speed\":80}", 100)
|
||||
// installLog.State = 0
|
||||
// installLog.Speed = 75
|
||||
// installLog.Type = types.NOTIFY_TYPE_ERROR
|
||||
// installLog.Message = err.Error()
|
||||
// service.MyService.Notify().UpdateLog(installLog)
|
||||
// return
|
||||
// }
|
||||
containerId, err := service.MyService.Docker().DockerContainerCreate(dockerImage+":"+dockerImageVersion, id, m, appInfo.NetworkModel)
|
||||
installLog.ContainerId = containerId
|
||||
if err != nil {
|
||||
@@ -867,20 +878,42 @@ func UpdateSetting(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(m.Ports, appInfo.Ports) || !reflect.DeepEqual(m.Envs, appInfo.Envs) || !reflect.DeepEqual(m.Volumes, appInfo.Volumes) || m.PortMap != appInfo.PortMap {
|
||||
//如果容器端口均未修改,这不进行处理
|
||||
portsStr, _ := json2.Marshal(m.Ports)
|
||||
|
||||
service.MyService.Docker().DockerContainerRemove(id)
|
||||
envsStr, _ := json2.Marshal(m.Envs)
|
||||
volumesStr, _ := json2.Marshal(m.Volumes)
|
||||
devicesStr, _ := json2.Marshal(m.Devices)
|
||||
if !reflect.DeepEqual(string(portsStr), appInfo.Ports) || !reflect.DeepEqual(string(envsStr), appInfo.Envs) || !reflect.DeepEqual(string(volumesStr), appInfo.Volumes) || m.PortMap != appInfo.PortMap || m.NetworkModel != appInfo.NetModel {
|
||||
|
||||
var newUUid = uuid.NewV4().String()
|
||||
var err error
|
||||
|
||||
containerId, err = service.MyService.Docker().DockerContainerCreate(appInfo.Image+":"+appInfo.Version, id, cpd, appInfo.NetModel)
|
||||
// networkName, err := service.MyService.Docker().GetNetWorkNameByNetWorkID(appInfo.NetModel)
|
||||
// if err != nil {
|
||||
// c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)})
|
||||
// return
|
||||
// }
|
||||
containerId, err = service.MyService.Docker().DockerContainerCreate(appInfo.Image+":"+appInfo.Version, newUUid, cpd, m.NetworkModel)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)})
|
||||
return
|
||||
}
|
||||
|
||||
} else if !reflect.DeepEqual(m.Devices, appInfo.Devices) || m.CpuShares != appInfo.CpuShares || m.Memory != appInfo.Memory || m.Restart != appInfo.Restart {
|
||||
err = service.MyService.Docker().DockerContainerRemove(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)})
|
||||
return
|
||||
}
|
||||
|
||||
service.MyService.Docker().DockerContainerUpdateName(appInfo.CustomId, newUUid)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)})
|
||||
return
|
||||
}
|
||||
|
||||
} else if !reflect.DeepEqual(string(devicesStr), appInfo.Devices) || m.CpuShares != appInfo.CpuShares || m.Memory != appInfo.Memory || m.Restart != appInfo.Restart {
|
||||
service.MyService.Docker().DockerContainerUpdate(cpd, id)
|
||||
}
|
||||
|
||||
@@ -954,19 +987,16 @@ func UpdateSetting(c *gin.Context) {
|
||||
//}
|
||||
}
|
||||
|
||||
//如果容器端口均未修改,这不进行处理
|
||||
portsStr, _ := json2.Marshal(m.Ports)
|
||||
envsStr, _ := json2.Marshal(m.Envs)
|
||||
volumesStr, _ := json2.Marshal(m.Volumes)
|
||||
devicesStr, _ := json2.Marshal(m.Devices)
|
||||
appInfo.ContainerId = containerId
|
||||
appInfo.PortMap = m.PortMap
|
||||
appInfo.Label = m.Label
|
||||
appInfo.Index = m.Index
|
||||
appInfo.Ports = string(portsStr)
|
||||
appInfo.Envs = string(envsStr)
|
||||
appInfo.Icon = m.Icon
|
||||
appInfo.Volumes = string(volumesStr)
|
||||
appInfo.Devices = string(devicesStr)
|
||||
appInfo.NetModel = m.NetworkModel
|
||||
appInfo.Position = m.Position
|
||||
appInfo.EnableUPNP = m.EnableUPNP
|
||||
appInfo.Restart = m.Restart
|
||||
|
||||
@@ -4,16 +4,17 @@ import (
|
||||
"bufio"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func downloadReadFile(c *gin.Context) {
|
||||
@@ -218,6 +219,25 @@ func MkdirAll(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Result{Success: code, Message: oasis_err2.GetMsg(code)})
|
||||
}
|
||||
|
||||
// @Summary 创建文件
|
||||
// @Produce application/json
|
||||
// @Accept multipart/form-data
|
||||
// @Tags file
|
||||
// @Security ApiKeyAuth
|
||||
// @Param path formData string false "路径"
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /file/create [post]
|
||||
func PostCreateFile(c *gin.Context) {
|
||||
path := c.PostForm("path")
|
||||
var code int
|
||||
if len(path) == 0 {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
|
||||
return
|
||||
}
|
||||
code, _ = service.MyService.ZiMa().CreateFile(path)
|
||||
c.JSON(http.StatusOK, model.Result{Success: code, Message: oasis_err2.GetMsg(code)})
|
||||
}
|
||||
|
||||
// @Summary 上传文件
|
||||
// @Produce application/json
|
||||
// @Accept multipart/form-data
|
||||
|
||||
22
route/v1/search.go
Normal file
22
route/v1/search.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetSearchList(c *gin.Context) {
|
||||
key := c.DefaultQuery("key", "")
|
||||
if len(key) == 0 {
|
||||
return
|
||||
}
|
||||
list, err := service.MyService.Search().SearchList(key)
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: list})
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
||||
@@ -10,9 +15,6 @@ import (
|
||||
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
||||
"github.com/IceWhaleTech/CasaOS/types"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// @Summary 系统信息
|
||||
@@ -51,10 +53,8 @@ func CheckVersion(c *gin.Context) {
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/update [post]
|
||||
func SystemUpdate(c *gin.Context) {
|
||||
fmt.Println("开始更新")
|
||||
need, version := version.IsNeedUpdate()
|
||||
if need {
|
||||
fmt.Println("进入更新")
|
||||
service.MyService.System().UpdateSystemVersion(version.Version)
|
||||
}
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
|
||||
@@ -62,7 +62,7 @@ func SystemUpdate(c *gin.Context) {
|
||||
|
||||
//系统配置
|
||||
func GetSystemConfig(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: config.SystemConfigInfo})
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: json.RawMessage(config.SystemConfigInfo.ConfigStr)})
|
||||
}
|
||||
|
||||
// @Summary 修改配置文件
|
||||
@@ -74,16 +74,16 @@ func GetSystemConfig(c *gin.Context) {
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /user/changhead [post]
|
||||
func PostSetSystemConfig(c *gin.Context) {
|
||||
var systemConfig model.SystemConfig
|
||||
c.BindJSON(&systemConfig)
|
||||
service.MyService.System().UpSystemConfig(systemConfig)
|
||||
buf := make([]byte, 1024)
|
||||
n, _ := c.Request.Body.Read(buf)
|
||||
|
||||
service.MyService.System().UpSystemConfig(string(buf[0:n]), "")
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{
|
||||
Success: oasis_err.SUCCESS,
|
||||
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
||||
Data: config.SystemConfigInfo,
|
||||
Data: json.RawMessage(config.SystemConfigInfo.ConfigStr),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
//系统配置
|
||||
@@ -98,3 +98,50 @@ func GetSystemConfigDebug(c *gin.Context) {
|
||||
func Sys(c *gin.Context) {
|
||||
service.DockerPull()
|
||||
}
|
||||
|
||||
//widget配置
|
||||
func GetWidgetConfig(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: json.RawMessage(config.SystemConfigInfo.WidgetList)})
|
||||
}
|
||||
|
||||
// @Summary 修改组件配置文件
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /sys/widget/config [post]
|
||||
func PostSetWidgetConfig(c *gin.Context) {
|
||||
buf := make([]byte, 1024)
|
||||
n, _ := c.Request.Body.Read(buf)
|
||||
|
||||
service.MyService.System().UpSystemConfig("", string(buf[0:n]))
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{
|
||||
Success: oasis_err.SUCCESS,
|
||||
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
||||
Data: json.RawMessage(config.SystemConfigInfo.WidgetList),
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary 检查是否进入引导状态
|
||||
// @Produce application/json
|
||||
// @Accept application/json
|
||||
// @Tags sys
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /guide/check [get]
|
||||
func GetGuideCheck(c *gin.Context) {
|
||||
initUser := false
|
||||
if config.UserInfo.UserName == "admin" && config.UserInfo.PWD == "zimaboard" && version.VersionCompared("0.1.7", types.CURRENTVERSION) {
|
||||
initUser = true
|
||||
}
|
||||
data := make(map[string]interface{}, 1)
|
||||
data["need_init_user"] = initUser
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{
|
||||
Success: oasis_err.SUCCESS,
|
||||
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ import (
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /task/list [get]
|
||||
func GetTaskList(c *gin.Context) {
|
||||
list := service.MyService.Task().List(true)
|
||||
//list := service.MyService.Task().List(true)
|
||||
list := service.MyService.Task().GetServerTasks()
|
||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: list})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,16 @@ package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
jwt2 "github.com/IceWhaleTech/CasaOS/pkg/utils/jwt"
|
||||
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/version"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/IceWhaleTech/CasaOS/types"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var user_service service.UserService
|
||||
@@ -32,7 +35,7 @@ func Set_Name_Pwd(c *gin.Context) {
|
||||
username := c.PostForm("username")
|
||||
pwd := c.PostForm("pwd")
|
||||
//老用户名是否存在即新用户名和密码的验证
|
||||
if len(config.UserInfo.UserName) > 0 || len(username) == 0 || len(pwd) == 0 {
|
||||
if (!(config.UserInfo.UserName == "admin" && config.UserInfo.PWD == "zimaboard" && version.VersionCompared("0.1.7", types.CURRENTVERSION)) && len(config.UserInfo.UserName) > 0) || len(username) == 0 || len(pwd) == 0 {
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
|
||||
return
|
||||
@@ -69,15 +72,18 @@ func Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
//if config.UserInfo.UserName == username && config.UserInfo.PWD == pwd {
|
||||
if username == "admin" && pwd == "admin" {
|
||||
token := jwt2.GetToken(username, pwd)
|
||||
if config.UserInfo.UserName == username && config.UserInfo.PWD == pwd {
|
||||
//if username == "admin" && pwd == "admin" {
|
||||
|
||||
data := make(map[string]string, 2)
|
||||
data["token"] = jwt2.GetToken(username, pwd)
|
||||
data["version"] = types.CURRENTVERSION
|
||||
//user_service.SetUser("", "", token, "", "")
|
||||
c.JSON(http.StatusOK,
|
||||
model.Result{
|
||||
Success: oasis_err2.SUCCESS,
|
||||
Message: oasis_err2.GetMsg(oasis_err2.SUCCESS),
|
||||
Data: token,
|
||||
Data: data,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,27 +7,23 @@ import (
|
||||
"encoding/binary"
|
||||
json2 "encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"syscall"
|
||||
|
||||
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
||||
types2 "github.com/IceWhaleTech/CasaOS/types"
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/cio"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/oci"
|
||||
"syscall"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/docker"
|
||||
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
|
||||
//"github.com/containerd/containerd/oci"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
client2 "github.com/docker/docker/client"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -35,6 +31,14 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
client2 "github.com/docker/docker/client"
|
||||
"github.com/docker/go-connections/nat"
|
||||
)
|
||||
|
||||
type DockerService interface {
|
||||
@@ -49,11 +53,13 @@ type DockerService interface {
|
||||
DockerImageRemove(name string) error
|
||||
DockerContainerRemove(name string) error
|
||||
DockerContainerStop(id string) error
|
||||
DockerContainerUpdateName(name, id string) (err error)
|
||||
DockerContainerUpdate(m model.CustomizationPostData, id string) (err error)
|
||||
DockerContainerLog(name string) (string, error)
|
||||
DockerContainerCommit(name string)
|
||||
DockerNetworkModelList() []types.NetworkResource
|
||||
DockerImageInfo(image string)
|
||||
GetNetWorkNameByNetWorkID(id string) (string, error)
|
||||
}
|
||||
|
||||
type dockerService struct {
|
||||
@@ -78,6 +84,7 @@ func DockerNetwork() {
|
||||
cli, _ := client2.NewClientWithOpts(client2.FromEnv)
|
||||
defer cli.Close()
|
||||
d, _ := cli.NetworkList(context.Background(), types.NetworkListOptions{})
|
||||
|
||||
for _, resource := range d {
|
||||
if resource.Name == docker.NETWORKNAME {
|
||||
return
|
||||
@@ -86,6 +93,19 @@ func DockerNetwork() {
|
||||
cli.NetworkCreate(context.Background(), docker.NETWORKNAME, types.NetworkCreate{})
|
||||
}
|
||||
|
||||
//根据网络id获取网络名
|
||||
func (ds *dockerService) GetNetWorkNameByNetWorkID(id string) (string, error) {
|
||||
cli, _ := client2.NewClientWithOpts(client2.FromEnv)
|
||||
defer cli.Close()
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("id", id)
|
||||
d, err := cli.NetworkList(context.Background(), types.NetworkListOptions{filter})
|
||||
if err == nil && len(d) > 0 {
|
||||
return d[0].Name, nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
//拉取镜像
|
||||
func DockerPull() {
|
||||
|
||||
@@ -336,9 +356,13 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s
|
||||
// if net != "host" {
|
||||
// portMaps[nat.Port(fmt.Sprint(m.Port)+"/tcp")] = []nat.PortBinding{{HostIP: "", HostPort: m.PortMap}}
|
||||
// }
|
||||
|
||||
port := ""
|
||||
for _, portMap := range m.Ports {
|
||||
if portMap.CommendPort == m.PortMap && portMap.Protocol == "tcp" || portMap.Protocol == "both" {
|
||||
port = portMap.ContainerPort
|
||||
}
|
||||
if portMap.Protocol == "tcp" {
|
||||
|
||||
tContainer, _ := strconv.Atoi(portMap.ContainerPort)
|
||||
if tContainer > 0 {
|
||||
ports[nat.Port(portMap.ContainerPort+"/tcp")] = struct{}{}
|
||||
@@ -399,6 +423,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s
|
||||
res.Devices = append(res.Devices, container.DeviceMapping{PathOnHost: p.Path, PathInContainer: p.ContainerPath})
|
||||
}
|
||||
}
|
||||
hostConfingBind := []string{}
|
||||
// volumes bind
|
||||
volumes := []mount.Mount{}
|
||||
for _, v := range m.Volumes {
|
||||
@@ -408,12 +433,21 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s
|
||||
if len(path) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
err := file.IsNotExistMkDir(path)
|
||||
if err != nil {
|
||||
ds.log.Error("mkdir error", err)
|
||||
continue
|
||||
reg1 := regexp.MustCompile(`([^<>/\\\|:""\*\?]+\.\w+$)`)
|
||||
result1 := reg1.FindAllStringSubmatch(path, -1)
|
||||
if len(result1) == 0 {
|
||||
err = file.IsNotExistMkDir(path)
|
||||
if err != nil {
|
||||
ds.log.Error("mkdir error", err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
err = file.IsNotExistCreateFile(path)
|
||||
if err != nil {
|
||||
ds.log.Error("mkdir error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
volumes = append(volumes, mount.Mount{
|
||||
@@ -422,6 +456,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s
|
||||
Target: v.ContainerPath,
|
||||
})
|
||||
|
||||
hostConfingBind = append(hostConfingBind, v.Path+":"+v.ContainerPath)
|
||||
}
|
||||
|
||||
rp := container.RestartPolicy{}
|
||||
@@ -429,11 +464,23 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s
|
||||
if len(m.Restart) > 0 {
|
||||
rp.Name = m.Restart
|
||||
}
|
||||
//fmt.Print(port)
|
||||
healthTest := []string{}
|
||||
if len(port) > 0 {
|
||||
healthTest = []string{"CMD-SHELL", "curl -f http://localhost:" + port + m.Index + " || exit 1"}
|
||||
}
|
||||
|
||||
health := &container.HealthConfig{
|
||||
Test: healthTest,
|
||||
//Test: []string{},
|
||||
StartPeriod: 0,
|
||||
Retries: 1000,
|
||||
}
|
||||
config := &container.Config{
|
||||
Image: imageName,
|
||||
Labels: map[string]string{"origin": m.Origin, m.Origin: m.Origin},
|
||||
Env: envArr,
|
||||
Image: imageName,
|
||||
Labels: map[string]string{"origin": m.Origin, m.Origin: m.Origin},
|
||||
Env: envArr,
|
||||
Healthcheck: health,
|
||||
}
|
||||
hostConfig := &container.HostConfig{Resources: res, Mounts: volumes, RestartPolicy: rp, NetworkMode: container.NetworkMode(net)}
|
||||
//if net != "host" {
|
||||
@@ -701,6 +748,23 @@ func (ds *dockerService) DockerContainerUpdate(m model.CustomizationPostData, id
|
||||
return
|
||||
}
|
||||
|
||||
//更新容器名称
|
||||
//param name 容器名称
|
||||
//param id 老的容器名称
|
||||
func (ds *dockerService) DockerContainerUpdateName(name, id string) (err error) {
|
||||
cli, err := client2.NewClientWithOpts(client2.FromEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cli.Close()
|
||||
|
||||
err = cli.ContainerRename(context.Background(), id, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//获取网络列表
|
||||
func (ds *dockerService) DockerNetworkModelList() []types.NetworkResource {
|
||||
|
||||
|
||||
57
service/search.go
Normal file
57
service/search.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/types"
|
||||
)
|
||||
|
||||
type SearchService interface {
|
||||
SearchList(key string) ([]model.SearchFileInfo, error)
|
||||
}
|
||||
|
||||
type searchService struct {
|
||||
}
|
||||
|
||||
func (s *searchService) SearchList(key string) ([]model.SearchFileInfo, error) {
|
||||
pathName := "/Users/liangjianli/go/CasaOSNew/searchTest"
|
||||
resArr := []model.SearchFileInfo{}
|
||||
files, _ := ioutil.ReadDir(pathName)
|
||||
for _, file := range files {
|
||||
if file.IsDir() {
|
||||
tempArr, err := s.SearchList(pathName + "/" + file.Name())
|
||||
if err != nil {
|
||||
resArr = append(resArr, tempArr...)
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(file.Name(), key) {
|
||||
resArr = append(resArr, model.SearchFileInfo{Path: pathName, Name: file.Name(), Type: GetSearchType(path.Ext(file.Name()))})
|
||||
}
|
||||
fmt.Println(pathName + "/" + file.Name())
|
||||
}
|
||||
}
|
||||
return resArr, nil
|
||||
}
|
||||
|
||||
func GetSearchType(ext string) int {
|
||||
var reType int = types.UNKNOWN
|
||||
switch ext {
|
||||
case ".png":
|
||||
reType = types.PICTURE
|
||||
case ".mp4":
|
||||
reType = types.MEDIA
|
||||
case ".mp3":
|
||||
reType = types.MUSIC
|
||||
default:
|
||||
reType = types.UNKNOWN
|
||||
}
|
||||
return reType
|
||||
}
|
||||
|
||||
func NewSearchService() SearchService {
|
||||
return &searchService{}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ type Repository interface {
|
||||
Rely() RelyService
|
||||
System() SystemService
|
||||
Shortcuts() ShortcutsService
|
||||
Search() SearchService
|
||||
}
|
||||
|
||||
func NewService(db *gorm.DB, log loger2.OLog) Repository {
|
||||
@@ -42,6 +43,7 @@ func NewService(db *gorm.DB, log loger2.OLog) Repository {
|
||||
rely: NewRelyService(db, log),
|
||||
system: NewSystemService(log),
|
||||
shortcuts: NewShortcutsService(db),
|
||||
search: NewSearchService(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +63,7 @@ type store struct {
|
||||
rely RelyService
|
||||
system SystemService
|
||||
shortcuts ShortcutsService
|
||||
search SearchService
|
||||
}
|
||||
|
||||
func (c *store) Rely() RelyService {
|
||||
@@ -112,3 +115,6 @@ func (c *store) ShareDirectory() ShareDirService {
|
||||
func (c *store) Task() TaskService {
|
||||
return c.task
|
||||
}
|
||||
func (c *store) Search() SearchService {
|
||||
return c.search
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type SystemService interface {
|
||||
UpSystemConfig(systemConfig model.SystemConfig)
|
||||
UpSystemConfig(str string, widget string)
|
||||
UpdateSystemVersion(version string)
|
||||
GetSystemConfigDebug() []string
|
||||
}
|
||||
@@ -18,7 +16,6 @@ type systemService struct {
|
||||
}
|
||||
|
||||
func (s *systemService) UpdateSystemVersion(version string) {
|
||||
s.log.Error(version)
|
||||
//command2.OnlyExec(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
|
||||
//s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
|
||||
s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/tools.sh ;update " + version))
|
||||
@@ -27,38 +24,14 @@ func (s *systemService) UpdateSystemVersion(version string) {
|
||||
func (s *systemService) GetSystemConfigDebug() []string {
|
||||
return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetSysInfo")
|
||||
}
|
||||
func (s *systemService) UpSystemConfig(systemConfig model.SystemConfig) {
|
||||
if systemConfig.AutoUpdate != config.SystemConfigInfo.AutoUpdate {
|
||||
config.Cfg.Section("system").Key("AutoUpdate").SetValue(strconv.FormatBool(systemConfig.AutoUpdate))
|
||||
config.SystemConfigInfo.AutoUpdate = systemConfig.AutoUpdate
|
||||
func (s *systemService) UpSystemConfig(str string, widget string) {
|
||||
if len(str) > 0 && str != config.SystemConfigInfo.ConfigStr {
|
||||
config.Cfg.Section("system").Key("ConfigStr").SetValue(str)
|
||||
config.SystemConfigInfo.ConfigStr = str
|
||||
}
|
||||
if systemConfig.SearchSwitch != config.SystemConfigInfo.SearchSwitch {
|
||||
config.Cfg.Section("system").Key("SearchSwitch").SetValue(strconv.FormatBool(systemConfig.SearchSwitch))
|
||||
config.SystemConfigInfo.SearchSwitch = systemConfig.SearchSwitch
|
||||
}
|
||||
if systemConfig.WidgetsSwitch != config.SystemConfigInfo.WidgetsSwitch {
|
||||
config.Cfg.Section("system").Key("WidgetsSwitch").SetValue(strconv.FormatBool(systemConfig.WidgetsSwitch))
|
||||
config.SystemConfigInfo.WidgetsSwitch = systemConfig.WidgetsSwitch
|
||||
}
|
||||
if systemConfig.ShortcutsSwitch != config.SystemConfigInfo.ShortcutsSwitch {
|
||||
config.Cfg.Section("system").Key("ShortcutsSwitch").SetValue(strconv.FormatBool(systemConfig.ShortcutsSwitch))
|
||||
config.SystemConfigInfo.ShortcutsSwitch = systemConfig.ShortcutsSwitch
|
||||
}
|
||||
if len(systemConfig.SearchEngine) > 0 && systemConfig.SearchEngine != config.SystemConfigInfo.SearchEngine {
|
||||
config.Cfg.Section("system").Key("SearchEngine").SetValue(systemConfig.SearchEngine)
|
||||
config.SystemConfigInfo.SearchEngine = systemConfig.SearchEngine
|
||||
}
|
||||
// if len(systemConfig.Version) > 0 && systemConfig.Version != config.SystemConfigInfo.Version {
|
||||
// config.Cfg.Section("system").Key("Version").SetValue(systemConfig.Version)
|
||||
// config.SystemConfigInfo.Version = systemConfig.Version
|
||||
//}
|
||||
if len(systemConfig.Background) > 0 && systemConfig.Background != config.SystemConfigInfo.Background {
|
||||
config.Cfg.Section("system").Key("Background").SetValue(systemConfig.Background)
|
||||
config.SystemConfigInfo.Background = systemConfig.Background
|
||||
}
|
||||
if len(systemConfig.BackgroundType) > 0 && systemConfig.BackgroundType != config.SystemConfigInfo.BackgroundType {
|
||||
config.Cfg.Section("system").Key("BackgroundType").SetValue(systemConfig.BackgroundType)
|
||||
config.SystemConfigInfo.BackgroundType = systemConfig.BackgroundType
|
||||
if len(widget) > 0 && widget != config.SystemConfigInfo.WidgetList {
|
||||
config.Cfg.Section("system").Key("WidgetList").SetValue(widget)
|
||||
config.SystemConfigInfo.WidgetList = widget
|
||||
}
|
||||
config.Cfg.SaveTo("conf/conf.ini")
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ type TaskService interface {
|
||||
Update(m *model.TaskDBModel)
|
||||
Info(id string) model.TaskDBModel
|
||||
SyncTaskService()
|
||||
GetServerTasks() []model.TaskDBModel
|
||||
}
|
||||
|
||||
type taskService struct {
|
||||
@@ -60,7 +61,33 @@ func (s *taskService) Info(id string) model.TaskDBModel {
|
||||
s.db.Where("id = ?", id).Delete(&m)
|
||||
return m
|
||||
}
|
||||
func (s *taskService) GetServerTasks() []model.TaskDBModel {
|
||||
var count int64
|
||||
s.db.Model(&model.TaskDBModel{}).Count(&count)
|
||||
head := make(map[string]string)
|
||||
|
||||
t := make(chan string)
|
||||
|
||||
go func() {
|
||||
str := httper2.Get(config.ServerInfo.ServerApi+"/token", nil)
|
||||
|
||||
t <- gjson.Get(str, "data").String()
|
||||
}()
|
||||
head["Authorization"] = <-t
|
||||
|
||||
listS := httper2.Get(config.ServerInfo.ServerApi+"/v1/task/list/0?desc=true", head)
|
||||
|
||||
list := []model.TaskDBModel{}
|
||||
json2.Unmarshal([]byte(gjson.Get(listS, "data").String()), &list)
|
||||
|
||||
//go func(list []model.TaskDBModel) {
|
||||
// for _, dbModel := range list {
|
||||
// dbModel.Id = 0
|
||||
// s.db.Create(&dbModel)
|
||||
// }
|
||||
//}(list)
|
||||
return list
|
||||
}
|
||||
func (s *taskService) SyncTaskService() {
|
||||
var count int64
|
||||
s.db.Model(&model.TaskDBModel{}).Count(&count)
|
||||
@@ -82,6 +109,7 @@ func (s *taskService) SyncTaskService() {
|
||||
|
||||
go func(list []model.TaskDBModel) {
|
||||
for _, dbModel := range list {
|
||||
dbModel.Id = 0
|
||||
s.db.Create(&dbModel)
|
||||
}
|
||||
}(list)
|
||||
@@ -107,6 +135,7 @@ func SyncTask(db *gorm.DB) {
|
||||
|
||||
go func(list []model.TaskDBModel) {
|
||||
for _, dbModel := range list {
|
||||
dbModel.Id = 0
|
||||
db.Create(&dbModel)
|
||||
}
|
||||
}(list)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
)
|
||||
|
||||
type UserService interface {
|
||||
@@ -37,7 +38,7 @@ func (c *user) SetUser(username, pwd, token, email, desc string) error {
|
||||
config.Cfg.Section("user").Key("Description").SetValue(desc)
|
||||
config.UserInfo.Description = desc
|
||||
}
|
||||
config.Cfg.SaveTo("conf/conf.ini")
|
||||
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,20 +2,22 @@ package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/disk"
|
||||
"github.com/shirou/gopsutil/v3/host"
|
||||
"github.com/shirou/gopsutil/v3/mem"
|
||||
"github.com/shirou/gopsutil/v3/net"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//系统信息
|
||||
@@ -30,6 +32,7 @@ type ZiMaService interface {
|
||||
GetSysInfo() host.InfoStat
|
||||
GetDirPath(path string) []model.Path
|
||||
MkdirAll(path string) (int, error)
|
||||
CreateFile(path string) (int, error)
|
||||
RenameFile(oldF, newF string) (int, error)
|
||||
GetCpuInfo() []cpu.InfoStat
|
||||
}
|
||||
@@ -81,17 +84,12 @@ func (c *zima) GetDirPath(path string) []model.Path {
|
||||
ls, _ := ioutil.ReadDir(path)
|
||||
dirs := []model.Path{}
|
||||
|
||||
if strings.Count(path, "/") > 1 {
|
||||
|
||||
if strings.Count(path, "/") > 0 {
|
||||
for _, l := range ls {
|
||||
if !strings.HasPrefix(l.Name(), ".") && l.IsDir() {
|
||||
dirs = append(dirs, model.Path{Name: l.Name(), Path: path + l.Name() + "/"})
|
||||
}
|
||||
dirs = append(dirs, model.Path{Name: l.Name(), Path: path + "/" + l.Name(), IsDir: l.IsDir()})
|
||||
}
|
||||
} else {
|
||||
dirs = append(dirs, model.Path{Name: "mnt", Path: "/mnt/"})
|
||||
dirs = append(dirs, model.Path{Name: "media", Path: "/media/"})
|
||||
dirs = append(dirs, model.Path{Name: "home", Path: "/home/"})
|
||||
dirs = append(dirs, model.Path{Name: "DATA", Path: "/DATA/", IsDir: true})
|
||||
}
|
||||
return dirs
|
||||
}
|
||||
@@ -133,6 +131,22 @@ func (c *zima) MkdirAll(path string) (int, error) {
|
||||
if os.IsNotExist(err) {
|
||||
os.MkdirAll(path, os.ModePerm)
|
||||
return oasis_err.SUCCESS, nil
|
||||
} else if strings.Contains(err.Error(), ": not a directory") {
|
||||
return oasis_err.FILE_OR_DIR_EXISTS, err
|
||||
}
|
||||
}
|
||||
return oasis_err.ERROR, err
|
||||
}
|
||||
|
||||
//create
|
||||
func (c *zima) CreateFile(path string) (int, error) {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return oasis_err.FILE_OR_DIR_EXISTS, nil
|
||||
} else {
|
||||
if os.IsNotExist(err) {
|
||||
file.CreateFile(path)
|
||||
return oasis_err.SUCCESS, nil
|
||||
}
|
||||
}
|
||||
return oasis_err.ERROR, err
|
||||
|
||||
10
types/search.go
Normal file
10
types/search.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package types
|
||||
|
||||
const (
|
||||
APPLICATION = iota
|
||||
MEDIA
|
||||
PICTURE
|
||||
MUSIC
|
||||
SEARCH
|
||||
UNKNOWN
|
||||
)
|
||||
@@ -1,3 +1,4 @@
|
||||
package types
|
||||
|
||||
const CURRENTVERSION = "0.1.0"
|
||||
const CURRENTVERSION = "0.1.7"
|
||||
const BODY = "<li>Add user authentication module, Login page and initialization page.</li><li>Fixed the problem that the application could not start after the system restarted.</li>"
|
||||
|
||||
BIN
web/img/bg.afedbc0b.jpeg
Normal file
BIN
web/img/bg.afedbc0b.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 301 KiB |
BIN
web/img/disk.573d4b55.png
Normal file
BIN
web/img/disk.573d4b55.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -6,17 +6,15 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/ui//img/icon/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/ui//img/icon/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/ui//img/icon/favicon-16x16.png">
|
||||
<link rel="manifest" href="/ui//site.webmanifest">
|
||||
<link rel="mask-icon" href="/ui//img/icon/safari-pinned-tab.svg" color="#5bbad5">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/ui/img/icon/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/ui/img/icon/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/ui/img/icon/favicon-16x16.png">
|
||||
<link rel="manifest" href="/ui/site.webmanifest">
|
||||
<link rel="mask-icon" href="/ui/img/icon/safari-pinned-tab.svg" color="#5bbad5">
|
||||
<meta name="msapplication-TileColor" content="#da532c">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
<link rel="icon" href="/ui/favicon.ico">
|
||||
<link rel="stylesheet" href="//cdn.materialdesignicons.com/2.0.46/css/materialdesignicons.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/js/all.js"
|
||||
integrity="sha256-GaerX2a/DuOnPrxn/4vH13dobiFUe/27LO6gCZDNauA=" crossorigin="anonymous"></script>
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@mdi/font@6.2.95/css/materialdesignicons.min.css">
|
||||
<title>
|
||||
CasaOS
|
||||
</title>
|
||||
|
||||
696
web/js/app.js
696
web/js/app.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user