-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconfig.py
More file actions
507 lines (416 loc) · 17.1 KB
/
config.py
File metadata and controls
507 lines (416 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Configuration and utilities for cross-platform Facebook tool.
Supports: Windows, Linux, Termux (Android)
Author: SHAJON
GitHub: SHAJON-404
"""
import os
import sys
import json
import platform
import signal
import time
import random
import binascii
import subprocess
import shutil
from pathlib import Path
from dataclasses import dataclass, field
from typing import List, Optional, Callable, Dict, Any
# ================== PLATFORM INFO ==================
@dataclass
class PlatformInfo:
"""Platform-specific configuration."""
name: str
is_termux: bool = False
is_windows: bool = False
is_linux: bool = False
output_dir: Path = field(default_factory=Path)
clear_cmd: str = "clear"
# ================== COLORS ==================
@dataclass
class Colors:
"""ANSI color codes."""
BLACK: str = '\x1b[1;30m'
RED: str = '\x1b[1;31m'
GREEN: str = '\x1b[1;32m'
YELLOW: str = '\x1b[1;33m'
BLUE: str = '\x1b[1;34m'
PURPLE: str = '\x1b[1;35m'
CYAN: str = '\x1b[1;36m'
WHITE: str = '\x1b[1;37m'
ORANGE: str = '\x1b[38;5;208m'
RESET: str = '\x1b[0m'
# ================== CONFIG CLASS ==================
class Config:
"""
Singleton configuration manager for the Facebook tool.
Handles platform detection, session storage, and utilities.
"""
_instance: Optional['Config'] = None
# Device models for user agent generation
SAMSUNG_MODELS: List[str] = [
"SM-G991B", "SM-G996B", "SM-G998B", "SM-A528B", "SM-M336B",
"SM-F926B", "SM-F711B", "SM-A127F", "SM-M127F", "SM-G973F",
"SM-G975F", "SM-G970F", "SM-A225F", "SM-M225FV", "SM-A325F",
"SM-M325F", "SM-A426B", "SM-M426B", "SM-A526B", "SM-M526B",
"SM-A715F", "SM-M715F", "SM-A515F", "SM-M515F", "SM-A105F",
"SM-M105F", "SM-A205F", "SM-M205F", "SM-N980F", "SM-N986B"
]
NETWORK_OPERATORS: List[str] = [
"Robi", "Airtel", "Grameenphone", "Banglalink", "Teletalk",
"Jio", "Vodafone", "Airtel India", "Telenor", "AT&T",
"Verizon", "Sprint", "T-Mobile", "Orange", "O2",
"Vodafone UK", "China Mobile", "China Unicom", "China Telecom",
"NTT Docomo", "SK Telecom", "KT", "Telstra", "Optus",
"Rogers", "Bell", "Telus", "MTN", "Vodacom", "Etisalat"
]
TERMINAL_TITLE: str = "🔥SHAJON~404🔥"
def __new__(cls) -> 'Config':
"""Singleton pattern - ensure only one instance exists."""
if cls._instance is None:
cls._instance = super().__new__(cls)
cls._instance._initialized = False
return cls._instance
def __init__(self) -> None:
"""Initialize configuration (only once due to singleton)."""
if self._initialized:
return
self._initialized = True
self._colors = Colors()
self._platform = self._detect_platform()
self._script_dir = Path(__file__).parent.resolve()
self._session_file = self._script_dir / ".shajon_session.json"
# Enable ANSI on Windows
if self._platform.is_windows:
try:
import colorama
colorama.init()
except ImportError:
os.system("")
# ================== PROPERTIES ==================
@property
def platform(self) -> PlatformInfo:
"""Get platform information."""
return self._platform
@property
def colors(self) -> Colors:
"""Get color codes."""
return self._colors
@property
def session_file(self) -> Path:
"""Get session file path."""
return self._session_file
@property
def script_dir(self) -> Path:
"""Get script directory path."""
return self._script_dir
@property
def r(self) -> str:
return self._colors.RED
@property
def g(self) -> str:
return self._colors.GREEN
@property
def w(self) -> str:
return self._colors.WHITE
@property
def b(self) -> str:
return self._colors.BLUE
@property
def p(self) -> str:
return self._colors.PURPLE
@property
def o(self) -> str:
return self._colors.BLACK
@property
def y(self) -> str:
return self._colors.YELLOW
@property
def style_box(self) -> str:
"""Get styled box prefix."""
return f"{self.r}[{self.w}ヅ{self.r}]{self.w}"
@property
def line(self) -> str:
"""Get separator line."""
return f"{self.b}━" * 56
@property
def logo(self) -> str:
"""Get application logo."""
return f'''{self.g}888888 88 88 888888 {self.r}/{self.g}/{self.r}/{self.w}OWNER {self.g}>{self.r}={self.g}={self.r}>{self.g} SHAJON
{self.g}88__ 88 88 88__ {self.r}/{self.g}/{self.r}/{self.w}GitHub {self.g}>{self.r}={self.g}={self.r}>{self.g} SHAJON-404
{self.g}88"" 88 88 .o 88"" {self.r}/{self.g}/{self.r}/{self.w}TOOL {self.g}>{self.r}={self.g}={self.r}>{self.g} FILE MAKE
{self.g}88 88 88ood8 888888 {self.r}/{self.g}/{self.r}/{self.w}VERSION {self.g}>{self.r}={self.g}={self.r}>{self.g} 3.1 {self.r}[{self.g}BETA{self.r}]
{self.line}'''
# ================== PLATFORM DETECTION ==================
@staticmethod
def _detect_platform() -> PlatformInfo:
"""Detect current platform and return configuration."""
system = platform.system().lower()
is_termux = (
os.path.exists("/data/data/com.termux") or
"com.termux" in os.environ.get("PREFIX", "") or
os.environ.get("TERMUX_VERSION") is not None
)
if is_termux:
return PlatformInfo(
name="Termux",
is_termux=True,
output_dir=Path("/sdcard/SHAJON"),
clear_cmd="clear"
)
elif system == "windows":
return PlatformInfo(
name="Windows",
is_windows=True,
output_dir=Path.cwd() / "SHAJON",
clear_cmd="cls"
)
else:
return PlatformInfo(
name="Linux",
is_linux=True,
output_dir=Path.cwd() / "SHAJON",
clear_cmd="clear"
)
# ================== USER AGENT GENERATORS ==================
@staticmethod
def generate_fb_user_agent() -> str:
"""Generate a random Facebook mobile user agent."""
fbav = f"{random.randint(11, 470)}.0.0.{random.randrange(9, 49)}{random.randint(11, 77)}"
fbbv = str(random.randint(100000000, 409614015))
fbcr = random.choice(Config.NETWORK_OPERATORS)
model = random.choice(Config.SAMSUNG_MODELS)
return (
f"[FBAN/FB4A;FBAV/{fbav};FBBV/{fbbv};"
f"FBDM/{{density=2.0,width=720,height=1456}};"
f"FBLC/en_GB;FBRV/{fbbv};FBCR/{fbcr};"
f"FBMF/samsung;FBBD/samsung;FBPN/com.facebook.katana;"
f"FBDV/{model};FBSV/10;FBBK/1;FBOP/1;FBCA/arm64-v8a:;]"
)
# ================== DISPLAY UTILITIES ==================
def clear_screen(self) -> None:
"""Clear terminal screen and show logo."""
os.system(self._platform.clear_cmd)
print(self.logo)
def set_terminal_title(self, title: str = None) -> None:
"""Set terminal title cross-platform."""
title = title or self.TERMINAL_TITLE
if self._platform.is_windows:
os.system(f'title {title}')
else:
sys.stdout.write(f'\x1b]2;{title}\x07')
sys.stdout.flush()
def linex(self) -> None:
"""Print a separator line."""
print(self.line)
def box(self, value: str) -> str:
"""Format a value in a styled box."""
return f"{self.r}[{self.w}{value}{self.r}]{self.w}"
def animate(self, text: str, delay: float = 0.01) -> None:
"""Animate text output character by character."""
for char in text + "\n":
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(delay)
def random_color(self) -> str:
"""Get a random ANSI color."""
colors = [self.o, self.r, self.g, self.y, self.b, self.p, self.w]
return random.choice(colors)
# ================== FILE OPERATIONS ==================
def ensure_output_dir(self) -> Path:
"""Ensure output directory exists and return path."""
self._platform.output_dir.mkdir(parents=True, exist_ok=True)
return self._platform.output_dir
def get_output_path(self, filename: str) -> Path:
"""Get full path for output file."""
self.ensure_output_dir()
return self._platform.output_dir / filename
def generate_filename(self, prefix: str = "shajon", ext: str = "txt") -> Path:
"""Generate a unique filename in output directory."""
random_id = random.randint(1, 9999)
return self.get_output_path(f"{prefix}_{random_id}.{ext}")
def clean_small_files(self, min_size_kb: int = 10) -> None:
"""Remove small txt files from output directory."""
try:
for file_path in self._platform.output_dir.glob("*.txt"):
if file_path.stat().st_size < min_size_kb * 1024:
file_path.unlink()
except Exception:
pass
def remove_duplicates_from_file(self, filepath: Path) -> int:
"""Remove duplicate lines from file. Returns count of unique lines."""
try:
with open(filepath, 'r', encoding='utf-8') as f:
lines = f.read().splitlines()
unique_lines = sorted(set(lines), reverse=True)
with open(filepath, 'w', encoding='utf-8') as f:
f.write('\n'.join(unique_lines))
return len(unique_lines)
except Exception as e:
print(f"{self.style_box} ERROR: {self.o}{e}")
return 0
# ================== SESSION MANAGEMENT ==================
def _load_session(self) -> Dict[str, Any]:
"""Load session data from JSON file."""
try:
return json.loads(self._session_file.read_text(encoding='utf-8'))
except (FileNotFoundError, json.JSONDecodeError):
return {}
def _save_session(self, data: Dict[str, Any]) -> None:
"""Save session data to JSON file."""
self._session_file.write_text(
json.dumps(data, indent=2, ensure_ascii=False),
encoding='utf-8'
)
def save_token(self, token: str) -> None:
"""Save token to session."""
session = self._load_session()
session['token'] = token
self._save_session(session)
def load_token(self) -> Optional[str]:
"""Load token from session."""
return self._load_session().get('token')
def save_cookie(self, cookie: str) -> None:
"""Save cookie to session."""
session = self._load_session()
session['cookie'] = cookie
self._save_session(session)
def load_cookie(self) -> Optional[str]:
"""Load cookie from session."""
return self._load_session().get('cookie')
def save_login_check(self, friend_ids: List[str]) -> None:
"""Save login check friend IDs to session."""
session = self._load_session()
session['login_check'] = friend_ids
self._save_session(session)
def load_login_check(self) -> List[str]:
"""Load login check friend IDs from session."""
return self._load_session().get('login_check', [])
def clear_credentials(self) -> None:
"""Remove session file and legacy files."""
try:
self._session_file.unlink()
except FileNotFoundError:
pass
# Remove legacy .txt files
legacy_files = [
self._script_dir / ".shajon_token.txt",
self._script_dir / ".shajon_cookies.txt",
self._script_dir / ".login_check.txt"
]
for file in legacy_files:
try:
file.unlink()
except FileNotFoundError:
pass
def get_session_info(self) -> Dict[str, Any]:
"""Get full session info for display."""
session = self._load_session()
return {
'has_token': bool(session.get('token')),
'has_cookie': bool(session.get('cookie')),
'friend_count': len(session.get('login_check', []))
}
# ================== SIGNAL HANDLING ==================
def setup_signal_handlers(self, on_exit: Optional[Callable] = None) -> None:
"""Setup signal handlers for graceful exit."""
def handle_interrupt(signum, frame):
pass
def handle_stop(signum, frame):
self.linex()
print(f"\r{self.style_box} THANKS FOR USING THIS TOOL....")
if on_exit:
on_exit()
self.linex()
sys.exit(0)
signal.signal(signal.SIGINT, handle_interrupt)
if hasattr(signal, 'SIGTSTP') and not self._platform.is_windows:
signal.signal(signal.SIGTSTP, handle_stop)
# ================== URL HANDLING ==================
def open_url(self, url: str) -> None:
"""Open URL in default browser - cross-platform."""
try:
if self._platform.is_termux:
os.system(f'am start -a android.intent.action.VIEW -d "{url}" > /dev/null 2>&1')
elif self._platform.is_windows:
os.system(f'start "" "{url}"')
else:
os.system(f'xdg-open "{url}" 2>/dev/null || open "{url}" 2>/dev/null')
except Exception:
pass
def open_social(self, platform_name: str) -> None:
"""Open social media links."""
urls = {
"wp": "https://chat.whatsapp.com/FBMupd6ED8xA3B3IvofPb5",
"tg": "https://t.me/SHAJON",
"git": "https://github.com/SHAJON-404/",
"fb": "https://www.facebook.com/share/1A3Ljftimf/"
}
# Disabled for now
# url = urls.get(platform_name, urls["fb"])
# self.open_url(url)
# ================== STORAGE CHECK ==================
def check_storage_permission(self) -> bool:
"""Check and request storage permission on Termux."""
if not self._platform.is_termux:
return True
try:
test_file = Path("/sdcard/.shajon_test")
test_file.write_text("test")
test_file.unlink()
return True
except PermissionError:
print(f"{self.style_box} PLEASE ALLOW STORAGE PERMISSION...✅")
self.linex()
os.system("termux-setup-storage")
return False
except Exception as e:
print(f"{self.style_box} ERROR: {self.o}{e}")
return False
# ================== INITIALIZATION ==================
def initialize(self) -> None:
"""Initialize the application."""
self.set_terminal_title()
self.ensure_output_dir()
self.clean_small_files()
# ================== GLOBAL INSTANCE ==================
# Create singleton instance for backward compatibility
config = Config()
# Backward compatibility exports
PLATFORM = config.platform
C = config.colors
r, g, w, b, p, o, y = config.r, config.g, config.w, config.b, config.p, config.o, config.y
STYLE_BOX = config.style_box
LINE = config.line
LOGO = config.logo
SESSION_FILE = config.session_file
# Function aliases for backward compatibility
clear_screen = config.clear_screen
linex = config.linex
box = config.box
animate = config.animate
random_color = config.random_color
open_social = config.open_social
save_token = config.save_token
load_token = config.load_token
save_cookie = config.save_cookie
load_cookie = config.load_cookie
save_login_check = config.save_login_check
load_login_check = config.load_login_check
clear_credentials = config.clear_credentials
get_output_path = config.get_output_path
generate_filename = config.generate_filename
ensure_output_dir = config.ensure_output_dir
remove_duplicates_from_file = config.remove_duplicates_from_file
setup_signal_handlers = config.setup_signal_handlers
initialize = config.initialize
check_storage_permission = config.check_storage_permission
generate_fb_user_agent = Config.generate_fb_user_agent
if __name__ == "__main__":
cfg = Config()
print(f"Platform: {cfg.platform.name}")
print(f"Output Directory: {cfg.platform.output_dir}")
print(f"Session File: {cfg.session_file}")