Metadata-Version: 2.4
Name: omniline
Version: 0.8.2
Summary: User-friendly CLI and terminal UI for LINE Messenger, powered by OkLine.
Author: Greg Chao-Kuei Hung
License: MIT
Project-URL: Homepage, https://github.com/ckhung/OmniLine
Project-URL: Documentation, https://github.com/ckhung/OmniLine/tree/main/docs
Project-URL: Repository, https://github.com/ckhung/OmniLine
Project-URL: Issues, https://github.com/ckhung/OmniLine/issues
Project-URL: Changelog, https://github.com/ckhung/OmniLine/blob/main/CHANGELOG.md
Keywords: line,line-messenger,line-api,line-bot,line-messenger-api,line-chrome,line-chrome-extension-api,line-client,line-sdk,python-line,unofficial-line,line-personal-account,line-qr-login,line-login-qr-code,letter-sealing,line-e2ee,e2ee,end-to-end-encryption,line-notify-alternative,linepy-alternative,line-selfbot,line-automation,line-mcp,chatbot,automation,messaging,reverse-engineering,chrome-extension,thrift,x-hmac,okline
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Natural Language :: Chinese (Traditional)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Requires-Dist: cryptography>=41.0
Requires-Dist: qrcode>=7.0
Requires-Dist: prompt-toolkit>=3.0.52
Requires-Dist: wcwidth>=0.9.4
Requires-Dist: okline>=2.7.0
Requires-Dist: tomli>=2.0; python_version < "3.11"
Requires-Dist: flask>=3.1
Requires-Dist: gunicorn>=23.0.0
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == "test"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: mypy>=1.8; extra == "dev"
Requires-Dist: types-requests; extra == "dev"
Requires-Dist: pre-commit>=3.5; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Dynamic: license-file

# OmniLine

OmniLine is a local user interface for LINE, a popular messaging app in Taiwan. Authentication and communication are provided by [OkLine](https://nicedayzc.github.io/OkLine/), created by NiceDayZc.

OmniLine has three frontends:

- `omniline web`: a browser interface; the recommended frontend for ordinary use
- `omniline tui`: a terminal interface
- `omniline cli`: a small command-line interface, mainly useful for testing

This README first explains the simplest local setup. Server deployment and other security-sensitive details are in the final section, [Security](#security).

## Quick start: local computer

You need Python 3.9 or newer and a LINE account that can approve a login on its main device.

### 1. Create a virtual environment

Using Python's built-in virtual-environment support:

```bash
python3 -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install omniline
```

Alternatively, if you already use `uv`:

```bash
uv venv
. .venv/bin/activate
uv pip install omniline
```

Keep the virtual environment activated. All commands in this README assume that it is active; if the terminal prompt no longer shows the environment, activate it again with `. .venv/bin/activate`.

### 2. Initialize OmniLine

```bash
omniline init
```

This creates OmniLine's user-data directory and copies the default configuration and themes. Existing files are preserved. To replace the default files explicitly:

```bash
omniline init --force
```

User data is stored under `~/.omniline/`, that is, `$HOME/.omniline/`.

### 3. Log in to LINE

Run:

```bash
okline login
```

Then:

1. Have your main LINE device available.
2. Scan the QR code printed in the terminal using LINE's “add contact” → “scan QR code” function.
3. Read the six-digit PIN from the terminal.
4. Enter the PIN on the main LINE device and approve the login.

A `tokens.json` login credential is then stored in the OmniLine user-data directory. Keep it private. Future OmniLine commands need to read it.

![OkLine login process](docs/assets/login.png)

### 4. Set the web password

Before starting the web interface, create its local password:

```bash
omniline web passwd
```

The password is used to protect the browser interface. It is not the same as your LINE password.

### 5. Start the local web interface

```bash
omniline web
```

Open this address in Firefox, Brave, or another browser:

```text
http://127.0.0.1:1730/
```

Log in with the web password you just created.

The local server listens only on your computer by default. For ordinary local use, do not expose it to the network and do not set `OMNILINE_COOKIE_SECURE`; that setting is for HTTPS deployments.

The default port is configured in `~/.omniline/config.toml`:

```toml
[web]
port = 1730
```

To override it for one local run:

```bash
omniline web --port 1731
```

Then open `http://127.0.0.1:1731/`.

## Using the Web Interface

The web interface is server-rendered and remains usable when JavaScript is disabled. JavaScript makes common operations smoother but is not required for reading, sending, replying, or reacting.

### Chat list and conversation

- The chat list is on the left in graphical browsers.
- The selected conversation is on the right.
- Chats are ordered by most recent activity. Pinned chats remain in a separate pinned section at the top, also ordered by recent activity.
- On narrow screens, selecting a chat displays the conversation; the chat list is available through the normal navigation flow.
- Text browsers such as `lynx` and `w3m` display the conversation before the chat list so that the useful content is reached first.
- Recent history is bounded by the configured history limit; the web interface does not imply that all historical messages are loaded.

### Reading messages

Messages show their sender, text or media, timestamp, reactions, and available actions. Incoming sender names are links to that person's profile.

A divider such as the following marks the beginning of unread messages:

```text
----- unread messages -----
```

### Sending a message

At the bottom of a conversation, use the “Write a message” text box. The small blue arrow button at its right sends the message.

The ordinary HTML form remains available as a fallback. If JavaScript is enabled, the message is submitted asynchronously and the conversation is updated without a full-page reload.

### Replying

Select `Reply` beside a message. The composer identifies the message being answered. Write the reply and use the same blue arrow button. Select `Cancel reply` to leave reply mode.

### Reactions

Select `React` beside a message, choose one of the available reactions, and submit it. If you have already reacted, the action becomes `Remove my reaction`.

When a message has reactions:

- the reaction summary shows symbols and counts;
- hover, keyboard focus, or click can show who reacted and how;
- the ordinary reaction-details link remains available when JavaScript is disabled.

### Unsend

For messages sent by you, select `Unsend` and confirm the operation.

### New-message notifications

The browser periodically checks unread counts. When new unread messages appear:

- unread badges in the chat list are updated;
- the total appears in the browser tab title;
- a desktop browser notification is shown only if notification permission was already granted.

OmniLine does not automatically request browser notification permission.

### Text browsers

For a text-browser session on the same computer, start the local server and use one of:

```bash
lynx http://127.0.0.1:1730/
w3m http://127.0.0.1:1730/
```

The essential conversation, forms, links, profile pages, and reaction details use ordinary HTML navigation and forms.

### Troubleshooting local use

If the browser says that authentication is not configured, run this in the activated virtual environment:

```bash
omniline web passwd
```

If login succeeds but messages cannot be loaded, verify that `okline login` completed and that the current OmniLine process can read the resulting `tokens.json`.

To stop the local server, press `Ctrl-C` in the terminal where `omniline web` is running.

## Using the TUI

Start the terminal interface with:

```bash
omniline tui
```

The full-screen layout has a chat list on the left and the selected chat or profile on the right. The status bar shows the currently available keyboard commands.

- List mode: navigate chats, search, open a chat, open a profile, refresh unread counts, and quit.
- Profile mode: view chat information, pin or unpin the chat, and return.
- Content mode: navigate and search messages, move between search matches, open the first URL on the current line, compose a new message or reply, react to a message, and return.
- In reaction mode, `[` and `]` choose a reaction and `Enter` applies it.
- Search and compose overlays accept text, submission, and cancellation using the displayed keys.

Important settings are in `~/.omniline/config.toml`: token-file path, pinned chats, history limit, TUI theme, and conservative sending options. Dark and light themes are stored under the corresponding `themes/` directory.

![TUI screenshot](docs/assets/tui.png)

## Using the CLI

The CLI is intentionally small and is mainly useful for diagnostics and testing. See:

```bash
omniline cli --help
```

## Security

This section is for users who want to expose OmniLine beyond a single local computer or operate it as a server. If you only use `omniline web` on `127.0.0.1`, the Quick start instructions are sufficient.

### Web authentication files

`omniline web passwd` creates:

```text
~/.omniline/password.hash
~/.omniline/session.secret
```

under `$HOME/.omniline/`.

The password is stored only as a verifier, never as clear text. `session.secret` signs Flask session cookies. Both files must remain private and should have restrictive permissions. Running `omniline web passwd` again changes the password and rotates the session secret, which logs out existing browser sessions.

Login attempts are recorded in `access.log` without recording the password. The `[web]` section of `config.toml` controls the rolling failure limit:

```toml
[web]
max_failed_attempts = 5
failed_attempt_window_seconds = 300
session_lifetime_hours = 24
```

After five failed attempts, further attempts are rejected until the five-minute window expires. The current deployment assumes one Gunicorn worker, so the access log is the shared rate-limit state. If multiple workers are introduced, replace this with a transactional shared store such as SQLite or Redis.

Successful sessions expire after the configured absolute lifetime; ordinary browsing does not extend that lifetime indefinitely.

### Local HTTP versus public deployment

The built-in Flask server is intended for local development and testing:

```bash
omniline web
```

Keep it bound to `127.0.0.1`. Do not bind it to all network interfaces unless you understand the consequences and have provided an HTTPS and authentication boundary.

For a server deployment, use Apache as the public HTTPS boundary and keep Gunicorn bound to loopback. The command below assumes the virtual environment is active:

The `--bind` port should match `[web].port` in `~/.omniline/config.toml`. Gunicorn does not read OmniLine's TOML configuration itself, so update the Gunicorn and Apache port values if you change that setting.

```bash
gunicorn \
    --bind 127.0.0.1:1730 \
    omniline.web:app
```

If OmniLine is being run from a source checkout rather than an installed package, install that checkout into the virtual environment first, for example:

```bash
python -m pip install -e ~/OmniLine
```

The `.omniline` directory contains user data and credentials; it is not the application-code directory.

The simplified command uses the default files under `~/.omniline/`:

```text
~/.omniline/tokens.json
~/.omniline/password.hash
```

Use the application factory only when you need different secret locations, for example:

```bash
gunicorn \
    --bind 127.0.0.1:1730 \
    'omniline.web:create_app(tokens_file="/secure/other/tokens.json", password_file="/secure/other/password.hash")'
```

Alternatively, using the installed environment and enabling secure cookies for HTTPS:

```bash
OMNILINE_COOKIE_SECURE=1 \
gunicorn \
    --bind 127.0.0.1:1730 \
    omniline.web:app
```

`OMNILINE_COOKIE_SECURE=1` only sets the cookie `Secure` attribute. It does not bypass authentication. Password checking always remains enabled.

### Apache reverse proxy

If Apache already serves other pages, add this inside the existing HTTPS `<VirtualHost>` block. It exposes only `/omniline/` publicly and forwards it to Gunicorn:

```apache
RedirectMatch 301 ^/omniline$ /omniline/

ProxyAddHeaders On
ProxyPass        /omniline/ http://127.0.0.1:1730/
ProxyPassReverse /omniline/ http://127.0.0.1:1730/

<Location /omniline/>
    RequestHeader set X-Forwarded-Prefix "/omniline"
    Require all granted
</Location>

ProxyPassReverseCookiePath / /omniline/
```

Place these rules before a generic `ProxyPass / ...` rule, if one exists. `X-Forwarded-Prefix` allows Flask to generate redirects such as `/omniline/login` rather than `/login`. `ProxyPassReverseCookiePath` keeps the authentication cookie scoped to OmniLine.

Enable the required modules and validate the configuration:

```bash
sudo a2enmod proxy proxy_http headers
sudo apache2ctl configtest
sudo apache2ctl -k graceful
```

On systems without `systemctl`, use `apache2ctl -k start`, `-k graceful`, and `-k stop`. Start Gunicorn before testing the Apache proxy.

### Optional Fail2ban IP bans

The application limiter is global. Fail2ban can add a second, IP-specific layer with longer bans. Create `/etc/fail2ban/filter.d/omniline.conf`:

```ini
[Definition]
# Fail2ban removes the matched date before applying failregex.
datepattern = "time":"{DATE}",
failregex = ^.*"result":"(?:failure|blocked)".*"remote_addr":"<HOST>".*$
ignoreregex =
```

For example, create `/etc/fail2ban/jail.d/omniline.local`:

```ini
[omniline]
enabled = true
filter = omniline
logpath = /home/YOUR_USER/.omniline/access.log
maxretry = 5
findtime = 300
bantime = 3600
```

Replace `YOUR_USER`, then test and reload:

```bash
sudo fail2ban-regex \
    /home/YOUR_USER/.omniline/access.log \
    /etc/fail2ban/filter.d/omniline.conf
sudo fail2ban-client reload
sudo fail2ban-client status omniline
```

Apache must preserve the client address with:

```apache
ProxyAddHeaders On
```

The application trusts one forwarded proxy hop. Gunicorn must remain bound to `127.0.0.1`; otherwise clients could forge `X-Forwarded-For` and influence IP-based bans.

### Security checklist

- Use HTTPS for any non-local deployment.
- Set `OMNILINE_COOKIE_SECURE=1` when HTTPS is genuinely in use.
- Keep Gunicorn on loopback and use Apache as the public TLS boundary.
- Never enable Flask debug mode in deployment.
- Keep `tokens.json`, `password.hash`, `session.secret`, and `access.log` private.
- Use a strong web password and a strong LINE account password.
- Keep CSRF protection enabled for state-changing operations.
- Trust forwarded headers only from the known reverse proxy hop.
- Do not expose tokens, raw backend payloads, message contents, or encrypted material in logs or error pages.

## License

[MIT](LICENSE)
