Skip to content

Commit 31cb06a

Browse files
committed
feat(#1): implementing the basic rules
1 parent 74ab265 commit 31cb06a

File tree

8 files changed

+734
-1
lines changed

8 files changed

+734
-1
lines changed

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# iOSMB-Router Environment Variables
2+
# Copy this to .env and customize
3+
4+
# iOSMB Server Configuration
5+
IOSMB_SERVER_IP=192.168.1.100
6+
IOSMB_SERVER_PORT=8180
7+
IOSMB_SERVER_PASSWORD=your-password-here
8+
IOSMB_SERVER_SSL=false
9+
10+
# Rules file path
11+
IOSMB_RULES_FILE=rules.yaml

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Build stage
2+
FROM golang:1.21-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Copy go mod files
7+
COPY go.mod go.sum* ./
8+
9+
# Download dependencies
10+
RUN go mod download
11+
12+
# Copy source code
13+
COPY . .
14+
15+
# Build the application
16+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o iosmb-router .
17+
18+
# Production stage
19+
FROM alpine:latest
20+
21+
# Install ca-certificates for HTTPS
22+
RUN apk --no-cache add ca-certificates
23+
24+
WORKDIR /app
25+
26+
# Copy the binary from builder
27+
COPY --from=builder /app/iosmb-router .
28+
29+
# Copy example rules file
30+
COPY rules.example.yaml .
31+
32+
# Create volume for rules
33+
VOLUME ["/app/rules"]
34+
35+
# Expose no ports (this is a client service)
36+
37+
# Run the application
38+
CMD ["./iosmb-router"]

README.md

Lines changed: 264 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,264 @@
1-
# iOSMB-Router
1+
# iOSMB-Router
2+
3+
Automated message routing and auto-reply service for iOSMB (iOS Message Bridge). Create rules to forward messages from specific senders to multiple recipients or automatically reply to incoming messages.
4+
5+
## Features
6+
7+
- **Message Forwarding** - Redirect messages from specific senders to multiple recipients
8+
- **Auto-Reply** - Automatically respond to messages based on sender
9+
- **YAML Configuration** - Easy-to-read and modify rules
10+
- **Real-time Processing** - Processes messages as they arrive via WebSocket
11+
- **Docker Support** - Easy deployment with Docker and Docker Compose
12+
- **Environment Variables** - Configure server connection without modifying code
13+
14+
## Quick Start
15+
16+
### Using Docker Compose (Recommended)
17+
18+
1. **Copy the environment file:**
19+
```bash
20+
cd iOSMB-Router
21+
cp .env.example .env
22+
```
23+
24+
2. **Edit `.env` with your iOSMB server details:**
25+
```bash
26+
IOSMB_SERVER_IP=192.168.1.100
27+
IOSMB_SERVER_PORT=8180
28+
IOSMB_SERVER_PASSWORD=your-server-password
29+
IOSMB_SERVER_SSL=false
30+
```
31+
32+
3. **Create your rules file:**
33+
```bash
34+
cp rules.example.yaml rules.yaml
35+
# Edit rules.yaml with your custom rules
36+
```
37+
38+
4. **Start the service:**
39+
```bash
40+
docker-compose up -d
41+
```
42+
43+
5. **View logs:**
44+
```bash
45+
docker-compose logs -f
46+
```
47+
48+
### Using Go Directly
49+
50+
1. **Install dependencies:**
51+
```bash
52+
go mod download
53+
```
54+
55+
2. **Create configuration:**
56+
```bash
57+
cp .env.example .env
58+
cp rules.example.yaml rules.yaml
59+
# Edit both files
60+
```
61+
62+
3. **Run the service:**
63+
```bash
64+
source .env
65+
go run main.go
66+
```
67+
68+
## Rules Configuration
69+
70+
Rules are defined in `rules.yaml` using a simple YAML format:
71+
72+
### Redirect Rule Example
73+
74+
Forward all messages from Netflix to multiple phone numbers:
75+
76+
```yaml
77+
rules:
78+
- name: "Forward Netflix notifications"
79+
type: redirect
80+
from_sender: "Netflix"
81+
to_receivers:
82+
- "+33722335544"
83+
- "+33755442211"
84+
enabled: true
85+
```
86+
87+
### Auto-Reply Rule Example
88+
89+
Automatically reply to a specific sender:
90+
91+
```yaml
92+
rules:
93+
- name: "Auto reply to friend"
94+
type: auto_reply
95+
from_sender: "+33233556699"
96+
reply_text: "I will answer you shortly"
97+
enabled: true
98+
```
99+
100+
### Rule Properties
101+
102+
| Property | Type | Required | Description |
103+
|----------|------|----------|-------------|
104+
| `name` | string | Yes | Descriptive name for the rule |
105+
| `type` | string | Yes | Rule type: `redirect` or `auto_reply` |
106+
| `from_sender` | string | Yes | Sender name or number to match (case-insensitive substring) |
107+
| `to_receivers` | array | For redirect | List of phone numbers to forward to |
108+
| `reply_text` | string | For auto_reply | Text to send as automatic reply |
109+
| `enabled` | boolean | Yes | Enable/disable the rule without deleting it |
110+
111+
## Environment Variables
112+
113+
| Variable | Default | Description |
114+
|----------|---------|-------------|
115+
| `IOSMB_SERVER_IP` | `192.168.1.100` | iOSMB server IP address |
116+
| `IOSMB_SERVER_PORT` | `8180` | iOSMB server port |
117+
| `IOSMB_SERVER_PASSWORD` | - | iOSMB server password |
118+
| `IOSMB_SERVER_SSL` | `false` | Use WSS instead of WS |
119+
| `IOSMB_RULES_FILE` | `rules.yaml` | Path to rules configuration file |
120+
121+
## How It Works
122+
123+
1. **Connects** to your iOSMB server via WebSocket (same connection as the web client)
124+
2. **Authenticates** using the server password
125+
3. **Listens** for incoming messages in real-time
126+
4. **Matches** messages against your defined rules
127+
5. **Executes** actions (forward or auto-reply) when rules match
128+
129+
```
130+
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
131+
│ iPhone │ ──────> │ iOSMB Server│ ──────> │ iOSMB-Relay │
132+
│ (Messages) │ │ (WebSocket)│ │ (Rules) │
133+
└─────────────┘ └─────────────┘ └─────────────┘
134+
135+
136+
┌──────────────────┐
137+
│ Forward to phones│
138+
│ or Auto-reply │
139+
└──────────────────┘
140+
```
141+
142+
## Use Cases
143+
144+
### Forward Important Notifications
145+
```yaml
146+
- name: "Forward bank alerts"
147+
type: redirect
148+
from_sender: "Bank"
149+
to_receivers:
150+
- "+33600000001" # Your work phone
151+
- "+33600000002" # Your partner's phone
152+
enabled: true
153+
```
154+
155+
### Out of Office Auto-Reply
156+
```yaml
157+
- name: "Vacation auto-reply"
158+
type: auto_reply
159+
from_sender: "work" # Matches any sender with "work" in name
160+
reply_text: "I'm on vacation until Monday. For urgent matters, call +33600000000"
161+
enabled: true
162+
```
163+
164+
### Emergency Contact Forwarding
165+
```yaml
166+
- name: "Forward urgent messages"
167+
type: redirect
168+
from_sender: "urgent"
169+
to_receivers:
170+
- "+33600000001"
171+
enabled: true
172+
```
173+
174+
### Delivery Acknowledgment
175+
```yaml
176+
- name: "Confirm delivery notifications"
177+
type: auto_reply
178+
from_sender: "UPS"
179+
reply_text: "Thank you for the delivery update!"
180+
enabled: false
181+
```
182+
183+
## Docker Production Deployment
184+
185+
For production with Docker Swarm:
186+
187+
```yaml
188+
version: '3.9'
189+
190+
services:
191+
iosmb-router:
192+
image: ghcr.io/enzodjabali/iosmb-router:latest
193+
environment:
194+
- IOSMB_SERVER_IP=${IOSMB_SERVER_IP}
195+
- IOSMB_SERVER_PORT=${IOSMB_SERVER_PORT}
196+
- IOSMB_SERVER_PASSWORD=${IOSMB_SERVER_PASSWORD}
197+
- IOSMB_SERVER_SSL=${IOSMB_SERVER_SSL}
198+
configs:
199+
- source: relay_rules
200+
target: /app/rules.yaml
201+
deploy:
202+
replicas: 1
203+
restart_policy:
204+
condition: on-failure
205+
206+
configs:
207+
relay_rules:
208+
file: ./rules.yaml
209+
```
210+
211+
## Building from Source
212+
213+
```bash
214+
# Clone the repository
215+
cd iOSMB-Router
216+
217+
# Build binary
218+
go build -o iosmb-router .
219+
220+
# Run
221+
./iosmb-router
222+
```
223+
224+
## Troubleshooting
225+
226+
### Connection Issues
227+
- Verify `IOSMB_SERVER_IP` and `IOSMB_SERVER_PORT` are correct
228+
- Ensure the iOSMB server is running and accessible
229+
- Check if SSL is required (`IOSMB_SERVER_SSL=true`)
230+
231+
### Rules Not Matching
232+
- The `from_sender` field uses case-insensitive substring matching
233+
- Example: `"Netflix"` will match "netflix", "NETFLIX", "Netflix Support"
234+
- Check logs to see incoming message details
235+
236+
### Messages Not Sending
237+
- Verify phone numbers include country code (e.g., `+33...`)
238+
- Check that the iOSMB server allows message sending
239+
- View logs for error messages
240+
241+
## Logs
242+
243+
The service provides detailed logging:
244+
245+
```
246+
iOSMB-Router starting...
247+
Server: 192.168.1.100:8180 (SSL: false)
248+
Loaded 5 rules from rules.yaml
249+
Connecting to ws://192.168.1.100:8180...
250+
Connected to iOSMB server
251+
[NEW MESSAGE] From: Netflix | Text: Your payment was successful...
252+
Rule matched: Forward Netflix notifications
253+
Redirecting to +33722335544
254+
Redirecting to +33755442211
255+
Message sent successfully
256+
```
257+
258+
## License
259+
260+
MIT License
261+
262+
## Credits
263+
264+
Part of the iOSMB (iOS Message Bridge) ecosystem.

docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
iosmb-router:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
environment:
7+
# iOSMB Server Configuration (same as your client)
8+
- IOSMB_SERVER_IP=${IOSMB_SERVER_IP:-192.168.1.100}
9+
- IOSMB_SERVER_PORT=${IOSMB_SERVER_PORT:-8180}
10+
- IOSMB_SERVER_PASSWORD=${IOSMB_SERVER_PASSWORD:-your-password-here}
11+
- IOSMB_SERVER_SSL=${IOSMB_SERVER_SSL:-false}
12+
13+
# Rules file location
14+
- IOSMB_RULES_FILE=${IOSMB_RULES_FILE:-rules.yaml}
15+
16+
volumes:
17+
# Mount your rules file
18+
- ./rules.yaml:/app/rules.yaml:ro
19+
20+
restart: unless-stopped
21+
22+
# Optional: if using Docker networks
23+
# networks:
24+
# - iosmb-network
25+
26+
# networks:
27+
# iosmb-network:
28+
# external: true

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/enzodjabali/iosmb-router
2+
3+
go 1.21
4+
5+
require (
6+
github.com/gorilla/websocket v1.5.1
7+
gopkg.in/yaml.v3 v3.0.1
8+
)
9+
10+
require golang.org/x/net v0.17.0 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
2+
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
3+
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
4+
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
5+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
6+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
8+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)