mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-12-23 13:04:42 +00:00
Compare commits
250 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e5381710f | ||
|
|
fa62c65526 | ||
|
|
3aea945277 | ||
|
|
4d8ca182cb | ||
|
|
b727606a0a | ||
|
|
428be5f2c2 | ||
|
|
995d67543d | ||
|
|
590beac43a | ||
|
|
e7bf227232 | ||
|
|
eedfdde311 | ||
|
|
38c7b5a569 | ||
|
|
8c0b219621 | ||
|
|
23fc677f30 | ||
|
|
a06508783c | ||
|
|
37fee157dd | ||
|
|
3f1c7098bd | ||
|
|
b11d046c52 | ||
|
|
d6a9ba65ed | ||
|
|
5f1df76dbf | ||
|
|
0cf353c56e | ||
|
|
5dc6297047 | ||
|
|
f26ae2793c | ||
|
|
d7641e1b93 | ||
|
|
37c496fd6a | ||
|
|
cb15c06f7e | ||
|
|
89a0ea34b0 | ||
|
|
d8dd815baa | ||
|
|
a77b5d1954 | ||
|
|
d0fb2f06f5 | ||
|
|
dd8032a8be | ||
|
|
760882e147 | ||
|
|
dfeed76a66 | ||
|
|
28d724731a | ||
|
|
4549d8778b | ||
|
|
05cadaabf3 | ||
|
|
1a0c15208c | ||
|
|
4f5b4b0887 | ||
|
|
cbfe44be61 | ||
|
|
e1bbb998df | ||
|
|
f48cddf924 | ||
|
|
23ce3487e1 | ||
|
|
6246421dae | ||
|
|
f867453573 | ||
|
|
78e7a8b411 | ||
|
|
1aa8fb600b | ||
|
|
7ecfea71ab | ||
|
|
d911d80254 | ||
|
|
9bfe37305c | ||
|
|
94dd2e00c7 | ||
|
|
c5d2cebe92 | ||
|
|
955e8dea07 | ||
|
|
4c7b3a749b | ||
|
|
e86a61596b | ||
|
|
c9617e583f | ||
|
|
dda15b0821 | ||
|
|
50816c68b0 | ||
|
|
c5de0319fb | ||
|
|
78b7c6ce09 | ||
|
|
b420a2d930 | ||
|
|
c67ee1731c | ||
|
|
eaca399ef9 | ||
|
|
e0e9f97764 | ||
|
|
2fefee87fa | ||
|
|
280ad4fcf9 | ||
|
|
538639b623 | ||
|
|
39535d6a38 | ||
|
|
4d977d7a62 | ||
|
|
08c500c434 | ||
|
|
705bf1facb | ||
|
|
aae1802191 | ||
|
|
8e1b9b82c1 | ||
|
|
af440eac55 | ||
|
|
34b4e154a1 | ||
|
|
79db93ec02 | ||
|
|
f8ec3b20cd | ||
|
|
8c7c8dc1ec | ||
|
|
60a141fe25 | ||
|
|
02e712f649 | ||
|
|
7022cf5d29 | ||
|
|
6cf46ce50c | ||
|
|
202c1de570 | ||
|
|
858ab5b124 | ||
|
|
e319975a60 | ||
|
|
5c2c3b5e98 | ||
|
|
a0dc58264a | ||
|
|
717b47ca2c | ||
|
|
f530f69ba5 | ||
|
|
87b190a84b | ||
|
|
10191a1be3 | ||
|
|
59f2ccbeb3 | ||
|
|
076b7198b2 | ||
|
|
eb483a4c5d | ||
|
|
60e81bc781 | ||
|
|
dc8ee89c85 | ||
|
|
c995750312 | ||
|
|
de6ed093a2 | ||
|
|
449e1515d9 | ||
|
|
e6ddb0d849 | ||
|
|
c19e32c6e9 | ||
|
|
94755e221a | ||
|
|
86a3692dad | ||
|
|
45a5567978 | ||
|
|
3190421fd9 | ||
|
|
a7126cac63 | ||
|
|
151aa037bb | ||
|
|
08ed9933ee | ||
|
|
8425011e73 | ||
|
|
96ff550d61 | ||
|
|
85a803d352 | ||
|
|
5def3e5856 | ||
|
|
c768260b1b | ||
|
|
46e146e633 | ||
|
|
1a2f917b30 | ||
|
|
86adfbaef8 | ||
|
|
143af78745 | ||
|
|
7b07f22685 | ||
|
|
c8b6a1c228 | ||
|
|
827fba2164 | ||
|
|
6217009caf | ||
|
|
fbfcc2c43a | ||
|
|
b331c484f5 | ||
|
|
a1fbbf9584 | ||
|
|
3611ec7d09 | ||
|
|
7dedbafc8a | ||
|
|
b7634402bd | ||
|
|
8e025a9836 | ||
|
|
8bfc8178cf | ||
|
|
8343f52137 | ||
|
|
7501833cf9 | ||
|
|
4c917a33a4 | ||
|
|
173997c44b | ||
|
|
76bc6e68ae | ||
|
|
d0fc2cc8cb | ||
|
|
32980f4033 | ||
|
|
28d3ca0ca6 | ||
|
|
3d31ad6689 | ||
|
|
0bb138e39e | ||
|
|
e8db1767e5 | ||
|
|
6b01263252 | ||
|
|
b2a4fafdb4 | ||
|
|
fcfb48d88e | ||
|
|
86380d912d | ||
|
|
87d8be8c61 | ||
|
|
9123974811 | ||
|
|
be50579544 | ||
|
|
91bb0cba6f | ||
|
|
b9946db854 | ||
|
|
9eb650b444 | ||
|
|
84f17b4c4b | ||
|
|
8cff99f726 | ||
|
|
ea166f890b | ||
|
|
d350c3e96f | ||
|
|
ec0d98627d | ||
|
|
fd3cb5b0f0 | ||
|
|
0155dc1877 | ||
|
|
cd79e51f8f | ||
|
|
c6d89f9cb2 | ||
|
|
4b26631374 | ||
|
|
ba742b9fb2 | ||
|
|
57e5a710e0 | ||
|
|
062d95c1eb | ||
|
|
75643287a5 | ||
|
|
6bda9406fb | ||
|
|
be9a010d17 | ||
|
|
3875827b7a | ||
|
|
5338d4662e | ||
|
|
3b9c4b62c5 | ||
|
|
536eac788d | ||
|
|
fc371bf068 | ||
|
|
299b20a087 | ||
|
|
eb31bf5586 | ||
|
|
04d4eacc60 | ||
|
|
60608c5dc7 | ||
|
|
b582e8f53e | ||
|
|
5690ccc1b5 | ||
|
|
13c2967889 | ||
|
|
8a37f9c879 | ||
|
|
96e9284235 | ||
|
|
06f83d3d68 | ||
|
|
438b8a1dd2 | ||
|
|
29e701cb7c | ||
|
|
43cc7596d2 | ||
|
|
11f800d138 | ||
|
|
a58a9e5477 | ||
|
|
5f015e9038 | ||
|
|
3922296d9b | ||
|
|
908a16ace4 | ||
|
|
f7a3863720 | ||
|
|
e94c2ff5c5 | ||
|
|
89487eb5db | ||
|
|
0fb5cab480 | ||
|
|
f210f29ae5 | ||
|
|
7bd5c6a2b4 | ||
|
|
230f1585a3 | ||
|
|
ca967ec59c | ||
|
|
c0b3260a6c | ||
|
|
9ed82cd55e | ||
|
|
381fb85b1d | ||
|
|
2beb1c0d82 | ||
|
|
772c3e0bc0 | ||
|
|
bcda992322 | ||
|
|
8cec47e4db | ||
|
|
87de9cec0a | ||
|
|
6d47d4ff18 | ||
|
|
4bb81e4669 | ||
|
|
c05d837350 | ||
|
|
8908c39969 | ||
|
|
df0f015944 | ||
|
|
46a37f0510 | ||
|
|
6ea3cdb364 | ||
|
|
be80d0cd95 | ||
|
|
296e88d099 | ||
|
|
b61a3db611 | ||
|
|
0f3d3e82f5 | ||
|
|
dd66f73157 | ||
|
|
cbbb907d6a | ||
|
|
ff6cdb6fda | ||
|
|
2eac040875 | ||
|
|
b41d855f73 | ||
|
|
182bc25343 | ||
|
|
12d5e5db03 | ||
|
|
455d226dcd | ||
|
|
f0448cd1b9 | ||
|
|
aff18fa091 | ||
|
|
80c347ac01 | ||
|
|
8113f51cf7 | ||
|
|
4f491fa22f | ||
|
|
3935489d8b | ||
|
|
d14381e6a2 | ||
|
|
42ebd5f325 | ||
|
|
a51bf70b79 | ||
|
|
3787c7bf99 | ||
|
|
ec7f6573ad | ||
|
|
50d68f3f76 | ||
|
|
d9c6a5c875 | ||
|
|
4bace9b16a | ||
|
|
84dfa7f5bf | ||
|
|
582f85c3ba | ||
|
|
7f4562629a | ||
|
|
4776b76b16 | ||
|
|
466350dd21 | ||
|
|
fb39529e8f | ||
|
|
4434ba522b | ||
|
|
aac8fe85ba | ||
|
|
9f938f65b1 | ||
|
|
314dbdab57 | ||
|
|
4ccae3f67f | ||
|
|
9f2e8dae6f | ||
|
|
727aca564b | ||
|
|
70ba4d5e3d |
53
.github/ISSUE_TEMPLATE/app_request.yaml
vendored
53
.github/ISSUE_TEMPLATE/app_request.yaml
vendored
@@ -1,53 +0,0 @@
|
||||
name: "App Request"
|
||||
description: "Request to add an app to the app store."
|
||||
title: "[App Request] AppName"
|
||||
labels: ["App Request"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
### ❤ Thanks for taking the time to fill out this app request!
|
||||
> Before proceeding, please make sure that this app is not in App Store and no one has [requested](https://github.com/IceWhaleTech/CasaOS/labels/App%20Request) the same app before.
|
||||
> If you have already requested the app, please ask your friends to help add a 👍 to this issue. Then be patient and wait for the developers to work on it.
|
||||
> If you have any questions, please ask them on [Discord](https://discord.gg/knqAbbBbeX) or [Github Discussions](https://github.com/IceWhaleTech/CasaOS/discussions).
|
||||
|
||||
- type: textarea
|
||||
id: app-info
|
||||
attributes:
|
||||
label: "App Information"
|
||||
description: "The formal information of this app, as detailed as possible."
|
||||
value: |
|
||||
- Name: <!-- eg. Nextcloud -->
|
||||
- Short Description: <!-- eg. Personal cloud and file sharing solution -->
|
||||
- Official Website: <!-- If available. eg. https://nextcloud.com -->
|
||||
- GitHub Repository: <!-- If available. eg. https://github.com/nextcloud/server -->
|
||||
- Docker Image: <!-- If available. eg. nextcloud/server:latest, ghcr.io/nextcloud/server:latest -->
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: why
|
||||
attributes:
|
||||
label: "Why do you want this app?"
|
||||
description: "Detailed notes can help developers and others understand the importance of this app."
|
||||
placeholder: |
|
||||
As a [what role], it helps me solve [what problem], and especially [what function] is great!
|
||||
or
|
||||
It solves [what problem] and especially [what feature] works well, which is hard to do with other app.
|
||||
or
|
||||
This is the app that [some device/service] must use and will not work without it.
|
||||
or
|
||||
others
|
||||
|
||||
- type: textarea
|
||||
id: additional-info
|
||||
attributes:
|
||||
label: "Additional information?"
|
||||
description: "Anything else you want to share with the developers and others?"
|
||||
placeholder: |
|
||||
Example:
|
||||
- Noteworthy matters.
|
||||
- Recommended Docker image.
|
||||
- Validated Docker deployment instructions.
|
||||
- Notable Docker setup details.
|
||||
- Recommended config files, user data, accessible directory settings.
|
||||
42
.github/ISSUE_TEMPLATE/bug_report.md
vendored
42
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -8,25 +8,57 @@ assignees: ''
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
> A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
> Steps to reproduce the behavior:
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
> A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
> If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
|
||||
```
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
```
|
||||
|
||||
**System Time**
|
||||
|
||||
> Run `timedatectl` and share the output
|
||||
|
||||
```
|
||||
(timedatectl output here)
|
||||
```
|
||||
|
||||
**Logs**
|
||||
|
||||
> Run following command to collect corresponding logs:
|
||||
|
||||
```bash
|
||||
sudo journalctl -xef -u casaos-gateway
|
||||
sudo journalctl -xef -u casaos-user-service
|
||||
sudo journalctl -xef -u casaos-local-storage
|
||||
sudo journalctl -xef -u casaos-app-management
|
||||
sudo journalctl -xef -u casaos.service
|
||||
```
|
||||
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
||||
> Add any other context about the problem here.
|
||||
>
|
||||
> If you are a Zimaboard user, make it explicit with when you got your Zimaboard.
|
||||
|
||||
3
.github/ISSUE_TEMPLATE/config.yml
vendored
3
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +1,8 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: App Request
|
||||
url: https://github.com/IceWhaleTech/CasaOS-AppStore/issues/new?assignees=&labels=App+Request&template=app_request.yml&title=%5BApp+Request%5D+AppName
|
||||
about: Request to add an app to the app store.
|
||||
- name: Feature/Enhancement Ideas
|
||||
url: https://github.com/IceWhaleTech/CasaOS/discussions/164
|
||||
about: Have an idea for a new feature/enhancement?
|
||||
|
||||
15
.github/ISSUE_TEMPLATE/submit-application.md
vendored
15
.github/ISSUE_TEMPLATE/submit-application.md
vendored
@@ -1,15 +0,0 @@
|
||||
---
|
||||
name: Submit application
|
||||
about: Add an app to this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: LinkLeong
|
||||
|
||||
---
|
||||
|
||||
Tested platform
|
||||
e.g. linux/amd64,linux/arm-v7,linux-arm64
|
||||
|
||||
|
||||
|
||||
Please export and upload the configuration file of this application
|
||||
6
.github/workflows/casa.yml
vendored
6
.github/workflows/casa.yml
vendored
@@ -40,7 +40,7 @@ jobs:
|
||||
# env:
|
||||
# GITHUB_TOKEN: ${{ github.token }}
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
@@ -65,7 +65,7 @@ jobs:
|
||||
# ls
|
||||
|
||||
|
||||
- name: Set enviroment for github-release
|
||||
- name: Set environment 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
|
||||
@@ -73,7 +73,7 @@ jobs:
|
||||
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '14'
|
||||
|
||||
|
||||
26
.github/workflows/codecov.yml
vendored
Normal file
26
.github/workflows/codecov.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: Collect Code Coverage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: "1.20"
|
||||
- name: Run coverage
|
||||
run: go test -race -failfast -coverprofile=coverage.txt -covermode=atomic -v ./...
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
13
.github/workflows/demo.yml
vendored
13
.github/workflows/demo.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Configure AWS credentials from Test account
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
@@ -33,9 +33,10 @@ jobs:
|
||||
|
||||
- name: Get old instance and snapshot name, create new instance name
|
||||
run: |
|
||||
echo "OLD_INSTANCE_SNAPSHOT_NAME=$(aws lightsail get-instance-snapshots | grep '"name": "0.3.3-demo-1658402149' | sed 's/ //g' | sed 's/"//g' | sed 's/,//g' | sed 's/name://g')" >> $GITHUB_ENV
|
||||
echo "OLD_INSTANCE_NAME=$(aws lightsail get-instances | grep '"name": "CasaOS-Demo-[0-9]' | sed 's/ //g' | sed 's/"//g' | sed 's/,//g' | sed 's/name://g')" >> $GITHUB_ENV
|
||||
echo "NEW_INSTANCE_NAME=CasaOS-Demo-$(date +%s)" >> $GITHUB_ENV
|
||||
echo "OLD_INSTANCE_SNAPSHOT_NAME=updateto_to_0.4.4-1684926517" >> $GITHUB_ENV
|
||||
echo "OLD_INSTANCE_NAME=$(aws lightsail get-instances | grep '"name": "CasaOS-Demo-[0-9]' | tail -1 | sed 's/ //g' | sed 's/"//g' | sed 's/,//g' | sed 's/name://g')" >> $GITHUB_ENV
|
||||
# echo "OLD_INSTANCE_NAME=CasaOS-Demo-1687680295" >> $GITHUB_ENV
|
||||
echo "NEW_INSTANCE_NAME= CasaOS-Demo-$(date +%s)" >> $GITHUB_ENV
|
||||
|
||||
- name: Create instances from snapshot
|
||||
run: |
|
||||
@@ -75,5 +76,9 @@ jobs:
|
||||
run: |
|
||||
aws lightsail delete-instance \
|
||||
--instance-name ${{ env.OLD_INSTANCE_NAME }}
|
||||
- name: Demo Reset Error Handling
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"Demo Reset Error"}}' ${{ secrets.SSH_ROBOT_URL }}
|
||||
|
||||
|
||||
|
||||
46
.github/workflows/publish_npm.yaml
vendored
Normal file
46
.github/workflows/publish_npm.yaml
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
name: publish npm
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*.*.*
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
publish-npm:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
registry-url: https://registry.npmjs.org/
|
||||
|
||||
- run: git tag --sort=-creatordate | head -n 1
|
||||
- name: Get version
|
||||
id: get_version
|
||||
run: echo "VERSION=$(git tag --sort=-creatordate | head -n 1)" >> $GITHUB_OUTPUT
|
||||
- name: Get commit id
|
||||
id: get_commit_id
|
||||
run: echo "COMMIT_ID=$( git rev-parse --short "$GITHUB_SHA" )" >> $GITHUB_OUTPUT
|
||||
|
||||
- run: echo "${{ steps.get_version.outputs.VERSION }}-${{ steps.get_commit_id.outputs.COMMIT_ID }}"
|
||||
- name: Set version
|
||||
run: |
|
||||
sudo apt-get install jq
|
||||
jq '.version="${{ steps.get_version.outputs.VERSION }}-${{ steps.get_commit_id.outputs.COMMIT_ID }}"' package.json > package.json.new
|
||||
mv package.json.new package.json
|
||||
- name: Generate SDK
|
||||
run: |
|
||||
npm cache clean --force
|
||||
npm install @openapitools/openapi-generator-cli -g
|
||||
- run: npm i
|
||||
- run: npm run start
|
||||
- run: npm publish --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
||||
92
.github/workflows/push_test_server.yml
vendored
Normal file
92
.github/workflows/push_test_server.yml
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
name: Auto Publish Website
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: isntall git
|
||||
run: sudo apt install --yes git
|
||||
- name: git global
|
||||
run: sudo git config --global --add safe.directory '*'
|
||||
- name: set version
|
||||
run: sudo git tag v00.00.00-alpha
|
||||
|
||||
- name: Fetch all tags
|
||||
run: sudo git fetch --force --tags
|
||||
|
||||
- name: Get version
|
||||
id: get_version
|
||||
# run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
|
||||
run: echo "VERSION=$(git describe --abbrev=0 --tags | awk -F- '{print $1}')" >> $GITHUB_ENV
|
||||
|
||||
- name: show version
|
||||
id: show_version
|
||||
# run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
|
||||
run: echo ${{env.VERSION}}
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: 'stable'
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v4
|
||||
with:
|
||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||
distribution: goreleaser
|
||||
version: 1.14.1
|
||||
args: release --rm-dist --snapshot
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GoogleID: ${{ secrets.GoogleID }}
|
||||
GoogleSecret: ${{ secrets.GoogleSecret }}
|
||||
DropboxKey: ${{ secrets.DropboxKey }}
|
||||
DropboxSecret: ${{ secrets.DropboxSecret }}
|
||||
OneDriveID: ${{ secrets.OneDriveID }}
|
||||
OneDriveSecret: ${{ secrets.OneDriveSecret }}
|
||||
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
|
||||
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
||||
|
||||
- name: remove migration file
|
||||
run: sudo find . -type f \( -name '*migration*' \) -delete
|
||||
|
||||
- name: install sshpass
|
||||
run: sudo apt install sshpass --yes
|
||||
|
||||
- name: ZeroTier
|
||||
uses: zerotier/github-action@v1.0.1
|
||||
with:
|
||||
network_id: ${{ secrets.ZEROTIER_NETWORK_ID }}
|
||||
auth_token: ${{ secrets.ZEROTIER_CENTRAL_TOKEN }}
|
||||
|
||||
- name: ping host
|
||||
shell: bash
|
||||
run: |
|
||||
count=10
|
||||
while ! ping -c 1 10.147.18.11 ; do
|
||||
echo "waiting..." ;
|
||||
sleep 1 ;
|
||||
let count=count-1
|
||||
done
|
||||
echo "ping success"
|
||||
|
||||
- name: copy tar to target host
|
||||
shell: bash
|
||||
run: |
|
||||
sshpass -p "${{ secrets.ssh_password }}" scp -r -o StrictHostKeyChecking=no -P 22 ./dist/*.gz root@10.147.18.11:/var/www/download
|
||||
echo "ping success"
|
||||
- name: send message
|
||||
run: |
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"CasaOS updated"}}' ${{ secrets.SSH_ROBOT_URL }}
|
||||
69
.github/workflows/release.yml
vendored
Normal file
69
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
name: goreleaser
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*.*.*
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Install dependencies for cross-compiling
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt-get --no-install-recommends --yes install \
|
||||
upx libc6-dev-amd64-cross \
|
||||
gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
|
||||
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Fetch all tags
|
||||
run: git fetch --force --tags
|
||||
|
||||
- name: Get version
|
||||
id: get_version
|
||||
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: "1.20"
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v4
|
||||
with:
|
||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GoogleID: ${{ secrets.GoogleID }}
|
||||
GoogleSecret: ${{ secrets.GoogleSecret }}
|
||||
DropboxKey: ${{ secrets.DropboxKey }}
|
||||
DropboxSecret: ${{ secrets.DropboxSecret }}
|
||||
OneDriveID: ${{ secrets.OneDriveID }}
|
||||
OneDriveSecret: ${{ secrets.OneDriveSecret }}
|
||||
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
|
||||
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
||||
|
||||
- name: Upload to oss
|
||||
id: upload_to_oss
|
||||
uses: tvrcgo/upload-to-oss@master
|
||||
with:
|
||||
key-id: ${{ secrets.OSS_KEY_ID }}
|
||||
key-secret: ${{ secrets.OSS_KEY_SECRET }}
|
||||
region: oss-cn-shanghai
|
||||
bucket: casaos
|
||||
assets: |
|
||||
dist/checksums.txt:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/checksums.txt
|
||||
dist/linux-arm-7-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-arm-7-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz
|
||||
dist/linux-arm64-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-arm64-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz
|
||||
dist/linux-amd64-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-amd64-casaos-${{ steps.get_version.outputs.VERSION }}.tar.gz
|
||||
dist/linux-arm-7-casaos-migration-tool-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-arm-7-casaos-migration-tool-${{ steps.get_version.outputs.VERSION }}.tar.gz
|
||||
dist/linux-arm64-casaos-migration-tool-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-arm64-casaos-migration-tool-${{ steps.get_version.outputs.VERSION }}.tar.gz
|
||||
dist/linux-amd64-casaos-migration-tool-${{ steps.get_version.outputs.VERSION }}.tar.gz:/IceWhaleTech/CasaOS/releases/download/${{ steps.get_version.outputs.VERSION }}/linux-amd64-casaos-migration-tool-${{ steps.get_version.outputs.VERSION }}.tar.gz
|
||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -28,16 +28,15 @@ gen
|
||||
/sql/
|
||||
/out/
|
||||
/db/
|
||||
/docs/
|
||||
/web/
|
||||
/conf/conf.ini
|
||||
/conf/conf.conf
|
||||
/conf/conf.json
|
||||
__debug_bin
|
||||
main
|
||||
CasaOS
|
||||
github.com
|
||||
.all-contributorsrc
|
||||
build
|
||||
dist
|
||||
.goreleaser.yaml
|
||||
CasaOS
|
||||
|
||||
# System Files
|
||||
.DS_Store
|
||||
|
||||
159
.goreleaser.debug.yaml
Normal file
159
.goreleaser.debug.yaml
Normal file
@@ -0,0 +1,159 @@
|
||||
# This is an example .goreleaser.yml file with some sensible defaults.
|
||||
# Make sure to check the documentation at https://goreleaser.com
|
||||
project_name: casaos
|
||||
before:
|
||||
hooks:
|
||||
- go generate
|
||||
- go run github.com/google/go-licenses@latest check . --disallowed_types=restricted
|
||||
- go mod tidy
|
||||
- go test -race -v ./...
|
||||
|
||||
builds:
|
||||
- id: casaos-amd64
|
||||
binary: build/sysroot/usr/bin/casaos
|
||||
env:
|
||||
- CC=x86_64-linux-gnu-gcc
|
||||
gcflags:
|
||||
- all=-N -l
|
||||
ldflags:
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- amd64
|
||||
- id: casaos-arm64
|
||||
binary: build/sysroot/usr/bin/casaos
|
||||
env:
|
||||
- CC=aarch64-linux-gnu-gcc
|
||||
gcflags:
|
||||
- all=-N -l
|
||||
ldflags:
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- arm64
|
||||
- id: casaos-arm-7
|
||||
binary: build/sysroot/usr/bin/casaos
|
||||
env:
|
||||
- CC=arm-linux-gnueabihf-gcc
|
||||
gcflags:
|
||||
- all=-N -l
|
||||
ldflags:
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
- id: casaos-migration-tool-amd64
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
main: ./cmd/migration-tool
|
||||
env:
|
||||
- CC=x86_64-linux-gnu-gcc
|
||||
gcflags:
|
||||
- all=-N -l
|
||||
ldflags:
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- amd64
|
||||
- id: casaos-migration-tool-arm64
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
main: ./cmd/migration-tool
|
||||
env:
|
||||
- CC=aarch64-linux-gnu-gcc
|
||||
gcflags:
|
||||
- all=-N -l
|
||||
ldflags:
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- arm64
|
||||
- id: casaos-migration-tool-arm-7
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
main: ./cmd/migration-tool
|
||||
env:
|
||||
- CC=arm-linux-gnueabihf-gcc
|
||||
gcflags:
|
||||
- all=-N -l
|
||||
ldflags:
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
archives:
|
||||
- name_template: >-
|
||||
{{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }}
|
||||
id: casaos
|
||||
builds:
|
||||
- casaos-amd64
|
||||
- casaos-arm64
|
||||
- casaos-arm-7
|
||||
files:
|
||||
- build/**/*
|
||||
- name_template: >-
|
||||
{{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-migration-tool-v{{ .Version }}
|
||||
id: casaos-migration-tool
|
||||
builds:
|
||||
- casaos-migration-tool-amd64
|
||||
- casaos-migration-tool-arm64
|
||||
- casaos-migration-tool-arm-7
|
||||
files:
|
||||
- build/sysroot/etc/**/*
|
||||
checksum:
|
||||
name_template: "checksums.txt"
|
||||
snapshot:
|
||||
name_template: "{{ incpatch .Version }}"
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
||||
# release:
|
||||
# github:
|
||||
# owner: IceWhaleTech
|
||||
# name: CasaOS
|
||||
# draft: true
|
||||
# prerelease: auto
|
||||
# mode: replace
|
||||
# name_template: "v{{ .Version }}"
|
||||
release:
|
||||
github:
|
||||
owner: IceWhaleTech
|
||||
name: CasaOS
|
||||
draft: true
|
||||
prerelease: auto
|
||||
mode: replace
|
||||
name_template: "v{{ .Version }}"
|
||||
207
.goreleaser.yaml
Normal file
207
.goreleaser.yaml
Normal file
@@ -0,0 +1,207 @@
|
||||
# This is an example .goreleaser.yml file with some sensible defaults.
|
||||
# Make sure to check the documentation at https://goreleaser.com
|
||||
project_name: casaos
|
||||
before:
|
||||
hooks:
|
||||
- go generate
|
||||
- go run github.com/google/go-licenses@latest check . --disallowed_types=restricted
|
||||
- go mod tidy
|
||||
- go test -race -v ./...
|
||||
|
||||
builds:
|
||||
- id: casaos-amd64
|
||||
binary: build/sysroot/usr/bin/casaos
|
||||
hooks:
|
||||
post:
|
||||
- upx --best --lzma -v --no-progress "{{ .Path }}"
|
||||
env:
|
||||
- CC=x86_64-linux-gnu-gcc
|
||||
ldflags:
|
||||
- -X main.commit={{.Commit}}
|
||||
- -X main.date={{.Date}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/google_drive.client_id={{.Env.GoogleID}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/google_drive.client_secret={{.Env.GoogleSecret}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/onedrive.client_id={{.Env.OneDriveID}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/onedrive.client_secret={{.Env.OneDriveSecret}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/dropbox.app_key={{.Env.DropboxKey}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/dropbox.app_secret={{.Env.DropboxSecret}}
|
||||
- -s
|
||||
- -w
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- amd64
|
||||
- id: casaos-arm64
|
||||
binary: build/sysroot/usr/bin/casaos
|
||||
hooks:
|
||||
post:
|
||||
- upx --best --lzma -v --no-progress "{{ .Path }}"
|
||||
env:
|
||||
- CC=aarch64-linux-gnu-gcc
|
||||
ldflags:
|
||||
- -X main.commit={{.Commit}}
|
||||
- -X main.date={{.Date}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/google_drive.client_id={{.Env.GoogleID}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/google_drive.client_secret={{.Env.GoogleSecret}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/onedrive.client_id={{.Env.OneDriveID}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/onedrive.client_secret={{.Env.OneDriveSecret}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/dropbox.app_key={{.Env.DropboxKey}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/dropbox.app_secret={{.Env.DropboxSecret}}
|
||||
- -s
|
||||
- -w
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- arm64
|
||||
- id: casaos-arm-7
|
||||
binary: build/sysroot/usr/bin/casaos
|
||||
hooks:
|
||||
post:
|
||||
- upx --best --lzma -v --no-progress "{{ .Path }}"
|
||||
env:
|
||||
- CC=arm-linux-gnueabihf-gcc
|
||||
ldflags:
|
||||
- -X main.commit={{.Commit}}
|
||||
- -X main.date={{.Date}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/google_drive.client_id={{.Env.GoogleID}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/google_drive.client_secret={{.Env.GoogleSecret}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/onedrive.client_id={{.Env.OneDriveID}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/onedrive.client_secret={{.Env.OneDriveSecret}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/dropbox.app_key={{.Env.DropboxKey}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/dropbox.app_secret={{.Env.DropboxSecret}}
|
||||
- -s
|
||||
- -w
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
- id: casaos-migration-tool-amd64
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
hooks:
|
||||
post:
|
||||
- upx --best --lzma -v --no-progress "{{ .Path }}"
|
||||
main: ./cmd/migration-tool
|
||||
env:
|
||||
- CC=x86_64-linux-gnu-gcc
|
||||
ldflags:
|
||||
- -X main.commit={{.Commit}}
|
||||
- -X main.date={{.Date}}
|
||||
- -s
|
||||
- -w
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- amd64
|
||||
- id: casaos-migration-tool-arm64
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
hooks:
|
||||
post:
|
||||
- upx --best --lzma -v --no-progress "{{ .Path }}"
|
||||
main: ./cmd/migration-tool
|
||||
env:
|
||||
- CC=aarch64-linux-gnu-gcc
|
||||
ldflags:
|
||||
- -X main.commit={{.Commit}}
|
||||
- -X main.date={{.Date}}
|
||||
- -s
|
||||
- -w
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- arm64
|
||||
- id: casaos-migration-tool-arm-7
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
hooks:
|
||||
post:
|
||||
- upx --best --lzma -v --no-progress "{{ .Path }}"
|
||||
main: ./cmd/migration-tool
|
||||
env:
|
||||
- CC=arm-linux-gnueabihf-gcc
|
||||
ldflags:
|
||||
- -X main.commit={{.Commit}}
|
||||
- -X main.date={{.Date}}
|
||||
- -s
|
||||
- -w
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
archives:
|
||||
- name_template: >-
|
||||
{{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }}
|
||||
id: casaos
|
||||
builds:
|
||||
- casaos-amd64
|
||||
- casaos-arm64
|
||||
- casaos-arm-7
|
||||
files:
|
||||
- build/**/*
|
||||
- name_template: >-
|
||||
{{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-migration-tool-v{{ .Version }}
|
||||
id: casaos-migration-tool
|
||||
builds:
|
||||
- casaos-migration-tool-amd64
|
||||
- casaos-migration-tool-arm64
|
||||
- casaos-migration-tool-arm-7
|
||||
files:
|
||||
- build/sysroot/etc/**/*
|
||||
checksum:
|
||||
name_template: "checksums.txt"
|
||||
snapshot:
|
||||
name_template: "{{ incpatch .Version }}"
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
||||
# release:
|
||||
# github:
|
||||
# owner: IceWhaleTech
|
||||
# name: CasaOS
|
||||
# draft: true
|
||||
# prerelease: auto
|
||||
# mode: replace
|
||||
# name_template: "v{{ .Version }}"
|
||||
release:
|
||||
github:
|
||||
owner: IceWhaleTech
|
||||
name: CasaOS
|
||||
draft: true
|
||||
prerelease: auto
|
||||
mode: replace
|
||||
name_template: "v{{ .Version }}"
|
||||
138
CHANGELOG.md
138
CHANGELOG.md
@@ -16,9 +16,145 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Security
|
||||
|
||||
## [0.4.3]
|
||||
|
||||
### Added
|
||||
|
||||
- [Disk] Now usb also supports merging to
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- [File] Solve the installation dependency problem, make the installation more smoothly
|
||||
- [File] Change the default permissions of the sharing folder
|
||||
|
||||
### Fixed
|
||||
|
||||
## [0.3.5-alpha] - 2022-08-08
|
||||
- [System] Fixed not see wlan iface ([#909](https://github.com/IceWhaleTech/CasaOS/issues/909))
|
||||
- [System] Terminal font issue fix ([#929](https://github.com/IceWhaleTech/CasaOS/issues/929))
|
||||
- [File] Fixed the problem of not being able to launch after mounting
|
||||
|
||||
### Removed
|
||||
|
||||
|
||||
## [0.4.2]
|
||||
|
||||
### Added
|
||||
|
||||
- [App] Increase the display of progress during the installation process
|
||||
- [App] Label whether the current app supports x86 or Pi devices
|
||||
- [App] Support single app version upgrade
|
||||
- [File] Support mounting of Google Drive and Dropbox cloud drives
|
||||
- [System] Support Mint Linux
|
||||
|
||||
### Changed
|
||||
|
||||
- [File] Optimize the download speed of a single file
|
||||
|
||||
### Fixed
|
||||
|
||||
- [Share] Fix the samba permission issue
|
||||
- [Disk] Fix the problem of disk mount point plus 1 after upgrade ([#770](https://github.com/IceWhaleTech/CasaOS/issues/770))
|
||||
- [File] Fix the problem of file permission change caused by modifying files in casaos ([#829](https://github.com/IceWhaleTech/CasaOS/issues/829))
|
||||
- [Share] Fix the problem of files being deleted due to samba uninstallation failure ([#843](https://github.com/IceWhaleTech/CasaOS/issues/843))
|
||||
|
||||
|
||||
|
||||
## [0.4.1] - 2023-1-19
|
||||
|
||||
|
||||
### Added
|
||||
- [Disk] Added disk merging feature in storage management (beta) that allows for multiple disks to be merged into a single storage space
|
||||
- [System] Added option for startpage.com search engine
|
||||
- [APP] Added app cloning feature in the app's context menu.
|
||||
### Changed
|
||||
- [APP] Improved app installation process, including display of the installation process, checks for successful installation, and prompts
|
||||
- [System] Binary sizes are 40%~60% smaller (thanks to upx)
|
||||
- [App] Optimization of install and update for certain country.
|
||||
- [All] Lots of bug fixes
|
||||
|
||||
## [0.4.0] - 2022-12-13
|
||||
### Added
|
||||
|
||||
- [Developer] Included `casaos-cli` command tool for debugging
|
||||
- [Developer] Added message bus for events and actions - Use `casaos-cli message-bus` to manage.
|
||||
- [Disk] Disk notification in Dashboard
|
||||
- [System] Restart/shutdown directly from CasaOS Dashboard
|
||||
### Changed
|
||||
|
||||
- [General] CasaOS new logo!
|
||||
- [App] Redesign of Featured App
|
||||
- [App] Now you can choose to delete userdata along with app uninstallation
|
||||
|
||||
### Security
|
||||
|
||||
- [System] Fixed a shell injection issue for better security
|
||||
|
||||
### Fixed
|
||||
|
||||
- [System] Re-instate default zone0 for CPU Temp ([#694](https://github.com/IceWhaleTech/CasaOS/issues/694))
|
||||
- [Disk] Fixed storage name with extra `-1` after rebooting ([#698](https://github.com/IceWhaleTech/CasaOS/issues/698))
|
||||
- [Disk] Fixed disk check so it does not impact disk going into idle ([#704](https://github.com/IceWhaleTech/CasaOS/issues/704))
|
||||
|
||||
## [0.3.8] 2022-11-21
|
||||
|
||||
### Added
|
||||
- [System] Add system announcement
|
||||
- [App] Allow to turn off the display of "Existing Docker Apps" in the settings.
|
||||
|
||||
### Changed
|
||||
- [System] Improve the feedback function, you can submit feedback in the bottom right corner of WebUI.
|
||||
|
||||
### Fixed
|
||||
- [System] Fix CPU Temp for other platforms ([#661](https://github.com/IceWhaleTech/CasaOS/issues/661))
|
||||
|
||||
## [0.3.7.1] 2022-11-04
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix memory leak issue ([#658](https://github.com/IceWhaleTech/CasaOS/issues/658)[#646](https://github.com/IceWhaleTech/CasaOS/issues/646))
|
||||
- Solve the problem of local application import failure ([#490](https://github.com/IceWhaleTech/CasaOS/issues/490))
|
||||
|
||||
## [0.3.7] 2022-10-28
|
||||
|
||||
### Added
|
||||
- [Storage] Disk merge (Beta), you can merge multiple disks into a single storage space (currently you need to enable this feature from the command line)
|
||||
|
||||
### Changed
|
||||
- [Files] Changed the cache file storage location, now the file upload size is not limited by the system disk capacity.
|
||||
- [Scripts] Updated installation and upgrade scripts to support more Debian-based Linux distributions.
|
||||
- [Engineering] Refactored Local Storage into a standalone service as part of CasaOS modularization.
|
||||
|
||||
### Fixed
|
||||
- [Apps] App list update mechanism improved, now you can see the latest apps in App Store immediately.
|
||||
- [Storage] Fixed a lot of known issues
|
||||
|
||||
### Added
|
||||
- [Storage] Disk merge (Beta), you can merge multiple disks into a single storage space (currently you need to enable this feature from the command line)
|
||||
|
||||
### Changed
|
||||
- [Files] Changed the cache file storage location, now the file upload size is not limited by the system disk capacity.
|
||||
- [Scripts] Updated installation and upgrade scripts to support more Debian-based Linux distributions.
|
||||
- [Engineering] Refactored Local Storage into a standalone service as part of CasaOS modularization.
|
||||
|
||||
### Fixed
|
||||
- [Apps] App list update mechanism improved, now you can see the latest apps in App Store immediately.
|
||||
- [Storage] Fixed a lot of known issues
|
||||
|
||||
|
||||
## [0.3.6] - 2022-09-06
|
||||
|
||||
### Added
|
||||
- [System] Added power and temperature info to performance widget (Intel)
|
||||
- [Apps] Custom links can be added to Apps section
|
||||
|
||||
### Fixed
|
||||
- [Apps] Fixed the problem of not being able to modify some App settings ([#510](https://github.com/IceWhaleTech/CasaOS/issues/510))
|
||||
|
||||
### Changed
|
||||
- [System] Architecture optimization. Improved performance.
|
||||
|
||||
## [0.3.5] - 2022-08-23
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,128 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
wiki@casaos.io.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
||||
86
README.md
86
README.md
@@ -1,18 +1,16 @@
|
||||
# CasaOS - Your Home Cloud OS
|
||||
|
||||
|
||||
# CasaOS - Your Personal Cloud
|
||||
<!-- Readme i18n links -->
|
||||
<!-- > English | [中文](#) | [Français](#) -->
|
||||
|
||||
<p align="center">
|
||||
<!-- CasaOS Banner -->
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_dark_night_800px.png">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800px.png">
|
||||
<img alt="CasaOS" src="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800px.png">
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_dark_night_800x300.png">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800x300.png">
|
||||
<img alt="CasaOS" src="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800x300.png">
|
||||
</picture>
|
||||
<br/>
|
||||
<i>Connect with the community developing HOME CLOUD, creating self-sovereign, and defining the future of the distributed cloud.</i>
|
||||
<i>Connect with the community, establish autonomy, reduce the cost of SaaS, and MAXIMIZE the potential for a personalized copilot.</i>
|
||||
<br/>
|
||||
<br/>
|
||||
<!-- CasaOS Badges -->
|
||||
@@ -28,6 +26,9 @@
|
||||
<a href="https://github.com/IceWhaleTech/CasaOS/issues" target="_blank">
|
||||
<img alt="CasaOS Issues" src="https://img.shields.io/github/issues/IceWhaleTech/CasaOS?color=162453&style=flat-square&label=Issues" />
|
||||
</a>
|
||||
<a href="https://codecov.io/gh/IceWhaleTech/CasaOS" >
|
||||
<img src="https://codecov.io/gh/IceWhaleTech/CasaOS/branch/main/graph/badge.svg?token=l9uMKGlkxM"/>
|
||||
</a>
|
||||
<a href="https://github.com/IceWhaleTech/CasaOS/stargazers" target="_blank">
|
||||
<img alt="CasaOS Stargazers" src="https://img.shields.io/github/stars/IceWhaleTech/CasaOS?color=162453&style=flat-square&label=Stars" />
|
||||
</a>
|
||||
@@ -62,18 +63,16 @@
|
||||
</kbd>
|
||||
</p>
|
||||
|
||||
## Why do we need Home Cloud?
|
||||
## Why do you need Personal Cloud?
|
||||
|
||||
Think about it seriously. Is control of our data, smart devices and digital assets now only in the hands of some big company?
|
||||
In 2020, the team noticed three important trends:
|
||||
- The cost of computing power and storage was decreasing fast.
|
||||
- A part of cloud computing was moving towards edge computing.
|
||||
- The issue of consumer data asset ownership and attribution had been ignored.
|
||||
|
||||
- Is your photo album saved in their cloud service?
|
||||
- Do your thermostats, monitors, lamps need to be used through their cloud services?
|
||||
- Do your personal documents, memos, contacts, passwords, etc. reside in their cloud storage services?
|
||||
- Are you just going to have to accept their decisions when they decide to change prices, review content or even discontinue services?
|
||||
Based on these trends, the team proposed a thought experiment internally: what if personal clouds were available under $100 in next five years? This personal cloud would provide a low-cost data collaboration solution as a personal data center, storing and managing data for creators and small organizations. A distributed collaborative computing network can be formed by personal servers located around the world. It could also control and connect all smart devices, providing cross-ecosystem local intelligent services.
|
||||
|
||||
It sounds ridiculous, doesn't it? We are losing control of our own data!
|
||||
|
||||
Our ideal home cloud is one where you can manage all your data, devices and data assets very easily. In your own home, you have absolute control.
|
||||
Furthermore, the personal cloud could combine personal data to train personalized AI assistants. The idea is that this technology would be an effective way to solve the issue of consumer data asset ownership and , as well as provide a more affordable and efficient computing solution for individuals and small organizations.
|
||||
|
||||
> If you think what we are doing is valuable. Please **give us a star ⭐** and **fork it 🤞**!
|
||||
|
||||
@@ -84,7 +83,7 @@ Our ideal home cloud is one where you can manage all your data, devices and data
|
||||
- Multiple hardware and base system support
|
||||
- ZimaBoard, NUC, RPi, old computers, whatever is available.
|
||||
- Selected apps in the app store, one-click installation
|
||||
- Nextcloud, HomeAssiant, AdGuard, Jellyfin, *arr and more!
|
||||
- Nextcloud, HomeAssistant, AdGuard, Jellyfin, *arr and more!
|
||||
- Easily install numerous Docker apps
|
||||
- Over 100,000 apps from the Docker ecosystem can be easily installed
|
||||
- Elegant drive and file management
|
||||
@@ -105,7 +104,7 @@ CasaOS fully supports ZimaBoard, Intel NUC, and Raspberry Pi. Also, more compute
|
||||
### System Compatibility
|
||||
|
||||
Official Support
|
||||
- Debian 11 (✅ Tested, Recommended)
|
||||
- Debian 12 (✅ Tested, Recommended)
|
||||
- Ubuntu Server 20.04 (✅ Tested)
|
||||
- Raspberry Pi OS (✅ Tested)
|
||||
|
||||
@@ -114,19 +113,20 @@ Community Support
|
||||
- Armbian 22.04 (✅ Tested)
|
||||
- Alpine (🚧 Not Fully Tested Yet)
|
||||
- OpenWrt (🚧 Not Fully Tested Yet)
|
||||
- ArchLinux (🚧 Not Fully Tested Yet)
|
||||
|
||||
### Quick Setup CasaOS
|
||||
|
||||
Freshly install a system from the list above and run this command:
|
||||
|
||||
```sh
|
||||
wget -qO- https://get.casaos.io | bash
|
||||
wget -qO- https://get.casaos.io | sudo bash
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
curl -fsSL https://get.casaos.io | bash
|
||||
curl -fsSL https://get.casaos.io | sudo bash
|
||||
```
|
||||
|
||||
### Uninstall CasaOS
|
||||
@@ -141,18 +141,18 @@ casaos-uninstall
|
||||
Before v0.3.3
|
||||
|
||||
```sh
|
||||
curl -fsSL https://get.icewhale.io/casaos-uninstall.sh | bash
|
||||
curl -fsSL https://get.icewhale.io/casaos-uninstall.sh | sudo bash
|
||||
```
|
||||
|
||||
## Community
|
||||
|
||||
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.
|
||||
The word Casa comes from the Spanish word for "home". Project CasaOS originated as a pre-installed system for the crowdfunded product [ZimaBoard](https://www.zimaboard.com) on Kickstarter.
|
||||
|
||||
After looking at many systems and software on the market, the team found no server system designed for home scenarios, sadly true.
|
||||
|
||||
So, we set out to build this open source project to develop CasaOS with our own hands, everyone 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.
|
||||
|
||||
We believes that through community-driven collaborative innovation and open communication with global developers, we can reshape the digital home experience like never before.
|
||||
We believe that through community-driven collaborative innovation and open communication with global developers, we can reshape the digital home experience like never before.
|
||||
|
||||
**A warm welcome for you to get help or share great ideas in the [Discord](https://discord.gg/knqAbbBbeX)!**
|
||||
|
||||
@@ -162,38 +162,12 @@ We believes that through community-driven collaborative innovation and open comm
|
||||
|
||||
CasaOS is a community-driven open source project and the people involved are CasaOS users. That means CasaOS will always need contributions from community members just like you!
|
||||
|
||||
<details>
|
||||
<summary><b>How can I get involved? 🧐</b></summary>
|
||||
<p>
|
||||
- See <https://wiki.casaos.io/en/contribute> for ways of contributing to CasaOS
|
||||
- See <https://wiki.casaos.io/en/contribute/development> if you want to be involved in code contribution specifically
|
||||
|
||||
### Coding 💻 (WIP)
|
||||
## Donate
|
||||
<p ><a href="https://www.buymeacoffee.com/icewhaletech"> <img align="center" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="50" width="210" alt="bappi2097" target="_blank" /></a></p>
|
||||
|
||||
We are refining documentation that can be used for effective community collaboration. Feel free to start a discussion if you have a good idea.
|
||||
|
||||
### Helping Users 💬
|
||||
|
||||
If you have extensive knowledge of CasaOS and related areas. We highly encourage you to help others as much as you can in Discord and Discussions.
|
||||
|
||||
Discord: [https://discord.gg/knqAbbBbeX](https://discord.gg/knqAbbBbeX)
|
||||
|
||||
GitHub Discussions: [https://github.com/IceWhaleTech/CasaOS/discussions](https://github.com/IceWhaleTech/CasaOS/discussions)
|
||||
|
||||
### Helping with Translations 🌍 (WIP)
|
||||
|
||||
CasaOS officially supports English and Chinese. You are welcome to help make CasaOS available in more languages.
|
||||
|
||||
### Performing Alpha Testing ⚠️
|
||||
|
||||
Alpha testing is quality assurance testing that is engaged and driven by the community. It's a great way to get involved in contributing and experiencing the latest features before a new release.
|
||||
|
||||
The documentation is being refined and you can contact @JohnGuan via [Discord](https://discord.gg/knqAbbBbeX). Ask to join the #casaos-alpha channel.
|
||||
|
||||
### Writing Documentation 📖 (WIP)
|
||||
|
||||
Help make our documentation better by writing new content for the CasaOS Wiki, correcting existing material, or translating content into new languages.
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
## Credits
|
||||
|
||||
@@ -225,6 +199,8 @@ Everyone's contribution is greatly appreciated. ([Emoji Key](https://allcontribu
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/llwaini"><img src="https://avatars.githubusercontent.com/u/59589857?v=4?s=100" width="100px;" alt=""/><br /><sub><b>llwaini</b></sub></a><br /><a href="#projectManagement-llwaini" title="Project Management">📆</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=llwaini" title="Tests">⚠️</a> <a href="#tutorial-llwaini" title="Tutorials">✅</a></td>
|
||||
<td align="center"><a href="https://github.com/CorrectRoadH"><img src="https://avatars.githubusercontent.com/u/29306285?v=4?s=100" width="100px;" alt=""/><br /><sub><b>CorrectRoadH</b></sub></a><br /><a href="https://github.com/IceWhaleTech/CasaOS/commits?author=correctroadh" title="Code">💻</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=correctroadh" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/zhanghengxin"><img src="https://avatars.githubusercontent.com/u/24197448?v=4?s=100" width="100px;" alt=""/><br /><sub><b>zhanghengxin</b></sub></a><br /><a href="https://github.com/IceWhaleTech/CasaOS/commits?author=zhanghengxin" title="Code">💻</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=zhanghengxin" title="Documentation">📖</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -233,7 +209,7 @@ Everyone's contribution is greatly appreciated. ([Emoji Key](https://allcontribu
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!
|
||||
|
||||
## Changelog
|
||||
|
||||
|
||||
9
SECURITY.md
Normal file
9
SECURITY.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
CasaOS is currently under active development. Support is limited before CasaOS reaches v1.0.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you see any vulnerabiility, email us at wiki@casaos.io
|
||||
1
UI
1
UI
Submodule UI deleted from bca27426e1
235
api/casaos/openapi.yaml
Normal file
235
api/casaos/openapi.yaml
Normal file
@@ -0,0 +1,235 @@
|
||||
openapi: 3.0.3
|
||||
|
||||
info:
|
||||
title: CasaOS API
|
||||
version: v2
|
||||
description: |
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_dark_night_800px.png">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800px.png">
|
||||
<img alt="CasaOS" src="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800px.png">
|
||||
</picture>
|
||||
|
||||
CasaOS API provides miscellaneous methods for different scenarios.
|
||||
|
||||
For issues and discussions, please visit the [GitHub repository](https://github.com/IceWhaleTech/CasaOS) or join [our Discord](https://discord.gg/knqAbbBbeX).
|
||||
|
||||
servers:
|
||||
- url: /v2/casaos
|
||||
|
||||
tags:
|
||||
- name: Health methods
|
||||
description: |-
|
||||
(TODO)
|
||||
- name: File methods
|
||||
description: |-
|
||||
(TODO)
|
||||
|
||||
x-tagGroups:
|
||||
- name: Methods
|
||||
tags:
|
||||
- Health methods
|
||||
|
||||
security:
|
||||
- access_token: []
|
||||
|
||||
paths:
|
||||
/health/services:
|
||||
get:
|
||||
tags:
|
||||
- Health methods
|
||||
summary: Get service status
|
||||
description: |-
|
||||
Get running status of each `casaos-*` service.
|
||||
operationId: getHealthServices
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/GetHealthServicesOK"
|
||||
"500":
|
||||
$ref: "#/components/responses/ResponseInternalServerError"
|
||||
|
||||
/health/ports:
|
||||
get:
|
||||
tags:
|
||||
- Health methods
|
||||
summary: Get port in use
|
||||
operationId: getHealthPorts
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/GetHealthPortsOK"
|
||||
"500":
|
||||
$ref: "#/components/responses/ResponseInternalServerError"
|
||||
/health/logs:
|
||||
get:
|
||||
tags:
|
||||
- Health methods
|
||||
summary: Get log
|
||||
operationId: getHealthlogs
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/octet-stream:
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
"500":
|
||||
$ref: "#/components/responses/ResponseInternalServerError"
|
||||
|
||||
/file/test:
|
||||
get:
|
||||
tags:
|
||||
- File methods
|
||||
summary: Test file methods
|
||||
description: |-
|
||||
Test file methods.
|
||||
operationId: getFileTest
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/ResponseOK"
|
||||
"500":
|
||||
$ref: "#/components/responses/ResponseInternalServerError"
|
||||
/zt/info:
|
||||
get:
|
||||
tags:
|
||||
- Zerotier methods
|
||||
summary: Get Zerotier info
|
||||
description: |-
|
||||
Get Zerotier info.
|
||||
operationId: getZerotierInfo
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/GetZTInfoOK"
|
||||
"500":
|
||||
$ref: "#/components/responses/ResponseInternalServerError"
|
||||
/zt/{network_id}/status:
|
||||
put:
|
||||
tags:
|
||||
- Zerotier methods
|
||||
summary: Set Zerotier network status
|
||||
description: |-
|
||||
Set Zerotier network status.
|
||||
operationId: setZerotierNetworkStatus
|
||||
parameters:
|
||||
- name: network_id
|
||||
in: path
|
||||
description: network id
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
enum:
|
||||
- online
|
||||
- offline
|
||||
type: string
|
||||
example: "online"
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/GetZTInfoOK"
|
||||
"500":
|
||||
$ref: "#/components/responses/ResponseInternalServerError"
|
||||
|
||||
components:
|
||||
securitySchemes:
|
||||
access_token:
|
||||
type: apiKey
|
||||
in: header
|
||||
name: Authorization
|
||||
|
||||
responses:
|
||||
ResponseOK:
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BaseResponse"
|
||||
|
||||
ResponseInternalServerError:
|
||||
description: Internal Server Error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BaseResponse"
|
||||
|
||||
GetHealthServicesOK:
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/BaseResponse"
|
||||
- properties:
|
||||
data:
|
||||
$ref: "#/components/schemas/HealthServices"
|
||||
|
||||
GetHealthPortsOK:
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/BaseResponse"
|
||||
- properties:
|
||||
data:
|
||||
$ref: "#/components/schemas/HealthPorts"
|
||||
GetZTInfoOK:
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ZTInfo"
|
||||
|
||||
|
||||
schemas:
|
||||
BaseResponse:
|
||||
properties:
|
||||
message:
|
||||
readOnly: true
|
||||
description: message returned by server side if there is any
|
||||
type: string
|
||||
example: ""
|
||||
|
||||
HealthServices:
|
||||
properties:
|
||||
running:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
example: "casaos-gateway.service"
|
||||
not_running:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
example: "casaos.service"
|
||||
|
||||
HealthPorts:
|
||||
properties:
|
||||
tcp:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
example: 80
|
||||
x-go-name: TCP
|
||||
udp:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
example: 53
|
||||
x-go-name: UDP
|
||||
ZTInfo:
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
example: "1234567890"
|
||||
name:
|
||||
type: string
|
||||
example: "CasaOS"
|
||||
status:
|
||||
type: string
|
||||
example: "online"
|
||||
24
api/index.html
Normal file
24
api/index.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>CasaOS | Developers</title>
|
||||
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<redoc spec-url='casaos/openapi.yaml' expandResponses='all' jsonSampleExpandLevel='all'></redoc>
|
||||
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
194
build/scripts/migration/script.d/03-migrate-casaos.sh
Normal file
194
build/scripts/migration/script.d/03-migrate-casaos.sh
Normal file
@@ -0,0 +1,194 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# functions
|
||||
__info() {
|
||||
echo -e "🟩 ${1}"
|
||||
}
|
||||
|
||||
__info_done() {
|
||||
echo -e "✅ ${1}"
|
||||
}
|
||||
|
||||
__warning() {
|
||||
echo -e "🟨 ${1}"
|
||||
}
|
||||
|
||||
__error() {
|
||||
echo "🟥 ${1}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
__is_version_gt() {
|
||||
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"
|
||||
}
|
||||
__normalize_version() {
|
||||
local version
|
||||
if [ "${1::1}" = "v" ]; then
|
||||
version="${1:1}"
|
||||
else
|
||||
version="${1}"
|
||||
fi
|
||||
|
||||
echo "$version"
|
||||
}
|
||||
|
||||
__is_migration_needed() {
|
||||
local version1
|
||||
local version2
|
||||
|
||||
version1=$(__normalize_version "${1}")
|
||||
version2=$(__normalize_version "${2}")
|
||||
|
||||
if [ "${version1}" = "${version2}" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "CURRENT_VERSION_NOT_FOUND" = "${version1}" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "LEGACY_WITHOUT_VERSION" = "${version1}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
__is_version_gt "${version2}" "${version1}"
|
||||
}
|
||||
|
||||
__get_download_domain(){
|
||||
local region
|
||||
# Use ipconfig.io/country and https://ifconfig.io/country_code to get the country code
|
||||
region=$(curl --connect-timeout 2 -s ipconfig.io/country || echo "")
|
||||
if [ "${region}" = "" ]; then
|
||||
region=$(curl --connect-timeout 2 -s https://ifconfig.io/country_code || echo "")
|
||||
fi
|
||||
if [[ "${region}" = "China" ]] || [[ "${region}" = "CN" ]]; then
|
||||
echo "https://casaos.oss-cn-shanghai.aliyuncs.com/"
|
||||
else
|
||||
echo "https://github.com/"
|
||||
fi
|
||||
}
|
||||
|
||||
DOWNLOAD_DOMAIN=$(__get_download_domain)
|
||||
|
||||
BUILD_PATH=$(dirname "${BASH_SOURCE[0]}")/../../..
|
||||
SOURCE_ROOT=${BUILD_PATH}/sysroot
|
||||
|
||||
APP_NAME="casaos"
|
||||
|
||||
# check if migration is needed
|
||||
SOURCE_BIN_PATH=${SOURCE_ROOT}/usr/bin
|
||||
SOURCE_BIN_FILE=${SOURCE_BIN_PATH}/${APP_NAME}
|
||||
|
||||
CURRENT_BIN_PATH=/usr/bin
|
||||
CURRENT_BIN_PATH_LEGACY=/usr/local/bin
|
||||
CURRENT_BIN_FILE=${CURRENT_BIN_PATH}/${APP_NAME}
|
||||
CURRENT_BIN_FILE_LEGACY=$(realpath -e ${CURRENT_BIN_PATH_LEGACY}/${APP_NAME} || which ${APP_NAME} || echo CURRENT_BIN_FILE_LEGACY_NOT_FOUND)
|
||||
|
||||
SOURCE_VERSION="$(${SOURCE_BIN_FILE} -v)"
|
||||
CURRENT_VERSION="$(${CURRENT_BIN_FILE} -v || ${CURRENT_BIN_FILE_LEGACY} -v || (stat "${CURRENT_BIN_FILE_LEGACY}" >/dev/null && echo LEGACY_WITHOUT_VERSION) || echo CURRENT_VERSION_NOT_FOUND)"
|
||||
|
||||
__info_done "CURRENT_VERSION: ${CURRENT_VERSION}"
|
||||
__info_done "SOURCE_VERSION: ${SOURCE_VERSION}"
|
||||
|
||||
NEED_MIGRATION=$(__is_migration_needed "${CURRENT_VERSION}" "${SOURCE_VERSION}" && echo "true" || echo "false")
|
||||
|
||||
if [ "${NEED_MIGRATION}" = "false" ]; then
|
||||
__info_done "Migration is not needed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ARCH="unknown"
|
||||
|
||||
case $(uname -m) in
|
||||
x86_64)
|
||||
ARCH="amd64"
|
||||
;;
|
||||
aarch64)
|
||||
ARCH="arm64"
|
||||
;;
|
||||
armv7l)
|
||||
ARCH="arm-7"
|
||||
;;
|
||||
*)
|
||||
__error "Unsupported architecture"
|
||||
;;
|
||||
esac
|
||||
|
||||
__info "ARCH: ${ARCH}"
|
||||
|
||||
MIGRATION_SERVICE_DIR=${1}
|
||||
|
||||
if [ -z "${MIGRATION_SERVICE_DIR}" ]; then
|
||||
MIGRATION_SERVICE_DIR=${BUILD_PATH}/scripts/migration/service.d/${APP_NAME}
|
||||
fi
|
||||
MIGRATION_LIST_FILE=${MIGRATION_SERVICE_DIR}/migration.list
|
||||
MIGRATION_PATH=()
|
||||
|
||||
CURRENT_VERSION_FOUND="false"
|
||||
|
||||
# a VERSION_PAIR looks like "v0.3.5 <url>"
|
||||
#
|
||||
# - "v0.3.5" is the current version installed on this host
|
||||
# - "<url>" is the url of the migration tool
|
||||
while read -r VERSION_PAIR; do
|
||||
if [ -z "${VERSION_PAIR}" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# obtain "v0.3.5" from "v0.3.5 v0.3.6-alpha2"
|
||||
VER1=$(echo "${VERSION_PAIR}" | cut -d' ' -f1)
|
||||
|
||||
# obtain "<url>" from "v0.3.5 <url>"
|
||||
URL=$(eval echo "${VERSION_PAIR}" | cut -d' ' -f2)
|
||||
|
||||
if [ "${CURRENT_VERSION}" = "${VER1// /}" ] || [ "${CURRENT_VERSION}" = "LEGACY_WITHOUT_VERSION" ]; then
|
||||
CURRENT_VERSION_FOUND="true"
|
||||
fi
|
||||
|
||||
if [ "${CURRENT_VERSION_FOUND}" = "true" ]; then
|
||||
MIGRATION_PATH+=("${URL// /}")
|
||||
fi
|
||||
done <"${MIGRATION_LIST_FILE}"
|
||||
|
||||
if [ ${#MIGRATION_PATH[@]} -eq 0 ]; then
|
||||
__warning "No migration path found from ${CURRENT_VERSION} to ${SOURCE_VERSION}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
pushd "${MIGRATION_SERVICE_DIR}"
|
||||
|
||||
{
|
||||
for URL in "${MIGRATION_PATH[@]}"; do
|
||||
MIGRATION_TOOL_FILE=$(basename "${URL}")
|
||||
|
||||
if [ -f "${MIGRATION_TOOL_FILE}" ]; then
|
||||
__info "Migration tool ${MIGRATION_TOOL_FILE} exists. Skip downloading."
|
||||
continue
|
||||
fi
|
||||
|
||||
__info "Dowloading ${URL}..."
|
||||
curl -fsSL -o "${MIGRATION_TOOL_FILE}" -O "${URL}"
|
||||
done
|
||||
} || {
|
||||
popd
|
||||
__error "Failed to download migration tools"
|
||||
}
|
||||
|
||||
{
|
||||
for URL in "${MIGRATION_PATH[@]}"; do
|
||||
MIGRATION_TOOL_FILE=$(basename "${URL}")
|
||||
__info "Extracting ${MIGRATION_TOOL_FILE}..."
|
||||
tar zxvf "${MIGRATION_TOOL_FILE}" || __error "Failed to extract ${MIGRATION_TOOL_FILE}"
|
||||
|
||||
MIGRATION_TOOL_PATH=build/sysroot/usr/bin/${APP_NAME}-migration-tool
|
||||
__info "Running ${MIGRATION_TOOL_PATH}..."
|
||||
${MIGRATION_TOOL_PATH}
|
||||
done
|
||||
} || {
|
||||
popd
|
||||
__error "Failed to extract and run migration tools"
|
||||
}
|
||||
|
||||
popd
|
||||
3
build/scripts/migration/service.d/casaos/migration.list
Normal file
3
build/scripts/migration/service.d/casaos/migration.list
Normal file
@@ -0,0 +1,3 @@
|
||||
LEGACY_WITHOUT_VERSION ${DOWNLOAD_DOMAIN}IceWhaleTech/CasaOS/releases/download/v0.3.6/linux-${ARCH}-casaos-migration-tool-v0.3.6.tar.gz
|
||||
v0.3.5 ${DOWNLOAD_DOMAIN}IceWhaleTech/CasaOS/releases/download/v0.3.6/linux-${ARCH}-casaos-migration-tool-v0.3.6.tar.gz
|
||||
v0.3.5.1 ${DOWNLOAD_DOMAIN}IceWhaleTech/CasaOS/releases/download/v0.3.6/linux-${ARCH}-casaos-migration-tool-v0.3.6.tar.gz
|
||||
56
build/scripts/setup/script.d/03-setup-casaos.sh
Executable file
56
build/scripts/setup/script.d/03-setup-casaos.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
BUILD_PATH=$(dirname "${BASH_SOURCE[0]}")/../../..
|
||||
|
||||
APP_NAME_SHORT=casaos
|
||||
|
||||
__get_setup_script_directory_by_os_release() {
|
||||
pushd "$(dirname "${BASH_SOURCE[0]}")/../service.d/${APP_NAME_SHORT}" >/dev/null
|
||||
|
||||
{
|
||||
# shellcheck source=/dev/null
|
||||
{
|
||||
source /etc/os-release
|
||||
{
|
||||
pushd "${ID}"/"${VERSION_CODENAME}" >/dev/null
|
||||
} || {
|
||||
pushd "${ID}" >/dev/null
|
||||
} || {
|
||||
[[ -n ${ID_LIKE} ]] && for ID in ${ID_LIKE}; do
|
||||
pushd "${ID}" >/dev/null && break
|
||||
done
|
||||
} || {
|
||||
echo "Unsupported OS: ${ID} ${VERSION_CODENAME} (${ID_LIKE})"
|
||||
exit 1
|
||||
}
|
||||
|
||||
pwd
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
} || {
|
||||
echo "Unsupported OS: unknown"
|
||||
exit 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
SETUP_SCRIPT_DIRECTORY=$(__get_setup_script_directory_by_os_release)
|
||||
SETUP_SCRIPT_FILENAME="setup-${APP_NAME_SHORT}.sh"
|
||||
|
||||
SETUP_SCRIPT_FILEPATH="${SETUP_SCRIPT_DIRECTORY}/${SETUP_SCRIPT_FILENAME}"
|
||||
|
||||
{
|
||||
echo "🟩 Running ${SETUP_SCRIPT_FILENAME}..."
|
||||
$BASH "${SETUP_SCRIPT_FILEPATH}" "${BUILD_PATH}"
|
||||
} || {
|
||||
echo "🟥 ${SETUP_SCRIPT_FILENAME} failed."
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "✅ ${SETUP_SCRIPT_FILENAME} finished."
|
||||
40
build/scripts/setup/service.d/casaos/arch/setup-casaos.sh
Normal file
40
build/scripts/setup/service.d/casaos/arch/setup-casaos.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
###
|
||||
# @Author: LinkLeong link@icewhale.org
|
||||
# @Date: 2022-08-25 11:41:22
|
||||
# @LastEditors: LinkLeong
|
||||
# @LastEditTime: 2022-08-31 17:54:17
|
||||
# @FilePath: /CasaOS/build/scripts/setup/service.d/casaos/debian/setup-casaos.sh
|
||||
# @Description:
|
||||
|
||||
# @Website: https://www.casaos.io
|
||||
# Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
###
|
||||
|
||||
set -e
|
||||
|
||||
APP_NAME="casaos"
|
||||
|
||||
# copy config files
|
||||
CONF_PATH=/etc/casaos
|
||||
OLD_CONF_PATH=/etc/casaos.conf
|
||||
CONF_FILE=${CONF_PATH}/${APP_NAME}.conf
|
||||
CONF_FILE_SAMPLE=${CONF_PATH}/${APP_NAME}.conf.sample
|
||||
|
||||
|
||||
if [ -f "${OLD_CONF_PATH}" ]; then
|
||||
echo "copy old conf"
|
||||
cp "${OLD_CONF_PATH}" "${CONF_FILE}"
|
||||
fi
|
||||
if [ ! -f "${CONF_FILE}" ]; then
|
||||
echo "Initializing config file..."
|
||||
cp -v "${CONF_FILE_SAMPLE}" "${CONF_FILE}"
|
||||
fi
|
||||
|
||||
rm -rf /etc/systemd/system/casaos.service # remove old service file
|
||||
|
||||
systemctl daemon-reload
|
||||
|
||||
# enable service (without starting)
|
||||
echo "Enabling service..."
|
||||
systemctl enable --force --no-ask-password "${APP_NAME}.service"
|
||||
@@ -0,0 +1 @@
|
||||
../setup-casaos.sh
|
||||
40
build/scripts/setup/service.d/casaos/debian/setup-casaos.sh
Normal file
40
build/scripts/setup/service.d/casaos/debian/setup-casaos.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
###
|
||||
# @Author: LinkLeong link@icewhale.org
|
||||
# @Date: 2022-08-25 11:41:22
|
||||
# @LastEditors: LinkLeong
|
||||
# @LastEditTime: 2022-08-31 17:54:17
|
||||
# @FilePath: /CasaOS/build/scripts/setup/service.d/casaos/debian/setup-casaos.sh
|
||||
# @Description:
|
||||
|
||||
# @Website: https://www.casaos.io
|
||||
# Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
###
|
||||
|
||||
set -e
|
||||
|
||||
APP_NAME="casaos"
|
||||
|
||||
# copy config files
|
||||
CONF_PATH=/etc/casaos
|
||||
OLD_CONF_PATH=/etc/casaos.conf
|
||||
CONF_FILE=${CONF_PATH}/${APP_NAME}.conf
|
||||
CONF_FILE_SAMPLE=${CONF_PATH}/${APP_NAME}.conf.sample
|
||||
|
||||
|
||||
if [ -f "${OLD_CONF_PATH}" ]; then
|
||||
echo "copy old conf"
|
||||
cp "${OLD_CONF_PATH}" "${CONF_FILE}"
|
||||
fi
|
||||
if [ ! -f "${CONF_FILE}" ]; then
|
||||
echo "Initializing config file..."
|
||||
cp -v "${CONF_FILE_SAMPLE}" "${CONF_FILE}"
|
||||
fi
|
||||
|
||||
rm -rf /etc/systemd/system/casaos.service # remove old service file
|
||||
|
||||
systemctl daemon-reload
|
||||
|
||||
# enable service (without starting)
|
||||
echo "Enabling service..."
|
||||
systemctl enable --force --no-ask-password "${APP_NAME}.service"
|
||||
@@ -0,0 +1 @@
|
||||
../setup-casaos.sh
|
||||
1
build/scripts/setup/service.d/casaos/ubuntu/setup-casaos.sh
Symbolic link
1
build/scripts/setup/service.d/casaos/ubuntu/setup-casaos.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
../debian/setup-casaos.sh
|
||||
22
build/sysroot/etc/casaos/casaos.conf.sample
Normal file
22
build/sysroot/etc/casaos/casaos.conf.sample
Normal file
@@ -0,0 +1,22 @@
|
||||
[app]
|
||||
PAGE_SIZE = 10
|
||||
RuntimeRootPath = runtime/
|
||||
LogPath = /var/log/casaos/
|
||||
LogSaveName = log
|
||||
LogFileExt = log
|
||||
DateStrFormat = 20060102
|
||||
DateTimeFormat = 2006-01-02 15:04:05
|
||||
TimeFormat = 15:04:05
|
||||
DateFormat = 2006-01-02
|
||||
DBPath = /var/lib/casaos
|
||||
ShellPath = /usr/share/casaos/shell
|
||||
UserDataPath = /var/lib/casaos/conf
|
||||
|
||||
[server]
|
||||
RunMode = release
|
||||
ServerApi = https://api.casaos.io/casaos-api
|
||||
Handshake = socket.casaos.io
|
||||
Token =
|
||||
USBAutoMount =
|
||||
|
||||
[system]
|
||||
13
build/sysroot/usr/lib/systemd/system/casaos.service
Normal file
13
build/sysroot/usr/lib/systemd/system/casaos.service
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
After=casaos-message-bus.service
|
||||
After=rclone.service
|
||||
Description=CasaOS Main Service
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/casaos -c /etc/casaos/casaos.conf
|
||||
PIDFile=/var/run/casaos/casaos.pid
|
||||
Restart=always
|
||||
Type=notify
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
12
build/sysroot/usr/lib/systemd/system/rclone.service
Normal file
12
build/sysroot/usr/lib/systemd/system/rclone.service
Normal file
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=rclone
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/usr/bin/mkdir -p /var/run/rclone
|
||||
ExecStartPre=/usr/bin/rm -f /var/run/rclone/rclone.sock
|
||||
ExecStart=/usr/bin/rclone rcd --rc-addr unix:///var/run/rclone/rclone.sock --rc-no-auth --rc-allow-origin "*"
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
###
|
||||
# @Author: LinkLeong link@icewhale.org
|
||||
# @Date: 2022-11-15 15:51:44
|
||||
# @LastEditors: LinkLeong
|
||||
# @LastEditTime: 2022-11-15 15:53:37
|
||||
# @FilePath: /CasaOS/build/sysroot/usr/share/casaos/cleanup/script.d/03-cleanup-casaos.sh
|
||||
# @Description:
|
||||
# @Website: https://www.casaos.io
|
||||
# Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
###
|
||||
|
||||
set -e
|
||||
|
||||
readonly APP_NAME_SHORT=casaos
|
||||
|
||||
__get_setup_script_directory_by_os_release() {
|
||||
pushd "$(dirname "${BASH_SOURCE[0]}")/../service.d/${APP_NAME_SHORT}" &>/dev/null
|
||||
|
||||
{
|
||||
# shellcheck source=/dev/null
|
||||
{
|
||||
source /etc/os-release
|
||||
{
|
||||
pushd "${ID}"/"${VERSION_CODENAME}" &>/dev/null
|
||||
} || {
|
||||
pushd "${ID}" &>/dev/null
|
||||
} || {
|
||||
[[ -n ${ID_LIKE} ]] && for ID in ${ID_LIKE}; do
|
||||
pushd "${ID}" >/dev/null && break
|
||||
done
|
||||
} || {
|
||||
echo "Unsupported OS: ${ID} ${VERSION_CODENAME} (${ID_LIKE})"
|
||||
exit 1
|
||||
}
|
||||
|
||||
pwd
|
||||
|
||||
popd &>/dev/null
|
||||
|
||||
} || {
|
||||
echo "Unsupported OS: unknown"
|
||||
exit 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
popd &>/dev/null
|
||||
}
|
||||
|
||||
SETUP_SCRIPT_DIRECTORY=$(__get_setup_script_directory_by_os_release)
|
||||
|
||||
readonly SETUP_SCRIPT_DIRECTORY
|
||||
readonly SETUP_SCRIPT_FILENAME="cleanup-${APP_NAME_SHORT}.sh"
|
||||
readonly SETUP_SCRIPT_FILEPATH="${SETUP_SCRIPT_DIRECTORY}/${SETUP_SCRIPT_FILENAME}"
|
||||
|
||||
echo "🟩 Running ${SETUP_SCRIPT_FILENAME}..."
|
||||
$SHELL "${SETUP_SCRIPT_FILEPATH}" "${BUILD_PATH}"
|
||||
@@ -0,0 +1,204 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
readonly CASA_SERVICES=(
|
||||
"casaos.service"
|
||||
"devmon@devmon.service"
|
||||
)
|
||||
|
||||
readonly CASA_EXEC=casaos
|
||||
readonly CASA_CONF=/etc/casaos/casaos.conf
|
||||
readonly CASA_URL=/var/run/casaos/casaos.url
|
||||
readonly CASA_SERVICE_USR=/usr/lib/systemd/system/casaos.service
|
||||
readonly CASA_SERVICE_LIB=/lib/systemd/system/casaos.service
|
||||
readonly CASA_SERVICE_ETC=/etc/systemd/system/casaos.service
|
||||
|
||||
# Old Casa Files
|
||||
readonly CASA_PATH=/casaOS
|
||||
readonly CASA_CONF_PATH_OLD=/etc/casaos.conf
|
||||
|
||||
readonly aCOLOUR=(
|
||||
'\e[38;5;154m' # green | Lines, bullets and separators
|
||||
'\e[1m' # Bold white | Main descriptions
|
||||
'\e[90m' # Grey | Credits
|
||||
'\e[91m' # Red | Update notifications Alert
|
||||
'\e[33m' # Yellow | Emphasis
|
||||
)
|
||||
|
||||
Show() {
|
||||
# OK
|
||||
if (($1 == 0)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} OK $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
# FAILED
|
||||
elif (($1 == 1)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]}FAILED$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
# INFO
|
||||
elif (($1 == 2)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} INFO $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
# NOTICE
|
||||
elif (($1 == 3)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]}NOTICE$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
fi
|
||||
}
|
||||
|
||||
Warn() {
|
||||
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET"
|
||||
}
|
||||
|
||||
trap 'onCtrlC' INT
|
||||
onCtrlC() {
|
||||
echo -e "${COLOUR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Detecting_CasaOS() {
|
||||
if [[ ! -x "$(command -v ${CASA_EXEC})" ]]; then
|
||||
Show 2 "CasaOS is not detected, exit the script."
|
||||
exit 1
|
||||
else
|
||||
Show 0 "This script will delete the containers you no longer use, and the CasaOS configuration files."
|
||||
fi
|
||||
}
|
||||
|
||||
Uninstall_Container() {
|
||||
if [[ ${UNINSTALL_ALL_CONTAINER} == true && "$(docker ps -aq)" != "" ]]; then
|
||||
Show 2 "Start deleting containers."
|
||||
docker stop "$(docker ps -aq)" || Show 1 "Failed to stop all containers."
|
||||
docker rm "$(docker ps -aq)" || Show 1 "Failed to delete all containers."
|
||||
fi
|
||||
}
|
||||
|
||||
Remove_Images() {
|
||||
if [[ ${REMOVE_IMAGES} == "all" && "$(docker images -q)" != "" ]]; then
|
||||
Show 2 "Start deleting all images."
|
||||
docker rmi "$(docker images -q)" || Show 1 "Failed to delete all images."
|
||||
elif [[ ${REMOVE_IMAGES} == "unuse" && "$(docker images -q)" != "" ]]; then
|
||||
Show 2 "Start deleting unuse images."
|
||||
docker image prune -af || Show 1 "Failed to delete unuse images."
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Uninstall_Casaos() {
|
||||
|
||||
for SERVICE in "${CASA_SERVICES[@]}"; do
|
||||
Show 2 "Stopping ${SERVICE}..."
|
||||
systemctl disable --now "${SERVICE}" || Show 3 "Failed to disable ${SERVICE}"
|
||||
done
|
||||
|
||||
# Remove Service file
|
||||
if [[ -f ${CASA_SERVICE_USR} ]]; then
|
||||
rm -rvf ${CASA_SERVICE_USR}
|
||||
fi
|
||||
|
||||
if [[ -f ${CASA_SERVICE_LIB} ]]; then
|
||||
rm -rvf ${CASA_SERVICE_LIB}
|
||||
fi
|
||||
|
||||
if [[ -f ${CASA_SERVICE_ETC} ]]; then
|
||||
rm -rvf ${CASA_SERVICE_ETC}
|
||||
fi
|
||||
|
||||
# Old Casa Files
|
||||
if [[ -d ${CASA_PATH} ]]; then
|
||||
rm -rvf ${CASA_PATH} || Show 1 "Failed to delete legacy CasaOS files."
|
||||
fi
|
||||
|
||||
if [[ -f ${CASA_CONF_PATH_OLD} ]]; then
|
||||
rm -rvf ${CASA_CONF_PATH_OLD}
|
||||
fi
|
||||
|
||||
# New Casa Files
|
||||
if [[ ${REMOVE_APP_DATA} = true ]]; then
|
||||
rm -rvf /DATA/AppData || Show 1 "Failed to delete AppData."
|
||||
fi
|
||||
|
||||
rm -rvf "$(which ${CASA_EXEC})" || Show 3 "Failed to remove ${CASA_EXEC}"
|
||||
rm -rvf ${CASA_CONF} || Show 3 "Failed to remove ${CASA_CONF}"
|
||||
rm -rvf ${CASA_URL} || Show 3 "Failed to remove ${CASA_URL}"
|
||||
|
||||
rm -rvf /var/lib/casaos/app_category.json
|
||||
rm -rvf /var/lib/casaos/app_list.json
|
||||
rm -rvf /var/lib/casaos/docker_root
|
||||
}
|
||||
|
||||
Detecting_CasaOS
|
||||
|
||||
while true; do
|
||||
echo -n -e " ${aCOLOUR[4]}Do you want delete all containers? Y/n :${COLOUR_RESET}"
|
||||
read -r input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
UNINSTALL_ALL_CONTAINER=true
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
UNINSTALL_ALL_CONTAINER=false
|
||||
break
|
||||
;;
|
||||
*)
|
||||
Warn " Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ${UNINSTALL_ALL_CONTAINER} == true ]]; then
|
||||
while true; do
|
||||
echo -n -e " ${aCOLOUR[4]}Do you want delete all images? Y/n :${COLOUR_RESET}"
|
||||
read -r input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
REMOVE_IMAGES="all"
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
REMOVE_IMAGES="none"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
Warn " Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
while true; do
|
||||
echo -n -e " ${aCOLOUR[4]}Do you want delete all AppData of CasaOS? Y/n :${COLOUR_RESET}"
|
||||
read -r input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
REMOVE_APP_DATA=true
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
REMOVE_APP_DATA=false
|
||||
break
|
||||
;;
|
||||
*)
|
||||
Warn " Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
while true; do
|
||||
echo -n -e " ${aCOLOUR[4]}Do you want to delete all images that are not used by the container? Y/n :${COLOUR_RESET}"
|
||||
read -r input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
REMOVE_IMAGES="unuse"
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
REMOVE_IMAGES="none"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
Warn " Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
Uninstall_Container
|
||||
Remove_Images
|
||||
Uninstall_Casaos
|
||||
@@ -0,0 +1 @@
|
||||
../cleanup-casaos.sh
|
||||
@@ -0,0 +1,204 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
readonly CASA_SERVICES=(
|
||||
"casaos.service"
|
||||
"devmon@devmon.service"
|
||||
)
|
||||
|
||||
readonly CASA_EXEC=casaos
|
||||
readonly CASA_CONF=/etc/casaos/casaos.conf
|
||||
readonly CASA_URL=/var/run/casaos/casaos.url
|
||||
readonly CASA_SERVICE_USR=/usr/lib/systemd/system/casaos.service
|
||||
readonly CASA_SERVICE_LIB=/lib/systemd/system/casaos.service
|
||||
readonly CASA_SERVICE_ETC=/etc/systemd/system/casaos.service
|
||||
|
||||
# Old Casa Files
|
||||
readonly CASA_PATH=/casaOS
|
||||
readonly CASA_CONF_PATH_OLD=/etc/casaos.conf
|
||||
|
||||
readonly aCOLOUR=(
|
||||
'\e[38;5;154m' # green | Lines, bullets and separators
|
||||
'\e[1m' # Bold white | Main descriptions
|
||||
'\e[90m' # Grey | Credits
|
||||
'\e[91m' # Red | Update notifications Alert
|
||||
'\e[33m' # Yellow | Emphasis
|
||||
)
|
||||
|
||||
Show() {
|
||||
# OK
|
||||
if (($1 == 0)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} OK $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
# FAILED
|
||||
elif (($1 == 1)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]}FAILED$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
# INFO
|
||||
elif (($1 == 2)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} INFO $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
# NOTICE
|
||||
elif (($1 == 3)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]}NOTICE$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
fi
|
||||
}
|
||||
|
||||
Warn() {
|
||||
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET"
|
||||
}
|
||||
|
||||
trap 'onCtrlC' INT
|
||||
onCtrlC() {
|
||||
echo -e "${COLOUR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Detecting_CasaOS() {
|
||||
if [[ ! -x "$(command -v ${CASA_EXEC})" ]]; then
|
||||
Show 2 "CasaOS is not detected, exit the script."
|
||||
exit 1
|
||||
else
|
||||
Show 0 "This script will delete the containers you no longer use, and the CasaOS configuration files."
|
||||
fi
|
||||
}
|
||||
|
||||
Uninstall_Container() {
|
||||
if [[ ${UNINSTALL_ALL_CONTAINER} == true && "$(docker ps -aq)" != "" ]]; then
|
||||
Show 2 "Start deleting containers."
|
||||
docker stop "$(docker ps -aq)" || Show 1 "Failed to stop all containers."
|
||||
docker rm "$(docker ps -aq)" || Show 1 "Failed to delete all containers."
|
||||
fi
|
||||
}
|
||||
|
||||
Remove_Images() {
|
||||
if [[ ${REMOVE_IMAGES} == "all" && "$(docker images -q)" != "" ]]; then
|
||||
Show 2 "Start deleting all images."
|
||||
docker rmi "$(docker images -q)" || Show 1 "Failed to delete all images."
|
||||
elif [[ ${REMOVE_IMAGES} == "unuse" && "$(docker images -q)" != "" ]]; then
|
||||
Show 2 "Start deleting unuse images."
|
||||
docker image prune -af || Show 1 "Failed to delete unuse images."
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Uninstall_Casaos() {
|
||||
|
||||
for SERVICE in "${CASA_SERVICES[@]}"; do
|
||||
Show 2 "Stopping ${SERVICE}..."
|
||||
systemctl disable --now "${SERVICE}" || Show 3 "Failed to disable ${SERVICE}"
|
||||
done
|
||||
|
||||
# Remove Service file
|
||||
if [[ -f ${CASA_SERVICE_USR} ]]; then
|
||||
rm -rvf ${CASA_SERVICE_USR}
|
||||
fi
|
||||
|
||||
if [[ -f ${CASA_SERVICE_LIB} ]]; then
|
||||
rm -rvf ${CASA_SERVICE_LIB}
|
||||
fi
|
||||
|
||||
if [[ -f ${CASA_SERVICE_ETC} ]]; then
|
||||
rm -rvf ${CASA_SERVICE_ETC}
|
||||
fi
|
||||
|
||||
# Old Casa Files
|
||||
if [[ -d ${CASA_PATH} ]]; then
|
||||
rm -rvf ${CASA_PATH} || Show 1 "Failed to delete legacy CasaOS files."
|
||||
fi
|
||||
|
||||
if [[ -f ${CASA_CONF_PATH_OLD} ]]; then
|
||||
rm -rvf ${CASA_CONF_PATH_OLD}
|
||||
fi
|
||||
|
||||
# New Casa Files
|
||||
if [[ ${REMOVE_APP_DATA} = true ]]; then
|
||||
rm -rvf /DATA/AppData || Show 1 "Failed to delete AppData."
|
||||
fi
|
||||
|
||||
rm -rvf "$(which ${CASA_EXEC})" || Show 3 "Failed to remove ${CASA_EXEC}"
|
||||
rm -rvf ${CASA_CONF} || Show 3 "Failed to remove ${CASA_CONF}"
|
||||
rm -rvf ${CASA_URL} || Show 3 "Failed to remove ${CASA_URL}"
|
||||
|
||||
rm -rvf /var/lib/casaos/app_category.json
|
||||
rm -rvf /var/lib/casaos/app_list.json
|
||||
rm -rvf /var/lib/casaos/docker_root
|
||||
}
|
||||
|
||||
Detecting_CasaOS
|
||||
|
||||
while true; do
|
||||
echo -n -e " ${aCOLOUR[4]}Do you want delete all containers? Y/n :${COLOUR_RESET}"
|
||||
read -r input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
UNINSTALL_ALL_CONTAINER=true
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
UNINSTALL_ALL_CONTAINER=false
|
||||
break
|
||||
;;
|
||||
*)
|
||||
Warn " Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ${UNINSTALL_ALL_CONTAINER} == true ]]; then
|
||||
while true; do
|
||||
echo -n -e " ${aCOLOUR[4]}Do you want delete all images? Y/n :${COLOUR_RESET}"
|
||||
read -r input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
REMOVE_IMAGES="all"
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
REMOVE_IMAGES="none"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
Warn " Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
while true; do
|
||||
echo -n -e " ${aCOLOUR[4]}Do you want delete all AppData of CasaOS? Y/n :${COLOUR_RESET}"
|
||||
read -r input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
REMOVE_APP_DATA=true
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
REMOVE_APP_DATA=false
|
||||
break
|
||||
;;
|
||||
*)
|
||||
Warn " Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
while true; do
|
||||
echo -n -e " ${aCOLOUR[4]}Do you want to delete all images that are not used by the container? Y/n :${COLOUR_RESET}"
|
||||
read -r input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
REMOVE_IMAGES="unuse"
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
REMOVE_IMAGES="none"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
Warn " Invalid input..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
Uninstall_Container
|
||||
Remove_Images
|
||||
Uninstall_Casaos
|
||||
@@ -0,0 +1 @@
|
||||
../debian/cleanup-casaos.sh
|
||||
@@ -0,0 +1 @@
|
||||
../../debian/bullseye/cleanup-casaos.sh
|
||||
@@ -25,7 +25,7 @@ GetNetCard() {
|
||||
fi
|
||||
else
|
||||
if [ -d "/sys/devices/virtual/net" ] && [ -d "/sys/class/net" ]; then
|
||||
ls /sys/class/net/ | grep -v "$(ls /sys/devices/virtual/net/)"
|
||||
ls /sys/class/net/ | grep -v "$(ls /sys/devices/virtual/net/)" -w
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -66,18 +66,6 @@ GetLocalJoinNetworks() {
|
||||
zerotier-cli listnetworks -j
|
||||
}
|
||||
|
||||
#移除挂载点,删除已挂在的文件夹
|
||||
UMountPorintAndRemoveDir() {
|
||||
DEVICE=$1
|
||||
MOUNT_POINT=$(mount | grep ${DEVICE} | awk '{ print $3 }')
|
||||
if [[ -z ${MOUNT_POINT} ]]; then
|
||||
${log} "Warning: ${DEVICE} is not mounted"
|
||||
else
|
||||
umount -lf ${DEVICE}
|
||||
/bin/rmdir "${MOUNT_POINT}"
|
||||
fi
|
||||
}
|
||||
|
||||
#格式化fat32磁盘
|
||||
#param 需要格式化的目录 /dev/sda1
|
||||
#param 格式
|
||||
@@ -133,11 +121,7 @@ GetPlugInDisk() {
|
||||
fdisk -l | grep 'Disk' | grep 'sd' | awk -F , '{print substr($1,11,3)}'
|
||||
}
|
||||
|
||||
#获取磁盘状态
|
||||
#param 磁盘路径
|
||||
GetDiskHealthState() {
|
||||
smartctl -H $1 | grep "SMART Health Status" | awk -F ":" '{print$2}'
|
||||
}
|
||||
|
||||
|
||||
#获取磁盘字节数量和扇区数量
|
||||
#param 磁盘路径 /dev/sda
|
||||
@@ -370,20 +354,6 @@ MountCIFS(){
|
||||
$sudo_cmd mount -t cifs -o username=$1,password=$6,port=$4 //$2/$3 $5
|
||||
}
|
||||
|
||||
# $1:service name
|
||||
CheckServiceStatus(){
|
||||
rs="`systemctl status $1 |grep -E 'Active|PID'`"
|
||||
#echo "$rs"
|
||||
run="`echo "$rs" |grep -B 2 'running'`"
|
||||
fai="`echo "$rs" |grep -E -B 2 'failed|inactive|dead'`"
|
||||
if [ "$run" == "" ]
|
||||
then
|
||||
echo "failed"
|
||||
else
|
||||
echo "running"
|
||||
fi
|
||||
}
|
||||
UDEVILUmount(){
|
||||
$sudo_cmd udevil umount -f $1
|
||||
}
|
||||
|
||||
12
build/sysroot/usr/share/casaos/shell/update.sh
Normal file
12
build/sysroot/usr/share/casaos/shell/update.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
###
|
||||
# @Author: LinkLeong link@icewhale.com
|
||||
# @Date: 2022-06-30 10:08:33
|
||||
# @LastEditors: LinkLeong
|
||||
# @LastEditTime: 2022-09-01 22:33:06
|
||||
# @FilePath: /CasaOS/build/sysroot/usr/share/casaos/shell/update.sh
|
||||
# @Description:
|
||||
###
|
||||
|
||||
|
||||
curl -fsSL https://raw.githubusercontent.com/IceWhaleTech/get/main/update.sh | bash
|
||||
28
cmd/message-bus-docgen/main.go
Normal file
28
cmd/message-bus-docgen/main.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/IceWhaleTech/CasaOS-Common/external"
|
||||
"github.com/IceWhaleTech/CasaOS/codegen/message_bus"
|
||||
"github.com/IceWhaleTech/CasaOS/common"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
eventTypes := lo.Map(common.EventTypes, func(item message_bus.EventType, index int) external.EventType {
|
||||
return external.EventType{
|
||||
Name: item.Name,
|
||||
SourceID: item.SourceID,
|
||||
PropertyTypeList: lo.Map(
|
||||
item.PropertyTypeList, func(item message_bus.PropertyType, index int) external.PropertyType {
|
||||
return external.PropertyType{
|
||||
Name: item.Name,
|
||||
Description: item.Description,
|
||||
Example: item.Example,
|
||||
}
|
||||
},
|
||||
),
|
||||
}
|
||||
})
|
||||
|
||||
external.PrintEventTypesAsMarkdown(common.SERVICENAME, common.VERSION, eventTypes)
|
||||
}
|
||||
37
cmd/migration-tool/log.go
Normal file
37
cmd/migration-tool/log.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Logger struct {
|
||||
DebugMode bool
|
||||
|
||||
_debug *log.Logger
|
||||
_info *log.Logger
|
||||
_error *log.Logger
|
||||
}
|
||||
|
||||
func NewLogger() *Logger {
|
||||
return &Logger{
|
||||
DebugMode: false,
|
||||
_debug: log.New(os.Stdout, "DEBUG: ", 0),
|
||||
_info: log.New(os.Stdout, "", 0),
|
||||
_error: log.New(os.Stderr, "ERROR: ", 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Logger) Debug(format string, v ...interface{}) {
|
||||
if l.DebugMode {
|
||||
l._debug.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Logger) Info(format string, v ...interface{}) {
|
||||
l._info.Printf(format, v...)
|
||||
}
|
||||
|
||||
func (l *Logger) Error(format string, v ...interface{}) {
|
||||
l._error.Printf(format, v...)
|
||||
}
|
||||
128
cmd/migration-tool/main.go
Normal file
128
cmd/migration-tool/main.go
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.org
|
||||
* @Date: 2022-08-23 18:09:11
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-08-31 14:17:51
|
||||
* @FilePath: /CasaOS/cmd/migration-tool/main.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
interfaces "github.com/IceWhaleTech/CasaOS-Common"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/systemctl"
|
||||
"github.com/IceWhaleTech/CasaOS/common"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const (
|
||||
casaosServiceName = "casaos.service"
|
||||
)
|
||||
|
||||
var (
|
||||
commit = "private build"
|
||||
date = "private build"
|
||||
|
||||
_logger *Logger
|
||||
sqliteDB *gorm.DB
|
||||
|
||||
configFlag = ""
|
||||
dbFlag = ""
|
||||
)
|
||||
|
||||
func init() {
|
||||
versionFlag := flag.Bool("v", false, "version")
|
||||
debugFlag := flag.Bool("d", true, "debug")
|
||||
forceFlag := flag.Bool("f", true, "force")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *versionFlag {
|
||||
fmt.Println("v" + common.VERSION)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
println("git commit:", commit)
|
||||
println("build date:", date)
|
||||
|
||||
_logger = NewLogger()
|
||||
|
||||
if os.Getuid() != 0 {
|
||||
_logger.Info("Root privileges are required to run this program.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *debugFlag {
|
||||
_logger.DebugMode = true
|
||||
}
|
||||
|
||||
if !*forceFlag {
|
||||
serviceEnabled, err := systemctl.IsServiceEnabled(casaosServiceName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if serviceEnabled {
|
||||
_logger.Info("%s is already enabled. If migration is still needed, try with -f.", casaosServiceName)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
config.InitSetup(configFlag, "")
|
||||
|
||||
if len(dbFlag) == 0 {
|
||||
dbFlag = config.AppInfo.DBPath + "/db"
|
||||
}
|
||||
|
||||
sqliteDB = sqlite.GetDb(dbFlag)
|
||||
// gredis.GetRedisConn(config.RedisInfo),
|
||||
|
||||
service.MyService = service.NewService(sqliteDB, "")
|
||||
}
|
||||
|
||||
func main() {
|
||||
migrationTools := []interfaces.MigrationTool{
|
||||
// nothing to migrate from last version
|
||||
}
|
||||
|
||||
var selectedMigrationTool interfaces.MigrationTool
|
||||
|
||||
// look for the right migration tool matching current version
|
||||
for _, tool := range migrationTools {
|
||||
migrationNeeded, err := tool.IsMigrationNeeded()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if migrationNeeded {
|
||||
selectedMigrationTool = tool
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if selectedMigrationTool == nil {
|
||||
_logger.Error("selectedMigrationTool is null")
|
||||
return
|
||||
}
|
||||
|
||||
if err := selectedMigrationTool.PreMigrate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := selectedMigrationTool.Migrate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := selectedMigrationTool.PostMigrate(); err != nil {
|
||||
_logger.Error("Migration succeeded, but post-migration failed: %s", err)
|
||||
}
|
||||
}
|
||||
27
cmd/migration-tool/migration_dummy.go
Normal file
27
cmd/migration-tool/migration_dummy.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
interfaces "github.com/IceWhaleTech/CasaOS-Common"
|
||||
)
|
||||
|
||||
type migrationTool struct{}
|
||||
|
||||
func (u *migrationTool) IsMigrationNeeded() (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (u *migrationTool) PreMigrate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *migrationTool) Migrate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *migrationTool) PostMigrate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewMigrationDummy() interfaces.MigrationTool {
|
||||
return &migrationTool{}
|
||||
}
|
||||
326
codegen/casaos_api.go
Normal file
326
codegen/casaos_api.go
Normal file
@@ -0,0 +1,326 @@
|
||||
// Package codegen provides primitives to interact with the openapi HTTP API.
|
||||
//
|
||||
// Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.
|
||||
package codegen
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/deepmap/oapi-codegen/pkg/runtime"
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
const (
|
||||
Access_tokenScopes = "access_token.Scopes"
|
||||
)
|
||||
|
||||
// Defines values for SetZerotierNetworkStatusJSONBodyStatus.
|
||||
const (
|
||||
Offline SetZerotierNetworkStatusJSONBodyStatus = "offline"
|
||||
Online SetZerotierNetworkStatusJSONBodyStatus = "online"
|
||||
)
|
||||
|
||||
// BaseResponse defines model for BaseResponse.
|
||||
type BaseResponse struct {
|
||||
// Message message returned by server side if there is any
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// HealthPorts defines model for HealthPorts.
|
||||
type HealthPorts struct {
|
||||
TCP *[]int `json:"tcp,omitempty"`
|
||||
UDP *[]int `json:"udp,omitempty"`
|
||||
}
|
||||
|
||||
// HealthServices defines model for HealthServices.
|
||||
type HealthServices struct {
|
||||
NotRunning *[]string `json:"not_running,omitempty"`
|
||||
Running *[]string `json:"running,omitempty"`
|
||||
}
|
||||
|
||||
// ZTInfo defines model for ZTInfo.
|
||||
type ZTInfo struct {
|
||||
Id *string `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Status *string `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// GetHealthPortsOK defines model for GetHealthPortsOK.
|
||||
type GetHealthPortsOK struct {
|
||||
Data *HealthPorts `json:"data,omitempty"`
|
||||
|
||||
// Message message returned by server side if there is any
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// GetHealthServicesOK defines model for GetHealthServicesOK.
|
||||
type GetHealthServicesOK struct {
|
||||
Data *HealthServices `json:"data,omitempty"`
|
||||
|
||||
// Message message returned by server side if there is any
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// GetZTInfoOK defines model for GetZTInfoOK.
|
||||
type GetZTInfoOK = ZTInfo
|
||||
|
||||
// ResponseInternalServerError defines model for ResponseInternalServerError.
|
||||
type ResponseInternalServerError = BaseResponse
|
||||
|
||||
// ResponseOK defines model for ResponseOK.
|
||||
type ResponseOK = BaseResponse
|
||||
|
||||
// SetZerotierNetworkStatusJSONBody defines parameters for SetZerotierNetworkStatus.
|
||||
type SetZerotierNetworkStatusJSONBody struct {
|
||||
Status *SetZerotierNetworkStatusJSONBodyStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// SetZerotierNetworkStatusJSONBodyStatus defines parameters for SetZerotierNetworkStatus.
|
||||
type SetZerotierNetworkStatusJSONBodyStatus string
|
||||
|
||||
// SetZerotierNetworkStatusJSONRequestBody defines body for SetZerotierNetworkStatus for application/json ContentType.
|
||||
type SetZerotierNetworkStatusJSONRequestBody SetZerotierNetworkStatusJSONBody
|
||||
|
||||
// ServerInterface represents all server handlers.
|
||||
type ServerInterface interface {
|
||||
// Test file methods
|
||||
// (GET /file/test)
|
||||
GetFileTest(ctx echo.Context) error
|
||||
// Get log
|
||||
// (GET /health/logs)
|
||||
GetHealthlogs(ctx echo.Context) error
|
||||
// Get port in use
|
||||
// (GET /health/ports)
|
||||
GetHealthPorts(ctx echo.Context) error
|
||||
// Get service status
|
||||
// (GET /health/services)
|
||||
GetHealthServices(ctx echo.Context) error
|
||||
// Get Zerotier info
|
||||
// (GET /zt/info)
|
||||
GetZerotierInfo(ctx echo.Context) error
|
||||
// Set Zerotier network status
|
||||
// (PUT /zt/{network_id}/status)
|
||||
SetZerotierNetworkStatus(ctx echo.Context, networkId string) error
|
||||
}
|
||||
|
||||
// ServerInterfaceWrapper converts echo contexts to parameters.
|
||||
type ServerInterfaceWrapper struct {
|
||||
Handler ServerInterface
|
||||
}
|
||||
|
||||
// GetFileTest converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) GetFileTest(ctx echo.Context) error {
|
||||
var err error
|
||||
|
||||
ctx.Set(Access_tokenScopes, []string{""})
|
||||
|
||||
// Invoke the callback with all the unmarshalled arguments
|
||||
err = w.Handler.GetFileTest(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetHealthlogs converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) GetHealthlogs(ctx echo.Context) error {
|
||||
var err error
|
||||
|
||||
ctx.Set(Access_tokenScopes, []string{""})
|
||||
|
||||
// Invoke the callback with all the unmarshalled arguments
|
||||
err = w.Handler.GetHealthlogs(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetHealthPorts converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) GetHealthPorts(ctx echo.Context) error {
|
||||
var err error
|
||||
|
||||
ctx.Set(Access_tokenScopes, []string{""})
|
||||
|
||||
// Invoke the callback with all the unmarshalled arguments
|
||||
err = w.Handler.GetHealthPorts(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetHealthServices converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) GetHealthServices(ctx echo.Context) error {
|
||||
var err error
|
||||
|
||||
ctx.Set(Access_tokenScopes, []string{""})
|
||||
|
||||
// Invoke the callback with all the unmarshalled arguments
|
||||
err = w.Handler.GetHealthServices(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetZerotierInfo converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) GetZerotierInfo(ctx echo.Context) error {
|
||||
var err error
|
||||
|
||||
ctx.Set(Access_tokenScopes, []string{""})
|
||||
|
||||
// Invoke the callback with all the unmarshalled arguments
|
||||
err = w.Handler.GetZerotierInfo(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetZerotierNetworkStatus converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) SetZerotierNetworkStatus(ctx echo.Context) error {
|
||||
var err error
|
||||
// ------------- Path parameter "network_id" -------------
|
||||
var networkId string
|
||||
|
||||
err = runtime.BindStyledParameterWithLocation("simple", false, "network_id", runtime.ParamLocationPath, ctx.Param("network_id"), &networkId)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter network_id: %s", err))
|
||||
}
|
||||
|
||||
ctx.Set(Access_tokenScopes, []string{""})
|
||||
|
||||
// Invoke the callback with all the unmarshalled arguments
|
||||
err = w.Handler.SetZerotierNetworkStatus(ctx, networkId)
|
||||
return err
|
||||
}
|
||||
|
||||
// This is a simple interface which specifies echo.Route addition functions which
|
||||
// are present on both echo.Echo and echo.Group, since we want to allow using
|
||||
// either of them for path registration
|
||||
type EchoRouter interface {
|
||||
CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
||||
}
|
||||
|
||||
// RegisterHandlers adds each server route to the EchoRouter.
|
||||
func RegisterHandlers(router EchoRouter, si ServerInterface) {
|
||||
RegisterHandlersWithBaseURL(router, si, "")
|
||||
}
|
||||
|
||||
// Registers handlers, and prepends BaseURL to the paths, so that the paths
|
||||
// can be served under a prefix.
|
||||
func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
|
||||
|
||||
wrapper := ServerInterfaceWrapper{
|
||||
Handler: si,
|
||||
}
|
||||
|
||||
router.GET(baseURL+"/file/test", wrapper.GetFileTest)
|
||||
router.GET(baseURL+"/health/logs", wrapper.GetHealthlogs)
|
||||
router.GET(baseURL+"/health/ports", wrapper.GetHealthPorts)
|
||||
router.GET(baseURL+"/health/services", wrapper.GetHealthServices)
|
||||
router.GET(baseURL+"/zt/info", wrapper.GetZerotierInfo)
|
||||
router.PUT(baseURL+"/zt/:network_id/status", wrapper.SetZerotierNetworkStatus)
|
||||
|
||||
}
|
||||
|
||||
// Base64 encoded, gzipped, json marshaled Swagger object
|
||||
var swaggerSpec = []string{
|
||||
|
||||
"H4sIAAAAAAAC/8xX72/bNhD9VwhuH5pBsbxk3ToB/dAfaxoUW4Ilw4bGhktLZ4mNRKp3pyRuoP99oCjb",
|
||||
"sq386pqhn2xRp7v3Hnnk47WMbVFaA4ZJRtcSgUprCJqHA+C3oHLOji0yHb1zY7E1DIbdX1WWuY4Va2vC",
|
||||
"j2SNG6M4g0I1b/P8aCajs2v5PcJMRvK7cFUq9HEUvlQEf7Y1ZR1cyxJtCcjaI0gUN8luS9GBKOu6Htd1",
|
||||
"HcgEKEZdOmwykkfvZB2s6JwAXugYvnFGC5R3knp/emhm9oFkbqvvE8obay7oHRoGNCp3SAF/Q7T41TCs",
|
||||
"y7iNZFFb+OLCV++A+4p63IXFqVIHbbJmlte+iDbXQAFEKm1erCdqXwgErtBAIqZzQZ4f6QSEngnOAEFo",
|
||||
"EsrMZSDhShVlDjKSMpAIKjky+VxGjBUEkuele0OM2qQeeLdZtnBxXLofzVA0z8vkz4bLZNowpNAo3Y4o",
|
||||
"ROWgXO2mdteowo2dvjp2EVVyQ8Kn+w9M+Nfr4y6BZW9scTCWJ1gZ4xj3lpaxImVpQD6F3JJpA0cdyPvk",
|
||||
"200Vw6Wa3z+vY9N22hYLnazX+HFv/6enP//y7NdhX16vUTf+lSJ1dNIXS6y42mBgTa5ND+IGIkFcoeb5",
|
||||
"iVvdHp2KYyCasD2Hpou0W7sZqARQLtDIFxVnFvXnpuFWuVWp30HLXrfc15tgVA2H+3GpY64QmgcYGSGE",
|
||||
"8C/IVhiDKCDR6vlIPikRZoC0G9vc4m7TgxCJROH5zkgKwpiAn49kxlxSFIaoLgep5qyaVgTYbg+D2Bbh",
|
||||
"YQx/ZyqHU4izMLepDQulTeint/2ZTJUxgBOXfmJ0mvHk2XBYXg1Kk47kl4LNXaJHRMuXuikxmeYV3A5Y",
|
||||
"F6lQuYPgl5AH9f8j8mjCjVUwMh6VeHF8KEq0FzoBEoWmGPJcGbAViQI4swmJmUWR6NkMEAwLisEo1JYG",
|
||||
"Lssbi0ITVeC20UQkmuKKSFtDgShzUATiQpNmt9uKswPNb6upQCgtabY4Hz9ZqOGV2KbvYe4Ii+Kj1Uac",
|
||||
"2QrFa02xxWT1deIHBmkanptPL6bTl1P4Z2cwatpFc6eTHWEZyAtA8k1yseea2ZZgVKllJPcHw8G+DGSp",
|
||||
"OGt6NJzpHEIGas6+FHi70U6BWLiwhWYD2aTEpmUPExk5d/FGO07EzfnSMYd7w+FN5+YyLuwcxnUgnz7k",
|
||||
"kz5z0exHVVEonPfhd7KplGR0Jt90h8fuuzBrTg63MqkjyRZff8A0Uf2Mb7AUNmbgXWIEVaxbi5nFQrGM",
|
||||
"5FQbh7z3YO7zWV9ZrwNgkdu0o5Ln2q9TufAItwvlrcSXrI2t28XjMHY8hDaiIrgnc+qYi97GcWlbTyD8",
|
||||
"eSrsTICKM/GhdQM/fBBtmt6m2nAx/0m+zm3mcRRsibRU7xLxM4eLc/1G8d4DWtaAwkX2CrSIaOzRF8qz",
|
||||
"vBc9jixrJDqqLMe3dLk2wJcWzyc6qcOVESurHplOuhXa79oZ2BbsZCXYHz70ZDFXpUJVAANSc3NdL7LI",
|
||||
"qxMZeBfnzo+Vh1vhbebgU6URksXtYrXBbW5nYx8MxC9tMn/QNWzdBnfMqqkKJ+7SqtrZrPk3Du5jZJcj",
|
||||
"dvoRYm6t7be2qm6Z8zvWV8enN9O87tDPxm5K/EXSL4MKcxnJ8GKv9WXSBbQFNhfJk9Oj10c7q0Wx0fV1",
|
||||
"cNcHa2exK3S1yyo9QFuVvl4b9/vWKb61wYzrfwMAAP//9tkexLESAAA=",
|
||||
}
|
||||
|
||||
// GetSwagger returns the content of the embedded swagger specification file
|
||||
// or error if failed to decode
|
||||
func decodeSpec() ([]byte, error) {
|
||||
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error base64 decoding spec: %s", err)
|
||||
}
|
||||
zr, err := gzip.NewReader(bytes.NewReader(zipped))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decompressing spec: %s", err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
_, err = buf.ReadFrom(zr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decompressing spec: %s", err)
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
var rawSpec = decodeSpecCached()
|
||||
|
||||
// a naive cached of a decoded swagger spec
|
||||
func decodeSpecCached() func() ([]byte, error) {
|
||||
data, err := decodeSpec()
|
||||
return func() ([]byte, error) {
|
||||
return data, err
|
||||
}
|
||||
}
|
||||
|
||||
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
|
||||
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
|
||||
var res = make(map[string]func() ([]byte, error))
|
||||
if len(pathToFile) > 0 {
|
||||
res[pathToFile] = rawSpec
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// GetSwagger returns the Swagger specification corresponding to the generated code
|
||||
// in this file. The external references of Swagger specification are resolved.
|
||||
// The logic of resolving external references is tightly connected to "import-mapping" feature.
|
||||
// Externally referenced files must be embedded in the corresponding golang packages.
|
||||
// Urls can be supported but this task was out of the scope.
|
||||
func GetSwagger() (swagger *openapi3.T, err error) {
|
||||
var resolvePath = PathToRawSpec("")
|
||||
|
||||
loader := openapi3.NewLoader()
|
||||
loader.IsExternalRefsAllowed = true
|
||||
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
|
||||
var pathToFile = url.String()
|
||||
pathToFile = path.Clean(pathToFile)
|
||||
getSpec, ok := resolvePath[pathToFile]
|
||||
if !ok {
|
||||
err1 := fmt.Errorf("path not found: %s", pathToFile)
|
||||
return nil, err1
|
||||
}
|
||||
return getSpec()
|
||||
}
|
||||
var specData []byte
|
||||
specData, err = rawSpec()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
swagger, err = loader.LoadFromData(specData)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
2254
codegen/message_bus/api.go
Normal file
2254
codegen/message_bus/api.go
Normal file
File diff suppressed because it is too large
Load Diff
8
common/constants.go
Normal file
8
common/constants.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package common
|
||||
|
||||
const (
|
||||
SERVICENAME = "casaos"
|
||||
VERSION = "0.4.4.2"
|
||||
BODY = " "
|
||||
RANW_NAME = "IceWhale-RemoteAccess"
|
||||
)
|
||||
12
common/message.go
Normal file
12
common/message.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/IceWhaleTech/CasaOS/codegen/message_bus"
|
||||
)
|
||||
|
||||
// devtype -> action -> event
|
||||
var EventTypes = []message_bus.EventType{
|
||||
{Name: "casaos:system:utilization", SourceID: SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}},
|
||||
{Name: "casaos:file:recover", SourceID: SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}},
|
||||
{Name: "casaos:file:operate", SourceID: SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}},
|
||||
}
|
||||
@@ -11,10 +11,8 @@ DateFormat = 2006-01-02
|
||||
DBPath = /var/lib/casaos
|
||||
ShellPath = /usr/share/casaos/shell
|
||||
UserDataPath = /var/lib/casaos/conf
|
||||
TempPath = /var/lib/casaos/temp
|
||||
|
||||
[server]
|
||||
HttpPort = 80
|
||||
RunMode = release
|
||||
ServerApi = https://api.casaos.io/casaos-api
|
||||
Handshake = socket.casaos.io
|
||||
@@ -22,3 +20,6 @@ Token =
|
||||
USBAutoMount =
|
||||
|
||||
[system]
|
||||
|
||||
[common]
|
||||
RuntimePath=/var/run/casaos
|
||||
13
drivers/all.go
Normal file
13
drivers/all.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package drivers
|
||||
|
||||
import (
|
||||
_ "github.com/IceWhaleTech/CasaOS/drivers/dropbox"
|
||||
_ "github.com/IceWhaleTech/CasaOS/drivers/google_drive"
|
||||
_ "github.com/IceWhaleTech/CasaOS/drivers/onedrive"
|
||||
)
|
||||
|
||||
// All do nothing,just for import
|
||||
// same as _ import
|
||||
func All() {
|
||||
|
||||
}
|
||||
30
drivers/base/client.go
Normal file
30
drivers/base/client.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
var NoRedirectClient *resty.Client
|
||||
var RestyClient = NewRestyClient()
|
||||
var HttpClient = &http.Client{}
|
||||
var UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
|
||||
var DefaultTimeout = time.Second * 30
|
||||
|
||||
func init() {
|
||||
NoRedirectClient = resty.New().SetRedirectPolicy(
|
||||
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}),
|
||||
)
|
||||
NoRedirectClient.SetHeader("user-agent", UserAgent)
|
||||
}
|
||||
|
||||
func NewRestyClient() *resty.Client {
|
||||
return resty.New().
|
||||
SetHeader("user-agent", UserAgent).
|
||||
SetRetryCount(3).
|
||||
SetTimeout(DefaultTimeout)
|
||||
}
|
||||
12
drivers/base/types.go
Normal file
12
drivers/base/types.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package base
|
||||
|
||||
import "github.com/go-resty/resty/v2"
|
||||
|
||||
type Json map[string]interface{}
|
||||
|
||||
type TokenResp struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
|
||||
type ReqCallback func(req *resty.Request)
|
||||
103
drivers/dropbox/drive.go
Normal file
103
drivers/dropbox/drive.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package dropbox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/internal/driver"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Dropbox struct {
|
||||
model.StorageA
|
||||
Addition
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
func (d *Dropbox) Config() driver.Config {
|
||||
return config
|
||||
}
|
||||
|
||||
func (d *Dropbox) GetAddition() driver.Additional {
|
||||
return &d.Addition
|
||||
}
|
||||
|
||||
func (d *Dropbox) Init(ctx context.Context) error {
|
||||
if len(d.RefreshToken) == 0 {
|
||||
d.getRefreshToken()
|
||||
}
|
||||
return d.refreshToken()
|
||||
}
|
||||
|
||||
func (d *Dropbox) Drop(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Dropbox) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
|
||||
files, err := d.getFiles(dir.GetID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceConvert(files, func(src File) (model.Obj, error) {
|
||||
return fileToObj(src), nil
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Dropbox) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
||||
url := "https://content.dropboxapi.com/2/files/download"
|
||||
link := model.Link{
|
||||
URL: url,
|
||||
Method: http.MethodPost,
|
||||
Header: http.Header{
|
||||
"Authorization": []string{"Bearer " + d.AccessToken},
|
||||
"Dropbox-API-Arg": []string{`{"path": "` + file.GetPath() + `"}`},
|
||||
},
|
||||
}
|
||||
return &link, nil
|
||||
}
|
||||
func (d *Dropbox) GetUserInfo(ctx context.Context) (string, error) {
|
||||
url := "https://api.dropboxapi.com/2/users/get_current_account"
|
||||
user := UserInfo{}
|
||||
resp, err := d.request(url, http.MethodPost, func(req *resty.Request) {
|
||||
req.SetHeader("Content-Type", "")
|
||||
}, &user)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
logger.Info("resp", zap.Any("resp", string(resp)))
|
||||
return user.Email, nil
|
||||
}
|
||||
func (d *Dropbox) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Dropbox) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Dropbox) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Dropbox) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
|
||||
return errors.New("not support")
|
||||
}
|
||||
|
||||
func (d *Dropbox) Remove(ctx context.Context, obj model.Obj) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Dropbox) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
|
||||
return nil
|
||||
}
|
||||
func (d *Dropbox) GetInfo(ctx context.Context) (string, string, string, error) {
|
||||
return "", "", "", nil
|
||||
}
|
||||
|
||||
var _ driver.Driver = (*Dropbox)(nil)
|
||||
24
drivers/dropbox/meta.go
Normal file
24
drivers/dropbox/meta.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package dropbox
|
||||
|
||||
import (
|
||||
"github.com/IceWhaleTech/CasaOS/internal/driver"
|
||||
)
|
||||
|
||||
const ICONURL = "./img/driver/Dropbox.svg"
|
||||
|
||||
type Addition struct {
|
||||
driver.RootID
|
||||
RefreshToken string `json:"refresh_token" required:"true" omit:"true"`
|
||||
AppKey string `json:"app_key" type:"string" default:"tciqajyazzdygt9" omit:"true"`
|
||||
AppSecret string `json:"app_secret" type:"string" default:"e7gtmv441cwdf0n" omit:"true"`
|
||||
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" omit:"true"`
|
||||
AuthUrl string `json:"auth_url" type:"string" default:""`
|
||||
Icon string `json:"icon" type:"string" default:"./img/driver/Dropbox.svg"`
|
||||
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
|
||||
}
|
||||
|
||||
var config = driver.Config{
|
||||
Name: "Dropbox",
|
||||
OnlyProxy: true,
|
||||
DefaultRoot: "root",
|
||||
}
|
||||
88
drivers/dropbox/types.go
Normal file
88
drivers/dropbox/types.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package dropbox
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
AccountID string `json:"account_id"`
|
||||
Name struct {
|
||||
GivenName string `json:"given_name"`
|
||||
Surname string `json:"surname"`
|
||||
FamiliarName string `json:"familiar_name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
AbbreviatedName string `json:"abbreviated_name"`
|
||||
} `json:"name"`
|
||||
Email string `json:"email"`
|
||||
EmailVerified bool `json:"email_verified"`
|
||||
Disabled bool `json:"disabled"`
|
||||
Country string `json:"country"`
|
||||
Locale string `json:"locale"`
|
||||
ReferralLink string `json:"referral_link"`
|
||||
IsPaired bool `json:"is_paired"`
|
||||
AccountType struct {
|
||||
Tag string `json:".tag"`
|
||||
} `json:"account_type"`
|
||||
RootInfo struct {
|
||||
Tag string `json:".tag"`
|
||||
RootNamespaceID string `json:"root_namespace_id"`
|
||||
HomeNamespaceID string `json:"home_namespace_id"`
|
||||
} `json:"root_info"`
|
||||
}
|
||||
type TokenError struct {
|
||||
Error string `json:"error"`
|
||||
ErrorDescription string `json:"error_description"`
|
||||
}
|
||||
type File struct {
|
||||
Tag string `json:".tag"`
|
||||
Name string `json:"name"`
|
||||
PathLower string `json:"path_lower"`
|
||||
PathDisplay string `json:"path_display"`
|
||||
ID string `json:"id"`
|
||||
ClientModified time.Time `json:"client_modified,omitempty"`
|
||||
ServerModified time.Time `json:"server_modified,omitempty"`
|
||||
Rev string `json:"rev,omitempty"`
|
||||
Size int `json:"size,omitempty"`
|
||||
IsDownloadable bool `json:"is_downloadable,omitempty"`
|
||||
ContentHash string `json:"content_hash,omitempty"`
|
||||
}
|
||||
|
||||
type Files struct {
|
||||
Files []File `json:"entries"`
|
||||
Cursor string `json:"cursor"`
|
||||
HasMore bool `json:"has_more"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Error struct {
|
||||
Errors []struct {
|
||||
Domain string `json:"domain"`
|
||||
Reason string `json:"reason"`
|
||||
Message string `json:"message"`
|
||||
LocationType string `json:"location_type"`
|
||||
Location string `json:"location"`
|
||||
}
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"error"`
|
||||
}
|
||||
|
||||
func fileToObj(f File) *model.ObjThumb {
|
||||
logger.Info("dropbox file", zap.Any("file", f))
|
||||
obj := &model.ObjThumb{
|
||||
Object: model.Object{
|
||||
ID: f.ID,
|
||||
Name: f.Name,
|
||||
Size: int64(f.Size),
|
||||
Modified: f.ClientModified,
|
||||
IsFolder: f.Tag == "folder",
|
||||
Path: f.PathDisplay,
|
||||
},
|
||||
Thumbnail: model.Thumbnail{},
|
||||
}
|
||||
return obj
|
||||
}
|
||||
116
drivers/dropbox/util.go
Normal file
116
drivers/dropbox/util.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package dropbox
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/drivers/base"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
app_key = "private build"
|
||||
app_secret = "private build"
|
||||
)
|
||||
|
||||
func (d *Dropbox) getRefreshToken() error {
|
||||
url := "https://api.dropbox.com/oauth2/token"
|
||||
var resp base.TokenResp
|
||||
var e TokenError
|
||||
|
||||
res, err := base.RestyClient.R().SetResult(&resp).SetError(&e).
|
||||
SetFormData(map[string]string{
|
||||
"code": d.Code,
|
||||
"grant_type": "authorization_code",
|
||||
"redirect_uri": "https://cloudoauth.files.casaos.app",
|
||||
}).SetBasicAuth(d.Addition.AppKey, d.Addition.AppSecret).SetHeader("Content-Type", "application/x-www-form-urlencoded").Post(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("get refresh token", zap.String("res", res.String()))
|
||||
if e.Error != "" {
|
||||
return fmt.Errorf(e.Error)
|
||||
}
|
||||
d.RefreshToken = resp.RefreshToken
|
||||
return nil
|
||||
|
||||
}
|
||||
func (d *Dropbox) refreshToken() error {
|
||||
url := "https://api.dropbox.com/oauth2/token"
|
||||
var resp base.TokenResp
|
||||
var e TokenError
|
||||
|
||||
res, err := base.RestyClient.R().SetResult(&resp).SetError(&e).
|
||||
SetFormData(map[string]string{
|
||||
"refresh_token": d.RefreshToken,
|
||||
"grant_type": "refresh_token",
|
||||
}).SetBasicAuth(d.Addition.AppKey, d.Addition.AppSecret).SetHeader("Content-Type", "application/x-www-form-urlencoded").Post(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("get refresh token", zap.String("res", res.String()))
|
||||
if e.Error != "" {
|
||||
return fmt.Errorf(e.Error)
|
||||
}
|
||||
d.AccessToken = resp.AccessToken
|
||||
return nil
|
||||
|
||||
}
|
||||
func (d *Dropbox) request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||
req := base.RestyClient.R()
|
||||
req.SetHeader("Authorization", "Bearer "+d.AccessToken)
|
||||
req.SetHeader("Content-Type", "application/json")
|
||||
if callback != nil {
|
||||
callback(req)
|
||||
}
|
||||
if resp != nil {
|
||||
req.SetResult(resp)
|
||||
}
|
||||
var e Error
|
||||
req.SetError(&e)
|
||||
res, err := req.Execute(method, url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if e.Error.Code != 0 {
|
||||
if e.Error.Code == 401 {
|
||||
err = d.refreshToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d.request(url, method, callback, resp)
|
||||
}
|
||||
return nil, fmt.Errorf("%s: %v", e.Error.Message, e.Error.Errors)
|
||||
}
|
||||
return res.Body(), nil
|
||||
}
|
||||
func (d *Dropbox) getFiles(path string) ([]File, error) {
|
||||
|
||||
res := make([]File, 0)
|
||||
var resp Files
|
||||
body := base.Json{
|
||||
"limit": 2000,
|
||||
"path": path,
|
||||
}
|
||||
|
||||
_, err := d.request("https://api.dropboxapi.com/2/files/list_folder", http.MethodPost, func(req *resty.Request) {
|
||||
req.SetBody(body)
|
||||
}, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = append(res, resp.Files...)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
func GetConfig() Dropbox {
|
||||
dp := Dropbox{}
|
||||
dp.RootFolderID = ""
|
||||
dp.AuthUrl = "https://www.dropbox.com/oauth2/authorize?client_id=" + app_key + "&redirect_uri=https://cloudoauth.files.casaos.app&response_type=code&token_access_type=offline&state=${HOST}%2Fv1%2Frecover%2FDropbox&&force_reapprove=true&force_reauthentication=true"
|
||||
dp.AppKey = app_key
|
||||
dp.AppSecret = app_secret
|
||||
dp.Icon = "./img/driver/Dropbox.svg"
|
||||
return dp
|
||||
}
|
||||
186
drivers/google_drive/drive.go
Normal file
186
drivers/google_drive/drive.go
Normal file
@@ -0,0 +1,186 @@
|
||||
package google_drive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/drivers/base"
|
||||
"github.com/IceWhaleTech/CasaOS/internal/driver"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type GoogleDrive struct {
|
||||
model.StorageA
|
||||
Addition
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Config() driver.Config {
|
||||
return config
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) GetAddition() driver.Additional {
|
||||
return &d.Addition
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Init(ctx context.Context) error {
|
||||
if d.ChunkSize == 0 {
|
||||
d.ChunkSize = 5
|
||||
}
|
||||
if len(d.RefreshToken) == 0 {
|
||||
d.getRefreshToken()
|
||||
}
|
||||
return d.refreshToken()
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Drop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
|
||||
files, err := d.getFiles(dir.GetID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceConvert(files, func(src File) (model.Obj, error) {
|
||||
return fileToObj(src), nil
|
||||
})
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
||||
url := fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%s?includeItemsFromAllDrives=true&supportsAllDrives=true", file.GetID())
|
||||
_, err := d.request(url, http.MethodGet, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
link := model.Link{
|
||||
Method: http.MethodGet,
|
||||
URL: url + "&alt=media",
|
||||
Header: http.Header{
|
||||
"Authorization": []string{"Bearer " + d.AccessToken},
|
||||
},
|
||||
}
|
||||
return &link, nil
|
||||
}
|
||||
func (d *GoogleDrive) GetUserInfo(ctx context.Context) (string, error) {
|
||||
url := "https://content.googleapis.com/drive/v3/about?fields=user"
|
||||
user := UserInfo{}
|
||||
resp, err := d.request(url, http.MethodGet, nil, &user)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
logger.Info("resp", zap.Any("resp", resp))
|
||||
return user.User.EmailAddress, nil
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) GetInfo(ctx context.Context) (string, string, string, error) {
|
||||
return "", "", "", nil
|
||||
}
|
||||
func (d *GoogleDrive) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
|
||||
data := base.Json{
|
||||
"name": dirName,
|
||||
"parents": []string{parentDir.GetID()},
|
||||
"mimeType": "application/vnd.google-apps.folder",
|
||||
}
|
||||
_, err := d.request("https://www.googleapis.com/drive/v3/files", http.MethodPost, func(req *resty.Request) {
|
||||
req.SetBody(data)
|
||||
}, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
|
||||
query := map[string]string{
|
||||
"addParents": dstDir.GetID(),
|
||||
"removeParents": "root",
|
||||
}
|
||||
url := "https://www.googleapis.com/drive/v3/files/" + srcObj.GetID()
|
||||
_, err := d.request(url, http.MethodPatch, func(req *resty.Request) {
|
||||
req.SetQueryParams(query)
|
||||
}, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
|
||||
data := base.Json{
|
||||
"name": newName,
|
||||
}
|
||||
url := "https://www.googleapis.com/drive/v3/files/" + srcObj.GetID()
|
||||
_, err := d.request(url, http.MethodPatch, func(req *resty.Request) {
|
||||
req.SetBody(data)
|
||||
}, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
|
||||
return errors.New("not support")
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Remove(ctx context.Context, obj model.Obj) error {
|
||||
url := "https://www.googleapis.com/drive/v3/files/" + obj.GetID()
|
||||
_, err := d.request(url, http.MethodDelete, nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
|
||||
obj := stream.GetOld()
|
||||
var (
|
||||
e Error
|
||||
url string
|
||||
data base.Json
|
||||
res *resty.Response
|
||||
err error
|
||||
)
|
||||
if obj != nil {
|
||||
url = fmt.Sprintf("https://www.googleapis.com/upload/drive/v3/files/%s?uploadType=resumable&supportsAllDrives=true", obj.GetID())
|
||||
data = base.Json{}
|
||||
} else {
|
||||
data = base.Json{
|
||||
"name": stream.GetName(),
|
||||
"parents": []string{dstDir.GetID()},
|
||||
}
|
||||
url = "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&supportsAllDrives=true"
|
||||
}
|
||||
req := base.NoRedirectClient.R().
|
||||
SetHeaders(map[string]string{
|
||||
"Authorization": "Bearer " + d.AccessToken,
|
||||
"X-Upload-Content-Type": stream.GetMimetype(),
|
||||
"X-Upload-Content-Length": strconv.FormatInt(stream.GetSize(), 10),
|
||||
}).
|
||||
SetError(&e).SetBody(data).SetContext(ctx)
|
||||
if obj != nil {
|
||||
res, err = req.Patch(url)
|
||||
} else {
|
||||
res, err = req.Post(url)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if e.Error.Code != 0 {
|
||||
if e.Error.Code == 401 {
|
||||
err = d.refreshToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return d.Put(ctx, dstDir, stream, up)
|
||||
}
|
||||
return fmt.Errorf("%s: %v", e.Error.Message, e.Error.Errors)
|
||||
}
|
||||
putUrl := res.Header().Get("location")
|
||||
if stream.GetSize() < d.ChunkSize*1024*1024 {
|
||||
_, err = d.request(putUrl, http.MethodPut, func(req *resty.Request) {
|
||||
req.SetHeader("Content-Length", strconv.FormatInt(stream.GetSize(), 10)).SetBody(stream.GetReadCloser())
|
||||
}, nil)
|
||||
} else {
|
||||
err = d.chunkUpload(ctx, stream, putUrl)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
var _ driver.Driver = (*GoogleDrive)(nil)
|
||||
26
drivers/google_drive/meta.go
Normal file
26
drivers/google_drive/meta.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package google_drive
|
||||
|
||||
import (
|
||||
"github.com/IceWhaleTech/CasaOS/internal/driver"
|
||||
)
|
||||
|
||||
const ICONURL = "./img/driver/GoogleDrive.svg"
|
||||
|
||||
type Addition struct {
|
||||
driver.RootID
|
||||
RefreshToken string `json:"refresh_token" required:"true" omit:"true"`
|
||||
OrderBy string `json:"order_by" type:"string" help:"such as: folder,name,modifiedTime" omit:"true"`
|
||||
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" omit:"true"`
|
||||
ClientID string `json:"client_id" required:"true" default:"" omit:"true"`
|
||||
ClientSecret string `json:"client_secret" required:"true" default:"" omit:"true"`
|
||||
ChunkSize int64 `json:"chunk_size" type:"number" help:"chunk size while uploading (unit: MB)" omit:"true"`
|
||||
AuthUrl string `json:"auth_url" type:"string" default:""`
|
||||
Icon string `json:"icon" type:"string" default:"./img/driver/GoogleDrive.svg"`
|
||||
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
|
||||
}
|
||||
|
||||
var config = driver.Config{
|
||||
Name: "GoogleDrive",
|
||||
OnlyProxy: true,
|
||||
DefaultRoot: "root",
|
||||
}
|
||||
77
drivers/google_drive/types.go
Normal file
77
drivers/google_drive/types.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package google_drive
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
User struct {
|
||||
Kind string `json:"kind"`
|
||||
DisplayName string `json:"displayName"`
|
||||
PhotoLink string `json:"photoLink"`
|
||||
Me bool `json:"me"`
|
||||
PermissionID string `json:"permissionId"`
|
||||
EmailAddress string `json:"emailAddress"`
|
||||
} `json:"user"`
|
||||
}
|
||||
|
||||
type TokenError struct {
|
||||
Error string `json:"error"`
|
||||
ErrorDescription string `json:"error_description"`
|
||||
}
|
||||
|
||||
type Files struct {
|
||||
NextPageToken string `json:"nextPageToken"`
|
||||
Files []File `json:"files"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
MimeType string `json:"mimeType"`
|
||||
ModifiedTime time.Time `json:"modifiedTime"`
|
||||
Size string `json:"size"`
|
||||
ThumbnailLink string `json:"thumbnailLink"`
|
||||
ShortcutDetails struct {
|
||||
TargetId string `json:"targetId"`
|
||||
TargetMimeType string `json:"targetMimeType"`
|
||||
} `json:"shortcutDetails"`
|
||||
}
|
||||
|
||||
func fileToObj(f File) *model.ObjThumb {
|
||||
log.Debugf("google file: %+v", f)
|
||||
size, _ := strconv.ParseInt(f.Size, 10, 64)
|
||||
obj := &model.ObjThumb{
|
||||
Object: model.Object{
|
||||
ID: f.Id,
|
||||
Name: f.Name,
|
||||
Size: size,
|
||||
Modified: f.ModifiedTime,
|
||||
IsFolder: f.MimeType == "application/vnd.google-apps.folder",
|
||||
},
|
||||
Thumbnail: model.Thumbnail{},
|
||||
}
|
||||
if f.MimeType == "application/vnd.google-apps.shortcut" {
|
||||
obj.ID = f.ShortcutDetails.TargetId
|
||||
obj.IsFolder = f.ShortcutDetails.TargetMimeType == "application/vnd.google-apps.folder"
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Error struct {
|
||||
Errors []struct {
|
||||
Domain string `json:"domain"`
|
||||
Reason string `json:"reason"`
|
||||
Message string `json:"message"`
|
||||
LocationType string `json:"location_type"`
|
||||
Location string `json:"location"`
|
||||
}
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"error"`
|
||||
}
|
||||
167
drivers/google_drive/util.go
Normal file
167
drivers/google_drive/util.go
Normal file
@@ -0,0 +1,167 @@
|
||||
package google_drive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/drivers/base"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils"
|
||||
"github.com/go-resty/resty/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
client_id = "private build"
|
||||
client_secret = "private build"
|
||||
)
|
||||
|
||||
// do others that not defined in Driver interface
|
||||
|
||||
func (d *GoogleDrive) getRefreshToken() error {
|
||||
url := "https://www.googleapis.com/oauth2/v4/token"
|
||||
var resp base.TokenResp
|
||||
var e TokenError
|
||||
res, err := base.RestyClient.R().SetResult(&resp).SetError(&e).
|
||||
SetFormData(map[string]string{
|
||||
"client_id": d.ClientID,
|
||||
"client_secret": d.ClientSecret,
|
||||
"code": d.Code,
|
||||
"grant_type": "authorization_code",
|
||||
"redirect_uri": "https://cloudoauth.files.casaos.app",
|
||||
}).Post(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("get refresh token", zap.String("res", res.String()))
|
||||
if e.Error != "" {
|
||||
return fmt.Errorf(e.Error)
|
||||
}
|
||||
d.RefreshToken = resp.RefreshToken
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) refreshToken() error {
|
||||
url := "https://www.googleapis.com/oauth2/v4/token"
|
||||
var resp base.TokenResp
|
||||
var e TokenError
|
||||
res, err := base.RestyClient.R().SetResult(&resp).SetError(&e).
|
||||
SetFormData(map[string]string{
|
||||
"client_id": d.ClientID,
|
||||
"client_secret": d.ClientSecret,
|
||||
"refresh_token": d.RefreshToken,
|
||||
"grant_type": "refresh_token",
|
||||
}).Post(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debug(res.String())
|
||||
if e.Error != "" {
|
||||
return fmt.Errorf(e.Error)
|
||||
}
|
||||
d.AccessToken = resp.AccessToken
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||
req := base.RestyClient.R()
|
||||
req.SetHeader("Authorization", "Bearer "+d.AccessToken)
|
||||
req.SetQueryParam("includeItemsFromAllDrives", "true")
|
||||
req.SetQueryParam("supportsAllDrives", "true")
|
||||
if callback != nil {
|
||||
callback(req)
|
||||
}
|
||||
if resp != nil {
|
||||
req.SetResult(resp)
|
||||
}
|
||||
var e Error
|
||||
req.SetError(&e)
|
||||
res, err := req.Execute(method, url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if e.Error.Code != 0 {
|
||||
if e.Error.Code == 401 {
|
||||
err = d.refreshToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d.request(url, method, callback, resp)
|
||||
}
|
||||
return nil, fmt.Errorf("%s: %v", e.Error.Message, e.Error.Errors)
|
||||
}
|
||||
return res.Body(), nil
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) getFiles(id string) ([]File, error) {
|
||||
pageToken := "first"
|
||||
res := make([]File, 0)
|
||||
for pageToken != "" {
|
||||
if pageToken == "first" {
|
||||
pageToken = ""
|
||||
}
|
||||
var resp Files
|
||||
orderBy := "folder,name,modifiedTime desc"
|
||||
if d.OrderBy != "" {
|
||||
orderBy = d.OrderBy + " " + d.OrderDirection
|
||||
}
|
||||
query := map[string]string{
|
||||
"orderBy": orderBy,
|
||||
"fields": "files(id,name,mimeType,size,modifiedTime,thumbnailLink,shortcutDetails),nextPageToken",
|
||||
"pageSize": "1000",
|
||||
"q": fmt.Sprintf("'%s' in parents and trashed = false", id),
|
||||
//"includeItemsFromAllDrives": "true",
|
||||
//"supportsAllDrives": "true",
|
||||
"pageToken": pageToken,
|
||||
}
|
||||
_, err := d.request("https://www.googleapis.com/drive/v3/files", http.MethodGet, func(req *resty.Request) {
|
||||
req.SetQueryParams(query)
|
||||
}, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pageToken = resp.NextPageToken
|
||||
res = append(res, resp.Files...)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (d *GoogleDrive) chunkUpload(ctx context.Context, stream model.FileStreamer, url string) error {
|
||||
var defaultChunkSize = d.ChunkSize * 1024 * 1024
|
||||
var finish int64 = 0
|
||||
for finish < stream.GetSize() {
|
||||
if utils.IsCanceled(ctx) {
|
||||
return ctx.Err()
|
||||
}
|
||||
chunkSize := stream.GetSize() - finish
|
||||
if chunkSize > defaultChunkSize {
|
||||
chunkSize = defaultChunkSize
|
||||
}
|
||||
_, err := d.request(url, http.MethodPut, func(req *resty.Request) {
|
||||
req.SetHeaders(map[string]string{
|
||||
"Content-Length": strconv.FormatInt(chunkSize, 10),
|
||||
"Content-Range": fmt.Sprintf("bytes %d-%d/%d", finish, finish+chunkSize-1, stream.GetSize()),
|
||||
}).SetBody(io.LimitReader(stream.GetReadCloser(), chunkSize)).SetContext(ctx)
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
finish += chunkSize
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func GetConfig() GoogleDrive {
|
||||
config := GoogleDrive{}
|
||||
config.ClientID = client_id
|
||||
config.ClientSecret = client_secret
|
||||
config.RootFolderID = "root"
|
||||
config.AuthUrl = "https://accounts.google.com/o/oauth2/auth/oauthchooseaccount?response_type=code&client_id=" + client_id + "&redirect_uri=https%3A%2F%2Fcloudoauth.files.casaos.app&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&approval_prompt=force&state=${HOST}%2Fv1%2Frecover%2FGoogleDrive&service=lso&o2v=1&flowName=GeneralOAuthFlow"
|
||||
config.Icon = "./img/driver/GoogleDrive.svg"
|
||||
|
||||
return config
|
||||
}
|
||||
70
drivers/onedrive/drive.go
Normal file
70
drivers/onedrive/drive.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package onedrive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/internal/driver"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Onedrive struct {
|
||||
model.StorageA
|
||||
Addition
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
func (d *Onedrive) Config() driver.Config {
|
||||
return config
|
||||
}
|
||||
|
||||
func (d *Onedrive) GetAddition() driver.Additional {
|
||||
return &d.Addition
|
||||
}
|
||||
func (d *Onedrive) Init(ctx context.Context) error {
|
||||
if d.ChunkSize < 1 {
|
||||
d.ChunkSize = 5
|
||||
}
|
||||
if len(d.RefreshToken) == 0 {
|
||||
return d.getRefreshToken()
|
||||
}
|
||||
return d.refreshToken()
|
||||
}
|
||||
func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) {
|
||||
url := d.GetMetaUrl(false, "/")
|
||||
user := Info{}
|
||||
resp, err := d.Request(url, http.MethodGet, nil, &user)
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
|
||||
logger.Info("resp", zap.Any("resp", resp))
|
||||
return user.LastModifiedBy.User.DisplayName, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
|
||||
}
|
||||
|
||||
func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) {
|
||||
host := onedriveHostMap[d.Region]
|
||||
url := fmt.Sprintf("%s/v1.0/me/drive/quota", host.Api)
|
||||
size := About{}
|
||||
resp, err := d.Request(url, http.MethodGet, nil, &size)
|
||||
if err != nil {
|
||||
return used, total, err
|
||||
}
|
||||
logger.Info("resp", zap.Any("resp", resp))
|
||||
used = strconv.Itoa(size.Used)
|
||||
total = strconv.Itoa(size.Total)
|
||||
return
|
||||
}
|
||||
func (d *Onedrive) Drop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ driver.Driver = (*Onedrive)(nil)
|
||||
69
drivers/onedrive/meta.go
Normal file
69
drivers/onedrive/meta.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package onedrive
|
||||
|
||||
import (
|
||||
"github.com/IceWhaleTech/CasaOS/internal/driver"
|
||||
)
|
||||
|
||||
const ICONURL = "./img/driver/OneDrive.svg"
|
||||
|
||||
type Host struct {
|
||||
Oauth string
|
||||
Api string
|
||||
}
|
||||
|
||||
type TokenErr struct {
|
||||
Error string `json:"error"`
|
||||
ErrorDescription string `json:"error_description"`
|
||||
}
|
||||
|
||||
type RespErr struct {
|
||||
Error struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"error"`
|
||||
}
|
||||
type Addition struct {
|
||||
Region string `json:"region" type:"select" required:"true" options:"global,cn,us,de" default:"global"`
|
||||
IsSharepoint bool `json:"is_sharepoint"`
|
||||
ClientID string `json:"client_id" required:"true"`
|
||||
ClientSecret string `json:"client_secret" required:"true"`
|
||||
RedirectUri string `json:"redirect_uri" required:"true" default:""`
|
||||
RefreshToken string `json:"refresh_token" required:"true"`
|
||||
SiteId string `json:"site_id"`
|
||||
ChunkSize int64 `json:"chunk_size" type:"number" default:"5"`
|
||||
RootFolderID string `json:"root_folder_id"`
|
||||
AuthUrl string `json:"auth_url" type:"string" default:""`
|
||||
Icon string `json:"icon" type:"string" default:""`
|
||||
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
|
||||
}
|
||||
type About struct {
|
||||
Total int `json:"total"`
|
||||
Used int `json:"used"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
LastModifiedBy struct {
|
||||
Application struct {
|
||||
DisplayName string `json:"displayName"`
|
||||
ID string `json:"id"`
|
||||
} `json:"application"`
|
||||
Device struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"device"`
|
||||
User struct {
|
||||
DisplayName string `json:"displayName"`
|
||||
ID string `json:"id"`
|
||||
} `json:"user"`
|
||||
} `json:"lastModifiedBy"`
|
||||
ParentReference struct {
|
||||
DriveID string `json:"driveId"`
|
||||
DriveType string `json:"driveType"`
|
||||
} `json:"parentReference"`
|
||||
}
|
||||
|
||||
var config = driver.Config{
|
||||
Name: "Onedrive",
|
||||
LocalSort: true,
|
||||
DefaultRoot: "/",
|
||||
}
|
||||
182
drivers/onedrive/util.go
Normal file
182
drivers/onedrive/util.go
Normal file
@@ -0,0 +1,182 @@
|
||||
package onedrive
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/drivers/base"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
client_id = "private build"
|
||||
client_secret = "private build"
|
||||
)
|
||||
var onedriveHostMap = map[string]Host{
|
||||
"global": {
|
||||
Oauth: "https://login.microsoftonline.com",
|
||||
Api: "https://graph.microsoft.com",
|
||||
},
|
||||
"cn": {
|
||||
Oauth: "https://login.chinacloudapi.cn",
|
||||
Api: "https://microsoftgraph.chinacloudapi.cn",
|
||||
},
|
||||
"us": {
|
||||
Oauth: "https://login.microsoftonline.us",
|
||||
Api: "https://graph.microsoft.us",
|
||||
},
|
||||
"de": {
|
||||
Oauth: "https://login.microsoftonline.de",
|
||||
Api: "https://graph.microsoft.de",
|
||||
},
|
||||
}
|
||||
|
||||
func EncodePath(path string, all ...bool) string {
|
||||
seg := strings.Split(path, "/")
|
||||
toReplace := []struct {
|
||||
Src string
|
||||
Dst string
|
||||
}{
|
||||
{Src: "%", Dst: "%25"},
|
||||
{"%", "%25"},
|
||||
{"?", "%3F"},
|
||||
{"#", "%23"},
|
||||
}
|
||||
for i := range seg {
|
||||
if len(all) > 0 && all[0] {
|
||||
seg[i] = url.PathEscape(seg[i])
|
||||
} else {
|
||||
for j := range toReplace {
|
||||
seg[i] = strings.ReplaceAll(seg[i], toReplace[j].Src, toReplace[j].Dst)
|
||||
}
|
||||
}
|
||||
}
|
||||
return strings.Join(seg, "/")
|
||||
}
|
||||
func (d *Onedrive) GetMetaUrl(auth bool, path string) string {
|
||||
host := onedriveHostMap[d.Region]
|
||||
path = EncodePath(path, true)
|
||||
if auth {
|
||||
return host.Oauth
|
||||
}
|
||||
if d.IsSharepoint {
|
||||
if path == "/" || path == "\\" {
|
||||
return fmt.Sprintf("%s/v1.0/sites/%s/drive/root", host.Api, d.SiteId)
|
||||
} else {
|
||||
return fmt.Sprintf("%s/v1.0/sites/%s/drive/root:%s:", host.Api, d.SiteId, path)
|
||||
}
|
||||
} else {
|
||||
if path == "/" || path == "\\" {
|
||||
return fmt.Sprintf("%s/v1.0/me/drive/root", host.Api)
|
||||
} else {
|
||||
return fmt.Sprintf("%s/v1.0/me/drive/root:%s:", host.Api, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Onedrive) refreshToken() error {
|
||||
var err error
|
||||
for i := 0; i < 3; i++ {
|
||||
err = d._refreshToken()
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *Onedrive) getRefreshToken() error {
|
||||
url := d.GetMetaUrl(true, "") + "/common/oauth2/v2.0/token"
|
||||
var resp base.TokenResp
|
||||
var e TokenErr
|
||||
|
||||
res, err := base.RestyClient.R().SetResult(&resp).SetError(&e).SetFormData(map[string]string{
|
||||
"grant_type": "authorization_code",
|
||||
"client_id": d.ClientID,
|
||||
"client_secret": d.ClientSecret,
|
||||
"code": d.Code,
|
||||
"redirect_uri": d.RedirectUri,
|
||||
}).Post(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("get refresh token", zap.String("res", res.String()))
|
||||
if e.Error != "" {
|
||||
return fmt.Errorf("%s", e.ErrorDescription)
|
||||
}
|
||||
if resp.RefreshToken == "" {
|
||||
return errors.New("refresh token is empty")
|
||||
}
|
||||
d.RefreshToken, d.AccessToken = resp.RefreshToken, resp.AccessToken
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Onedrive) _refreshToken() error {
|
||||
url := d.GetMetaUrl(true, "") + "/common/oauth2/v2.0/token"
|
||||
var resp base.TokenResp
|
||||
var e TokenErr
|
||||
|
||||
res, err := base.RestyClient.R().SetResult(&resp).SetError(&e).SetFormData(map[string]string{
|
||||
"grant_type": "refresh_token",
|
||||
"client_id": d.ClientID,
|
||||
"client_secret": d.ClientSecret,
|
||||
"redirect_uri": d.RedirectUri,
|
||||
"refresh_token": d.RefreshToken,
|
||||
}).Post(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("get refresh token", zap.String("res", res.String()))
|
||||
if e.Error != "" {
|
||||
return fmt.Errorf("%s", e.ErrorDescription)
|
||||
}
|
||||
if resp.RefreshToken == "" {
|
||||
return errors.New("refresh token is empty")
|
||||
}
|
||||
d.RefreshToken, d.AccessToken = resp.RefreshToken, resp.AccessToken
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Onedrive) Request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||
req := base.RestyClient.R()
|
||||
req.SetHeader("Authorization", "Bearer "+d.AccessToken)
|
||||
if callback != nil {
|
||||
callback(req)
|
||||
}
|
||||
if resp != nil {
|
||||
req.SetResult(resp)
|
||||
}
|
||||
var e RespErr
|
||||
req.SetError(&e)
|
||||
res, err := req.Execute(method, url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if e.Error.Code != "" {
|
||||
if e.Error.Code == "InvalidAuthenticationToken" {
|
||||
err = d.refreshToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d.Request(url, method, callback, resp)
|
||||
}
|
||||
return nil, errors.New(e.Error.Message)
|
||||
}
|
||||
return res.Body(), nil
|
||||
}
|
||||
|
||||
func GetConfig() Onedrive {
|
||||
config := Onedrive{}
|
||||
config.ClientID = client_id
|
||||
config.ClientSecret = client_secret
|
||||
config.RootFolderID = "/"
|
||||
config.AuthUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=" + client_id + "&response_type=code&redirect_uri=https%3A%2F%2Fcloudoauth.files.casaos.app&scope=offline_access+files.readwrite.all&state=${HOST}%2Fv1%2Frecover%2FOnedrive"
|
||||
config.Icon = "./img/driver/OneDrive.svg"
|
||||
config.Region = "global"
|
||||
config.RedirectUri = "https://cloudoauth.files.casaos.app"
|
||||
|
||||
return config
|
||||
}
|
||||
190
go.mod
190
go.mod
@@ -1,80 +1,138 @@
|
||||
module github.com/IceWhaleTech/CasaOS
|
||||
|
||||
go 1.16
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d
|
||||
github.com/Microsoft/go-winio v0.5.0 // indirect
|
||||
github.com/Microsoft/hcsshim v0.8.22 // indirect
|
||||
github.com/ambelovsky/go-structs v1.1.0 // indirect
|
||||
github.com/ambelovsky/gosf v0.0.0-20201109201340-237aea4d6109
|
||||
github.com/ambelovsky/gosf-socketio v0.0.0-20201109193639-add9d32f8b19 // 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/IceWhaleTech/CasaOS-Common v0.4.7-alpha4
|
||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
|
||||
github.com/deckarep/golang-set/v2 v2.3.0
|
||||
github.com/deepmap/oapi-codegen v1.12.4
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/docker/distribution v2.8.0+incompatible // indirect
|
||||
github.com/docker/docker v20.10.7+incompatible
|
||||
github.com/docker/go-connections v0.4.0
|
||||
github.com/dsoprea/go-exif/v3 v3.0.0-20210625224831-a6301f85c82b
|
||||
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
|
||||
github.com/gin-contrib/gzip v0.0.2
|
||||
github.com/gin-gonic/gin v1.7.2
|
||||
github.com/go-ini/ini v1.62.0
|
||||
github.com/go-playground/validator/v10 v10.6.1 // indirect
|
||||
github.com/gogo/googleapis v1.4.1 // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.4.1
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/dsoprea/go-exif/v3 v3.0.0-20221012082141-d21ac8e2de85
|
||||
github.com/getkin/kin-openapi v0.115.0
|
||||
github.com/gin-contrib/gzip v0.0.6
|
||||
github.com/gin-gonic/gin v1.9.0
|
||||
github.com/glebarez/sqlite v1.7.0
|
||||
github.com/go-ini/ini v1.67.0
|
||||
github.com/go-resty/resty/v2 v2.7.0
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/gomodule/redigo v1.8.5
|
||||
github.com/gomodule/redigo v1.8.9
|
||||
github.com/google/go-github/v36 v36.0.0
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/googollee/go-socket.io v1.6.2
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/googollee/go-socket.io v1.7.0
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/h2non/filetype v1.1.3
|
||||
github.com/hirochachacha/go-smb2 v1.1.0
|
||||
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/kr/text v0.2.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/lucas-clemente/quic-go v0.25.0
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.11 // indirect
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/labstack/echo/v4 v4.10.2
|
||||
github.com/maruel/natural v1.1.0
|
||||
github.com/mholt/archiver/v3 v3.5.1
|
||||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
|
||||
github.com/morikuni/aec v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.0.2 // indirect
|
||||
github.com/opencontainers/selinux v1.8.5 // indirect
|
||||
github.com/mileusna/useragent v1.2.1
|
||||
github.com/moby/sys/mount v0.3.3
|
||||
github.com/moby/sys/mountinfo v0.6.2
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/pilebones/go-udev v0.9.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
github.com/robfig/cron v1.2.0
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/samber/lo v1.38.1
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/shirou/gopsutil/v3 v3.22.7
|
||||
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/stretchr/testify v1.8.0
|
||||
github.com/tidwall/gjson v1.10.2
|
||||
github.com/ugorji/go v1.2.6 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
go.uber.org/zap v1.10.0
|
||||
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/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/natefinch/lumberjack.v2 v2.0.0
|
||||
gorm.io/driver/sqlite v1.2.6
|
||||
gorm.io/gorm v1.22.5
|
||||
github.com/shirou/gopsutil/v3 v3.23.2
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/stretchr/testify v1.8.2
|
||||
github.com/tidwall/gjson v1.14.4
|
||||
go.uber.org/goleak v1.2.1
|
||||
go.uber.org/zap v1.24.0
|
||||
golang.org/x/crypto v0.8.0
|
||||
golang.org/x/oauth2 v0.6.0
|
||||
golang.org/x/sync v0.1.0
|
||||
golang.org/x/sys v0.7.0
|
||||
gorm.io/gorm v1.24.6
|
||||
gotest.tools v2.2.0+incompatible
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
|
||||
github.com/benbjohnson/clock v1.3.0 // indirect
|
||||
github.com/bytedance/sonic v1.8.5 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
|
||||
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
|
||||
github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/geoffgarside/ber v1.1.0 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/glebarez/go-sqlite v1.21.0 // indirect
|
||||
github.com/go-errors/errors v1.4.2 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||
github.com/go-openapi/swag v0.22.3 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.12.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/gofrs/uuid v4.4.0+incompatible // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
|
||||
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/invopop/yaml v0.2.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/klauspost/compress v1.16.5 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||
github.com/klauspost/pgzip v1.2.5 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/labstack/gommon v0.4.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.3 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20230110061619-bbe2e5e100de // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.18 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
||||
github.com/nwaples/rardecode v1.1.3 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
|
||||
github.com/perimeterx/marshmallow v1.1.4 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.17 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
||||
github.com/tklauser/numcpus v0.6.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
github.com/ulikunitz/xz v0.5.11 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/arch v0.3.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
|
||||
golang.org/x/image v0.6.0 // indirect
|
||||
golang.org/x/net v0.9.0 // indirect
|
||||
golang.org/x/text v0.9.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
modernc.org/libc v1.22.3 // indirect
|
||||
modernc.org/mathutil v1.5.0 // indirect
|
||||
modernc.org/memory v1.5.0 // indirect
|
||||
modernc.org/sqlite v1.21.0 // indirect
|
||||
)
|
||||
|
||||
18
interfaces/migrationTool.go
Normal file
18
interfaces/migrationTool.go
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.org
|
||||
* @Date: 2022-08-24 17:37:36
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-08-24 17:38:48
|
||||
* @FilePath: /CasaOS/interfaces/migrationTool.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package interfaces
|
||||
|
||||
type MigrationTool interface {
|
||||
IsMigrationNeeded() (bool, error)
|
||||
PostMigrate() error
|
||||
Migrate() error
|
||||
PreMigrate() error
|
||||
}
|
||||
43
internal/conf/config.go
Normal file
43
internal/conf/config.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package conf
|
||||
|
||||
type Database struct {
|
||||
Type string `json:"type" env:"DB_TYPE"`
|
||||
Host string `json:"host" env:"DB_HOST"`
|
||||
Port int `json:"port" env:"DB_PORT"`
|
||||
User string `json:"user" env:"DB_USER"`
|
||||
Password string `json:"password" env:"DB_PASS"`
|
||||
Name string `json:"name" env:"DB_NAME"`
|
||||
DBFile string `json:"db_file" env:"DB_FILE"`
|
||||
TablePrefix string `json:"table_prefix" env:"DB_TABLE_PREFIX"`
|
||||
SSLMode string `json:"ssl_mode" env:"DB_SSL_MODE"`
|
||||
}
|
||||
|
||||
type Scheme struct {
|
||||
Https bool `json:"https" env:"HTTPS"`
|
||||
CertFile string `json:"cert_file" env:"CERT_FILE"`
|
||||
KeyFile string `json:"key_file" env:"KEY_FILE"`
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
Enable bool `json:"enable" env:"LOG_ENABLE"`
|
||||
Name string `json:"name" env:"LOG_NAME"`
|
||||
MaxSize int `json:"max_size" env:"MAX_SIZE"`
|
||||
MaxBackups int `json:"max_backups" env:"MAX_BACKUPS"`
|
||||
MaxAge int `json:"max_age" env:"MAX_AGE"`
|
||||
Compress bool `json:"compress" env:"COMPRESS"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Force bool `json:"force" env:"FORCE"`
|
||||
Address string `json:"address" env:"ADDR"`
|
||||
Port int `json:"port" env:"PORT"`
|
||||
SiteURL string `json:"site_url" env:"SITE_URL"`
|
||||
Cdn string `json:"cdn" env:"CDN"`
|
||||
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
||||
TokenExpiresIn int `json:"token_expires_in" env:"TOKEN_EXPIRES_IN"`
|
||||
Database Database `json:"database"`
|
||||
Scheme Scheme `json:"scheme"`
|
||||
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
||||
BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"`
|
||||
Log LogConfig `json:"log"`
|
||||
}
|
||||
72
internal/conf/const.go
Normal file
72
internal/conf/const.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package conf
|
||||
|
||||
const (
|
||||
TypeString = "string"
|
||||
TypeSelect = "select"
|
||||
TypeBool = "bool"
|
||||
TypeText = "text"
|
||||
TypeNumber = "number"
|
||||
)
|
||||
|
||||
const (
|
||||
// site
|
||||
VERSION = "version"
|
||||
ApiUrl = "api_url"
|
||||
BasePath = "base_path"
|
||||
SiteTitle = "site_title"
|
||||
Announcement = "announcement"
|
||||
AllowIndexed = "allow_indexed"
|
||||
|
||||
Logo = "logo"
|
||||
Favicon = "favicon"
|
||||
MainColor = "main_color"
|
||||
|
||||
// preview
|
||||
TextTypes = "text_types"
|
||||
AudioTypes = "audio_types"
|
||||
VideoTypes = "video_types"
|
||||
ImageTypes = "image_types"
|
||||
ProxyTypes = "proxy_types"
|
||||
ProxyIgnoreHeaders = "proxy_ignore_headers"
|
||||
AudioAutoplay = "audio_autoplay"
|
||||
VideoAutoplay = "video_autoplay"
|
||||
|
||||
// global
|
||||
HideFiles = "hide_files"
|
||||
CustomizeHead = "customize_head"
|
||||
CustomizeBody = "customize_body"
|
||||
LinkExpiration = "link_expiration"
|
||||
SignAll = "sign_all"
|
||||
PrivacyRegs = "privacy_regs"
|
||||
OcrApi = "ocr_api"
|
||||
FilenameCharMapping = "filename_char_mapping"
|
||||
|
||||
// index
|
||||
SearchIndex = "search_index"
|
||||
AutoUpdateIndex = "auto_update_index"
|
||||
IndexPaths = "index_paths"
|
||||
IgnorePaths = "ignore_paths"
|
||||
|
||||
// aria2
|
||||
Aria2Uri = "aria2_uri"
|
||||
Aria2Secret = "aria2_secret"
|
||||
|
||||
// single
|
||||
Token = "token"
|
||||
IndexProgress = "index_progress"
|
||||
|
||||
//Github
|
||||
GithubClientId = "github_client_id"
|
||||
GithubClientSecrets = "github_client_secrets"
|
||||
GithubLoginEnabled = "github_login_enabled"
|
||||
)
|
||||
|
||||
const (
|
||||
UNKNOWN = iota
|
||||
FOLDER
|
||||
//OFFICE
|
||||
VIDEO
|
||||
AUDIO
|
||||
TEXT
|
||||
IMAGE
|
||||
)
|
||||
30
internal/conf/var.go
Normal file
30
internal/conf/var.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package conf
|
||||
|
||||
import "regexp"
|
||||
|
||||
var (
|
||||
BuiltAt string
|
||||
GoVersion string
|
||||
GitAuthor string
|
||||
GitCommit string
|
||||
Version string = "dev"
|
||||
WebVersion string
|
||||
)
|
||||
|
||||
var (
|
||||
Conf *Config
|
||||
)
|
||||
|
||||
var SlicesMap = make(map[string][]string)
|
||||
var FilenameCharMap = make(map[string]string)
|
||||
var PrivacyReg []*regexp.Regexp
|
||||
|
||||
var (
|
||||
// StoragesLoaded loaded success if empty
|
||||
StoragesLoaded = false
|
||||
)
|
||||
var (
|
||||
RawIndexHtml string
|
||||
ManageHtml string
|
||||
IndexHtml string
|
||||
)
|
||||
25
internal/driver/config.go
Normal file
25
internal/driver/config.go
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* @Author: a624669980@163.com a624669980@163.com
|
||||
* @Date: 2022-12-13 11:05:05
|
||||
* @LastEditors: a624669980@163.com a624669980@163.com
|
||||
* @LastEditTime: 2022-12-13 11:05:13
|
||||
* @FilePath: /drive/internal/driver/config.go
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
package driver
|
||||
|
||||
type Config struct {
|
||||
Name string `json:"name"`
|
||||
LocalSort bool `json:"local_sort"`
|
||||
OnlyLocal bool `json:"only_local"`
|
||||
OnlyProxy bool `json:"only_proxy"`
|
||||
NoCache bool `json:"no_cache"`
|
||||
NoUpload bool `json:"no_upload"`
|
||||
NeedMs bool `json:"need_ms"` // if need get message from user, such as validate code
|
||||
DefaultRoot string `json:"default_root"`
|
||||
CheckStatus bool
|
||||
}
|
||||
|
||||
func (c Config) MustProxy() bool {
|
||||
return c.OnlyProxy || c.OnlyLocal
|
||||
}
|
||||
133
internal/driver/driver.go
Normal file
133
internal/driver/driver.go
Normal file
@@ -0,0 +1,133 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
)
|
||||
|
||||
type Driver interface {
|
||||
Meta
|
||||
Reader
|
||||
User
|
||||
//Writer
|
||||
//Other
|
||||
}
|
||||
|
||||
type Meta interface {
|
||||
Config() Config
|
||||
// GetStorage just get raw storage, no need to implement, because model.Storage have implemented
|
||||
GetStorage() *model.StorageA
|
||||
SetStorage(model.StorageA)
|
||||
// GetAddition Additional is used for unmarshal of JSON, so need return pointer
|
||||
GetAddition() Additional
|
||||
// Init If already initialized, drop first
|
||||
Init(ctx context.Context) error
|
||||
Drop(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Other interface {
|
||||
Other(ctx context.Context, args model.OtherArgs) (interface{}, error)
|
||||
}
|
||||
|
||||
type Reader interface {
|
||||
// List files in the path
|
||||
// if identify files by path, need to set ID with path,like path.Join(dir.GetID(), obj.GetName())
|
||||
// if identify files by id, need to set ID with corresponding id
|
||||
// List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error)
|
||||
// Link get url/filepath/reader of file
|
||||
// Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error)
|
||||
}
|
||||
type User interface {
|
||||
// GetRoot get root directory of user
|
||||
GetUserInfo(ctx context.Context) (string, error)
|
||||
GetInfo(ctx context.Context) (string, string, string, error)
|
||||
}
|
||||
|
||||
type Getter interface {
|
||||
GetRoot(ctx context.Context) (model.Obj, error)
|
||||
}
|
||||
|
||||
//type Writer interface {
|
||||
// Mkdir
|
||||
// Move
|
||||
// Rename
|
||||
// Copy
|
||||
// Remove
|
||||
// Put
|
||||
//}
|
||||
|
||||
type Mkdir interface {
|
||||
MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error
|
||||
}
|
||||
|
||||
type Move interface {
|
||||
Move(ctx context.Context, srcObj, dstDir model.Obj) error
|
||||
}
|
||||
|
||||
type Rename interface {
|
||||
Rename(ctx context.Context, srcObj model.Obj, newName string) error
|
||||
}
|
||||
|
||||
type Copy interface {
|
||||
Copy(ctx context.Context, srcObj, dstDir model.Obj) error
|
||||
}
|
||||
|
||||
type Remove interface {
|
||||
Remove(ctx context.Context, obj model.Obj) error
|
||||
}
|
||||
|
||||
type Put interface {
|
||||
Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up UpdateProgress) error
|
||||
}
|
||||
|
||||
//type WriteResult interface {
|
||||
// MkdirResult
|
||||
// MoveResult
|
||||
// RenameResult
|
||||
// CopyResult
|
||||
// PutResult
|
||||
// Remove
|
||||
//}
|
||||
|
||||
type MkdirResult interface {
|
||||
MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error)
|
||||
}
|
||||
|
||||
type MoveResult interface {
|
||||
Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error)
|
||||
}
|
||||
|
||||
type RenameResult interface {
|
||||
Rename(ctx context.Context, srcObj model.Obj, newName string) (model.Obj, error)
|
||||
}
|
||||
|
||||
type CopyResult interface {
|
||||
Copy(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error)
|
||||
}
|
||||
|
||||
type PutResult interface {
|
||||
Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up UpdateProgress) (model.Obj, error)
|
||||
}
|
||||
|
||||
type UpdateProgress func(percentage int)
|
||||
|
||||
type Progress struct {
|
||||
Total int64
|
||||
Done int64
|
||||
up UpdateProgress
|
||||
}
|
||||
|
||||
func (p *Progress) Write(b []byte) (n int, err error) {
|
||||
n = len(b)
|
||||
p.Done += int64(n)
|
||||
p.up(int(float64(p.Done) / float64(p.Total) * 100))
|
||||
return
|
||||
}
|
||||
|
||||
func NewProgress(total int64, up UpdateProgress) *Progress {
|
||||
return &Progress{
|
||||
Total: total,
|
||||
up: up,
|
||||
}
|
||||
}
|
||||
56
internal/driver/item.go
Normal file
56
internal/driver/item.go
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* @Author: a624669980@163.com a624669980@163.com
|
||||
* @Date: 2022-12-13 11:05:47
|
||||
* @LastEditors: a624669980@163.com a624669980@163.com
|
||||
* @LastEditTime: 2022-12-13 11:05:54
|
||||
* @FilePath: /drive/internal/driver/item.go
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
package driver
|
||||
|
||||
type Additional interface{}
|
||||
|
||||
type Select string
|
||||
|
||||
type Item struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Default string `json:"default"`
|
||||
Options string `json:"options"`
|
||||
Required bool `json:"required"`
|
||||
Help string `json:"help"`
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
Common []Item `json:"common"`
|
||||
Additional []Item `json:"additional"`
|
||||
Config Config `json:"config"`
|
||||
}
|
||||
|
||||
type IRootPath interface {
|
||||
GetRootPath() string
|
||||
}
|
||||
|
||||
type IRootId interface {
|
||||
GetRootId() string
|
||||
}
|
||||
|
||||
type RootPath struct {
|
||||
RootFolderPath string `json:"root_folder_path"`
|
||||
}
|
||||
|
||||
type RootID struct {
|
||||
RootFolderID string `json:"root_folder_id" omit:"true"`
|
||||
}
|
||||
|
||||
func (r RootPath) GetRootPath() string {
|
||||
return r.RootFolderPath
|
||||
}
|
||||
|
||||
func (r *RootPath) SetRootPath(path string) {
|
||||
r.RootFolderPath = path
|
||||
}
|
||||
|
||||
func (r RootID) GetRootId() string {
|
||||
return r.RootFolderID
|
||||
}
|
||||
6
internal/op/const.go
Normal file
6
internal/op/const.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package op
|
||||
|
||||
const (
|
||||
WORK = "work"
|
||||
RootName = "root"
|
||||
)
|
||||
173
internal/op/driver.go
Normal file
173
internal/op/driver.go
Normal file
@@ -0,0 +1,173 @@
|
||||
package op
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/internal/conf"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/internal/driver"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type New func() driver.Driver
|
||||
|
||||
var driverNewMap = map[string]New{}
|
||||
var driverInfoMap = map[string][]driver.Item{} //driver.Info{}
|
||||
|
||||
func RegisterDriver(driver New) {
|
||||
// log.Infof("register driver: [%s]", config.Name)
|
||||
tempDriver := driver()
|
||||
tempConfig := tempDriver.Config()
|
||||
registerDriverItems(tempConfig, tempDriver.GetAddition())
|
||||
driverNewMap[tempConfig.Name] = driver
|
||||
}
|
||||
|
||||
func GetDriverNew(name string) (New, error) {
|
||||
n, ok := driverNewMap[name]
|
||||
if !ok {
|
||||
return nil, errors.Errorf("no driver named: %s", name)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func GetDriverNames() []string {
|
||||
var driverNames []string
|
||||
for k := range driverInfoMap {
|
||||
driverNames = append(driverNames, k)
|
||||
}
|
||||
return driverNames
|
||||
}
|
||||
|
||||
// func GetDriverInfoMap() map[string]driver.Info {
|
||||
// return driverInfoMap
|
||||
// }
|
||||
func GetDriverInfoMap() map[string][]driver.Item {
|
||||
return driverInfoMap
|
||||
}
|
||||
func registerDriverItems(config driver.Config, addition driver.Additional) {
|
||||
// log.Debugf("addition of %s: %+v", config.Name, addition)
|
||||
tAddition := reflect.TypeOf(addition)
|
||||
for tAddition.Kind() == reflect.Pointer {
|
||||
tAddition = tAddition.Elem()
|
||||
}
|
||||
//mainItems := getMainItems(config)
|
||||
additionalItems := getAdditionalItems(tAddition, config.DefaultRoot)
|
||||
driverInfoMap[config.Name] = additionalItems
|
||||
// driver.Info{
|
||||
// Common: mainItems,
|
||||
// Additional: additionalItems,
|
||||
// Config: config,
|
||||
// }
|
||||
}
|
||||
|
||||
func getMainItems(config driver.Config) []driver.Item {
|
||||
items := []driver.Item{{
|
||||
Name: "mount_path",
|
||||
Type: conf.TypeString,
|
||||
Required: true,
|
||||
Help: "",
|
||||
}, {
|
||||
Name: "order",
|
||||
Type: conf.TypeNumber,
|
||||
Help: "use to sort",
|
||||
}, {
|
||||
Name: "remark",
|
||||
Type: conf.TypeText,
|
||||
}}
|
||||
if !config.NoCache {
|
||||
items = append(items, driver.Item{
|
||||
Name: "cache_expiration",
|
||||
Type: conf.TypeNumber,
|
||||
Default: "30",
|
||||
Required: true,
|
||||
Help: "The cache expiration time for this storage",
|
||||
})
|
||||
}
|
||||
if !config.OnlyProxy && !config.OnlyLocal {
|
||||
items = append(items, []driver.Item{{
|
||||
Name: "web_proxy",
|
||||
Type: conf.TypeBool,
|
||||
}, {
|
||||
Name: "webdav_policy",
|
||||
Type: conf.TypeSelect,
|
||||
Options: "302_redirect,use_proxy_url,native_proxy",
|
||||
Default: "302_redirect",
|
||||
Required: true,
|
||||
},
|
||||
}...)
|
||||
} else {
|
||||
items = append(items, driver.Item{
|
||||
Name: "webdav_policy",
|
||||
Type: conf.TypeSelect,
|
||||
Default: "native_proxy",
|
||||
Options: "use_proxy_url,native_proxy",
|
||||
Required: true,
|
||||
})
|
||||
}
|
||||
items = append(items, driver.Item{
|
||||
Name: "down_proxy_url",
|
||||
Type: conf.TypeText,
|
||||
})
|
||||
if config.LocalSort {
|
||||
items = append(items, []driver.Item{{
|
||||
Name: "order_by",
|
||||
Type: conf.TypeSelect,
|
||||
Options: "name,size,modified",
|
||||
}, {
|
||||
Name: "order_direction",
|
||||
Type: conf.TypeSelect,
|
||||
Options: "asc,desc",
|
||||
}}...)
|
||||
}
|
||||
items = append(items, driver.Item{
|
||||
Name: "extract_folder",
|
||||
Type: conf.TypeSelect,
|
||||
Options: "front,back",
|
||||
})
|
||||
return items
|
||||
}
|
||||
|
||||
func getAdditionalItems(t reflect.Type, defaultRoot string) []driver.Item {
|
||||
var items []driver.Item
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
|
||||
field := t.Field(i)
|
||||
if field.Type.Kind() == reflect.Struct {
|
||||
items = append(items, getAdditionalItems(field.Type, defaultRoot)...)
|
||||
continue
|
||||
}
|
||||
tag := field.Tag
|
||||
ignore, ok1 := tag.Lookup("ignore")
|
||||
name, ok2 := tag.Lookup("json")
|
||||
if (ok1 && ignore == "true") || !ok2 {
|
||||
continue
|
||||
}
|
||||
if tag.Get("omit") == "true" {
|
||||
continue
|
||||
}
|
||||
item := driver.Item{
|
||||
Name: name,
|
||||
Type: strings.ToLower(field.Type.Name()),
|
||||
Default: tag.Get("default"),
|
||||
Options: tag.Get("options"),
|
||||
Required: tag.Get("required") == "true",
|
||||
Help: tag.Get("help"),
|
||||
}
|
||||
if tag.Get("type") != "" {
|
||||
item.Type = tag.Get("type")
|
||||
}
|
||||
if item.Name == "root_folder_id" || item.Name == "root_folder_path" {
|
||||
if item.Default == "" {
|
||||
item.Default = defaultRoot
|
||||
}
|
||||
item.Required = item.Default != ""
|
||||
}
|
||||
// set default type to string
|
||||
if item.Type == "" {
|
||||
item.Type = "string"
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
return items
|
||||
}
|
||||
109
internal/op/hook.go
Normal file
109
internal/op/hook.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package op
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/internal/conf"
|
||||
"github.com/IceWhaleTech/CasaOS/internal/driver"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Obj
|
||||
type ObjsUpdateHook = func(parent string, objs []model.Obj)
|
||||
|
||||
var (
|
||||
ObjsUpdateHooks = make([]ObjsUpdateHook, 0)
|
||||
)
|
||||
|
||||
func RegisterObjsUpdateHook(hook ObjsUpdateHook) {
|
||||
ObjsUpdateHooks = append(ObjsUpdateHooks, hook)
|
||||
}
|
||||
|
||||
func HandleObjsUpdateHook(parent string, objs []model.Obj) {
|
||||
for _, hook := range ObjsUpdateHooks {
|
||||
hook(parent, objs)
|
||||
}
|
||||
}
|
||||
|
||||
// Setting
|
||||
type SettingItemHook func(item *model.SettingItem) error
|
||||
|
||||
var settingItemHooks = map[string]SettingItemHook{
|
||||
conf.VideoTypes: func(item *model.SettingItem) error {
|
||||
conf.SlicesMap[conf.VideoTypes] = strings.Split(item.Value, ",")
|
||||
return nil
|
||||
},
|
||||
conf.AudioTypes: func(item *model.SettingItem) error {
|
||||
conf.SlicesMap[conf.AudioTypes] = strings.Split(item.Value, ",")
|
||||
return nil
|
||||
},
|
||||
conf.ImageTypes: func(item *model.SettingItem) error {
|
||||
conf.SlicesMap[conf.ImageTypes] = strings.Split(item.Value, ",")
|
||||
return nil
|
||||
},
|
||||
conf.TextTypes: func(item *model.SettingItem) error {
|
||||
conf.SlicesMap[conf.TextTypes] = strings.Split(item.Value, ",")
|
||||
return nil
|
||||
},
|
||||
conf.ProxyTypes: func(item *model.SettingItem) error {
|
||||
conf.SlicesMap[conf.ProxyTypes] = strings.Split(item.Value, ",")
|
||||
return nil
|
||||
},
|
||||
conf.ProxyIgnoreHeaders: func(item *model.SettingItem) error {
|
||||
conf.SlicesMap[conf.ProxyIgnoreHeaders] = strings.Split(item.Value, ",")
|
||||
return nil
|
||||
},
|
||||
conf.PrivacyRegs: func(item *model.SettingItem) error {
|
||||
regStrs := strings.Split(item.Value, "\n")
|
||||
regs := make([]*regexp.Regexp, 0, len(regStrs))
|
||||
for _, regStr := range regStrs {
|
||||
reg, err := regexp.Compile(regStr)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
regs = append(regs, reg)
|
||||
}
|
||||
conf.PrivacyReg = regs
|
||||
return nil
|
||||
},
|
||||
conf.FilenameCharMapping: func(item *model.SettingItem) error {
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.UnmarshalFromString(item.Value, &conf.FilenameCharMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("filename char mapping", zap.Any("FilenameCharMap", conf.FilenameCharMap))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func RegisterSettingItemHook(key string, hook SettingItemHook) {
|
||||
settingItemHooks[key] = hook
|
||||
}
|
||||
|
||||
func HandleSettingItemHook(item *model.SettingItem) (hasHook bool, err error) {
|
||||
if hook, ok := settingItemHooks[item.Key]; ok {
|
||||
return true, hook(item)
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// Storage
|
||||
type StorageHook func(typ string, storage driver.Driver)
|
||||
|
||||
var storageHooks = make([]StorageHook, 0)
|
||||
|
||||
func CallStorageHooks(typ string, storage driver.Driver) {
|
||||
for _, hook := range storageHooks {
|
||||
hook(typ, storage)
|
||||
}
|
||||
}
|
||||
|
||||
func RegisterStorageHook(hook StorageHook) {
|
||||
storageHooks = append(storageHooks, hook)
|
||||
}
|
||||
36
internal/sign/sign.go
Normal file
36
internal/sign/sign.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package sign
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/sign"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
var instance sign.Sign
|
||||
|
||||
func Sign(data string) string {
|
||||
|
||||
return NotExpired(data)
|
||||
|
||||
}
|
||||
|
||||
func WithDuration(data string, d time.Duration) string {
|
||||
once.Do(Instance)
|
||||
return instance.Sign(data, time.Now().Add(d).Unix())
|
||||
}
|
||||
|
||||
func NotExpired(data string) string {
|
||||
once.Do(Instance)
|
||||
return instance.Sign(data, 0)
|
||||
}
|
||||
|
||||
func Verify(data string, sign string) error {
|
||||
once.Do(Instance)
|
||||
return instance.Verify(data, sign)
|
||||
}
|
||||
|
||||
func Instance() {
|
||||
instance = sign.NewHMACSign([]byte("token"))
|
||||
}
|
||||
242
main.go
242
main.go
@@ -1,63 +1,92 @@
|
||||
//go:generate bash -c "mkdir -p codegen && go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.12.4 -generate types,server,spec -package codegen api/casaos/openapi.yaml > codegen/casaos_api.go"
|
||||
//go:generate bash -c "mkdir -p codegen/message_bus && go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.12.4 -generate types,client -package message_bus https://raw.githubusercontent.com/IceWhaleTech/CasaOS-MessageBus/main/api/message_bus/openapi.yaml > codegen/message_bus/api.go"
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model/notify"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/model"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/constants"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
|
||||
util_http "github.com/IceWhaleTech/CasaOS-Common/utils/http"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/common"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/cache"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/encryption"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/random"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/command"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
"github.com/IceWhaleTech/CasaOS/route"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/IceWhaleTech/CasaOS/types"
|
||||
"github.com/coreos/go-systemd/daemon"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/robfig/cron"
|
||||
"github.com/robfig/cron/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const LOCALHOST = "127.0.0.1"
|
||||
|
||||
var sqliteDB *gorm.DB
|
||||
|
||||
var configFlag = flag.String("c", "", "config address")
|
||||
var dbFlag = flag.String("db", "", "db path")
|
||||
var resetUser = flag.Bool("ru", false, "reset user")
|
||||
var user = flag.String("user", "", "user name")
|
||||
var version = flag.Bool("v", false, "show version")
|
||||
var (
|
||||
commit = "private build"
|
||||
date = "private build"
|
||||
|
||||
//go:embed api/index.html
|
||||
_docHTML string
|
||||
|
||||
//go:embed api/casaos/openapi.yaml
|
||||
_docYAML string
|
||||
|
||||
//go:embed build/sysroot/etc/casaos/casaos.conf.sample
|
||||
_confSample string
|
||||
|
||||
configFlag = flag.String("c", "", "config address")
|
||||
dbFlag = flag.String("db", "", "db path")
|
||||
versionFlag = flag.Bool("v", false, "version")
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.Parse()
|
||||
if *version {
|
||||
fmt.Println("v" + types.CURRENTVERSION)
|
||||
if *versionFlag {
|
||||
fmt.Println("v" + common.VERSION)
|
||||
return
|
||||
}
|
||||
config.InitSetup(*configFlag)
|
||||
config.UpdateSetup()
|
||||
|
||||
loger.LogInit()
|
||||
println("git commit:", commit)
|
||||
println("build date:", date)
|
||||
|
||||
config.InitSetup(*configFlag, _confSample)
|
||||
|
||||
logger.LogInit(config.AppInfo.LogPath, config.AppInfo.LogSaveName, config.AppInfo.LogFileExt)
|
||||
if len(*dbFlag) == 0 {
|
||||
*dbFlag = config.AppInfo.DBPath + "/db"
|
||||
}
|
||||
|
||||
sqliteDB = sqlite.GetDb(*dbFlag)
|
||||
//gredis.GetRedisConn(config.RedisInfo),
|
||||
// gredis.GetRedisConn(config.RedisInfo),
|
||||
|
||||
service.MyService = service.NewService(sqliteDB)
|
||||
service.MyService = service.NewService(sqliteDB, config.CommonInfo.RuntimePath)
|
||||
|
||||
service.Cache = cache.Init()
|
||||
|
||||
service.GetToken()
|
||||
service.GetCPUThermalZone()
|
||||
|
||||
service.NewVersionApp = make(map[string]string)
|
||||
route.InitFunction()
|
||||
|
||||
// go service.LoopFriend()
|
||||
// go service.MyService.App().CheckNewImage()
|
||||
|
||||
//service.MyService.System().GenreateSystemEntry()
|
||||
///
|
||||
//service.MountLists = make(map[string]*mountlib.MountPoint)
|
||||
//configfile.Install()
|
||||
}
|
||||
|
||||
// @title casaOS API
|
||||
@@ -72,63 +101,130 @@ func init() {
|
||||
// @name Authorization
|
||||
// @BasePath /v1
|
||||
func main() {
|
||||
service.NotifyMsg = make(chan notify.Message, 10)
|
||||
if *version {
|
||||
if *versionFlag {
|
||||
return
|
||||
}
|
||||
if *resetUser {
|
||||
if user == nil || len(*user) == 0 {
|
||||
fmt.Println("user is empty")
|
||||
return
|
||||
}
|
||||
userData := service.MyService.User().GetUserAllInfoByName(*user)
|
||||
if userData.Id == 0 {
|
||||
fmt.Println("user not exist")
|
||||
return
|
||||
}
|
||||
password := random.RandomString(6, false)
|
||||
userData.Password = encryption.GetMD5ByStr(password)
|
||||
service.MyService.User().UpdateUserPassword(userData)
|
||||
fmt.Println("User reset successful")
|
||||
fmt.Println("UserName:" + userData.Username)
|
||||
fmt.Println("Password:" + password)
|
||||
return
|
||||
}
|
||||
go route.SocketInit(service.NotifyMsg)
|
||||
go route.MonitoryUSB()
|
||||
//model.Setup()
|
||||
//gredis.Setup()
|
||||
r := route.InitRouter()
|
||||
//service.SyncTask(sqliteDB)
|
||||
cron2 := cron.New()
|
||||
//every day execution
|
||||
v1Router := route.InitV1Router()
|
||||
|
||||
err := cron2.AddFunc("0/5 * * * * *", func() {
|
||||
if service.ClientCount > 0 {
|
||||
//route.SendNetINfoBySocket()
|
||||
//route.SendCPUBySocket()
|
||||
//route.SendMemBySocket()
|
||||
// route.SendDiskBySocket()
|
||||
//route.SendUSBBySocket()
|
||||
route.SendAllHardwareStatusBySocket()
|
||||
v2Router := route.InitV2Router()
|
||||
v2DocRouter := route.InitV2DocRouter(_docHTML, _docYAML)
|
||||
v3File := route.InitFile()
|
||||
mux := &util_http.HandlerMultiplexer{
|
||||
HandlerMap: map[string]http.Handler{
|
||||
"v1": v1Router,
|
||||
"v2": v2Router,
|
||||
"v3": v3File,
|
||||
"doc": v2DocRouter,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
crontab := cron.New(cron.WithSeconds())
|
||||
if _, err := crontab.AddFunc("@every 5s", route.SendAllHardwareStatusBySocket); err != nil {
|
||||
logger.Error("add crontab error", zap.Error(err))
|
||||
}
|
||||
|
||||
crontab.Start()
|
||||
defer crontab.Stop()
|
||||
|
||||
listener, err := net.Listen("tcp", net.JoinHostPort(LOCALHOST, "0"))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
panic(err)
|
||||
}
|
||||
cron2.Start()
|
||||
defer cron2.Stop()
|
||||
routers := []string{
|
||||
"/v1/sys",
|
||||
"/v1/port",
|
||||
"/v1/file",
|
||||
"/v1/folder",
|
||||
"/v1/batch",
|
||||
"/v1/image",
|
||||
"/v1/samba",
|
||||
"/v1/notify",
|
||||
"/v1/driver",
|
||||
"/v1/cloud",
|
||||
"/v1/recover",
|
||||
"/v1/other",
|
||||
"/v1/zt",
|
||||
"/v1/test",
|
||||
route.V2APIPath,
|
||||
route.V2DocPath,
|
||||
route.V3FilePath,
|
||||
}
|
||||
for _, apiPath := range routers {
|
||||
err = service.MyService.Gateway().CreateRoute(&model.Route{
|
||||
Path: apiPath,
|
||||
Target: "http://" + listener.Addr().String(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("err", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// register at message bus
|
||||
for i := 0; i < 10; i++ {
|
||||
response, err := service.MyService.MessageBus().RegisterEventTypesWithResponse(context.Background(), common.EventTypes)
|
||||
if err != nil {
|
||||
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.Error(err))
|
||||
}
|
||||
if response != nil && response.StatusCode() != http.StatusOK {
|
||||
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.String("status", response.Status()), zap.String("body", string(response.Body)))
|
||||
}
|
||||
if response.StatusCode() == http.StatusOK {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
go func() {
|
||||
time.Sleep(time.Second * 2)
|
||||
// v0.3.6
|
||||
if config.ServerInfo.HttpPort != "" {
|
||||
changePort := model.ChangePortRequest{}
|
||||
changePort.Port = config.ServerInfo.HttpPort
|
||||
err := service.MyService.Gateway().ChangePort(&changePort)
|
||||
if err == nil {
|
||||
config.Cfg.Section("server").Key("HttpPort").SetValue("")
|
||||
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
urlFilePath := filepath.Join(config.CommonInfo.RuntimePath, "casaos.url")
|
||||
if err := file.CreateFileAndWriteContent(urlFilePath, "http://"+listener.Addr().String()); err != nil {
|
||||
logger.Error("error when creating address file", zap.Error(err),
|
||||
zap.Any("address", listener.Addr().String()),
|
||||
zap.Any("filepath", urlFilePath),
|
||||
)
|
||||
}
|
||||
|
||||
// run any script that needs to be executed
|
||||
scriptDirectory := filepath.Join(constants.DefaultConfigPath, "start.d")
|
||||
command.ExecuteScripts(scriptDirectory)
|
||||
|
||||
if supported, err := daemon.SdNotify(false, daemon.SdNotifyReady); err != nil {
|
||||
logger.Error("Failed to notify systemd that casaos main service is ready", zap.Any("error", err))
|
||||
} else if supported {
|
||||
logger.Info("Notified systemd that casaos main service is ready")
|
||||
} else {
|
||||
logger.Info("This process is not running as a systemd service.")
|
||||
}
|
||||
// http.HandleFunc("/v1/file/test", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// //http.ServeFile(w, r, r.URL.Path[1:])
|
||||
// http.ServeFile(w, r, "/DATA/test.img")
|
||||
// })
|
||||
// go http.ListenAndServe(":8081", nil)
|
||||
|
||||
s := &http.Server{
|
||||
Addr: fmt.Sprintf(":%v", config.ServerInfo.HttpPort),
|
||||
Handler: r,
|
||||
ReadTimeout: 60 * time.Second,
|
||||
WriteTimeout: 60 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
Handler: mux,
|
||||
ReadHeaderTimeout: 5 * time.Second, // fix G112: Potential slowloris attack (see https://github.com/securego/gosec)
|
||||
}
|
||||
|
||||
s.ListenAndServe()
|
||||
|
||||
// if err := r.Run(fmt.Sprintf(":%v", config.ServerInfo.HttpPort)); err != nil {
|
||||
// fmt.Println("failed run app: ", err)
|
||||
// }
|
||||
logger.Info("CasaOS main service is listening...", zap.Any("address", listener.Addr().String()))
|
||||
// defer service.MyService.Storage().UnmountAllStorage()
|
||||
err = s.Serve(listener) // not using http.serve() to fix G114: Use of net/http serve function that has no support for setting timeouts (see https://github.com/securego/gosec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-10-08 10:29:08
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-22 11:06:07
|
||||
* @FilePath: /CasaOS/middleware/gin.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Cors() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
method := c.Request.Method
|
||||
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE")
|
||||
//允许跨域设置可以返回其他子段,可以自定义字段
|
||||
c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session,Language,Content-Type,Access-Control-Allow-Origin,Access-Control-Allow-Headers,Access-Control-Allow-Methods,Connection,Host,Origin,Referer,User-Agent,X-Requested-With")
|
||||
// 允许浏览器(客户端)可以解析的头部 (重要)
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers")
|
||||
//c.Writer.Header().Set("Access-Control-Allow-Headers", "Accept, Authorization, Content-Type, Content-Length, X-CSRF-Token, Token, session, Origin, Host, Connection, Accept-Encoding, Accept-Language, X-Requested-With")
|
||||
//设置缓存时间
|
||||
c.Header("Access-Control-Max-Age", "172800")
|
||||
c.Header("Access-Control-Allow-Credentials", "true")
|
||||
c.Set("Content-Type", "application/json")
|
||||
//}
|
||||
|
||||
//允许类型校验
|
||||
if method == "OPTIONS" {
|
||||
c.JSON(http.StatusOK, "ok!")
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
func WriteLog() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if !strings.Contains(c.Request.URL.String(), "password") {
|
||||
loger.Info("request:", zap.Any("path", c.Request.URL.String()), zap.Any("param", c.Params), zap.Any("query", c.Request.URL.Query()), zap.Any("method", c.Request.Method))
|
||||
c.Next()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
128
model/app.go
128
model/app.go
@@ -1,128 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ServerAppListCollection struct {
|
||||
List []ServerAppList `json:"list"`
|
||||
Recommend []ServerAppList `json:"recommend"`
|
||||
Community []ServerAppList `json:"community"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// @tiger - 对于用于出参的数据结构,静态信息(例如 title)和
|
||||
// 动态信息(例如 state、query_count)应该划分到不同的数据结构中
|
||||
//
|
||||
// 这样的好处是
|
||||
// 1 - 多次获取动态信息时可以减少出参复杂度,因为静态信息只获取一次就好
|
||||
// 2 - 在未来的迭代中,可以降低维护成本(所有字段都展开放在一个层级维护成本略高)
|
||||
//
|
||||
// 另外,一些针对性字段,例如 Docker 相关的,可以用 map 来保存。
|
||||
// 这样在未来增加多态 App,例如 Snap,不需要维护多个结构,或者一个结构保存不必要的字段
|
||||
type ServerAppList struct {
|
||||
Id uint `gorm:"column:id;primary_key" json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Tagline string `json:"tagline"`
|
||||
Tags Strings `gorm:"type:json" json:"tags"`
|
||||
Icon string `json:"icon"`
|
||||
ScreenshotLink Strings `gorm:"type:json" json:"screenshot_link"`
|
||||
Category string `json:"category"`
|
||||
CategoryId int `json:"category_id"`
|
||||
CategoryFont string `json:"category_font"`
|
||||
PortMap string `json:"port_map"`
|
||||
ImageVersion string `json:"image_version"`
|
||||
Tip string `json:"tip"`
|
||||
Envs EnvArray `json:"envs"`
|
||||
Ports PortArray `json:"ports"`
|
||||
Volumes PathArray `json:"volumes"`
|
||||
Devices PathArray `json:"devices"`
|
||||
NetworkModel string `json:"network_model"`
|
||||
Image string `json:"image"`
|
||||
Index string `json:"index"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
State int `json:"state"`
|
||||
Author string `json:"author"`
|
||||
MinMemory int `json:"min_memory"`
|
||||
MinDisk int `json:"min_disk"`
|
||||
MaxMemory uint64 `json:"max_memory"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
Healthy string `json:"healthy"`
|
||||
Plugins Strings `json:"plugins"`
|
||||
Origin string `json:"origin"`
|
||||
Type int `json:"type"`
|
||||
QueryCount int `json:"query_count"`
|
||||
Developer string `json:"developer"`
|
||||
HostName string `json:"host_name"`
|
||||
Privileged bool `json:"privileged"`
|
||||
CapAdd Strings `json:"cap_add"`
|
||||
Cmd Strings `json:"cmd"`
|
||||
}
|
||||
|
||||
type Ports struct {
|
||||
ContainerPort uint `json:"container_port"`
|
||||
CommendPort int `json:"commend_port"`
|
||||
Desc string `json:"desc"`
|
||||
Type int `json:"type"` // 1:必选 2:可选 3:默认值不必显示 4:系统处理 5:container内容也可编辑
|
||||
}
|
||||
|
||||
type Volume struct {
|
||||
ContainerPath string `json:"container_path"`
|
||||
Path string `json:"path"`
|
||||
Desc string `json:"desc"`
|
||||
Type int `json:"type"` // 1:必选 2:可选 3:默认值不必显示 4:系统处理 5:container内容也可编辑
|
||||
}
|
||||
|
||||
type Envs struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
Desc string `json:"desc"`
|
||||
Type int `json:"type"` // 1:必选 2:可选 3:默认值不必显示 4:系统处理 5:container内容也可编辑
|
||||
}
|
||||
|
||||
type Devices struct {
|
||||
ContainerPath string `json:"container_path"`
|
||||
Path string `json:"path"`
|
||||
Desc string `json:"desc"`
|
||||
Type int `json:"type"` // 1:必选 2:可选 3:默认值不必显示 4:系统处理 5:container内容也可编辑
|
||||
}
|
||||
|
||||
type configures struct {
|
||||
TcpPorts []Ports `json:"tcp_ports"`
|
||||
UdpPorts []Ports `json:"udp_ports"`
|
||||
Envs []Envs `json:"envs"`
|
||||
Volumes []Volume `json:"volumes"`
|
||||
Devices []Devices `json:"devices"`
|
||||
}
|
||||
|
||||
/****************使gorm支持[]string结构*******************/
|
||||
type Strings []string
|
||||
|
||||
func (c Strings) Value() (driver.Value, error) {
|
||||
b, err := json.Marshal(c)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
func (c *Strings) Scan(input interface{}) error {
|
||||
return json.Unmarshal(input.([]byte), c)
|
||||
}
|
||||
|
||||
/****************使gorm支持[]string结构*******************/
|
||||
|
||||
/****************使gorm支持[]string结构*******************/
|
||||
type MapStrings []map[string]string
|
||||
|
||||
func (c MapStrings) Value() (driver.Value, error) {
|
||||
b, err := json.Marshal(c)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
func (c *MapStrings) Scan(input interface{}) error {
|
||||
return json.Unmarshal(input.([]byte), c)
|
||||
}
|
||||
|
||||
/****************使gorm支持[]string结构*******************/
|
||||
39
model/args.go
Normal file
39
model/args.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ListArgs struct {
|
||||
ReqPath string
|
||||
}
|
||||
|
||||
type LinkArgs struct {
|
||||
IP string
|
||||
Header http.Header
|
||||
Type string
|
||||
}
|
||||
|
||||
type Link struct {
|
||||
URL string `json:"url"`
|
||||
Header http.Header `json:"header"` // needed header
|
||||
Data io.ReadCloser // return file reader directly
|
||||
Status int // status maybe 200 or 206, etc
|
||||
FilePath *string // local file, return the filepath
|
||||
Expiration *time.Duration // url expiration time
|
||||
Method string `json:"method"` // http method
|
||||
}
|
||||
|
||||
type OtherArgs struct {
|
||||
Obj Obj
|
||||
Method string
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
type FsOtherArgs struct {
|
||||
Path string `json:"path" form:"path"`
|
||||
Method string `json:"method" form:"method"`
|
||||
Data interface{} `json:"data" form:"data"`
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* @Author: link a624669980@163.com
|
||||
* @Date: 2022-05-16 17:37:08
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-13 10:46:38
|
||||
* @FilePath: /CasaOS/model/category.go
|
||||
* @Description:
|
||||
*/
|
||||
package model
|
||||
|
||||
type ServerCategoryList struct {
|
||||
Version string `json:"version"`
|
||||
Item []CategoryList `json:"item"`
|
||||
}
|
||||
type CategoryList struct {
|
||||
Id uint `gorm:"column:id;primary_key" json:"id"`
|
||||
//CreatedAt time.Time `json:"created_at"`
|
||||
//
|
||||
//UpdatedAt time.Time `json:"updated_at"`
|
||||
Font string `json:"font"` // @tiger - 如果这个和前端有关,应该不属于后端的出参范围,而是前端去界定
|
||||
Name string `json:"name"`
|
||||
Count uint `json:"count"` // @tiger - count 属于动态信息,应该单独放在一个出参结构中(原因见另外一个关于 静态/动态 出参的注释)
|
||||
}
|
||||
6
model/common.go
Normal file
6
model/common.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type PageResp struct {
|
||||
Content interface{} `json:"content"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-07-13 10:43:45
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-08-03 14:45:35
|
||||
* @FilePath: /CasaOS/model/disk.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package model
|
||||
|
||||
type LSBLKModel struct {
|
||||
Name string `json:"name"`
|
||||
FsType string `json:"fstype"`
|
||||
Size uint64 `json:"size"`
|
||||
FSSize string `json:"fssize"`
|
||||
Path string `json:"path"`
|
||||
Model string `json:"model"` //设备标识符
|
||||
RM bool `json:"rm"` //是否为可移动设备
|
||||
RO bool `json:"ro"` //是否为只读设备
|
||||
State string `json:"state"`
|
||||
PhySec int `json:"phy-sec"` //物理扇区大小
|
||||
Type string `json:"type"`
|
||||
Vendor string `json:"vendor"` //供应商
|
||||
Rev string `json:"rev"` //修订版本
|
||||
FSAvail string `json:"fsavail"` //可用空间
|
||||
FSUse string `json:"fsuse%"` //已用百分比
|
||||
MountPoint string `json:"mountpoint"`
|
||||
Format string `json:"format"`
|
||||
Health string `json:"health"`
|
||||
HotPlug bool `json:"hotplug"`
|
||||
UUID string `json:"uuid"`
|
||||
FSUsed string `json:"fsused"`
|
||||
Temperature int `json:"temperature"`
|
||||
Tran string `json:"tran"`
|
||||
MinIO uint64 `json:"min-io"`
|
||||
UsedPercent float64 `json:"used_percent"`
|
||||
Serial string `json:"serial"`
|
||||
Children []LSBLKModel `json:"children"`
|
||||
SubSystems string `json:"subsystems"`
|
||||
Label string `json:"label"`
|
||||
//详情特有
|
||||
StartSector uint64 `json:"start_sector,omitempty"`
|
||||
Rota bool `json:"rota"` //true(hhd) false(ssd)
|
||||
DiskType string `json:"disk_type"`
|
||||
EndSector uint64 `json:"end_sector,omitempty"`
|
||||
}
|
||||
|
||||
type Drive struct {
|
||||
Name string `json:"name"`
|
||||
Size uint64 `json:"size"`
|
||||
Model string `json:"model"`
|
||||
Health string `json:"health"`
|
||||
Temperature int `json:"temperature"`
|
||||
DiskType string `json:"disk_type"`
|
||||
NeedFormat bool `json:"need_format"`
|
||||
Serial string `json:"serial"`
|
||||
Path string `json:"path"`
|
||||
ChildrenNumber int `json:"children_number"`
|
||||
}
|
||||
|
||||
type DriveUSB struct {
|
||||
Name string `json:"name"`
|
||||
Size uint64 `json:"size"`
|
||||
Model string `json:"model"`
|
||||
Avail uint64 `json:"avail"`
|
||||
Children []USBChildren `json:"children"`
|
||||
}
|
||||
type USBChildren struct {
|
||||
Name string `json:"name"`
|
||||
Size uint64 `json:"size"`
|
||||
Avail uint64 `json:"avail"`
|
||||
MountPoint string `json:"mount_point"`
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
MountPoint string `json:"mount_point"`
|
||||
Size string `json:"size"`
|
||||
Avail string `json:"avail"` //可用空间
|
||||
Type string `json:"type"`
|
||||
Path string `json:"path"`
|
||||
DriveName string `json:"drive_name"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
type Storages struct {
|
||||
DiskName string `json:"disk_name"`
|
||||
Size uint64 `json:"size"`
|
||||
Path string `json:"path"`
|
||||
Children []Storage `json:"children"`
|
||||
}
|
||||
|
||||
type Summary struct {
|
||||
Size uint64 `json:"size"`
|
||||
Avail uint64 `json:"avail"` //可用空间
|
||||
Health bool `json:"health"`
|
||||
Used uint64 `json:"used"`
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-12-08 18:10:25
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-07-13 10:49:16
|
||||
* @FilePath: /CasaOS/model/docker.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package model
|
||||
|
||||
type DockerStatsModel struct {
|
||||
Icon string `json:"icon"`
|
||||
Title string `json:"title"`
|
||||
Data interface{} `json:"data"`
|
||||
Previous interface{} `json:"previous"`
|
||||
}
|
||||
7
model/drive.go
Normal file
7
model/drive.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
type Drive struct {
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
AuthUrl string `json:"auth_url"`
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type TcpPorts struct {
|
||||
Desc string `json:"desc"`
|
||||
ContainerPort int `json:"container_port"`
|
||||
}
|
||||
type UdpPorts struct {
|
||||
Desc string `json:"desc"`
|
||||
ContainerPort int `json:"container_port"`
|
||||
}
|
||||
|
||||
/*******************使用gorm支持json************************************/
|
||||
|
||||
type PortMap struct {
|
||||
ContainerPort string `json:"container"`
|
||||
CommendPort string `json:"host"`
|
||||
Protocol string `json:"protocol"`
|
||||
Desc string `json:"desc"`
|
||||
Type int `json:"type"`
|
||||
}
|
||||
|
||||
type PortArray []PortMap
|
||||
|
||||
// Value 实现方法
|
||||
func (p PortArray) Value() (driver.Value, error) {
|
||||
return json.Marshal(p)
|
||||
}
|
||||
|
||||
// Scan 实现方法
|
||||
func (p *PortArray) Scan(input interface{}) error {
|
||||
return json.Unmarshal(input.([]byte), p)
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/*******************使用gorm支持json************************************/
|
||||
|
||||
type Env struct {
|
||||
Name string `json:"container"`
|
||||
Value string `json:"host"`
|
||||
Desc string `json:"desc"`
|
||||
Type int `json:"type"`
|
||||
}
|
||||
|
||||
type JSON json.RawMessage
|
||||
|
||||
type EnvArray []Env
|
||||
|
||||
// Value 实现方法
|
||||
func (p EnvArray) Value() (driver.Value, error) {
|
||||
return json.Marshal(p)
|
||||
//return .MarshalJSON()
|
||||
}
|
||||
|
||||
// Scan 实现方法
|
||||
func (p *EnvArray) Scan(input interface{}) error {
|
||||
return json.Unmarshal(input.([]byte), p)
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/*******************使用gorm支持json************************************/
|
||||
|
||||
type PathMap struct {
|
||||
ContainerPath string `json:"container"`
|
||||
Path string `json:"host"`
|
||||
Type int `json:"type"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
type PathArray []PathMap
|
||||
|
||||
// Value 实现方法
|
||||
func (p PathArray) Value() (driver.Value, error) {
|
||||
return json.Marshal(p)
|
||||
}
|
||||
|
||||
// Scan 实现方法
|
||||
func (p *PathArray) Scan(input interface{}) error {
|
||||
return json.Unmarshal(input.([]byte), p)
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
//type PostData struct {
|
||||
// Envs EnvArrey `json:"envs,omitempty"`
|
||||
// Udp PortArrey `json:"udp_ports"`
|
||||
// Tcp PortArrey `json:"tcp_ports"`
|
||||
// Volumes PathArrey `json:"volumes"`
|
||||
// Devices PathArrey `json:"devices"`
|
||||
// Port string `json:"port,omitempty"`
|
||||
// PortMap string `json:"port_map"`
|
||||
// CpuShares int64 `json:"cpu_shares,omitempty"`
|
||||
// Memory int64 `json:"memory,omitempty"`
|
||||
// Restart string `json:"restart,omitempty"`
|
||||
// EnableUPNP bool `json:"enable_upnp"`
|
||||
// Label string `json:"label"`
|
||||
// Position bool `json:"position"`
|
||||
//}
|
||||
|
||||
type CustomizationPostData struct {
|
||||
ContainerName string `json:"container_name"`
|
||||
CustomId string `json:"custom_id"`
|
||||
Origin string `json:"origin"`
|
||||
NetworkModel string `json:"network_model"`
|
||||
Index string `json:"index"`
|
||||
Icon string `json:"icon"`
|
||||
Image string `json:"image"`
|
||||
Envs EnvArray `json:"envs"`
|
||||
Ports PortArray `json:"ports"`
|
||||
Volumes PathArray `json:"volumes"`
|
||||
Devices PathArray `json:"devices"`
|
||||
//Port string `json:"port,omitempty"`
|
||||
PortMap string `json:"port_map"`
|
||||
CpuShares int64 `json:"cpu_shares"`
|
||||
Memory int64 `json:"memory"`
|
||||
Restart string `json:"restart"`
|
||||
EnableUPNP bool `json:"enable_upnp"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
Position bool `json:"position"`
|
||||
HostName string `json:"host_name"`
|
||||
Privileged bool `json:"privileged"`
|
||||
CapAdd []string `json:"cap_add"`
|
||||
Cmd []string `json:"cmd"`
|
||||
Protocol string `json:"protocol"`
|
||||
Host string `json:"host"`
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-27 15:01:58
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-05-31 14:51:21
|
||||
* @FilePath: /CasaOS/model/notify/application.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package notify
|
||||
|
||||
type Application struct {
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Type string `json:"type"`
|
||||
Icon string `json:"icon"`
|
||||
Message string `json:"message"`
|
||||
Finished bool `json:"finished"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-05-26 14:39:22
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-05-26 19:08:52
|
||||
* @FilePath: /CasaOS/model/notify/message.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package notify
|
||||
|
||||
import (
|
||||
f "github.com/ambelovsky/gosf"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Path string `json:"path"`
|
||||
Msg f.Message `json:"msg"`
|
||||
}
|
||||
186
model/obj.go
Normal file
186
model/obj.go
Normal file
@@ -0,0 +1,186 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"io"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
|
||||
"github.com/maruel/natural"
|
||||
)
|
||||
|
||||
type UnwrapObj interface {
|
||||
Unwrap() Obj
|
||||
}
|
||||
|
||||
type Obj interface {
|
||||
GetSize() int64
|
||||
GetName() string
|
||||
ModTime() time.Time
|
||||
IsDir() bool
|
||||
|
||||
// The internal information of the driver.
|
||||
// If you want to use it, please understand what it means
|
||||
GetID() string
|
||||
GetPath() string
|
||||
}
|
||||
|
||||
type FileStreamer interface {
|
||||
io.ReadCloser
|
||||
Obj
|
||||
GetMimetype() string
|
||||
SetReadCloser(io.ReadCloser)
|
||||
NeedStore() bool
|
||||
GetReadCloser() io.ReadCloser
|
||||
GetOld() Obj
|
||||
}
|
||||
|
||||
type URL interface {
|
||||
URL() string
|
||||
}
|
||||
|
||||
type Thumb interface {
|
||||
Thumb() string
|
||||
}
|
||||
|
||||
type SetPath interface {
|
||||
SetPath(path string)
|
||||
}
|
||||
|
||||
func SortFiles(objs []Obj, orderBy, orderDirection string) {
|
||||
if orderBy == "" {
|
||||
return
|
||||
}
|
||||
sort.Slice(objs, func(i, j int) bool {
|
||||
switch orderBy {
|
||||
case "name":
|
||||
{
|
||||
c := natural.Less(objs[i].GetName(), objs[j].GetName())
|
||||
if orderDirection == "desc" {
|
||||
return !c
|
||||
}
|
||||
return c
|
||||
}
|
||||
case "size":
|
||||
{
|
||||
if orderDirection == "desc" {
|
||||
return objs[i].GetSize() >= objs[j].GetSize()
|
||||
}
|
||||
return objs[i].GetSize() <= objs[j].GetSize()
|
||||
}
|
||||
case "modified":
|
||||
if orderDirection == "desc" {
|
||||
return objs[i].ModTime().After(objs[j].ModTime())
|
||||
}
|
||||
return objs[i].ModTime().Before(objs[j].ModTime())
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
func ExtractFolder(objs []Obj, extractFolder string) {
|
||||
if extractFolder == "" {
|
||||
return
|
||||
}
|
||||
front := extractFolder == "front"
|
||||
sort.SliceStable(objs, func(i, j int) bool {
|
||||
if objs[i].IsDir() || objs[j].IsDir() {
|
||||
if !objs[i].IsDir() {
|
||||
return !front
|
||||
}
|
||||
if !objs[j].IsDir() {
|
||||
return front
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
// Wrap
|
||||
func WrapObjName(objs Obj) Obj {
|
||||
return &ObjWrapName{Obj: objs}
|
||||
}
|
||||
|
||||
func WrapObjsName(objs []Obj) {
|
||||
for i := 0; i < len(objs); i++ {
|
||||
objs[i] = &ObjWrapName{Obj: objs[i]}
|
||||
}
|
||||
}
|
||||
|
||||
func UnwrapObjs(obj Obj) Obj {
|
||||
if unwrap, ok := obj.(UnwrapObj); ok {
|
||||
obj = unwrap.Unwrap()
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
func GetThumb(obj Obj) (thumb string, ok bool) {
|
||||
if obj, ok := obj.(Thumb); ok {
|
||||
return obj.Thumb(), true
|
||||
}
|
||||
if unwrap, ok := obj.(UnwrapObj); ok {
|
||||
return GetThumb(unwrap.Unwrap())
|
||||
}
|
||||
return thumb, false
|
||||
}
|
||||
|
||||
func GetUrl(obj Obj) (url string, ok bool) {
|
||||
if obj, ok := obj.(URL); ok {
|
||||
return obj.URL(), true
|
||||
}
|
||||
if unwrap, ok := obj.(UnwrapObj); ok {
|
||||
return GetUrl(unwrap.Unwrap())
|
||||
}
|
||||
return url, false
|
||||
}
|
||||
|
||||
// Merge
|
||||
func NewObjMerge() *ObjMerge {
|
||||
return &ObjMerge{
|
||||
set: mapset.NewSet[string](),
|
||||
}
|
||||
}
|
||||
|
||||
type ObjMerge struct {
|
||||
regs []*regexp.Regexp
|
||||
set mapset.Set[string]
|
||||
}
|
||||
|
||||
func (om *ObjMerge) Merge(objs []Obj, objs_ ...Obj) []Obj {
|
||||
newObjs := make([]Obj, 0, len(objs)+len(objs_))
|
||||
newObjs = om.insertObjs(om.insertObjs(newObjs, objs...), objs_...)
|
||||
return newObjs
|
||||
}
|
||||
|
||||
func (om *ObjMerge) insertObjs(objs []Obj, objs_ ...Obj) []Obj {
|
||||
for _, obj := range objs_ {
|
||||
if om.clickObj(obj) {
|
||||
objs = append(objs, obj)
|
||||
}
|
||||
}
|
||||
return objs
|
||||
}
|
||||
|
||||
func (om *ObjMerge) clickObj(obj Obj) bool {
|
||||
for _, reg := range om.regs {
|
||||
if reg.MatchString(obj.GetName()) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return om.set.Add(obj.GetName())
|
||||
}
|
||||
|
||||
func (om *ObjMerge) InitHideReg(hides string) {
|
||||
rs := strings.Split(hides, "\n")
|
||||
om.regs = make([]*regexp.Regexp, 0, len(rs))
|
||||
for _, r := range rs {
|
||||
om.regs = append(om.regs, regexp.MustCompile(r))
|
||||
}
|
||||
}
|
||||
|
||||
func (om *ObjMerge) Reset() {
|
||||
om.set.Clear()
|
||||
}
|
||||
90
model/object.go
Normal file
90
model/object.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type ObjWrapName struct {
|
||||
Name string
|
||||
Obj
|
||||
}
|
||||
|
||||
func (o *ObjWrapName) Unwrap() Obj {
|
||||
return o.Obj
|
||||
}
|
||||
|
||||
func (o *ObjWrapName) GetName() string {
|
||||
if o.Name == "" {
|
||||
o.Name = o.Obj.GetName()
|
||||
}
|
||||
return o.Name
|
||||
}
|
||||
|
||||
type Object struct {
|
||||
ID string
|
||||
Path string
|
||||
Name string
|
||||
Size int64
|
||||
Modified time.Time
|
||||
IsFolder bool
|
||||
}
|
||||
|
||||
func (o *Object) GetName() string {
|
||||
return o.Name
|
||||
}
|
||||
|
||||
func (o *Object) GetSize() int64 {
|
||||
return o.Size
|
||||
}
|
||||
|
||||
func (o *Object) ModTime() time.Time {
|
||||
return o.Modified
|
||||
}
|
||||
|
||||
func (o *Object) IsDir() bool {
|
||||
return o.IsFolder
|
||||
}
|
||||
|
||||
func (o *Object) GetID() string {
|
||||
return o.ID
|
||||
}
|
||||
|
||||
func (o *Object) GetPath() string {
|
||||
return o.Path
|
||||
}
|
||||
|
||||
func (o *Object) SetPath(id string) {
|
||||
o.Path = id
|
||||
}
|
||||
|
||||
type Thumbnail struct {
|
||||
Thumbnail string
|
||||
}
|
||||
|
||||
type Url struct {
|
||||
Url string
|
||||
}
|
||||
|
||||
func (w Url) URL() string {
|
||||
return w.Url
|
||||
}
|
||||
|
||||
func (t Thumbnail) Thumb() string {
|
||||
return t.Thumbnail
|
||||
}
|
||||
|
||||
type ObjThumb struct {
|
||||
Object
|
||||
Thumbnail
|
||||
}
|
||||
|
||||
type ObjectURL struct {
|
||||
Object
|
||||
Url
|
||||
}
|
||||
|
||||
type ObjThumbURL struct {
|
||||
Object
|
||||
Thumbnail
|
||||
Url
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package receive
|
||||
23
model/req.go
Normal file
23
model/req.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
type PageReq struct {
|
||||
Index int `json:"page" form:"index"`
|
||||
Size int `json:"size" form:"size"`
|
||||
}
|
||||
|
||||
const MaxUint = ^uint(0)
|
||||
const MinUint = 0
|
||||
const MaxInt = int(MaxUint >> 1)
|
||||
const MinInt = -MaxInt - 1
|
||||
|
||||
func (p *PageReq) Validate() {
|
||||
if p.Index < 1 {
|
||||
p.Index = 1
|
||||
}
|
||||
if p.Size < 1 {
|
||||
p.Size = 100000
|
||||
}
|
||||
// if p.PerPage < 1 {
|
||||
// p.PerPage = MaxInt
|
||||
// }
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package model
|
||||
|
||||
type SearchFileInfo struct {
|
||||
Path string `json:"path"`
|
||||
type SearchEngine struct {
|
||||
Name string `json:"name"`
|
||||
Type int `json:"type"`
|
||||
Icon string `json:"icon"`
|
||||
SearchUrl string `json:"search_url"`
|
||||
RecoUrl string `json:"reco_url"`
|
||||
Data []string `json:"data"`
|
||||
}
|
||||
|
||||
33
model/setting.go
Normal file
33
model/setting.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
SINGLE = iota
|
||||
SITE
|
||||
STYLE
|
||||
PREVIEW
|
||||
GLOBAL
|
||||
ARIA2
|
||||
INDEX
|
||||
GITHUB
|
||||
)
|
||||
|
||||
const (
|
||||
PUBLIC = iota
|
||||
PRIVATE
|
||||
READONLY
|
||||
DEPRECATED
|
||||
)
|
||||
|
||||
type SettingItem struct {
|
||||
Key string `json:"key" gorm:"primaryKey" binding:"required"` // unique key
|
||||
Value string `json:"value"` // value
|
||||
Help string `json:"help"` // help message
|
||||
Type string `json:"type"` // string, number, bool, select
|
||||
Options string `json:"options"` // values for select
|
||||
Group int `json:"group"` // use to group setting in frontend
|
||||
Flag int `json:"flag"` // 0 = public, 1 = private, 2 = readonly, 3 = deprecated, etc.
|
||||
}
|
||||
|
||||
func (s SettingItem) IsDeprecated() bool {
|
||||
return s.Flag == DEPRECATED
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package model
|
||||
|
||||
//
|
||||
type SmartctlA struct {
|
||||
Smartctl struct {
|
||||
Version []int `json:"version"`
|
||||
SvnRevision string `json:"svn_revision"`
|
||||
PlatformInfo string `json:"platform_info"`
|
||||
BuildInfo string `json:"build_info"`
|
||||
Argv []string `json:"argv"`
|
||||
ExitStatus int `json:"exit_status"`
|
||||
} `json:"smartctl"`
|
||||
Device struct {
|
||||
Name string `json:"name"`
|
||||
InfoName string `json:"info_name"`
|
||||
Type string `json:"type"`
|
||||
Protocol string `json:"protocol"`
|
||||
} `json:"device"`
|
||||
ModelName string `json:"model_name"`
|
||||
SerialNumber string `json:"serial_number"`
|
||||
FirmwareVersion string `json:"firmware_version"`
|
||||
UserCapacity struct {
|
||||
Blocks int `json:"blocks"`
|
||||
Bytes int64 `json:"bytes"`
|
||||
} `json:"user_capacity"`
|
||||
SmartStatus struct {
|
||||
Passed bool `json:"passed"`
|
||||
} `json:"smart_status"`
|
||||
AtaSmartData struct {
|
||||
OfflineDataCollection struct {
|
||||
Status struct {
|
||||
Value int `json:"value"`
|
||||
String string `json:"string"`
|
||||
} `json:"status"`
|
||||
CompletionSeconds int `json:"completion_seconds"`
|
||||
} `json:"offline_data_collection"`
|
||||
SelfTest struct {
|
||||
Status struct {
|
||||
Value int `json:"value"`
|
||||
String string `json:"string"`
|
||||
Passed bool `json:"passed"`
|
||||
} `json:"status"`
|
||||
PollingMinutes struct {
|
||||
Short int `json:"short"`
|
||||
Extended int `json:"extended"`
|
||||
Conveyance int `json:"conveyance"`
|
||||
} `json:"polling_minutes"`
|
||||
} `json:"self_test"`
|
||||
Capabilities struct {
|
||||
Values []int `json:"values"`
|
||||
ExecOfflineImmediateSupported bool `json:"exec_offline_immediate_supported"`
|
||||
OfflineIsAbortedUponNewCmd bool `json:"offline_is_aborted_upon_new_cmd"`
|
||||
OfflineSurfaceScanSupported bool `json:"offline_surface_scan_supported"`
|
||||
SelfTestsSupported bool `json:"self_tests_supported"`
|
||||
ConveyanceSelfTestSupported bool `json:"conveyance_self_test_supported"`
|
||||
SelectiveSelfTestSupported bool `json:"selective_self_test_supported"`
|
||||
AttributeAutosaveEnabled bool `json:"attribute_autosave_enabled"`
|
||||
ErrorLoggingSupported bool `json:"error_logging_supported"`
|
||||
GpLoggingSupported bool `json:"gp_logging_supported"`
|
||||
} `json:"capabilities"`
|
||||
} `json:"ata_smart_data"`
|
||||
PowerOnTime struct {
|
||||
Hours int `json:"hours"`
|
||||
} `json:"power_on_time"`
|
||||
PowerCycleCount int `json:"power_cycle_count"`
|
||||
Temperature struct {
|
||||
Current int `json:"current"`
|
||||
} `json:"temperature"`
|
||||
}
|
||||
54
model/storage.go
Normal file
54
model/storage.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type StorageA struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"` // unique key
|
||||
MountPath string `json:"mount_path" gorm:"unique" binding:"required"` // must be standardized
|
||||
Order int `json:"order"` // use to sort
|
||||
Driver string `json:"driver"` // driver used
|
||||
CacheExpiration int `json:"cache_expiration"` // cache expire time
|
||||
Status string `json:"status"`
|
||||
Addition string `json:"addition" gorm:"type:text"` // Additional information, defined in the corresponding driver
|
||||
Remark string `json:"remark"`
|
||||
Modified time.Time `json:"modified"`
|
||||
Disabled bool `json:"disabled"` // if disabled
|
||||
Sort
|
||||
Proxy
|
||||
}
|
||||
|
||||
type Sort struct {
|
||||
OrderBy string `json:"order_by"`
|
||||
OrderDirection string `json:"order_direction"`
|
||||
ExtractFolder string `json:"extract_folder"`
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
WebProxy bool `json:"web_proxy"`
|
||||
WebdavPolicy string `json:"webdav_policy"`
|
||||
DownProxyUrl string `json:"down_proxy_url"`
|
||||
}
|
||||
|
||||
func (s *StorageA) GetStorage() *StorageA {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *StorageA) SetStorage(storage StorageA) {
|
||||
*s = storage
|
||||
}
|
||||
|
||||
func (s *StorageA) SetStatus(status string) {
|
||||
s.Status = status
|
||||
}
|
||||
|
||||
func (p Proxy) Webdav302() bool {
|
||||
return p.WebdavPolicy == "302_redirect"
|
||||
}
|
||||
|
||||
func (p Proxy) WebdavProxy() bool {
|
||||
return p.WebdavPolicy == "use_proxy_url"
|
||||
}
|
||||
|
||||
func (p Proxy) WebdavNative() bool {
|
||||
return !p.Webdav302() && !p.WebdavProxy()
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user