Skip to content

Commit

Permalink
third commit
Browse files Browse the repository at this point in the history
  • Loading branch information
creamlike1024 committed Mar 22, 2024
1 parent cf50d21 commit ecb6f6b
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 116 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/releaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release

on:
release:
types: [created]
workflow_dispatch:

permissions:
contents: write
packages: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux, windows, darwin, freebsd ]
goarch: [ "386", arm, amd64, arm64, mipsle ]
exclude:
- goarch: "386"
goos: darwin
- goarch: mipsle
goos: windows
- goarch: mipsle
goos: darwin
- goarch: mipsle
goos: freebsd
- goarch: arm
goos: windows
- goarch: arm
goos: darwin
- goarch: arm
goos: freebsd

steps:
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
ldflags: "-s -w"
78 changes: 71 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,75 @@
# rlpa-server

🚧🚧🚧 Under construction 🚧🚧🚧
Another go implement of estk.me [rlpa-server.php](https://github.com/estkme-group/lpac/blob/main/src/rlpa-server.php)

- [x] rlpa packet
- [x] Download Profile (not tested yet)
- [x] Process Notification (consistent with the behavior of `rlpa-server.php`, notifications for non "delete" operations will be removed after processing)

TODO
- [] json 化 http response
- [] api disconnect 逻辑
- [] 日志输出
- ...
Under construction:

- Remote Management(http api)

This feature is currently under construction. However, it is not necessary to use this feature in normal usage scenarios, and I am not sure if I should complete it

## Usage

Compile latest [lpac](https://github.com/estkme-group/lpac), then place the `lpac` binary program in the same directory as the `rlpa-server` program

use environment variables to set port

- `SOCKET_PORT`: socket port for estk rlpa, default 1888
- `API_PORT`: http management api port, default 8008

debug log output: start with `-debug` argument to enable debug log level

### systemd service example

Write the following content into `/etc/systemd/system/rlpa-server.service`
```
[Unit]
Description=rlpa server
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/path/to/rlpa-server
WorkingDirectory=/path/to/rlpa-server-directory
Restart=on-failure
User=[your-user]
[Install]
WantedBy=multi-user.target
```
- `ExecStart`: rlpa-server binary path
- `WorkingDirectory`: The directory where rlpa server is located
- `User`: Replace with actual user

Then execute `sudo systemctl daemon-reload` to reload services

- Start rlpa-server: `sudo systemctl start rlpa-server`
- Let rlpa-server start with system: `sudo systemctl enable rlpa-server`

## Public Server
⚠️ No guarantee, use at your own risk

| IP | Port | Location |
|:------------:|:----:|:-----------------:|
|205.185.117.85| 1888 | Las Vegas, NV, US |


## API Document

- lpac shell command

Post json to `/shell/{manageID}` with header `Password: {Password}`

example

```bash
curl -X POST -H "Content-Type: application/json" \
-H "Password: 2660" \
-d '{"type":0, "command":"chip info"}' \
http://example.com:8008/shell/rAct
```

Will get lpac output
22 changes: 5 additions & 17 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,26 @@ import (
)

type Config struct {
SocketPort uint16
APIPort uint16
LpacExeName string
LpacPath string
APDUInterface string
HTTPInterface string
SocketPort uint16
APIPort uint16
LpacExeName string
LpacPath string
}

var CFG Config

func InitConfig() error {
const apduInterface = "libapduinterface_stdio"
const httpInterface = "libhttpinterface_curl"
switch runtime.GOOS {
case "windows":
CFG.LpacExeName = "lpac.exe"
CFG.APDUInterface = apduInterface + ".dll"
CFG.HTTPInterface = httpInterface + ".dll"
case "darwin":
CFG.LpacExeName = "lpac"
CFG.APDUInterface = apduInterface + ".dylib"
CFG.HTTPInterface = httpInterface + ".dylib"
default:
CFG.LpacExeName = "lpac"
CFG.APDUInterface = apduInterface + ".so"
CFG.HTTPInterface = httpInterface + ".so"
}
pwd, err := os.Getwd()
if err != nil {
return errors.New(fmt.Sprint("Failed to get pwd: ", err))
}
CFG.LpacPath = filepath.Join(pwd, "lpac", CFG.LpacExeName)
CFG.LpacPath = filepath.Join(pwd, CFG.LpacExeName)
socketPort := strings.TrimSpace(os.Getenv("SOCKET_PORT"))
if socketPort == "" {
CFG.SocketPort = 1888
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module rlpa-server

go 1.22

require github.com/gorilla/mux v1.8.1 // indirect
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
17 changes: 6 additions & 11 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ func HttpServer() {
}

func homeHandler(w http.ResponseWriter, r *http.Request) {
// TODO
fmt.Fprintf(w, "rlpa-server\n")
}

func manifestHandler(w http.ResponseWriter, r *http.Request) {
// TODO
fmt.Fprintf(w, "manifest\n")
}

func infoHandler(w http.ResponseWriter, r *http.Request) {
// TODO
id := r.PathValue("id")
if verify(id, r.Header.Get("Password")) {
w.WriteHeader(http.StatusOK)
Expand All @@ -44,6 +47,7 @@ func infoHandler(w http.ResponseWriter, r *http.Request) {
}

func connectHandler(w http.ResponseWriter, r *http.Request) {
// TODO
id := r.PathValue("id")
passwd := r.Header.Get("Password")
if verify(id, passwd) {
Expand All @@ -53,11 +57,6 @@ func connectHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "rlpa client disconnected")
return
}
if c.WorkMode != ShellMode {
w.WriteHeader(http.StatusBadGateway)
fmt.Fprintf(w, "rlpa client not in shell mode")
return
}
if c.APILocked {
w.WriteHeader(http.StatusConflict)
return
Expand All @@ -77,6 +76,7 @@ func disconnectHandler(w http.ResponseWriter, r *http.Request) {
}

func keepaliveHandler(w http.ResponseWriter, r *http.Request) {
// TODO
id := r.PathValue("id")
passwd := r.Header.Get("Password")
if verify(id, passwd) {
Expand Down Expand Up @@ -109,11 +109,6 @@ func shellHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "rlpa client disconnected")
return
}
if c.WorkMode != ShellMode {
w.WriteHeader(http.StatusBadGateway)
fmt.Fprintf(w, "rlpa client not in shell mode")
return
}
// decode json body
var payload ShellRequest
err = json.NewDecoder(r.Body).Decode(&payload)
Expand All @@ -135,7 +130,7 @@ func shellHandler(w http.ResponseWriter, r *http.Request) {
return
}
c.DebugLog("command " + payload.Command)
err = c.processOpenLpac(strings.Split(strings.TrimSpace(payload.Command), " "))
err = c.processOpenLpac(strings.Split(strings.TrimSpace(payload.Command), " ")...)
if err != nil {
w.WriteHeader(http.StatusBadGateway)
fmt.Fprintf(w, "failed to open lpac")
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Environment Variables:
print(help)
return
}
slog.SetLogLoggerLevel(slog.LevelDebug)
slog.SetLogLoggerLevel(slog.LevelInfo)
if *debug {
slog.SetLogLoggerLevel(slog.LevelDebug)
}
Expand Down Expand Up @@ -70,7 +70,6 @@ Environment Variables:

func handleConnection(conn net.Conn) {
client := NewRLPAClient(conn)
Clients = append(Clients, client)

for {
// 接受 Packet
Expand Down
Loading

0 comments on commit ecb6f6b

Please sign in to comment.