lapctl 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lapctl/registry.py ADDED
@@ -0,0 +1,110 @@
1
+ """Command registry declaring risk levels, minimum profiles, and capabilities."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable
6
+ from dataclasses import dataclass, field
7
+ from typing import Any, Literal
8
+
9
+ from lapctl.core.confirm import ConfirmationManager
10
+ from lapctl.drivers.base import BaseDriver
11
+ from lapctl.results import CommandOutput
12
+
13
+ RiskLevel = Literal["R", "C", "S", "P", "X"]
14
+ ProfileLevel = Literal["aman", "standar", "lengkap"]
15
+
16
+ PROFILE_ORDER: dict[ProfileLevel, int] = {
17
+ "aman": 0,
18
+ "standar": 1,
19
+ "lengkap": 2,
20
+ }
21
+
22
+
23
+ def get_active_profile(config: dict[str, Any] | None) -> ProfileLevel:
24
+ """Extract the active permission profile from config (default: standar)."""
25
+ if not config:
26
+ return "standar"
27
+ general = config.get("general")
28
+ raw = general.get("profile") if isinstance(general, dict) else None
29
+ if raw is None:
30
+ raw = config.get("profile", "standar")
31
+ if raw in PROFILE_ORDER:
32
+ return raw # type: ignore[return-value]
33
+ return "standar"
34
+
35
+
36
+ @dataclass
37
+ class CommandContext:
38
+ """Structured context passed to a command handler."""
39
+
40
+ chat_id: int | str
41
+ command: str
42
+ args: str
43
+ config: dict[str, Any]
44
+ driver: BaseDriver
45
+ owner_id: int = 0
46
+ registry: CommandRegistry | None = None
47
+ confirmations: ConfirmationManager | None = None
48
+
49
+
50
+ CommandHandler = Callable[[CommandContext], CommandOutput]
51
+
52
+
53
+ @dataclass(frozen=True)
54
+ class Command:
55
+ """Declaration of a single bot command."""
56
+
57
+ name: str
58
+ handler: CommandHandler
59
+ risk: RiskLevel
60
+ min_profile: ProfileLevel
61
+ capabilities: tuple[str, ...] = ()
62
+ aliases: tuple[str, ...] = ()
63
+ description: str = ""
64
+ show_in_commands: bool = True
65
+
66
+
67
+ @dataclass
68
+ class CommandRegistry:
69
+ """Stores all registered commands and resolves names/aliases."""
70
+
71
+ _commands: list[Command] = field(default_factory=list)
72
+ _by_name: dict[str, Command] = field(default_factory=dict)
73
+
74
+ def register(self, command: Command) -> None:
75
+ """Register a command and all of its aliases."""
76
+ self._commands.append(command)
77
+ self._by_name[command.name.lower()] = command
78
+ for alias in command.aliases:
79
+ self._by_name[alias.lower()] = command
80
+
81
+ def resolve(self, name: str) -> Command | None:
82
+ """Look up a command by primary name or alias."""
83
+ return self._by_name.get(name.lower())
84
+
85
+ def all_commands(self) -> list[Command]:
86
+ """Return all registered commands in registration order."""
87
+ return list(self._commands)
88
+
89
+ def is_allowed(self, command: Command, config: dict[str, Any] | None) -> bool:
90
+ """Return True if command is permitted under the active profile."""
91
+ active = get_active_profile(config)
92
+ if command.name == "/cmd" and active != "lengkap":
93
+ return False
94
+ return PROFILE_ORDER[active] >= PROFILE_ORDER[command.min_profile]
95
+
96
+ def list_telegram_commands(
97
+ self,
98
+ config: dict[str, Any] | None = None,
99
+ ) -> list[dict[str, str]]:
100
+ """Return command entries formatted for Telegram setMyCommands, filtered by profile."""
101
+ items: list[dict[str, str]] = []
102
+ for cmd in self._commands:
103
+ if not cmd.show_in_commands or not cmd.name.startswith("/"):
104
+ continue
105
+ if config is not None and not self.is_allowed(cmd, config):
106
+ continue
107
+ tg_name = cmd.name.lstrip("/")
108
+ desc = cmd.description or tg_name
109
+ items.append({"command": tg_name, "description": desc[:256]})
110
+ return items
lapctl/results.py ADDED
@@ -0,0 +1,86 @@
1
+ """Structured result types returned by core command handlers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+
7
+
8
+ @dataclass(frozen=True)
9
+ class Button:
10
+ """An inline button with either callback_data or an external url."""
11
+
12
+ text: str
13
+ callback_data: str | None = None
14
+ url: str | None = None
15
+
16
+
17
+ @dataclass(frozen=True)
18
+ class Text:
19
+ """Plain or Markdown text message."""
20
+
21
+ text: str
22
+ parse_mode: str = "Markdown"
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class Buttons:
27
+ """Text message with an inline button grid."""
28
+
29
+ text: str
30
+ rows: list[list[Button]] = field(default_factory=list)
31
+ parse_mode: str = "Markdown"
32
+
33
+
34
+ @dataclass(frozen=True)
35
+ class Image:
36
+ """Image file to send."""
37
+
38
+ path: str
39
+ caption: str | None = None
40
+ cleanup: bool = False
41
+
42
+
43
+ @dataclass(frozen=True)
44
+ class Video:
45
+ """Video file to send."""
46
+
47
+ path: str
48
+ caption: str | None = None
49
+ cleanup: bool = False
50
+
51
+
52
+ @dataclass(frozen=True)
53
+ class Audio:
54
+ """Voice/audio file to send."""
55
+
56
+ path: str
57
+ caption: str | None = None
58
+ cleanup: bool = False
59
+
60
+
61
+ @dataclass(frozen=True)
62
+ class File:
63
+ """Document file to send."""
64
+
65
+ path: str
66
+ caption: str | None = None
67
+ cleanup: bool = False
68
+
69
+
70
+ @dataclass(frozen=True)
71
+ class Location:
72
+ """Geographic coordinates to send."""
73
+
74
+ latitude: float
75
+ longitude: float
76
+
77
+
78
+ @dataclass(frozen=True)
79
+ class DeleteMessage:
80
+ """Instruction to delete a previous message by ID."""
81
+
82
+ message_id: int
83
+
84
+
85
+ Result = Text | Buttons | Image | Video | Audio | File | Location | DeleteMessage
86
+ CommandOutput = Result | list[Result] | None
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: lapctl
3
+ Version: 0.1.1
4
+ Summary: Open-source laptop remote control agent via Telegram
5
+ License: MIT
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: requests>=2.31
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest>=8.0; extra == "dev"
12
+ Requires-Dist: ruff>=0.6; extra == "dev"
13
+ Dynamic: license-file
14
+
15
+ # Lapctl
16
+
17
+ Agent open source yang berjalan di laptop untuk mengendalikan laptop dari jarak jauh melalui Telegram (kunci layar, screenshot, kamera, kontrol media, cek status, file, dan kontrol daya) tanpa server tambahan dan tanpa membuka port jaringan masuk.
18
+
19
+ ## Privasi dan Keamanan
20
+
21
+ - Pesan, screenshot, foto, dan file **melewati server Telegram**. Bot API tidak terenkripsi end-to-end. Pertimbangkan hal ini sebelum memakai fitur sensitif.
22
+ - Lapctl tidak memiliki server, akun, atau telemetri.
23
+ - Panggilan jaringan selain ke `api.telegram.org` hanya terjadi pada fitur eksternal yang diaktifkan sendiri oleh pengguna (TTS via Google Translate, geolokasi IP via `ip-api.com`, atau notifikasi `ntfy`).
24
+ - Lapctl bukan produk resmi Telegram dan nama "Telegram" tidak dipakai dalam nama proyek.
25
+
26
+ ## Prasyarat
27
+
28
+ - **Python 3.11** atau lebih baru
29
+ - **OS:** Linux (saat ini mendukung Wayland/Hyprland; driver X11 & Windows direncanakan di rilis berikutnya)
30
+ - **pipx** (tool untuk menginstal aplikasi CLI Python secara terisolasi tanpa mengganggu Python sistem)
31
+
32
+ ### Cara Pasang `pipx`
33
+
34
+ **Linux:**
35
+ - **Arch Linux:**
36
+ ```bash
37
+ sudo pacman -S python-pipx
38
+ pipx ensurepath
39
+ ```
40
+ - **Ubuntu / Debian:**
41
+ ```bash
42
+ sudo apt update && sudo apt install pipx
43
+ pipx ensurepath
44
+ ```
45
+ - **Fedora:**
46
+ ```bash
47
+ sudo dnf install pipx
48
+ pipx ensurepath
49
+ ```
50
+ *(Setelah `pipx ensurepath`, tutup dan buka terminal baru, atau jalankan `source ~/.bashrc` / `source ~/.zshrc`.)*
51
+
52
+ **Windows (PowerShell):**
53
+ ```powershell
54
+ python -m pip install --user pipx
55
+ python -m pipx ensurepath
56
+ ```
57
+ *(Alternatif jika memakai Scoop: `scoop install pipx`. Setelah selesai, tutup lalu buka kembali PowerShell agar `PATH` aktif.)*
58
+
59
+ ## Cara Instalasi
60
+
61
+ ### Opsi 1: Langsung via `pipx` (Direkomendasikan)
62
+
63
+ ```bash
64
+ pipx install git+https://github.com/ryaleason/lapctl.git
65
+ ```
66
+
67
+ Untuk memperbarui ke versi terbaru nanti:
68
+
69
+ ```bash
70
+ pipx upgrade lapctl
71
+ ```
72
+
73
+ ### Opsi 2: Dari Source (`git clone`)
74
+
75
+ ```bash
76
+ git clone https://github.com/ryaleason/lapctl.git
77
+ cd lapctl
78
+ python3 -m venv .venv
79
+ source .venv/bin/activate
80
+ pip install .
81
+ ```
82
+
83
+ ## Setup Awal (Kurang dari 3 Menit)
84
+
85
+ 1. **Buat bot Telegram:** buka [@BotFather](https://t.me/BotFather) di Telegram, kirim `/newbot`, lalu salin **Bot Token** yang diberikan.
86
+ 2. **Jalankan wizard setup:**
87
+ ```bash
88
+ lapctl setup
89
+ ```
90
+ Wizard akan memandu kamu:
91
+ - Memasukkan **Bot Token** (input disembunyikan) dan memvalidasinya otomatis.
92
+ - Mendeteksi **Owner ID** secara otomatis: kamu cukup mengirim pesan apa saja ke bot barumu dari chat privat Telegram.
93
+ - Memilih profil izin (`aman`, `standar`, atau `lengkap`), bahasa, dan nama perangkat.
94
+ - Menyimpan konfigurasi ke `~/.config/lapctl/config.toml` dengan izin terbatas (`0600`).
95
+ - Memasang auto-start `systemd --user` (`lapctl.service`) agar bot berjalan otomatis saat login.
96
+ 3. **Cek dependensi alat OS:**
97
+ ```bash
98
+ lapctl doctor
99
+ ```
100
+ Perintah ini memeriksa alat seperti `grim`, `ffmpeg`, `wf-recorder`, `hyprlock`, `wpctl`, `brightnessctl`, `playerctl`, `wl-clipboard`, `swww`, `notify-send`, `xdotool`, dan `mpv`, beserta saran instalasinya jika ada yang kurang.
101
+
102
+ ## Perintah CLI
103
+
104
+ | Perintah | Fungsi |
105
+ |---|---|
106
+ | `lapctl setup` | Wizard pemasangan & konfigurasi awal |
107
+ | `lapctl doctor` | Cek Python, driver aktif, dan dependensi alat OS |
108
+ | `lapctl start` | Jalankan agent di foreground |
109
+ | `lapctl stop` / `restart` | Hentikan atau mulai ulang service systemd user |
110
+ | `lapctl status` | Cek status service dan koneksi ke Telegram |
111
+ | `lapctl logs` | Lihat log terbaru dari service |
112
+ | `lapctl config` | Lihat atau ubah pengaturan (`--profile`, `--language`, `--device-name`, `--ntfy-topic`) |
113
+ | `lapctl uninstall` | Hapus service dan file konfigurasi |
114
+ | `lapctl --version` | Tampilkan versi |
115
+
116
+ ## Profil Izin
117
+
118
+ | Profil | Isi |
119
+ |---|---|
120
+ | `aman` | Info sistem, kontrol media/volume/kecerahan, notifikasi, lock, power (dengan konfirmasi Ya/Batal) |
121
+ | `standar` (default) | Profil aman + screenshot, webcam, rekam layar/mic, baca clipboard, `/ls`, `/find`, `/download` dalam `allowed_roots` |
122
+ | `lengkap` | Profil standar + `/mouse`, `/keyboard`, `/upload`, `/setclip`, `/cmd` |
123
+
124
+ ## Daftar Perintah Telegram
125
+
126
+ | Kategori | Perintah | Risiko | Profil minimum |
127
+ |---|---|---|---|
128
+ | Navigasi | `/start`, `/help`, `/menu` | R | aman |
129
+ | Info | `/status`, `/health`, `/ps`, `/network`, `/ip`, `/logs` | R | aman |
130
+ | Power | `/lock` | C | aman |
131
+ | Power | `/suspend`, `/reboot`, `/shutdown` (wajib konfirmasi) | P | aman |
132
+ | Audio/Media | `/volume`, `/mute`, `/unmute`, `/volup`, `/voldown`, `/play`, `/pause`, `/next`, `/prev`, `/beep` | C | aman |
133
+ | Layar | `/brightness`, `/notify` | C | aman |
134
+ | Capture | `/ss`, `/cam`, `/vid`, `/screenrecord`, `/record` | S | standar |
135
+ | File | `/ls`, `/find`, `/download` (hanya `allowed_roots`) | S | standar |
136
+ | Clipboard | `/getclip` | S | standar |
137
+ | Browser & Tampilan | `/youtube`, `/wallpaper` | C | standar |
138
+ | Eksternal | `/say`, `/loc`, `/carihp` | S | standar |
139
+ | Input & File | `/mouse`, `/keyboard`, `/upload`, `/setclip` | X | lengkap |
140
+ | Shell | `/cmd` | X | lengkap |
141
+
142
+ ## Pengembangan
143
+
144
+ ```bash
145
+ python -m venv .venv && source .venv/bin/activate
146
+ pip install -e ".[dev]"
147
+ ruff check . && ruff format --check .
148
+ pytest -q
149
+ ```
@@ -0,0 +1,29 @@
1
+ lapctl/__init__.py,sha256=As5sXQhK4_sL9wc4rpwq9Udi3MO473fRD1E9NNd7F3I,69
2
+ lapctl/cli.py,sha256=HqIYlkLUgWbPzOV2uO38GCGHxyXQ_euO4LF12_f_e6c,18570
3
+ lapctl/config.py,sha256=FYrcUvBXr8ieZM8zCXZ5pF3FUUtgKzrAwXniRBUAgdU,5695
4
+ lapctl/main.py,sha256=ngsul4bfFUj198D6NCFQzBYOWOjqvKpDMyYDXpfgtZA,2802
5
+ lapctl/registry.py,sha256=9TU4yrSJugZYI19PHlo_jQQGQVmGyHqD-BpTQs_wRWA,3589
6
+ lapctl/results.py,sha256=NnFtiCI-9UKIIZ6wG_bEPaE5B-hRgqm2-DqiD1yGJoo,1615
7
+ lapctl/channels/__init__.py,sha256=plvL87KaqbTVKf0sAs3LG5iKyuCuAnPeNI3zCIveqtE,39
8
+ lapctl/channels/telegram/__init__.py,sha256=V4KKltFCIFW-0cDezsKjHjmBxU25KXN4eEqvBKANJOk,32
9
+ lapctl/channels/telegram/api.py,sha256=T_0b9vBlRUpwFcgrJROr1tAYtaORarUWYQK6CRfNf8k,12523
10
+ lapctl/channels/telegram/auth.py,sha256=H7aWrO5Q1TWE6AsYK1aNMaQbnaovnQj0fNdOE_VFUp4,780
11
+ lapctl/channels/telegram/handlers.py,sha256=14n_HslZ8TmzxA0Ub4Buzp1JVhhXl3LielpMwpnKzDY,6241
12
+ lapctl/channels/telegram/poller.py,sha256=f6o7p6OOKsh0nr6lXk7k_x0xrykWm-bO1ql8aLo3Kiw,6075
13
+ lapctl/channels/telegram/render.py,sha256=eSohQfkloMFS7UzKdTkxBs6_IPo-dddm-4V_-j1Od_M,5694
14
+ lapctl/core/__init__.py,sha256=rSHqAtey5oka9Iznqz_xrAhFHYRBnjAHR_1GDxdiEI4,61
15
+ lapctl/core/battery.py,sha256=BFXvVdznMKvFEIUfcz2fC3VgXAPN_xr7H9bdeUOn8xA,2227
16
+ lapctl/core/commands.py,sha256=nDzzEc9EfiORIPZgHsjtDNQhtrpEYVKJiO81XmDfj5w,41438
17
+ lapctl/core/confirm.py,sha256=mSPDI7KSOGEUUf8LMTGOhsJXJ9nHyMmkBst-pwY4MyQ,2278
18
+ lapctl/core/keyboards.py,sha256=Q5LQAX6saahk7V_p7O5fsDQkGixJ_JyeVORo3sdE9To,5192
19
+ lapctl/core/paths.py,sha256=Y5a_eyeui_kDtVzBwC31WSW0TJJcSjvXbSKxz9VcpEo,2691
20
+ lapctl/core/ratelimit.py,sha256=fTKoH5Qo2fydnlwdUt-e8kWhsIK49lThG05jtOawdY4,993
21
+ lapctl/drivers/__init__.py,sha256=Q_SP82wRphlnADGzo5Uhh9fQZeI611jbzfNgHtcZmIk,49
22
+ lapctl/drivers/base.py,sha256=jJWmSuOweiKT4-1m2fgTPtL0Qgo2OBCVSB9iOS_aMug,5370
23
+ lapctl/drivers/linux_hyprland.py,sha256=lCaqhqQIT-_N4oRlUWxuHX0Etc7sawxQhThFrQdUQ3g,19777
24
+ lapctl-0.1.1.dist-info/licenses/LICENSE,sha256=LzHHlpJu8WLoBmJXeKRDCfCpYjCNCNIemOlZXWTcC2M,1064
25
+ lapctl-0.1.1.dist-info/METADATA,sha256=FkjxP0vfLKVBezfHHxuDSdcTkJFt1sddmwsxR-Hp74M,5614
26
+ lapctl-0.1.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
27
+ lapctl-0.1.1.dist-info/entry_points.txt,sha256=UH-1XyiJFSW8bwzVCQ9ayvmUxakpL3DpJUTZBU_al3U,43
28
+ lapctl-0.1.1.dist-info/top_level.txt,sha256=GjPdseuocwM-HBOKXm4jUnIanWExAaygCdiqRC1YQCE,7
29
+ lapctl-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ lapctl = lapctl.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gabyrrr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ lapctl