Rename app.py to app.py\
Browse files- app.py → app.py// +47 -10
app.py → app.py//
RENAMED
|
@@ -171,7 +171,25 @@ def create_drive_folder(drive_service, name):
|
|
| 171 |
def setup_dependencies():
|
| 172 |
"""Install required system dependencies"""
|
| 173 |
try:
|
| 174 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
subprocess.run(['apt-get', 'update', '-y'], check=True)
|
| 176 |
packages = [
|
| 177 |
'libnss3', 'libnss3-tools', 'libnspr4', 'libatk1.0-0',
|
|
@@ -181,12 +199,9 @@ def setup_dependencies():
|
|
| 181 |
]
|
| 182 |
subprocess.run(['apt-get', 'install', '-y', '--no-install-recommends'] + packages, check=True)
|
| 183 |
|
| 184 |
-
# Install Python packages
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
# Install browsers
|
| 188 |
-
subprocess.run(['python3', '-m', 'playwright', 'install', 'chromium'], check=True)
|
| 189 |
-
subprocess.run(['python3', '-m', 'pyppeteer', 'install'], check=True)
|
| 190 |
|
| 191 |
st.success("Dependencies installed successfully!")
|
| 192 |
return True
|
|
@@ -201,10 +216,32 @@ def check_services():
|
|
| 201 |
"""Check if required services are running"""
|
| 202 |
try:
|
| 203 |
# Check Redis for Celery
|
| 204 |
-
redis_running =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
if not redis_running:
|
| 206 |
-
# Try to start Redis
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
# Create directories for intercepted data
|
| 210 |
os.makedirs(NETWORK_INTERCEPTOR_CONFIG['intercept_folder'], exist_ok=True)
|
|
|
|
| 171 |
def setup_dependencies():
|
| 172 |
"""Install required system dependencies"""
|
| 173 |
try:
|
| 174 |
+
# Check if browsers are already installed instead of installing them
|
| 175 |
+
if os.path.exists(os.path.join(os.environ.get('PLAYWRIGHT_BROWSERS_PATH', ''), 'chromium-1045')):
|
| 176 |
+
logger.info("Playwright browsers already installed, skipping installation")
|
| 177 |
+
installed = True
|
| 178 |
+
else:
|
| 179 |
+
# Only try to install browsers if they don't exist already
|
| 180 |
+
try:
|
| 181 |
+
subprocess.run(['python3', '-m', 'playwright', 'install', 'chromium'],
|
| 182 |
+
check=True, env=os.environ)
|
| 183 |
+
installed = True
|
| 184 |
+
except subprocess.CalledProcessError as e:
|
| 185 |
+
logger.warning(f"Could not install browsers: {e}")
|
| 186 |
+
installed = False
|
| 187 |
+
|
| 188 |
+
# Skip system dependency installation in container environment
|
| 189 |
+
if os.path.exists('/.dockerenv'):
|
| 190 |
+
return installed
|
| 191 |
+
|
| 192 |
+
# System packages installation
|
| 193 |
subprocess.run(['apt-get', 'update', '-y'], check=True)
|
| 194 |
packages = [
|
| 195 |
'libnss3', 'libnss3-tools', 'libnspr4', 'libatk1.0-0',
|
|
|
|
| 199 |
]
|
| 200 |
subprocess.run(['apt-get', 'install', '-y', '--no-install-recommends'] + packages, check=True)
|
| 201 |
|
| 202 |
+
# Install Python packages - only if not in Docker
|
| 203 |
+
if not os.path.exists('/.dockerenv'):
|
| 204 |
+
subprocess.run(['pip', 'install', 'playwright', 'pyppeteer', 'splash', 'celery[redis]', 'mitmproxy'], check=True)
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
st.success("Dependencies installed successfully!")
|
| 207 |
return True
|
|
|
|
| 216 |
"""Check if required services are running"""
|
| 217 |
try:
|
| 218 |
# Check Redis for Celery
|
| 219 |
+
redis_running = False
|
| 220 |
+
try:
|
| 221 |
+
redis_running = subprocess.run(['redis-cli', 'ping'],
|
| 222 |
+
capture_output=True,
|
| 223 |
+
text=True).stdout.strip() == 'PONG'
|
| 224 |
+
except Exception:
|
| 225 |
+
pass
|
| 226 |
+
|
| 227 |
if not redis_running:
|
| 228 |
+
# Try to start Redis as a non-root user
|
| 229 |
+
try:
|
| 230 |
+
if os.path.exists('/etc/redis/redis.conf'):
|
| 231 |
+
# Custom Redis config for non-root
|
| 232 |
+
subprocess.run(['redis-server', '/etc/redis/redis.conf'],
|
| 233 |
+
check=False,
|
| 234 |
+
stdout=subprocess.DEVNULL,
|
| 235 |
+
stderr=subprocess.DEVNULL)
|
| 236 |
+
else:
|
| 237 |
+
# Fallback to basic Redis without custom config
|
| 238 |
+
subprocess.run(['redis-server', '--daemonize', 'yes'],
|
| 239 |
+
check=False,
|
| 240 |
+
stdout=subprocess.DEVNULL,
|
| 241 |
+
stderr=subprocess.DEVNULL)
|
| 242 |
+
except Exception as e:
|
| 243 |
+
logger.warning(f"Could not start Redis: {e}")
|
| 244 |
+
st.warning("Redis service could not be started. Celery tasks will not work properly.")
|
| 245 |
|
| 246 |
# Create directories for intercepted data
|
| 247 |
os.makedirs(NETWORK_INTERCEPTOR_CONFIG['intercept_folder'], exist_ok=True)
|