bot 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533
  1. #!/bin/bash
  2. clear
  3. [[ ! -d /etc/SSHPlus ]] && exit 0
  4. [[ ! -d /etc/bot ]] && exit 0
  5. source ShellBot.sh
  6. api_bot=$1
  7. id_admin=$2
  8. [[ -z $api_bot ]] && exit 0
  9. [[ -z $id_admin ]] && exit 0
  10. [[ ! -e /usr/lib/licence ]] && exit 0
  11. ativos='/etc/bot/lista_ativos'
  12. suspensos='/etc/bot/lista_suspensos'
  13. ShellBot.init --token "$api_bot" --monitor --return map --flush
  14. ShellBot.username
  15. fun_menu() {
  16. [[ "${message_from_id[$id]}" == "$id_admin" ]] && {
  17. local env_msg
  18. env_msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  19. env_msg+="<b>🤖 SEJA BEM VINDO(a) AO BOT SSH 🤖</b>\n"
  20. env_msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  21. env_msg+="⚠️ <i>SELECIONE UMA OPCAO ABAIXO !</i>\n\n"
  22. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} --text "$env_msg" \
  23. --reply_markup "$keyboard1" \
  24. --parse_mode html
  25. return 0
  26. }
  27. [[ -d /etc/bot/suspensos/${message_from_username} ]] && {
  28. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  29. --text "$(echo -e "🚫 VC ESTA SUSPENSO 🚫\n\nCONTATE O ADMINISTRADOR")"
  30. return 0
  31. }
  32. if [[ "$(grep -w "${message_from_username}" $ativos | grep -wc 'revenda')" != '0' ]]; then
  33. local env_msg
  34. env_msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  35. env_msg+="<b>🤖 SEJA BEM VINDO(a) AO BOT SSH 🤖</b>\n"
  36. env_msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  37. env_msg+="⚠️ <i>SELECIONE UMA OPCAO ABAIXO !</i>\n\n"
  38. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} --text "$env_msg" \
  39. --reply_markup "$keyboard2" \
  40. --parse_mode html
  41. return 0
  42. elif [[ "$(grep -w "${message_from_username}" $ativos | grep -wc 'subrevenda')" != '0' ]]; then
  43. local env_msg
  44. env_msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  45. env_msg+="<b>🤖 SEJA BEM VINDO(a) AO BOT SSH 🤖</b>\n"
  46. env_msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  47. env_msg+="⚠️ <i>SELECIONE UMA OPCAO ABAIXO !</i>\n\n"
  48. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} --text "$env_msg" \
  49. --reply_markup "$keyboard3" \
  50. --parse_mode html
  51. return 0
  52. else
  53. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  54. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  55. return 0
  56. fi
  57. }
  58. fun_ajuda() {
  59. [[ ${message_chat_id[$id]} == "" ]] && {
  60. id_chatuser="${callback_query_message_chat_id[$id]}"
  61. id_name="${callback_query_from_username}"
  62. } || {
  63. id_chatuser="${message_chat_id[$id]}"
  64. id_name="${message_from_username}"
  65. }
  66. if [[ "$id_chatuser" = "$id_admin" ]]; then
  67. local env_msg
  68. env_msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  69. env_msg+="<b>🤖 BEM VINDO(a) AO BOT SSH 🤖</b>\n"
  70. env_msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  71. env_msg+="⚠️ <i>Comandos Disponiveis</i>\n\n"
  72. env_msg+="[<b>01</b>] /menu = Exibe menu\n"
  73. env_msg+="[<b>02</b>] /info = Exibe informacoes\n"
  74. env_msg+="[<b>03</b>] /ajuda = Informacoes sobre opcoes\n\n"
  75. env_msg+="⚠️ <i>Opções Disponiveis</i>\n\n"
  76. env_msg+="• <u>CRIAR USUARIO</u> = Cria usuario ssh\n\n"
  77. env_msg+="• <u>CRIAR TESTE</u> = Cria teste ssh\n\n"
  78. env_msg+="• <u>REMOVER</u> = Remove usuario ssh\n\n"
  79. env_msg+="• <u>INFO USUARIOS</u> = Informacoes do usuario\n\n"
  80. env_msg+="• <u>USUARIOS ONLINE</u> = Exibe Usuários onlines\n\n"
  81. env_msg+="• <u>INFO VPS</u> = Informacoes do servidor\n\n"
  82. env_msg+="• <u>ALTERAR SENHA</u> = Altera senha ssh\n\n"
  83. env_msg+="• <u>ALTERAR LIMITE</u> = Altera limite ssh\n\n"
  84. env_msg+="• <u>ALTERAR DATA</u> = Altera data ssh\n\n"
  85. env_msg+="• <u>EXPIRADOS</u> = Remove ssh expirados\n\n"
  86. env_msg+="• <u>BACKUP</u> = Cria Backup ssh e revendas\n\n"
  87. env_msg+="• <u>OTIMIZAR</u> = Limpa o cache - ram\n\n"
  88. env_msg+="• <u>SPEEDTESTE</u> = Teste de conexao\n\n"
  89. env_msg+="• <u>ARQUIVOS</u> = Hospeda Arquivos\n\n"
  90. env_msg+="• <u>REVENDAS</u> = Gerenciar Revendas\n\n"
  91. env_msg+="• <u>AUTOBACKUP</u> = lig/Des Backup automatico\n\n"
  92. env_msg+="• <u>RELATORIO</u> = Informacoes sobre revendas\n\n"
  93. env_msg+="• <u>AJUDA</u> = Informacoes sobre opcoes\n\n"
  94. ShellBot.sendMessage --chat_id $id_chatuser \
  95. --text "$(echo -e $env_msg)" \
  96. --parse_mode html
  97. return 0
  98. elif [[ -d /etc/bot/suspensos/$id_name ]]; then
  99. ShellBot.sendMessage --chat_id $id_chatuser \
  100. --text "$(echo -e "🚫 VC ESTA SUSPENSO 🚫\n\nCONTATE O ADMINISTRADOR")"
  101. return 0
  102. elif [[ "$(grep -w "$id_name" $ativos | awk '{print $NF}')" == 'revenda' ]]; then
  103. local env_msg
  104. env_msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  105. env_msg+="<b>🤖 BEM VINDO(a) AO BOT SSH 🤖</b>\n"
  106. env_msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  107. env_msg+="⚠️ <i>Comandos Disponiveis</i>\n\n"
  108. env_msg+="[<b>01</b>] /menu = Exibe menu\n"
  109. env_msg+="[<b>02</b>] /info = Exibe informacoes\n"
  110. env_msg+="[<b>03</b>] /ajuda = Informacoes sobre opcoes\n\n"
  111. env_msg+="⚠️ <i>Opções Disponiveis</i>\n\n"
  112. env_msg+="• <u>CRIAR USUARIO</u> = Cria usuario ssh\n\n"
  113. env_msg+="• <u>CRIAR TESTE</u> = Cria teste ssh\n\n"
  114. env_msg+="• <u>REMOVER</u> = Remove usuario ssh\n\n"
  115. env_msg+="• <u>INFO USUARIOS</u> = Informacoes do usuario\n\n"
  116. env_msg+="• <u>USUARIOS ONLINE</u> = Exibe Usuários onlines\n\n"
  117. env_msg+="• <u>ALTERAR SENHA</u> = Altera senha ssh\n\n"
  118. env_msg+="• <u>ALTERAR LIMITE</u> = Altera limite ssh\n\n"
  119. env_msg+="• <u>ALTERAR DATA</u> = Altera data ssh\n\n"
  120. env_msg+="• <u>EXPIRADOS</u> = Remove ssh expirados\n\n"
  121. env_msg+="• <u>REVENDAS</u> = Gerenciar Revendas\n\n"
  122. env_msg+="• <u>RELATORIO</u> = Informacoes sobre revendas\n\n"
  123. env_msg+="• <u>AJUDA</u> = Informacoes sobre opcoes\n\n"
  124. ShellBot.sendMessage --chat_id $id_chatuser \
  125. --text "$(echo -e $env_msg)" \
  126. --parse_mode html
  127. return 0
  128. elif [[ "$(grep -w "$id_name" $ativos | awk '{print $NF}')" == 'subrevenda' ]]; then
  129. local env_msg
  130. env_msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  131. env_msg+="<b>🤖 BEM VINDO(a) AO BOT SSH 🤖</b>\n"
  132. env_msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  133. env_msg+="⚠️ <i>Comandos Disponiveis</i>\n\n"
  134. env_msg+="[<b>01</b>] /menu = Exibe menu\n"
  135. env_msg+="[<b>02</b>] /info = Exibe informacoes\n"
  136. env_msg+="[<b>03</b>] /ajuda = Informacoes sobre opcoes\n\n"
  137. env_msg+="⚠️ <i>Opções Disponiveis</i>\n\n"
  138. env_msg+="• <u>CRIAR USUARIO</u> = Cria usuario ssh\n\n"
  139. env_msg+="• <u>CRIAR TESTE</u> = Cria teste ssh\n\n"
  140. env_msg+="• <u>REMOVER</u> = Remove usuario ssh\n\n"
  141. env_msg+="• <u>INFO USUARIOS</u> = Informacoes do usuario\n\n"
  142. env_msg+="• <u>USUARIOS ONLINE</u> = Exibe Usuários onlines\n\n"
  143. env_msg+="• <u>ALTERAR SENHA</u> = Altera senha ssh\n\n"
  144. env_msg+="• <u>ALTERAR LIMITE</u> = Altera limite ssh\n\n"
  145. env_msg+="• <u>ALTERAR DATA</u> = Altera data ssh\n\n"
  146. env_msg+="• <u>EXPIRADOS</u> = Remove ssh expirados\n\n"
  147. env_msg+="• <u>AJUDA</u> = Informacoes sobre opcoes\n\n"
  148. ShellBot.sendMessage --chat_id $id_chatuser \
  149. --text "$(echo -e $env_msg)" \
  150. --parse_mode html
  151. return 0
  152. else
  153. ShellBot.sendMessage --chat_id $id_chatuser \
  154. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  155. return 0
  156. fi
  157. }
  158. verifica_acesso() {
  159. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  160. [[ "$(grep -wc ${message_from_username} $suspensos)" != '0' ]] || [[ "$(grep -wc ${message_from_username} $ativos)" == '0' ]] && {
  161. _erro="1"
  162. return 0
  163. }
  164. }
  165. }
  166. fun_adduser() {
  167. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  168. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  169. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  170. return 0
  171. }
  172. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  173. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  174. --text "👤 CRIAR USUARIO 👤\n\nNome do usuario:" \
  175. --reply_markup "$(ShellBot.ForceReply)"
  176. } || {
  177. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  178. --text "🚫 ACESSO NEGADO 🚫"
  179. return 0
  180. }
  181. }
  182. criar_user() {
  183. IP=$(cat /etc/IP)
  184. newclient() {
  185. cp /etc/openvpn/client-common.txt ~/$1.ovpn
  186. echo "<ca>" >>~/$1.ovpn
  187. cat /etc/openvpn/easy-rsa/pki/ca.crt >>~/$1.ovpn
  188. echo "</ca>" >>~/$1.ovpn
  189. echo "<cert>" >>~/$1.ovpn
  190. cat /etc/openvpn/easy-rsa/pki/issued/$1.crt >>~/$1.ovpn
  191. echo "</cert>" >>~/$1.ovpn
  192. echo "<key>" >>~/$1.ovpn
  193. cat /etc/openvpn/easy-rsa/pki/private/$1.key >>~/$1.ovpn
  194. echo "</key>" >>~/$1.ovpn
  195. echo "<tls-auth>" >>~/$1.ovpn
  196. cat /etc/openvpn/ta.key >>~/$1.ovpn
  197. echo "</tls-auth>" >>~/$1.ovpn
  198. }
  199. file_user=$1
  200. usuario=$(sed -n '1 p' $file_user | cut -d' ' -f2)
  201. senha=$(sed -n '2 p' $file_user | cut -d' ' -f2)
  202. limite=$(sed -n '3 p' $file_user | cut -d' ' -f2)
  203. data=$(sed -n '4 p' $file_user | cut -d' ' -f2)
  204. validade=$(echo "$data" | awk -F'/' '{print $2FS$1FS$3}' | xargs -i date -d'{}' +%Y/%m/%d)
  205. useradd -M -N -s /bin/false $usuario -e $validade >/dev/null 2>&1
  206. (
  207. echo "${senha}"
  208. echo "${senha}"
  209. ) | passwd "${usuario}" >/dev/null 2>&1
  210. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  211. echo "$usuario:$senha:$info_data:$limite" >/etc/bot/revenda/${message_from_username}/usuarios/$usuario
  212. echo "$usuario:$senha:$info_data:$limite" >/etc/bot/info-users/$usuario
  213. }
  214. echo "$usuario $limite" >>/root/usuarios.db
  215. echo "$senha" >/etc/SSHPlus/senha/$usuario
  216. [[ -e "/etc/openvpn/server.conf" ]] && {
  217. cd /etc/openvpn/easy-rsa/
  218. ./easyrsa build-client-full $usuario nopass
  219. newclient "$usuario"
  220. }
  221. }
  222. fun_deluser() {
  223. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  224. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  225. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  226. return 0
  227. }
  228. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  229. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  230. --text "🗑 REMOVER USUARIO 🗑\n\nNome do usuario:" \
  231. --reply_markup "$(ShellBot.ForceReply)"
  232. } || {
  233. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  234. --text "🚫 ACESSO NEGADO 🚫"
  235. return 0
  236. }
  237. }
  238. fun_del_user() {
  239. usuario=$1
  240. [[ "${message_from_id[$id]}" = "$id_admin" ]] && {
  241. piduser=$(ps -u "$usuario" | grep sshd | cut -d? -f1)
  242. kill -9 $piduser >/dev/null 2>&1
  243. userdel --force "$usuario" 2>/dev/null
  244. grep -v ^$usuario[[:space:]] /root/usuarios.db >/tmp/ph
  245. cat /tmp/ph >/root/usuarios.db
  246. rm /etc/SSHPlus/senha/$usuario >/dev/null 2>&1
  247. } || {
  248. [[ ! -e /etc/bot/revenda/${message_from_username}/usuarios/$usuario ]] && {
  249. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  250. --text "$(echo -e "❌ O USUARIO NAO EXISTE ❌")" \
  251. --parse_mode html
  252. _erro='1'
  253. return 0
  254. }
  255. piduser=$(ps -u "$usuario" | grep sshd | cut -d? -f1)
  256. kill -9 $piduser >/dev/null 2>&1
  257. userdel --force "$usuario" 2>/dev/null
  258. grep -v ^$usuario[[:space:]] /root/usuarios.db >/tmp/ph
  259. cat /tmp/ph >/root/usuarios.db
  260. rm /etc/SSHPlus/senha/$usuario >/dev/null 2>&1
  261. rm /etc/bot/revenda/${message_from_username}/usuarios/$usuario
  262. rm /etc/bot/info-users/$usuario
  263. }
  264. [[ -e /etc/SSHPlus/userteste/$usuario.sh ]] && rm /etc/SSHPlus/userteste/$usuario.sh
  265. [[ -e "/etc/openvpn/easy-rsa/pki/private/$usuario.key" ]] && {
  266. [[ -e /etc/debian_version ]] && GROUPNAME=nogroup
  267. cd /etc/openvpn/easy-rsa/
  268. ./easyrsa --batch revoke $usuario
  269. ./easyrsa gen-crl
  270. rm -rf pki/reqs/$usuario.req
  271. rm -rf pki/private/$usuario.key
  272. rm -rf pki/issued/$usuario.crt
  273. rm -rf /etc/openvpn/crl.pem
  274. cp /etc/openvpn/easy-rsa/pki/crl.pem /etc/openvpn/crl.pem
  275. chown nobody:$GROUPNAME /etc/openvpn/crl.pem
  276. [[ -e $HOME/$usuario.ovpn ]] && rm $HOME/$usuario.ovpn >/dev/null 2>&1
  277. }
  278. }
  279. alterar_senha() {
  280. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  281. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  282. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  283. return 0
  284. }
  285. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  286. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  287. --text "🔐 Alterar Senha 🔐\n\nNome do usuario:" \
  288. --reply_markup "$(ShellBot.ForceReply)"
  289. } || {
  290. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  291. --text "🚫 ACESSO NEGADO 🚫"
  292. return 0
  293. }
  294. }
  295. alterar_senha_user() {
  296. usuario=$1
  297. senha=$2
  298. echo "$usuario:$senha" | chpasswd
  299. echo "$senha" >/etc/SSHPlus/senha/$usuario
  300. [[ -e /etc/bot/revenda/${message_from_username}/usuarios/$usuario ]] && {
  301. senha2=$(cat /etc/bot/revenda/${message_from_username}/usuarios/$usuario | awk -F : {'print $2'})
  302. sed -i "/$usuario/ s/\b$senha2\b/$senha/g" /etc/bot/revenda/${message_from_username}/usuarios/$usuario
  303. sed -i "/$usuario/ s/\b$senha2\b/$senha/g" /etc/bot/info-users/$usuario
  304. }
  305. [[ $(ps -u $usuario | grep sshd | wc -l) != '0' ]] && pkill -u $usuario >/dev/null 2>&1
  306. }
  307. alterar_limite() {
  308. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  309. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  310. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  311. return 0
  312. }
  313. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  314. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  315. --text "👥 Alterar Limite 👥\n\nNome do usuario:" \
  316. --reply_markup "$(ShellBot.ForceReply)"
  317. } || {
  318. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  319. --text "🚫 ACESSO NEGADO 🚫"
  320. return 0
  321. }
  322. }
  323. alterar_limite_user() {
  324. usuario=$1
  325. limite=$2
  326. database="/root/usuarios.db"
  327. [[ "${message_from_id[$id]}" == "$id_admin" ]] && {
  328. grep -v ^$usuario[[:space:]] /root/usuarios.db >/tmp/a
  329. mv /tmp/a /root/usuarios.db
  330. echo $usuario $limite >>/root/usuarios.db
  331. return 0
  332. }
  333. [[ -d /etc/bot/revenda/${message_from_username} ]] && {
  334. [[ ! -e /etc/bot/revenda/${message_from_username}/usuarios/$usuario ]] && {
  335. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  336. --text "$(echo -e "❌ O USUARIO NAO EXISTE ❌")" \
  337. --parse_mode html
  338. _erro='1'
  339. return 0
  340. }
  341. _limTotal=$(grep -w 'LIMITE_REVENDA' /etc/bot/revenda/${message_from_username}/${message_from_username} | awk '{print $NF}')
  342. [[ "$limite" -gt "$_limTotal" ]] && {
  343. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  344. --text "$(echo -e "❌ VC NAO TEM LIMITE SUFICIENTE ❌\n\nLimite Atual: $_limTotal ")" \
  345. --parse_mode html
  346. _erro='1'
  347. return 0
  348. }
  349. _limTotal=$(grep -w "${message_from_username}" $ativos | awk '{print $4}')
  350. fun_verif_limite_rev ${message_from_username}
  351. _limsomarev2=$(echo "$_result + $limite" | bc)
  352. echo "Total $_limsomarev2"
  353. [[ "$_limsomarev2" -gt "$_limTotal" ]] && {
  354. [[ "$_limTotal" == "$(($_limTotal - $_result))" ]] && _restant1='0' || _restant1=$(($_limTotal - $_result))
  355. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  356. --text "$(echo -e "❌ Vc nao tem limite suficiente\n\nLimite restante: $_restant1 ")" \
  357. --parse_mode html
  358. _erro='1'
  359. return 0
  360. }
  361. grep -v ^$usuario[[:space:]] /root/usuarios.db >/tmp/a
  362. mv /tmp/a /root/usuarios.db
  363. echo $usuario $limite >>/root/usuarios.db
  364. limite2=$(cat /etc/bot/revenda/${message_from_username}/usuarios/$usuario | awk -F : {'print $4'})
  365. sed -i "/\b$usuario\b/ s/\b$limite2\b/$limite/" /etc/bot/revenda/${message_from_username}/usuarios/$usuario
  366. sed -i "/\b$usuario\b/ s/\b$limite2\b/$limite/" /etc/bot/info-users/$usuario
  367. }
  368. }
  369. alterar_data() {
  370. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  371. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  372. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  373. return 0
  374. }
  375. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  376. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  377. --text "⏳ Alterar Data ⏳\n\nNome do usuario:" \
  378. --reply_markup "$(ShellBot.ForceReply)"
  379. } || {
  380. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  381. --text "🚫 ACESSO NEGADO 🚫"
  382. return 0
  383. }
  384. }
  385. alterar_data_user() {
  386. usuario=$1
  387. inputdate=$2
  388. database="/root/usuarios.db"
  389. [[ "$(echo -e "$inputdate" | sed -e 's/[^/]//ig')" != '//' ]] && {
  390. udata=$(date "+%d/%m/%Y" -d "+$inputdate days")
  391. sysdate="$(echo "$udata" | awk -v FS=/ -v OFS=- '{print $3,$2,$1}')"
  392. } || {
  393. udata=$(echo -e "$inputdate")
  394. sysdate="$(echo -e "$inputdate" | awk -v FS=/ -v OFS=- '{print $3,$2,$1}')"
  395. today="$(date -d today +"%Y%m%d")"
  396. timemachine="$(date -d "$sysdate" +"%Y%m%d")"
  397. [ $today -ge $timemachine ] && {
  398. verify='1'
  399. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  400. --text "$(echo -e "❌ Erro! Data invalida")" \
  401. --parse_mode html
  402. _erro='1'
  403. return 0
  404. }
  405. }
  406. chage -E $sysdate $usuario
  407. [[ -e /etc/bot/revenda/${message_from_username}/usuarios/$usuario ]] && {
  408. data2=$(cat /etc/bot/info-users/$usuario | awk -F : {'print $3'})
  409. sed -i "s;$data2;$udata;" /etc/bot/info-users/$usuario
  410. echo $usuario $udata ${message_from_username}
  411. sed -i "s;$data2;$udata;" /etc/bot/revenda/${message_from_username}/usuarios/$usuario
  412. }
  413. }
  414. ver_users() {
  415. if [[ "${callback_query_from_id[$id]}" == "$id_admin" ]]; then
  416. arq_info=/tmp/$(echo $RANDOM)
  417. local info_users
  418. info_users='=×=×=×=×=×=×=×=×=×=×=×=×=×=\n'
  419. info_users+='<b>INFORMACOES DOS USUARIOS</b>\n'
  420. info_users+='=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n'
  421. info_users+='⚠️ Exibe no formato abaixo:\n\n'
  422. info_users+='<code>USUÁRIO SENHA LIMITE DATA</code>\n'
  423. ShellBot.sendMessage --chat_id $id_admin \
  424. --text "$(echo -e $info_users)" \
  425. --parse_mode html
  426. fun_infu() {
  427. local info
  428. for user in $(cat /etc/passwd | awk -F : '$3 >= 1000 {print $1}' | grep -v nobody); do
  429. info='===========================\n'
  430. [[ -e /etc/SSHPlus/senha/$user ]] && senha=$(cat /etc/SSHPlus/senha/$user) || senha='Null'
  431. [[ $(grep -wc $user $HOME/usuarios.db) != '0' ]] && limite=$(grep -w $user $HOME/usuarios.db | cut -d' ' -f2) || limite='Null'
  432. datauser=$(chage -l $user | grep -i co | awk -F : '{print $2}')
  433. [[ $datauser = ' never' ]] && {
  434. data="00/00/00"
  435. } || {
  436. databr="$(date -d "$datauser" +"%Y%m%d")"
  437. hoje="$(date -d today +"%Y%m%d")"
  438. [[ $hoje -ge $databr ]] && {
  439. data="Venceu"
  440. } || {
  441. dat="$(date -d"$datauser" '+%Y-%m-%d')"
  442. data=$(echo -e "$((($(date -ud $dat +%s) - $(date -ud $(date +%Y-%m-%d) +%s)) / 86400)) DIAS")
  443. }
  444. }
  445. info+="$user • $senha • $limite • $data"
  446. echo -e "$info"
  447. done
  448. }
  449. fun_infu >$arq_info
  450. while :; do
  451. ShellBot.sendMessage --chat_id $id_admin \
  452. --text "$(while read linha; do echo $linha; done < <(sed '1,30!d' $arq_info))" \
  453. --parse_mode html
  454. sed -i 1,30d $arq_info
  455. [[ $(cat $arq_info | wc -l) = '0' ]] && rm $arq_info && break
  456. done
  457. elif [[ "$(grep -wc "${callback_query_from_username}" $ativos)" != '0' ]]; then
  458. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  459. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  460. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  461. return 0
  462. }
  463. [[ $(ls /etc/bot/revenda/${callback_query_from_username}/usuarios | wc -l) == '0' ]] && {
  464. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  465. --text "VC AINDA NAO CRIOU USUARIO!"
  466. return 0
  467. }
  468. arq_info=/tmp/$(echo $RANDOM)
  469. local info_users
  470. info_users='=×=×=×=×=×=×=×=×=×=×=×=×=×=\n'
  471. info_users+='<b>INFORMACOES DOS USUARIOS</b>\n'
  472. info_users+='=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n'
  473. info_users+='⚠️ Exibe no formato abaixo:\n\n'
  474. info_users+='<code>USUÁRIO SENHA LIMITE DATA</code>\n'
  475. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  476. --text "$(echo -e $info_users)" \
  477. --parse_mode html
  478. fun_infu() {
  479. local info
  480. for user in $(ls /etc/bot/revenda/${callback_query_from_username}/usuarios); do
  481. info='===========================\n'
  482. [[ -e /etc/SSHPlus/senha/$user ]] && senha=$(cat /etc/SSHPlus/senha/$user) || senha='Null'
  483. [[ $(grep -wc $user $HOME/usuarios.db) != '0' ]] && limite=$(grep -w $user $HOME/usuarios.db | cut -d' ' -f2) || limite='Null'
  484. datauser=$(chage -l $user | grep -i co | awk -F : '{print $2}')
  485. [[ $datauser = ' never' ]] && {
  486. data="00/00/00"
  487. } || {
  488. databr="$(date -d "$datauser" +"%Y%m%d")"
  489. hoje="$(date -d today +"%Y%m%d")"
  490. [[ $hoje -ge $databr ]] && {
  491. data="Venceu"
  492. } || {
  493. dat="$(date -d"$datauser" '+%Y-%m-%d')"
  494. data=$(echo -e "$((($(date -ud $dat +%s) - $(date -ud $(date +%Y-%m-%d) +%s)) / 86400)) DIAS")
  495. }
  496. }
  497. info+="$user • $senha • $limite • $data"
  498. echo -e "$info"
  499. done
  500. }
  501. fun_infu >$arq_info
  502. while :; do
  503. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  504. --text "$(while read linha; do echo $linha; done < <(sed '1,30!d' $arq_info))" \
  505. --parse_mode html
  506. sed -i 1,30d $arq_info
  507. [[ $(cat $arq_info | wc -l) = '0' ]] && rm $arq_info && break
  508. done
  509. else
  510. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  511. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  512. return 0
  513. fi
  514. }
  515. fun_drop() {
  516. port_dropbear=$(ps aux | grep dropbear | awk NR==1 | awk '{print $17;}')
  517. log=/var/log/auth.log
  518. loginsukses='Password auth succeeded'
  519. pids=$(ps ax | grep dropbear | grep " $port_dropbear" | awk -F" " '{print $1}')
  520. for pid in $pids; do
  521. pidlogs=$(grep $pid $log | grep "$loginsukses" | awk -F" " '{print $3}')
  522. i=0
  523. for pidend in $pidlogs; do
  524. let i=i+1
  525. done
  526. if [ $pidend ]; then
  527. login=$(grep $pid $log | grep "$pidend" | grep "$loginsukses")
  528. PID=$pid
  529. user=$(echo $login | awk -F" " '{print $10}' | sed -r "s/'/ /g")
  530. waktu=$(echo $login | awk -F" " '{print $2"-"$1,$3}')
  531. while [ ${#waktu} -lt 13 ]; do
  532. waktu=$waktu" "
  533. done
  534. while [ ${#user} -lt 16 ]; do
  535. user=$user" "
  536. done
  537. while [ ${#PID} -lt 8 ]; do
  538. PID=$PID" "
  539. done
  540. echo "$user $PID $waktu"
  541. fi
  542. done
  543. }
  544. monitor_ssh() {
  545. if [[ "${callback_query_from_id[$id]}" == "$id_admin" ]]; then
  546. database="/root/usuarios.db"
  547. cad_onli=/tmp/$(echo $RANDOM)
  548. local info_on
  549. info_on='=×=×=×=×=×=×=×=×=×=×=×=×=×=\n'
  550. info_on+='<b>MONITOR USUARIOS ONLINES</b>\n'
  551. info_on+='=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n'
  552. info_on+='⚠️ Exibe no formato abaixo:\n\n'
  553. info_on+='<code>USUÁRIO ONLINE/LIMITE TEMPO\n</code>'
  554. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  555. --text "$(echo -e $info_on)" \
  556. --parse_mode html
  557. fun_online() {
  558. local info2
  559. for user in $(cat /etc/passwd | awk -F : '$3 >= 1000 {print $1}' | grep -v nobody); do
  560. [[ "$(grep -w $user $database)" != "0" ]] && lim="$(grep -w $user $database | cut -d' ' -f2)" || lim=0
  561. [[ $(netstat -nltp | grep 'dropbear' | wc -l) != '0' ]] && drop="$(fun_drop | grep "$user" | wc -l)" || drop=0
  562. [[ -e /etc/openvpn/openvpn-status.log ]] && ovp="$(cat /etc/openvpn/openvpn-status.log | grep -E ,"$user", | wc -l)" || ovp=0
  563. sqd="$(ps -u $user | grep sshd | wc -l)"
  564. _cont=$(($drop + $ovp))
  565. conex=$(($_cont + $sqd))
  566. [[ $conex -gt '0' ]] && {
  567. timerr="$(ps -o etime $(ps -u $user | grep sshd | awk 'NR==1 {print $1}') | awk 'NR==2 {print $1}')"
  568. info2+="===========================\n"
  569. info2+="🟢 $user $conex/$lim ⏳$timerr\n"
  570. }
  571. done
  572. echo -e "$info2"
  573. }
  574. fun_online >$cad_onli
  575. [[ $(cat $cad_onli | wc -w) != '0' ]] && {
  576. while :; do
  577. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  578. --text "$(while read linha; do echo $linha; done < <(sed '1,30!d' $cad_onli))" \
  579. --parse_mode html
  580. sed -i 1,30d $cad_onli
  581. [[ "$(cat $cad_onli | wc -l)" = '0' ]] && {
  582. rm $cad_onli
  583. break
  584. }
  585. done
  586. } || {
  587. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  588. --text "Nenhum usuario online" \
  589. --parse_mode html
  590. return 0
  591. }
  592. elif [[ "$(grep -wc "${callback_query_from_username}" $ativos)" != '0' ]]; then
  593. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  594. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  595. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  596. return 0
  597. }
  598. [[ $(ls /etc/bot/revenda/${callback_query_from_username}/usuarios | wc -l) == '0' ]] && {
  599. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  600. --text "VC AINDA NAO CRIOU USUARIO!"
  601. return 0
  602. }
  603. database="/root/usuarios.db"
  604. cad_onli=/tmp/$(echo $RANDOM)
  605. local info_on
  606. info_on='=×=×=×=×=×=×=×=×=×=×=×=×=×=\n'
  607. info_on+='<b>MONITOR USUARIOS ONLINES</b>\n'
  608. info_on+='=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n'
  609. info_on+='⚠️ Exibe no formato abaixo:\n\n'
  610. info_on+='<code>USUÁRIO ONLINE/LIMITE TEMPO\n</code>'
  611. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  612. --text "$(echo -e $info_on)" \
  613. --parse_mode html
  614. fun_online() {
  615. local info2
  616. for user in $(ls /etc/bot/revenda/${callback_query_from_username}/usuarios); do
  617. [[ "$(grep -w $user $database)" != "0" ]] && lim="$(grep -w $user $database | cut -d' ' -f2)" || lim=0
  618. [[ $(netstat -nltp | grep 'dropbear' | wc -l) != '0' ]] && drop="$(fun_drop | grep "$user" | wc -l)" || drop=0
  619. [[ -e /etc/openvpn/openvpn-status.log ]] && ovp="$(cat /etc/openvpn/openvpn-status.log | grep -E ,"$user", | wc -l)" || ovp=0
  620. sqd="$(ps -u $user | grep sshd | wc -l)"
  621. conex=$(($sqd + $ovp + $drop))
  622. [[ $conex -gt '0' ]] && {
  623. timerr="$(ps -o etime $(ps -u $user | grep sshd | awk 'NR==1 {print $1}') | awk 'NR==2 {print $1}')"
  624. info2+="------------------------------\n"
  625. info2+="👤$user $conex/$lim ⏳$timerr\n"
  626. }
  627. done
  628. echo -e "$info2"
  629. }
  630. fun_online >$cad_onli
  631. [[ $(cat $cad_onli | wc -w) != '0' ]] && {
  632. while :; do
  633. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  634. --text "<code>$(while read linha; do echo $linha; done < <(sed '1,30!d' $cad_onli))</code>" \
  635. --parse_mode html
  636. sed -i 1,30d $cad_onli
  637. [[ "$(cat $cad_onli | wc -l)" = '0' ]] && {
  638. rm $cad_onli
  639. break
  640. }
  641. done
  642. } || {
  643. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  644. --text "Nenhum usuario online" \
  645. --parse_mode html
  646. return 0
  647. }
  648. else
  649. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  650. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  651. return 0
  652. fi
  653. }
  654. fun_verif_user() {
  655. user=$1
  656. [[ -z "$user" ]] && {
  657. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  658. --text "$(echo -e "Erro")" \
  659. --parse_mode html
  660. return 0
  661. }
  662. [[ "${message_from_id[$id]}" == "$id_admin" ]] && {
  663. [[ "$(awk -F : '$3 >= 1000 { print $1 }' /etc/passwd | grep -wc $user)" == '0' ]] && {
  664. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  665. --text "$(echo -e ❌ Usuario $user não existe !)" \
  666. --parse_mode html
  667. _erro='1'
  668. return 0
  669. }
  670. }
  671. [[ -d /etc/bot/revenda/${message_from_username} ]] && {
  672. [[ ! -e /etc/bot/revenda/${message_from_username}/usuarios/$user ]] && {
  673. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  674. --text "$(echo -e ❌ Usuario $user nao existe !)" \
  675. --parse_mode html
  676. _erro='1'
  677. return 0
  678. }
  679. }
  680. }
  681. fun_down() {
  682. [[ "${callback_query_from_id[$id]}" != "$id_admin" ]] && {
  683. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  684. --text "🚫 ACESSO NEGADO 🚫"
  685. return 0
  686. }
  687. [[ ! -d /tmp/file ]] && mkdir /tmp/file
  688. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  689. --text "[1] - ADICIONAR ARQUIVO\n[2] - EXCLUIR ARQUIVO\n\nInforme a opcao [1-2]:" \
  690. --reply_markup "$(ShellBot.ForceReply)"
  691. }
  692. infovps() {
  693. [[ "${callback_query_from_id[$id]}" != "$id_admin" ]] && {
  694. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  695. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  696. return 0
  697. }
  698. PTs='/tmp/prts'
  699. _ons=$(ps -x | grep sshd | grep -v root | grep priv | wc -l)
  700. [[ -e /etc/openvpn/openvpn-status.log ]] && _onop=$(grep -c "10.8.0" /etc/openvpn/openvpn-status.log) || _onop="0"
  701. [[ -e /etc/default/dropbear ]] && _drp=$(ps aux | grep dropbear | grep -v grep | wc -l) _ondrp=$(($_drp - 1)) || _ondrp="0"
  702. _on=$(($_ons + $_onop + $_ondrp))
  703. total=$(awk -F: '$3>=1000 {print $1}' /etc/passwd | grep -v nobody | wc -l)
  704. system=$(cat /etc/issue.net)
  705. uso=$(top -bn1 | awk '/Cpu/ { cpu = "" 100 - $8 "%" }; END { print cpu }')
  706. cpucores=$(grep -c cpu[0-9] /proc/stat)
  707. ram1=$(free -h | grep -i mem | awk {'print $2'})
  708. usoram=$(free -m | awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2 }')
  709. total=$(cat -n /root/usuarios.db | tail -n 1 | awk '{print $1}')
  710. echo -e "SSH: $(grep 'Port' /etc/ssh/sshd_config | cut -d' ' -f2 | grep -v 'no' | xargs)" >$PTs
  711. [[ -e "/etc/stunnel/stunnel.conf" ]] && echo -e "SSL Tunel: $(netstat -nplt | grep 'stunnel' | awk {'print $4'} | cut -d: -f2 | xargs)" >>$PTs
  712. [[ -e "/etc/openvpn/server.conf" ]] && echo -e "Openvpn: $(netstat -nplt | grep 'openvpn' | awk {'print $4'} | cut -d: -f2 | xargs)" >>$PTs
  713. [[ "$(netstat -nplt | grep 'sslh' | wc -l)" != '0' ]] && echo -e "SSlh: $(netstat -nplt | grep 'sslh' | awk {'print $4'} | cut -d: -f2 | xargs)" >>$PTs
  714. [[ "$(netstat -nplt | grep 'squid' | wc -l)" != '0' ]] && echo -e "Squid: $(netstat -nplt | grep 'squid' | awk -F ":" {'print $4'} | xargs)" >>$PTs
  715. [[ "$(netstat -nltp | grep 'dropbear' | wc -l)" != '0' ]] && echo -e "DropBear: $(netstat -nplt | grep 'dropbear' | awk -F ":" {'print $4'} | xargs)" >>$PTs
  716. [[ "$(netstat -nplt | grep 'python' | wc -l)" != '0' ]] && echo -e "Proxy Socks: $(netstat -nplt | grep 'python' | awk {'print $4'} | cut -d: -f2 | xargs)" >>$PTs
  717. local info
  718. info="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  719. info+="<b>INFORMACOES DO SERVIDOR</b>\n"
  720. info+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  721. info+="<b>SISTEMA OPERACIONAL</b>\n"
  722. info+="$system\n\n"
  723. info+="<b>PROCESSADOR</b>\n"
  724. info+="<b>Nucleos:</b> $cpucores\n"
  725. info+="<b>Ultilizacao:</b> $uso\n\n"
  726. info+="<b>MEMORIA RAM</b>\n"
  727. info+="<b>Total:</b> $ram1\n"
  728. info+="<b>Ultilizacao:</b> $usoram\n\n"
  729. while read linha; do
  730. info+="<b>$(echo -e "$linha")</b>\n"
  731. done < <(cat $PTs)
  732. info+="\n<b>$total</b><i> USUARIOS</i><b> $_on</b> <i>ONLINE</i>"
  733. ShellBot.sendMessage --chat_id $id_admin \
  734. --text "$(echo -e $info)" \
  735. --parse_mode html
  736. return 0
  737. }
  738. fun_download() {
  739. Opc=$1
  740. [[ -z "$Opc" ]] && {
  741. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  742. --text "$(echo -e "❌Erro tente novamente")"
  743. _erro='1'
  744. return 0
  745. }
  746. _file2=$2
  747. [[ -z "$_file2" ]] && {
  748. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  749. --text "$(echo -e "❌Erro tente novamente")"
  750. _erro='1'
  751. return 0
  752. }
  753. _DirArq=$(ls /etc/bot/arquivos)
  754. i=0
  755. unset _Pass
  756. while read _Arq; do
  757. i=$(expr $i + 1)
  758. _oP=$i
  759. [[ $i == [1-9] ]] && i=0$i && oP+=" 0$i"
  760. echo -e "[$i] - $_Arq"
  761. _Pass+="\n${_oP}:${_Arq}"
  762. done <<<"${_DirArq}"
  763. _file=$(echo -e "${_Pass}" | grep -E "\b$Opc\b" | cut -d: -f2)
  764. echo $_file2
  765. ShellBot.sendDocument --chat_id ${message_from_id[$id]} \
  766. --document "@/etc/bot/arquivos/$_file" \
  767. --caption "$(echo -e "✅ CRIADO COM SUCESSO ✅\n\nUSUARIO: <code>$(awk -F " " '/Nome/ {print $2}' $_file2)</code>\nSENHA: <code>$(awk -F " " '/Senha/ {print $2}' $_file2)</code>\nLIMITE: $(awk -F " " '/Limite/ {print $2}' $_file2)\nEXPIRA EM: $(awk -F " " '/Validade/ {print $2}' $_file2)")" \
  768. --parse_mode html
  769. [[ -e "/root/$(awk -F " " '/Nome/ {print $2}' $_file2).ovpn" ]] && {
  770. ShellBot.sendDocument --chat_id ${message_from_id[$id]} \
  771. --document "@/root/$(awk -F " " '/Nome/ {print $2}' $_file2).ovpn"
  772. }
  773. }
  774. otimizer() {
  775. [[ "${callback_query_from_id[$id]}" != "$id_admin" ]] && {
  776. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  777. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  778. return 0
  779. }
  780. MEM1=$(free | awk '/Mem:/ {print int(100*$3/$2)}')
  781. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  782. --text "🧹 LIMPANDO CACHE DO SERVIDOR"
  783. apt-get autoclean -y
  784. echo 3 >/proc/sys/vm/drop_caches
  785. sync && sysctl -w vm.drop_caches=3 1>/dev/null 2>/dev/null
  786. sysctl -w vm.drop_caches=0 1>/dev/null 2>/dev/null
  787. swapoff -a
  788. swapon -a
  789. ram1=$(free -h | grep -i mem | awk {'print $2'})
  790. ram2=$(free -h | grep -i mem | awk {'print $3'})
  791. ram3=$(free -h | grep -i mem | awk {'print $4'})
  792. MEM2=$(free | awk '/Mem:/ {print int(100*$3/$2)}')
  793. res=$(expr $MEM1 - $MEM2)
  794. local sucess
  795. sucess="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  796. sucess+="<b>OTIMIZADO COM SUCESSO !</b>\n"
  797. sucess+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  798. sucess+="<i>Ultilizacao anterior</i> $MEM1%\n\n"
  799. sucess+="<b>Memoria Ram Total</b> $ram1\n"
  800. sucess+="<b>livre</b> $ram3\n"
  801. sucess+="<b>Em uso</b> $ram2\n"
  802. sucess+="<i>Ultilizacao atual</i> $MEM2%\n\n"
  803. sucess+="<b>Economia de:</b> $res%"
  804. ShellBot.sendMessage --chat_id $id_admin \
  805. --text "$(echo -e $sucess)" \
  806. --parse_mode html
  807. return 0
  808. }
  809. speed_test() {
  810. [[ "${callback_query_from_id[$id]}" != "$id_admin" ]] && {
  811. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  812. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  813. return 0
  814. }
  815. rm -rf $HOME/speed >/dev/null 2>&1
  816. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  817. --text "🚀 TESTANDO VELOCIDADE DO SERVIDOR"
  818. speedtest --share >speed
  819. png=$(cat speed | sed -n '5 p' | awk -F : {'print $NF'})
  820. down=$(cat speed | sed -n '7 p' | awk -F : {'print $NF'})
  821. upl=$(cat speed | sed -n '9 p' | awk -F : {'print $NF'})
  822. lnk=$(cat speed | sed -n '10 p' | awk {'print $NF'})
  823. local msg
  824. msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  825. msg+="<b>🚀 VELOCIDADE DO SERVIDOR 🚀</b>\n"
  826. msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  827. msg+="<b>PING/LATENCIA:</b>$png\n"
  828. msg+="<b>DOWNLOAD:</b>$down\n"
  829. msg+="<b>UPLOAD:</b>$upl\n"
  830. ShellBot.sendMessage --chat_id $id_admin \
  831. --text "$(echo -e $msg)" \
  832. --parse_mode html
  833. ShellBot.sendMessage --chat_id $id_admin \
  834. --text "$(echo -e $lnk)" \
  835. --parse_mode html
  836. rm -rf $HOME/speed >/dev/null 2>&1
  837. return 0
  838. }
  839. backup_users() {
  840. [[ "${callback_query_from_id[$id]}" != "$id_admin" ]] && {
  841. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  842. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  843. return 0
  844. }
  845. rm /root/backup.vps 1>/dev/null 2>/dev/null
  846. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  847. --text "♻️ CRIANDO BACKUP DE USUARIOS"
  848. tar cvf /root/backup.vps /root/usuarios.db /etc/shadow /etc/passwd /etc/group /etc/gshadow /etc/bot /etc/SSHPlus/senha 1>/dev/null 2>/dev/null
  849. ShellBot.sendDocument --chat_id ${id_admin} \
  850. --document "@/root/backup.vps" \
  851. --caption "$(echo -e "♻️ BACKUP DE USUARIOS ♻️")"
  852. return 0
  853. }
  854. sobremim() {
  855. local msg
  856. msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  857. msg+="<b>🤖 BOT VPS MANAGER 🤖</b>\n"
  858. msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  859. msg+="Fui criado com o propósito de fornecer informações e ferramentas para gestão VPN em servidores 🐧 GNU/Linux 🐧.\n\n"
  860. msg+="<b>Menu:</b> /menu\n"
  861. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  862. --text "$(echo -e $msg)" \
  863. --parse_mode html
  864. return 0
  865. }
  866. fun_add_teste() {
  867. if [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]]; then
  868. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  869. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  870. return 0
  871. elif [[ "${callback_query_from_id[$id]}" == "$id_admin" ]]; then
  872. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  873. --text "👤 CRIAR TESTE 👤\n\nQuantas horas deve durar EX: 1:" \
  874. --reply_markup "$(ShellBot.ForceReply)"
  875. elif [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]]; then
  876. _limTotal=$(grep -w "${callback_query_from_username}" $ativos | awk '{print $4}')
  877. fun_verif_limite_rev ${callback_query_from_username}
  878. _limsomarev2=$(echo "$_result + 1" | bc)
  879. [[ "$_limsomarev2" -gt "$_limTotal" ]] && {
  880. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  881. --text "❌ VC NAO TEM LIMITE DISPONIVEL!"
  882. return 0
  883. } || {
  884. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  885. --text "👤 CRIAR TESTE 👤\n\nQuantas horas deve durar EX: 1:" \
  886. --reply_markup "$(ShellBot.ForceReply)"
  887. }
  888. else
  889. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  890. --text "🚫 ACESSO NEGADO 🚫"
  891. return 0
  892. fi
  893. }
  894. fun_teste() {
  895. usuario=$(echo teste$(( RANDOM% + 9999 + 1111 )))
  896. senha='1234'
  897. limite='1'
  898. dias='1 dia'
  899. ex_date=$(date '+%d/%m/%C%y' -d " +1 days")
  900. tuserdate=$(date '+%C%y/%m/%d' -d " +1 days")
  901. [[ -z $dias ]] && {
  902. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  903. --text "$(echo -e "❌ Erro tente novamente")" \
  904. --parse_mode html
  905. return 0
  906. _erro='1'
  907. }
  908. useradd -M -N -s /bin/false $usuario -e $tuserdate >/dev/null 2>&1
  909. (
  910. echo "$senha"
  911. echo "$senha"
  912. ) | passwd $usuario >/dev/null 2>&1
  913. echo "$senha" >/etc/SSHPlus/senha/$usuario
  914. echo "$usuario $limite" >>/root/usuarios.db
  915. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  916. echo "$usuario:$senha:$ex_date:$limite" >/etc/bot/revenda/${message_from_username}/usuarios/$usuario
  917. }
  918. dir_teste="/etc/bot/revenda/${message_from_username}/usuarios/$usuario"
  919. cat <<-EOF >/etc/SSHPlus/userteste/$usuario.sh
  920. #!/bin/bash
  921. clear
  922. [[ $(awk -F" " '{print $2}' /usr/lib/licence) != "@nzx" ]] && exit 0
  923. # USUARIO TESTE
  924. [[ \$(ps -u "$usuario" | grep -c sshd) != '0' ]] && pkill -u $usuario
  925. userdel --force $usuario
  926. grep -v ^$usuario[[:space:]] /root/usuarios.db > /tmp/ph ; cat /tmp/ph > /root/usuarios.db
  927. [[ -e $dir_teste ]] && rm $dir_teste
  928. rm /etc/SSHPlus/senha/$usuario > /dev/null 2>&1
  929. rm /etc/SSHPlus/userteste/$usuario.sh
  930. EOF
  931. chmod +x /etc/SSHPlus/userteste/$usuario.sh
  932. echo "/etc/SSHPlus/userteste/$usuario.sh" | at now + $dias hour >/dev/null 2>&1
  933. [[ "$dias" == '1' ]] && hrs="hora" || hrs="horas"
  934. [[ "$(ls /etc/bot/arquivos | wc -l)" != '0' ]] && {
  935. for arqv in $(ls /etc/bot/arquivos); do
  936. ShellBot.sendDocument --chat_id ${message_from_id[$id]} \
  937. --document "@/etc/bot/arquivos/$arqv" \
  938. --caption "$(echo -e "✅ CRIADO COM SUCESSO ✅\n\nUSUARIO: <code>$usuario</code>\nSENHA: <code>1234</code>\n\n⏳ Expira em: $dias")" \
  939. --parse_mode html
  940. done
  941. return 0
  942. } || {
  943. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  944. --text "$(echo -e "✅ <b>CRIADO COM SUCESSO</b> ✅\n\nUSUARIO: <code>$usuario</code>\nSENHA: <code>1234</code>\n\n⏳ Expira em: $dias")" \
  945. --parse_mode html
  946. return 0
  947. }
  948. }
  949. fun_exp_user() {
  950. if [[ "${callback_query_from_id[$id]}" == "$id_admin" ]]; then
  951. [[ $(cat /root/usuarios.db | wc -l) == '0' ]] && {
  952. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  953. --text "VC AINDA NAO CRIOU USUARIO!"
  954. return 0
  955. }
  956. datenow=$(date +%s)
  957. for user in $(cat /etc/passwd | awk -F : '$3 >= 1000 {print $1}' | grep -v nobody); do
  958. expdate=$(chage -l $user | awk -F: '/Account expires/{print $2}')
  959. echo $expdate | grep -q never && continue
  960. datanormal=$(date -d"$expdate" '+%d/%m/%Y')
  961. expsec=$(date +%s --date="$expdate")
  962. diff=$(echo $datenow - $expsec | bc -l)
  963. echo $diff | grep -q ^\- && continue
  964. pkill -u $user
  965. userdel --force $user
  966. grep -v ^$user[[:space:]] /root/usuarios.db >/tmp/ph
  967. cat /tmp/ph >/root/usuarios.db
  968. [[ -e /etc/bot/info-users/$user ]] && rm /etc/bot/info-users/$user
  969. [[ -e /etc/SSHPlus/userteste/$user.sh ]] && rm /etc/SSHPlus/userteste/$user.sh
  970. [[ "$(ls /etc/bot/revenda)" != '0' ]] && {
  971. for ex in $(ls /etc/bot/revenda); do
  972. [[ -e /etc/bot/revenda/$exp/usuarios/$user ]] && rm /etc/bot/revenda/$ex/usuarios/$user
  973. done
  974. }
  975. done
  976. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  977. --text "⌛️ USUARIOS SSH EXPIRADOS REMOVIDOS"
  978. return 0
  979. elif [[ "$(grep -wc "${callback_query_from_username}" $ativos)" != '0' ]]; then
  980. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  981. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  982. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  983. return 0
  984. }
  985. [[ $(ls /etc/bot/revenda/${callback_query_from_username}/usuarios | wc -l) == '0' ]] && {
  986. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  987. --text "VC AINDA NAO CRIOU USUARIO!"
  988. return 0
  989. }
  990. datenow=$(date +%s)
  991. dir_user="/etc/bot/revenda/${callback_query_from_username}/usuarios"
  992. for user in $(ls $dir_user); do
  993. expdate=$(chage -l $user | awk -F: '/Account expires/{print $2}')
  994. echo $expdate | grep -q never && continue
  995. datanormal=$(date -d"$expdate" '+%d/%m/%Y')
  996. expsec=$(date +%s --date="$expdate")
  997. diff=$(echo $datenow - $expsec | bc -l)
  998. echo $diff | grep -q ^\- && continue
  999. pkill -f $user
  1000. userdel --force $user
  1001. grep -v ^$user[[:space:]] /root/usuarios.db >/tmp/ph
  1002. cat /tmp/ph >/root/usuarios.db
  1003. [[ -e /etc/SSHPlus/userteste/$user.sh ]] && rm /etc/SSHPlus/userteste/$user.sh
  1004. [[ -e "$dir_user/$user" ]] && rm $dir_user/$user
  1005. done
  1006. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1007. --text "⌛️ USUARIOS SSH EXPIRADOS REMOVIDOS"
  1008. return 0
  1009. else
  1010. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1011. --text "$(echo -e 🚫 ACESSO NEGADO 🚫)"
  1012. return 0
  1013. fi
  1014. }
  1015. relatorio_rev() {
  1016. if [[ "${callback_query_from_id[$id]}" = "$id_admin" ]]; then
  1017. _ons=$(ps -x | grep sshd | grep -v root | grep priv | wc -l)
  1018. _tuser=$(awk -F: '$3>=1000 {print $1}' /etc/passwd | grep -v nobody | wc -l)
  1019. [[ -e /etc/openvpn/openvpn-status.log ]] && _onop=$(grep -c "10.8.0" /etc/openvpn/openvpn-status.log) || _onop="0"
  1020. [[ -e /etc/default/dropbear ]] && _drp=$(ps aux | grep dropbear | grep -v grep | wc -l) _ondrp=$(($_drp - 1)) || _ondrp="0"
  1021. _onli=$(($_ons + $_onop + $_ondrp))
  1022. _cont_rev=$(echo $(grep -wc revenda $ativos) - $(grep -wc revenda $suspensos) | bc)
  1023. _cont_sus=$(grep -wc revenda $suspensos)
  1024. _cont_sub=$(grep -wc subrevenda $ativos)
  1025. _cont_revt=$(grep -wc revenda $ativos)
  1026. local msg
  1027. msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  1028. msg+="<b>📊 RELATORIO | INFORMACOES</b>\n"
  1029. msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  1030. msg+="<b>Usuarios total:</b> $_tuser\n"
  1031. msg+="<b>Usuarios online:</b> $_onli\n"
  1032. msg+="<b>Revendas Ativas:</b> $_cont_rev\n"
  1033. msg+="<b>Revendas Suspensas:</b> $_cont_sus\n"
  1034. msg+="<b>Sub-Revendas:</b> $_cont_sub\n\n"
  1035. msg+="<b>User:</b> @${callback_query_from_username}\n"
  1036. msg+="<b>ID:</b> <code>${callback_query_from_id}</code>\n"
  1037. [[ $_cont_revt != '0' ]] && {
  1038. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1039. --text "📊 CRIANDO RELATORIO !"
  1040. } || {
  1041. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1042. --text "⚠️ NENHUM REVENDEDOR ENCONTRADO !"
  1043. return 0
  1044. }
  1045. echo -e "RELATORIO DOS REVENDEDORES\n\nTotal: $_cont_revt - $(printf 'Data: %(%d/%m/%Y)T\n')\n=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=" >/tmp/Relatorio.txt
  1046. while read _revlist; do
  1047. _nome_rev="$(echo $_revlist | awk '{print $2}')"
  1048. _limite_rev="$(echo $_revlist | awk '{print $4}')"
  1049. _data_rev="$(echo $_revlist | awk '{print $6}')"
  1050. [[ -e "/etc/bot/revenda/$_nome_rev/$_nome_rev" ]] && {
  1051. _dirsts='revenda'
  1052. _status='Ativo'
  1053. } || {
  1054. _dirsts='suspensos'
  1055. _status='Suspenso'
  1056. }
  1057. _subrev="$(grep -wc SUBREVENDA /etc/bot/$_dirsts/$_nome_rev/$_nome_rev)"
  1058. fun_on() {
  1059. for user in $(ls /etc/bot/$_dirsts/$_nome_rev/usuarios); do
  1060. [[ $(netstat -nltp | grep 'dropbear' | wc -l) != '0' ]] && drop="$(fun_drop | grep "$user" | wc -l)" || drop=0
  1061. [[ -e /etc/openvpn/openvpn-status.log ]] && ovp="$(cat /etc/openvpn/openvpn-status.log | grep -E ,"$user", | wc -l)" || ovp=0
  1062. sqd="$(ps -u $user | grep sshd | wc -l)"
  1063. conex=$(($sqd + $ovp + $drop))
  1064. echo -e "$conex"
  1065. done
  1066. }
  1067. [[ "$(ls /etc/bot/$_dirsts/$_nome_rev/usuarios | wc -l)" != '0' ]] && {
  1068. total_on=$(fun_on | paste -s -d + | bc)
  1069. total_users=$(ls /etc/bot/$_dirsts/$_nome_rev/usuarios | wc -l)
  1070. } || {
  1071. total_on='0'
  1072. total_users='0'
  1073. }
  1074. echo -e "\nSTATUS: $_status\nREVENDEDOR: @$_nome_rev\nLIMITE: $_limite_rev\nDIAS RESTANTES: $_data_rev\nSSH CRIADAS: $total_users\nSSH ONLINE: $total_on\nSUB-REVENDAS: $_subrev\n\n=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=" >>/tmp/Relatorio.txt
  1075. done <<<"$(grep -w 'revenda' $ativos)"
  1076. ShellBot.sendDocument --chat_id $id_admin \
  1077. --document "@/tmp/Relatorio.txt" \
  1078. --caption "$(echo -e "$msg")" \
  1079. --parse_mode html
  1080. return 0
  1081. elif [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]]; then
  1082. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  1083. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1084. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  1085. return 0
  1086. }
  1087. [[ $(grep -wc 'SUBREVENDA' /etc/bot/revenda/${callback_query_from_username}/${callback_query_from_username}) == '0' ]] && {
  1088. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1089. --text "⚠️ NENHUM SUB REVENDEDOR ENCONTRADO !"
  1090. _cont_limite=$(grep -w ${callback_query_from_username} $ativos | awk '{print $4}')
  1091. fun_verif_limite_rev ${callback_query_from_username}
  1092. _cont_disp=$(echo $_cont_limite - $_result | bc)
  1093. local msg
  1094. msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  1095. msg+="<b>📊 RELATORIO | INFORMACOES</b>\n"
  1096. msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  1097. msg+="<b>Limite de Logins:</b> $_cont_limite\n"
  1098. msg+="<b>Limite Disponivel:</b> $_cont_disp\n"
  1099. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  1100. --text "$msg" \
  1101. --parse_mode html
  1102. return 0
  1103. }
  1104. fun_contsub() {
  1105. while read _sublist; do
  1106. _usub="$(echo $_sublist | awk '{print $2}')"
  1107. echo $(grep -wc $_usub $suspensos)
  1108. done <<<"$(grep -w 'SUBREVENDA' /etc/bot/revenda/${callback_query_from_username}/${callback_query_from_username})"
  1109. }
  1110. _cont_limite=$(grep -w ${callback_query_from_username} $ativos | awk '{print $4}')
  1111. fun_verif_limite_rev ${callback_query_from_username}
  1112. _cont_disp=$(echo $_cont_limite - $_result | bc)
  1113. _cont_atv=$(grep -wc SUBREVENDA /etc/bot/revenda/${callback_query_from_username}/${callback_query_from_username})
  1114. _cont_sup=$(fun_contsub | paste -s -d + | bc)
  1115. local msg
  1116. msg="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  1117. msg+="<b>📊 RELATORIO | INFORMACOES</b>\n"
  1118. msg+="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n\n"
  1119. msg+="<b>Limite de Logins:</b> $_cont_limite\n"
  1120. msg+="<b>Limite Disponivel:</b> $_cont_disp\n"
  1121. msg+="<b>Sub-Revendas Total:</b> $_cont_atv\n"
  1122. msg+="<b>Sub-Revendas Suspensas:</b> $_cont_sup\n"
  1123. msg+="<b>User:</b> @${callback_query_from_username}\n"
  1124. msg+="<b>ID:</b> <code>${callback_query_from_id}</code>\n"
  1125. echo -e "RELATORIO DOS SUB REVENDEDORES\n\nTotal: $_cont_atv - $(printf 'Data: %(%d/%m/%Y)T\n')\n=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=" >/tmp/Relatorio-${callback_query_from_username}.txt
  1126. while read _sublist; do
  1127. _usub="$(echo $_sublist | awk '{print $2}')"
  1128. _limit_sub=$(echo $_sublist | awk '{print $4}')
  1129. _data_sub=$(grep -w $_usub $ativos | awk '{print $6}')
  1130. [[ -e "/etc/bot/revenda/$_usub/$_usub" ]] && {
  1131. _dirsts='revenda'
  1132. _status='Ativo'
  1133. } || {
  1134. _dirsts='suspensos'
  1135. _status='Suspenso'
  1136. }
  1137. fun_subon() {
  1138. for user in $(ls /etc/bot/$_dirsts/$_usub/usuarios); do
  1139. [[ $(netstat -nltp | grep 'dropbear' | wc -l) != '0' ]] && drop="$(fun_drop | grep "$user" | wc -l)" || drop=0
  1140. [[ -e /etc/openvpn/openvpn-status.log ]] && ovp="$(cat /etc/openvpn/openvpn-status.log | grep -E ,"$user", | wc -l)" || ovp=0
  1141. sqd="$(ps -u $user | grep sshd | wc -l)"
  1142. conex=$(($sqd + $ovp + $drop))
  1143. echo -e "$conex"
  1144. done
  1145. }
  1146. [[ "$(ls /etc/bot/$_dirsts/$_usub/usuarios | wc -l)" != '0' ]] && {
  1147. total_on=$(fun_on | paste -s -d + | bc)
  1148. total_users=$(ls /etc/bot/$_dirsts/$_usub/usuarios | wc -l)
  1149. } || {
  1150. total_on='0'
  1151. total_users='0'
  1152. }
  1153. echo -e "\nSTATUS: $_status\nSUB-REVENDEDOR: @$_usub\nLIMITE: $_limit_sub\nDIAS RESTANTES: $_data_sub\nSSH CRIADAS: $total_users\nSSH ONLINE: $total_on\n\n=×=×=×=×=×=×=×=×=×=×=×=×=×=×=×=" >>/tmp/Relatorio-${callback_query_from_username}.txt
  1154. done <<<"$(grep -w 'SUBREVENDA' /etc/bot/revenda/${callback_query_from_username}/${callback_query_from_username})"
  1155. ShellBot.sendDocument --chat_id ${callback_query_message_chat_id[$id]} \
  1156. --document "@/tmp/Relatorio-${callback_query_from_username}.txt" \
  1157. --caption "$(echo -e "$msg")" \
  1158. --parse_mode html
  1159. return 0
  1160. else
  1161. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1162. --text "🚫 ACESSO NEGADO 🚫"
  1163. return 0
  1164. fi
  1165. }
  1166. fun_backauto() {
  1167. [[ "${callback_query_from_id[$id]}" = "$id_admin" ]] && {
  1168. [[ ! -d /etc/SSHPlus/backups ]] && {
  1169. mkdir /etc/SSHPlus/backups
  1170. [[ $(crontab -l | grep -c "userbackup") = '0' ]] && (
  1171. crontab -l 2>/dev/null
  1172. echo "0 */6 * * * /bin/userbackup 1"
  1173. ) | crontab -
  1174. s
  1175. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1176. --text "♻️ BACKUP AUTOMATICO ATIVADO 🟢"
  1177. return 0
  1178. } || {
  1179. [[ $(crontab -l | grep -c "userbackup") != '0' ]] && crontab -l | grep -v 'userbackup' | crontab -
  1180. [[ -d /etc/SSHPlus/backups ]] && rm -rf /etc/SSHPlus/backups
  1181. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1182. --text "♻️ BACKUP AUTOMATICO DESATIVADO 🔴"
  1183. return 0
  1184. }
  1185. }
  1186. }
  1187. backup_auto() {
  1188. ShellBot.sendDocument --chat_id $id_admin \
  1189. --document "@/etc/SSHPlus/backups/backup.vps" \
  1190. --caption "$(echo -e "♻️ BACKUP AUTOMATICO ♻️")"
  1191. rm /etc/SSHPlus/backups/backup.vps
  1192. return 0
  1193. }
  1194. restaure_backup() {
  1195. [[ ${message_from_id[$id]} == ${id_admin} ]] && {
  1196. [[ "${message_document_file_name}" != 'backup.vps' ]] && return 0
  1197. local file_id
  1198. file_id=${message_document_file_id[$id]}
  1199. if [[ $file_id ]]; then
  1200. [[ -e /tmp/backup.vps ]] && rm /tmp/backup.vps
  1201. [[ "$(ls /tmp | grep -c '.vps')" != '0' ]] && {
  1202. for i in $(ls /tmp | grep '.vps'); do
  1203. rm /tmp/$i
  1204. done
  1205. }
  1206. ShellBot.getFile --file_id $file_id
  1207. if ShellBot.downloadFile --file_path "${return[file_path]}" --dir "/tmp"; then
  1208. msg='<b>♻️ ARQUIVO DE BACKUP ♻️</b>\n\n<i>O arquivo enviado é um arquivo\nde backup de usuários!</i>'
  1209. ShellBot.sendMessage --chat_id ${id_admin} \
  1210. --text "$(echo -e "$msg")" \
  1211. --parse_mode html
  1212. ShellBot.sendMessage --chat_id ${id_admin} \
  1213. --text 'Deseja restaurar ? [sim | nao]' \
  1214. --reply_markup "$(ShellBot.ForceReply)"
  1215. fi
  1216. fi
  1217. return 0
  1218. }
  1219. }
  1220. msg_bot() {
  1221. local msg
  1222. msg="🤖 \n\n"
  1223. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1224. --text "$(echo -e $msg)" \
  1225. --parse_mode html
  1226. return 0
  1227. }
  1228. msg_bem_vindo() {
  1229. local msg
  1230. msg="✌️😃 Ola <b>${message_from_first_name[$id]}</b>\n\nSEJA BEM VINDO(a)\n\n"
  1231. msg+="Para acessar o menu\nclick ou execute [ /menu ]\n\n"
  1232. msg+="Para obter informacoes\nclick ou execute [ /ajuda ]\n\n"
  1233. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1234. --text "$(echo -e $msg)" \
  1235. --parse_mode html
  1236. return 0
  1237. }
  1238. fun_verif_limite_rev() {
  1239. _userrev=$1
  1240. [[ "$(grep -w "$_userrev" $ativos | awk '{print $NF}')" == 'revenda' ]] && {
  1241. echo $_userrev
  1242. [[ $(grep -wc 'SUBREVENDA' /etc/bot/revenda/$_userrev/$_userrev) != '0' ]] && {
  1243. _limsomarev=$(grep -w 'SUBREVENDA' /etc/bot/revenda/$_userrev/$_userrev | awk {'print $4'} | paste -s -d + | bc)
  1244. } || {
  1245. _limsomarev='0'
  1246. }
  1247. [[ $(ls /etc/bot/revenda/$_userrev/usuarios | wc -l) != '0' ]] && {
  1248. _mlim1='0'
  1249. _meus_users="/etc/bot/revenda/$_userrev/usuarios"
  1250. for _user_ in $(ls $_meus_users); do
  1251. _mlim2=$(cat $_meus_users/$_user_ | awk -F : {'print $4'})
  1252. _mlim1=$(echo "${_mlim1} + ${_mlim2}" | bc)
  1253. done
  1254. }
  1255. [[ -z "$_mlim1" ]] && _mlim1='0'
  1256. _result=$(echo "${_limsomarev} + ${_mlim1}" | bc)
  1257. }
  1258. [[ "$(grep -w "$_userrev" $ativos | awk '{print $NF}')" == 'subrevenda' ]] && {
  1259. [[ "$(ls /etc/bot/revenda/$_userrev/usuarios | wc -l)" != '0' ]] && {
  1260. _dir_users="/etc/bot/revenda/$_userrev/usuarios"
  1261. _lim1='0'
  1262. for i in $(ls $_dir_users); do
  1263. _lim2=$(cat $_dir_users/$i | awk -F : {'print $4'})
  1264. _lim1=$(echo "${_lim1} + ${_lim2}" | bc)
  1265. done
  1266. }
  1267. [[ -z "$_lim1" ]] && _lim1='0'
  1268. _result=$(echo "${_lim1}")
  1269. }
  1270. }
  1271. fun_add_revenda() {
  1272. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  1273. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1274. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  1275. return 0
  1276. }
  1277. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  1278. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  1279. --text "👥 ADICIONAR REVENDEDOR 👥\n\nInforme o nome:" \
  1280. --reply_markup "$(ShellBot.ForceReply)"
  1281. } || {
  1282. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1283. --text "🚫 ACESSO NEGADO 🚫"
  1284. return 0
  1285. }
  1286. }
  1287. criar_rev() {
  1288. file_rev=$1
  1289. [[ -z "$file_rev" ]] && {
  1290. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1291. --text "$(echo -e Erro)"
  1292. _erro='1'
  1293. break
  1294. }
  1295. n_rev=$(sed -n '1 p' $file_rev | cut -d' ' -f2)
  1296. u_rev=$(sed -n '2 p' $file_rev | awk -F '@' {'print $2'})
  1297. l_rev=$(sed -n '3 p' $file_rev | cut -d' ' -f2)
  1298. d_rev=$(sed -n '4 p' $file_rev | cut -d' ' -f2)
  1299. [[ "${message_from_id[$id]}" = "$id_admin" ]] && {
  1300. t_rev='revenda'
  1301. } || {
  1302. t_rev='subrevenda'
  1303. echo -e "SUBREVENDA: $u_rev LIMITE_SUBREVENDA: $l_rev" >>/etc/bot/revenda/${message_from_username}/${message_from_username}
  1304. }
  1305. mkdir /etc/bot/revenda/"$u_rev"
  1306. mkdir /etc/bot/revenda/"$u_rev"/usuarios
  1307. touch /etc/bot/revenda/"$u_rev"/$u_rev
  1308. echo -e "USER: $u_rev LIMITE: $l_rev DIAS: $d_rev TIPO: $t_rev" >>$ativos
  1309. echo -e "=========================\nLIMITE_REVENDA: $l_rev\nDIAS_REVENDA: $d_rev\n=========================\n" >/etc/bot/revenda/"$u_rev"/$u_rev
  1310. sed -i '$d' $file_rev
  1311. echo -e "Vencimento: $(date "+%d/%m/%Y" -d "+$d_rev days")" >>$file_rev
  1312. }
  1313. fun_del_rev() {
  1314. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  1315. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1316. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  1317. return 0
  1318. }
  1319. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  1320. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  1321. --text "🗑 REMOVER REVENDEDOR 🗑\n\nInforme o user dele [Ex: @Nome Do Usuario]:" \
  1322. --reply_markup "$(ShellBot.ForceReply)"
  1323. } || {
  1324. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1325. --text "🚫 ACESSO NEGADO 🚫"
  1326. return 0
  1327. }
  1328. }
  1329. del_rev() {
  1330. _cli_rev=$1
  1331. [[ -z "$_cli_rev" ]] && {
  1332. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1333. --text "$(echo -e "Erro")"
  1334. return 0
  1335. }
  1336. [[ "${message_from_id[$id]}" == "$id_admin" ]] && {
  1337. [[ "$(grep -wc "$_cli_rev" $ativos)" != '0' ]] && {
  1338. [[ -e "/etc/bot/revenda/$_cli_rev/$_cli_rev" ]] && _dirsts='revenda' || _dirsts='suspensos'
  1339. [[ "$(grep -wc 'SUBREVENDA' /etc/bot/$_dirsts/$_cli_rev/$_cli_rev)" != '0' ]] && {
  1340. while read _listsub2; do
  1341. _usub="$(echo $_listsub2 | awk '{print $2}')"
  1342. [[ -e "/etc/bot/revenda/$_usub/$_usub" ]] && _dirsts2='revenda' || _dirsts2='suspensos'
  1343. _dir_users="/etc/bot/$_dirsts2/$_usub/usuarios"
  1344. [[ "$(ls $_dir_users | wc -l)" != '0' ]] && {
  1345. for _user in $(ls $_dir_users); do
  1346. piduser=$(ps -u "$_user" | grep sshd | cut -d? -f1)
  1347. kill -9 $piduser >/dev/null 2>&1
  1348. userdel --force "$_user" 2>/dev/null
  1349. grep -v ^$_user[[:space:]] /root/usuarios.db >/tmp/ph
  1350. cat /tmp/ph >/root/usuarios.db
  1351. rm /etc/bot/info-users/$_user
  1352. done
  1353. }
  1354. [[ -d /etc/bot/$_dirsts2/$_usub ]] && rm -rf /etc/bot/$_dirsts2/$_usub >/dev/null 2>&1
  1355. sed -i "/\b$_usub\b/d" $ativos
  1356. [[ $(grep -wc "$_usub" $suspensos) != '0' ]] && {
  1357. sed -i "/\b$_usub\b/d" $suspensos
  1358. }
  1359. done <<<"$(grep -w 'SUBREVENDA' /etc/bot/$_dirsts/$_cli_rev/$_cli_rev)"
  1360. }
  1361. [[ "$(ls /etc/bot/$_dirsts/$_cli_rev/usuarios | wc -l)" != '0' ]] && {
  1362. for _user in $(ls /etc/bot/$_dirsts/$_cli_rev/usuarios); do
  1363. piduser=$(ps -u "$_user" | grep sshd | cut -d? -f1)
  1364. kill -9 $piduser >/dev/null 2>&1
  1365. userdel --force "$_user" 2>/dev/null
  1366. grep -v ^$_user[[:space:]] /root/usuarios.db >/tmp/ph
  1367. cat /tmp/ph >/root/usuarios.db
  1368. rm /etc/bot/info-users/$_user
  1369. done
  1370. }
  1371. [[ -d /etc/bot/$_dirsts/$_cli_rev ]] && rm -rf /etc/bot/$_dirsts/$_cli_rev >/dev/null 2>&1
  1372. sed -i "/\b$_cli_rev\b/d" $ativos
  1373. [[ $(grep -wc "$_cli_rev" $suspensos) != '0' ]] && {
  1374. sed -i "/\b$_cli_rev\b/d" $suspensos
  1375. }
  1376. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1377. --text "$(echo -e "REMOVIDO COM SUCESSO")" \
  1378. --parse_mode html
  1379. return 0
  1380. } || {
  1381. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1382. --text "$(echo -e ❌ REVENDEDEDOR NAO EXISTE ❌)"
  1383. return 0
  1384. }
  1385. } || {
  1386. [[ "$(grep -wc "$_cli_rev" /etc/bot/revenda/${message_from_username}/${message_from_username})" != '0' ]] && {
  1387. [[ -d /etc/bot/revenda/$_cli_rev ]] && {
  1388. [[ "$(ls /etc/bot/revenda/$_cli_rev/usuarios | wc -l)" != '0' ]] && {
  1389. for _user in $(ls /etc/bot/revenda/$_cli_rev/usuarios); do
  1390. piduser=$(ps -u "$_user" | grep sshd | cut -d? -f1)
  1391. kill -9 $piduser >/dev/null 2>&1
  1392. userdel --force "$_user" 2>/dev/null
  1393. grep -v ^$_user[[:space:]] /root/usuarios.db >/tmp/ph
  1394. cat /tmp/ph >/root/usuarios.db
  1395. rm /etc/bot/info-users/$_user
  1396. done
  1397. }
  1398. [[ -d /etc/bot/revenda/$_cli_rev ]] && rm -rf /etc/bot/revenda/$_cli_rev >/dev/null 2>&1
  1399. sed -i "/\b$_cli_rev\b/d" $ativos
  1400. sed -i "/\b$_cli_rev\b/d" /etc/bot/revenda/${message_from_username}/${message_from_username}
  1401. }
  1402. [[ -d /etc/bot/suspensos/$_cli_rev ]] && {
  1403. [[ "$(ls /etc/bot/suspensos/$_cli_rev/usuarios | wc -l)" != '0' ]] && {
  1404. for _user in $(ls /etc/bot/suspensos/$_cli_rev/usuarios); do
  1405. piduser=$(ps -u "$_user" | grep sshd | cut -d? -f1)
  1406. kill -9 $piduser >/dev/null 2>&1
  1407. userdel --force "$_user" 2>/dev/null
  1408. grep -v ^$_user[[:space:]] /root/usuarios.db >/tmp/ph
  1409. cat /tmp/ph >/root/usuarios.db
  1410. rm /etc/bot/info-users/$_user
  1411. done
  1412. }
  1413. [[ -d /etc/bot/suspensos/$_cli_rev ]] && rm -rf /etc/bot/suspensos/$_cli_rev >/dev/null 2>&1
  1414. sed -i "/\b$_cli_rev\b/d" $ativos
  1415. sed -i "/\b$_cli_rev\b/d" $suspensos
  1416. sed -i "/\b$_cli_rev\b/d" /etc/bot/revenda/${message_from_username}/${message_from_username}
  1417. }
  1418. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1419. --text "$(echo -e "REMOVIDO COM SUCESSO")" \
  1420. --parse_mode html
  1421. return 0
  1422. } || {
  1423. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1424. --text "$(echo -e ❌ REVENDEDEDOR NAO EXISTE ❌)"
  1425. return 0
  1426. }
  1427. }
  1428. }
  1429. fun_lim_rev() {
  1430. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  1431. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1432. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  1433. return 0
  1434. }
  1435. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  1436. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  1437. --text "♾ ALTERAR LIMITE REVENDA ♾\n\nInforme o user dele [Ex: @Nome Do Usuario]:" \
  1438. --reply_markup "$(ShellBot.ForceReply)"
  1439. } || {
  1440. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1441. --text "🚫 ACESSO NEGADO 🚫"
  1442. return 0
  1443. }
  1444. }
  1445. lim_rev() {
  1446. _file_lim=$1
  1447. [[ -z "$_file_lim" ]] && {
  1448. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1449. --text "$(echo -e "Erro")"
  1450. return 0
  1451. }
  1452. _rev_usern=$(grep -w 'Revendedor' $_file_lim | awk -F '@' {'print $2'})
  1453. new_l=$(grep -w 'Limite' $_file_lim | awk {'print $2'})
  1454. [[ -d /etc/bot/revenda/$_rev_usern ]] && {
  1455. l_old=$(grep -w 'LIMITE_REVENDA' /etc/bot/revenda/$_rev_usern/$_rev_usern | awk {'print $2'})
  1456. sed -i "/LIMITE_REVENDA/ s/$l_old/$new_l/g" /etc/bot/revenda/$_rev_usern/$_rev_usern
  1457. sed -i "/$_rev_usern/ s/LIMITE: $l_old/LIMITE: $new_l/" $ativos
  1458. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  1459. sed -i "/\b$_rev_usern\b/ s/$l_old/$new_l/g" /etc/bot/revenda/${message_from_username}/${message_from_username}
  1460. }
  1461. echo $_rev_usern
  1462. } || {
  1463. l_old=$(grep -w 'LIMITE_REVENDA' /etc/bot/suspensos/$_rev_usern/$_rev_usern | awk {'print $2'})
  1464. sed -i "/LIMITE_REVENDA/ s/$l_old/$new_l/g" /etc/bot/suspensos/$_rev_usern/$_rev_usern
  1465. sed -i "/\b$_rev_usern\b/ s/LIMITE: $l_old/LIMITE: $new_l/" $ativos
  1466. sed -i "/\b$_rev_usern\b/ s/LIMITE: $l_old/LIMITE: $new_l/" $suspensos
  1467. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  1468. sed -i "/\b$_rev_usern\b/ s/$l_old/$new_l/" /etc/bot/revenda/${message_from_username}/${message_from_username}
  1469. }
  1470. echo $_rev_usern
  1471. }
  1472. }
  1473. fun_dat_rev() {
  1474. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  1475. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1476. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  1477. return 0
  1478. }
  1479. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  1480. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  1481. --text "📆 ALTERAR DATA REVENDA 📆\n\nInforme o user dele [Ex: @Nome Do Usuario]:" \
  1482. --reply_markup "$(ShellBot.ForceReply)"
  1483. } || {
  1484. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1485. --text "🚫 ACESSO NEGADO 🚫"
  1486. return 0
  1487. }
  1488. }
  1489. dat_rev() {
  1490. _datfile=$1
  1491. [[ -z "$_datfile" ]] && {
  1492. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1493. --text "$(echo -e "Erro")"
  1494. _erro='1'
  1495. return 0
  1496. }
  1497. _revd=$(grep -w 'Revendedor' $_datfile | cut -d'@' -f2)
  1498. new_d=$(grep -w 'Data' $_datfile | awk '{print $NF}')
  1499. [[ -d "/etc/bot/suspensos/$_revd" ]] && {
  1500. [[ "$(ls /etc/bot/suspensos/$_revd/usuarios | wc -l)" != '0' ]] && {
  1501. for _user in $(ls /etc/bot/suspensos/$_revd/usuarios); do
  1502. usermod -U $_user
  1503. done
  1504. }
  1505. d_old=$(grep -w 'DIAS_REVENDA' /etc/bot/suspensos/$_revd/$_revd | awk {'print $2'})
  1506. sed -i "/\b$_revd\b/ s/DIAS: $d_old/DIAS: $new_d/" $ativos
  1507. sed -i "/DIAS_REVENDA/ s/$d_old/$new_d/" /etc/bot/suspensos/$_revd/$_revd
  1508. [[ "$(grep -wc 'SUBREVENDA' /etc/bot/suspensos/$_revd/$_revd)" != '0' ]] && {
  1509. while read _listsub; do
  1510. _usub="$(echo $_listsub | awk '{print $2}')"
  1511. [[ "$(ls /etc/bot/suspensos/$_usub/usuarios | wc -l)" != '0' ]] && {
  1512. for _user in $(ls /etc/bot/suspensos/$_usub/usuarios); do
  1513. usermod -U $_user
  1514. done
  1515. }
  1516. mv /etc/bot/suspensos/$_usub /etc/bot/revenda/$_usub
  1517. sed -i "/\b$_usub\b/d" $suspensos
  1518. done <<<"$(grep -w 'SUBREVENDA' /etc/bot/suspensos/$_revd/$_revd)"
  1519. }
  1520. mv /etc/bot/suspensos/$_revd /etc/bot/revenda/$_revd
  1521. sed -i "/\b$_revd\b/d" $suspensos
  1522. sed -i "s;$new_d;$(date "+%d/%m/%Y" -d "+$new_d days");" $_datfile
  1523. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1524. --text "$(echo -e "⚠️ $_revd ESTAVA SUSPENSO E FOI REATIVADO !")" \
  1525. --parse_mode html
  1526. } || {
  1527. d_old=$(grep -w 'DIAS_REVENDA' /etc/bot/revenda/$_revd/$_revd | awk {'print $2'})
  1528. sed -i "/\b$_revd\b/ s/DIAS: $d_old/DIAS: $new_d/" $ativos
  1529. sed -i "/DIAS_REVENDA/ s/$d_old/$new_d/" /etc/bot/revenda/$_revd/$_revd
  1530. sed -i "s;$new_d;$(date "+%d/%m/%Y" -d "+$new_d days");" $_datfile
  1531. }
  1532. }
  1533. fun_list_rev() {
  1534. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  1535. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1536. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  1537. return 0
  1538. }
  1539. if [[ "${callback_query_from_id[$id]}" == "$id_admin" ]]; then
  1540. local msg1
  1541. msg1="=×=×=×=×=×=×=×=×=×=×=×=×=×=\n📃 LISTA DE REVENDEDORES !\n=×=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  1542. [[ "$(grep -wc 'revenda' $ativos)" != '0' ]] && {
  1543. while read _atvs; do
  1544. _uativ="$(echo $_atvs | awk '{print $2}')"
  1545. [[ "$(grep -wc "$_uativ" $suspensos)" == '0' ]] && _stsrev='ATIVO' || _stsrev='SUSPENSO'
  1546. msg1+="• @$_uativ - $_stsrev\n"
  1547. done <<<"$(grep -w 'revenda' /etc/bot/lista_ativos)"
  1548. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  1549. --text "$(echo -e "$msg1")" \
  1550. --parse_mode html
  1551. return 0
  1552. } || {
  1553. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1554. --text "VC NAO TEM REVENDEDORES"
  1555. return 0
  1556. }
  1557. elif [[ "$(grep -w ${callback_query_from_username} $ativos | awk '{print $NF}')" == 'revenda' ]]; then
  1558. _patch="/etc/bot/revenda"
  1559. local msg1
  1560. msg1="=×=×=×=×=×=×=×=×=×=×=×=×=\n📃 LISTA DE SUB REVENDEDORES !\n=×=×=×=×=×=×=×=×=×=×=×=×=\n"
  1561. [[ "$(grep -wc "SUBREVENDA" $_patch/${callback_query_from_username}/${callback_query_from_username})" != '0' ]] && {
  1562. while read _listsub; do
  1563. _usub="$(echo $_listsub | awk '{print $2}')"
  1564. [[ "$(grep -wc "$_usub" $suspensos)" == '0' ]] && _usts='ATIVO' || _usts='SUSPENSO'
  1565. msg1+="• @$_usub - $_usts\n"
  1566. done <<<"$(grep -w 'SUBREVENDA' $_patch/${callback_query_from_username}/${callback_query_from_username})"
  1567. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  1568. --text "$(echo -e "$msg1")" \
  1569. --parse_mode html
  1570. return 0
  1571. } || {
  1572. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1573. --text "VC NAO TEM SUB REVENDEDORES"
  1574. return 0
  1575. }
  1576. else
  1577. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1578. --text "🚫 ACESSO NEGADO 🚫"
  1579. return 0
  1580. fi
  1581. }
  1582. fun_susp_rev() {
  1583. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  1584. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1585. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  1586. return 0
  1587. }
  1588. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  1589. ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} \
  1590. --text "🔒 SUSPENDER REVENDEDOR 🔒\n\nInforme o user dele [Ex: @Nome Do Usuario]:" \
  1591. --reply_markup "$(ShellBot.ForceReply)"
  1592. } || {
  1593. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1594. --text "🚫 ACESSO NEGADO 🚫"
  1595. return 0
  1596. }
  1597. }
  1598. susp_rev() {
  1599. _revs=$1
  1600. [[ -z "$_revs" ]] && {
  1601. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1602. --text "$(echo -e "Erro")"
  1603. return 0
  1604. }
  1605. [[ -d "/etc/bot/suspensos/$_revs" ]] && {
  1606. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1607. --text "$(echo -e "O USUARIO JA ESTA SUSPENSO !")" \
  1608. --parse_mode html
  1609. return 0
  1610. }
  1611. [[ ! -d "/etc/bot/revenda/$_revs" ]] && {
  1612. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1613. --text "$(echo -e "O USUARIO NAO EXISTE !")" \
  1614. --parse_mode html
  1615. return 0
  1616. }
  1617. [[ "${message_from_id[$id]}" == "$id_admin" ]] && {
  1618. [[ "$(grep -wc 'SUBREVENDA' /etc/bot/revenda/$_revs/$_revs)" != '0' ]] && {
  1619. while read _listsub3; do
  1620. _usub3="$(echo $_listsub3 | awk '{print $2}')"
  1621. _dir_users="/etc/bot/revenda/$_usub3/usuarios"
  1622. [[ "$(ls $_dir_users | wc -l)" != '0' ]] && {
  1623. for _user in $(ls $_dir_users); do
  1624. usermod -L $_user
  1625. pkill -f $_user
  1626. done
  1627. }
  1628. mv /etc/bot/revenda/$_usub3 /etc/bot/suspensos/$_usub3
  1629. grep -w "$_usub3" $ativos >>$suspensos
  1630. done <<<"$(grep -w 'SUBREVENDA' /etc/bot/revenda/$_revs/$_revs)"
  1631. }
  1632. [[ "$(ls /etc/bot/revenda/$_revs/usuarios | wc -l)" != '0' ]] && {
  1633. for _user_ in $(ls /etc/bot/revenda/$_revs/usuarios); do
  1634. usermod -L $_user_
  1635. pkill -f $_user_
  1636. done
  1637. }
  1638. mv /etc/bot/revenda/$_revs /etc/bot/suspensos/$_revs
  1639. grep -w "$_revs" $ativos >>$suspensos
  1640. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1641. --text "$(echo -e "SUSPENDIDO COM SUCESSO")" \
  1642. --parse_mode html
  1643. return 0
  1644. } || {
  1645. [[ "$(grep -wc "$_revs" /etc/bot/revenda/${message_from_username}/${message_from_username})" != '0' ]] && {
  1646. [[ "$(ls /etc/bot/revenda/$_revs/usuarios | wc -l)" != '0' ]] && {
  1647. for _user_ in $(ls /etc/bot/revenda/$_revs/usuarios); do
  1648. usermod -L $_user_
  1649. pkill -f $_user_
  1650. done
  1651. }
  1652. mv /etc/bot/revenda/$_revs /etc/bot/suspensos/$_revs
  1653. grep -w "$_revs" $ativos >>$suspensos
  1654. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1655. --text "$(echo -e "SUSPENDIDO COM SUCESSO")" \
  1656. --parse_mode html
  1657. return 0
  1658. } || {
  1659. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1660. --text "$(echo -e "O SUB REVENDEDOR NAO EXISTE")" \
  1661. --parse_mode html
  1662. return 0
  1663. }
  1664. }
  1665. }
  1666. infouserbot() {
  1667. [[ $(grep -wc ${message_from_username} $ativos) != '0' ]] && {
  1668. _cont_limite=$(grep -w ${message_from_username} $ativos | awk '{print $4}')
  1669. fun_verif_limite_rev ${message_from_username}
  1670. _cont_disp=$(echo $_cont_limite - $_result | bc)
  1671. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1672. --text "$(echo -e "<b>NOME: </> ${message_from_first_name[$(ShellBot.ListUpdates)]}\n<b>USER:</>" "@${message_from_username[$(ShellBot.ListUpdates)]:-null}")\n<b>ID:</> ${message_from_id[$(ShellBot.ListUpdates)]}\nACESSO: REVENDA\n<b>LIMITE TOTAL:</b> $_cont_limite\n<b>LIMITE RESTANTE:</b> $_cont_disp" \
  1673. --parse_mode html
  1674. return 0
  1675. } || {
  1676. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1677. --text "$(echo -e "<b>NOME: </> ${message_from_first_name[$(ShellBot.ListUpdates)]}\n<b>USER:</>" "@${message_from_username[$(ShellBot.ListUpdates)]:-null}")\n<b>ID:</> ${message_from_id[$(ShellBot.ListUpdates)]} " \
  1678. --parse_mode html
  1679. return 0
  1680. }
  1681. }
  1682. fun_menurevenda() {
  1683. [[ "$(grep -wc ${callback_query_from_username} $suspensos)" != '0' ]] && {
  1684. ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
  1685. --text "⚠️ VC ESTA SUSPENSO! CONTATE O ADMINISTRADOR"
  1686. return 0
  1687. }
  1688. [[ "${callback_query_from_id[$id]}" == "$id_admin" ]] || [[ "$(grep -wc ${callback_query_from_username} $ativos)" != '0' ]] && {
  1689. ShellBot.editMessageText --chat_id ${callback_query_message_chat_id[$id]} \
  1690. --message_id ${callback_query_message_message_id[$id]} \
  1691. --text "SELECIONE UMA OPÇÃO ABAIXO:" \
  1692. --reply_markup "$(ShellBot.InlineKeyboardMarkup --button 'menu4')"
  1693. return 0
  1694. }
  1695. }
  1696. # LISTA MENU ADMIN
  1697. unset menu1
  1698. menu1=''
  1699. ShellBot.InlineKeyboardButton --button 'menu1' --line 1 --text 'CRIAR USUARIO' --callback_data '_criaruser'
  1700. ShellBot.InlineKeyboardButton --button 'menu1' --line 2 --text 'CRIAR TESTE' --callback_data '_criarteste'
  1701. ShellBot.InlineKeyboardButton --button 'menu1' --line 3 --text 'REMOVER' --callback_data '_deluser'
  1702. ShellBot.InlineKeyboardButton --button 'menu1' --line 4 --text 'ALTERAR SENHA' --callback_data '_altsenha'
  1703. ShellBot.InlineKeyboardButton --button 'menu1' --line 5 --text 'ALTERAR LIMITE' --callback_data '_altlimite'
  1704. ShellBot.InlineKeyboardButton --button 'menu1' --line 6 --text 'ALTERAR DATA' --callback_data '_altdata'
  1705. ShellBot.InlineKeyboardButton --button 'menu1' --line 7 --text 'USUARIOS ONLINE' --callback_data '_monitor'
  1706. ShellBot.InlineKeyboardButton --button 'menu1' --line 8 --text 'INFO USUARIOS' --callback_data '_verusers'
  1707. ShellBot.InlineKeyboardButton --button 'menu1' --line 9 --text 'EXPIRADOS' --callback_data '_expirados'
  1708. ShellBot.InlineKeyboardButton --button 'menu1' --line 1 --text 'INFO VPS' --callback_data '_infovps'
  1709. ShellBot.InlineKeyboardButton --button 'menu1' --line 2 --text 'OTIMIZAR' --callback_data '_otimizar'
  1710. ShellBot.InlineKeyboardButton --button 'menu1' --line 3 --text 'ARQUIVOS' --callback_data '_arqdown'
  1711. ShellBot.InlineKeyboardButton --button 'menu1' --line 4 --text 'REVENDA' --callback_data '_opcoesrev'
  1712. ShellBot.InlineKeyboardButton --button 'menu1' --line 5 --text 'SPEEDTESTE' --callback_data '_speedteste'
  1713. ShellBot.InlineKeyboardButton --button 'menu1' --line 6 --text 'BACKUP USUARIOS' --callback_data '_backupusers'
  1714. ShellBot.InlineKeyboardButton --button 'menu1' --line 7 --text "AUTO BACKUP" --callback_data '_autobkp'
  1715. ShellBot.InlineKeyboardButton --button 'menu1' --line 8 --text 'RELATORIO' --callback_data '_relatorio'
  1716. ShellBot.InlineKeyboardButton --button 'menu1' --line 9 --text 'AJUDA' --callback_data '_ajuda'
  1717. ShellBot.regHandleFunction --function fun_adduser --callback_data _criaruser
  1718. ShellBot.regHandleFunction --function fun_add_teste --callback_data _criarteste
  1719. ShellBot.regHandleFunction --function fun_deluser --callback_data _deluser
  1720. ShellBot.regHandleFunction --function alterar_senha --callback_data _altsenha
  1721. ShellBot.regHandleFunction --function alterar_limite --callback_data _altlimite
  1722. ShellBot.regHandleFunction --function alterar_data --callback_data _altdata
  1723. ShellBot.regHandleFunction --function fun_down --callback_data _arqdown
  1724. ShellBot.regHandleFunction --function monitor_ssh --callback_data _monitor
  1725. ShellBot.regHandleFunction --function ver_users --callback_data _verusers
  1726. ShellBot.regHandleFunction --function fun_exp_user --callback_data _expirados
  1727. ShellBot.regHandleFunction --function otimizer --callback_data _otimizar
  1728. ShellBot.regHandleFunction --function speed_test --callback_data _speedteste
  1729. ShellBot.regHandleFunction --function infovps --callback_data _infovps
  1730. ShellBot.regHandleFunction --function backup_users --callback_data _backupusers
  1731. ShellBot.regHandleFunction --function fun_backauto --callback_data _autobkp
  1732. ShellBot.regHandleFunction --function relatorio_rev --callback_data _relatorio
  1733. ShellBot.regHandleFunction --function fun_ajuda --callback_data _ajuda
  1734. ShellBot.regHandleFunction --function fun_menurevenda --callback_data _opcoesrev
  1735. unset keyboard1
  1736. keyboard1="$(ShellBot.InlineKeyboardMarkup -b 'menu1')"
  1737. # LISTA MENU REVENDEDOR
  1738. unset menu2
  1739. menu2=''
  1740. ShellBot.InlineKeyboardButton --button 'menu2' --line 1 --text 'CRIAR USUARIO' --callback_data '_criaruser2'
  1741. ShellBot.InlineKeyboardButton --button 'menu2' --line 1 --text 'CRIAR TESTE' --callback_data '_criarteste2'
  1742. ShellBot.InlineKeyboardButton --button 'menu2' --line 2 --text 'REMOVER' --callback_data '_deluser2'
  1743. ShellBot.InlineKeyboardButton --button 'menu2' --line 2 --text 'USUARIOS ONLINE' --callback_data '_monitor2'
  1744. ShellBot.InlineKeyboardButton --button 'menu2' --line 3 --text 'ALTERAR LIMITE' --callback_data '_altlimite2'
  1745. ShellBot.InlineKeyboardButton --button 'menu2' --line 3 --text 'INFO USUARIOS' --callback_data '_verusers2'
  1746. ShellBot.InlineKeyboardButton --button 'menu2' --line 4 --text 'ALTERAR SENHA' --callback_data '_altsenha2'
  1747. ShellBot.InlineKeyboardButton --button 'menu2' --line 4 --text 'EXPIRADOS' --callback_data '_expirados2'
  1748. ShellBot.InlineKeyboardButton --button 'menu2' --line 5 --text 'ALTERAR DATA' --callback_data '_altdata2'
  1749. ShellBot.InlineKeyboardButton --button 'menu2' --line 5 --text 'REVENDA' --callback_data '_opcoesrev2'
  1750. ShellBot.InlineKeyboardButton --button 'menu2' --line 6 --text 'RELATORIO' --callback_data '_relatorio2'
  1751. ShellBot.InlineKeyboardButton --button 'menu2' --line 6 --text 'AJUDA' --callback_data '_ajuda2'
  1752. ShellBot.regHandleFunction --function fun_adduser --callback_data _criaruser2
  1753. ShellBot.regHandleFunction --function fun_add_teste --callback_data _criarteste2
  1754. ShellBot.regHandleFunction --function fun_deluser --callback_data _deluser2
  1755. ShellBot.regHandleFunction --function alterar_senha --callback_data _altsenha2
  1756. ShellBot.regHandleFunction --function alterar_limite --callback_data _altlimite2
  1757. ShellBot.regHandleFunction --function alterar_data --callback_data _altdata2
  1758. ShellBot.regHandleFunction --function monitor_ssh --callback_data _monitor2
  1759. ShellBot.regHandleFunction --function ver_users --callback_data _verusers2
  1760. ShellBot.regHandleFunction --function fun_exp_user --callback_data _expirados2
  1761. ShellBot.regHandleFunction --function relatorio_rev --callback_data _relatorio2
  1762. ShellBot.regHandleFunction --function fun_menurevenda --callback_data _opcoesrev2
  1763. ShellBot.regHandleFunction --function fun_ajuda --callback_data _ajuda2
  1764. unset keyboard2
  1765. keyboard2="$(ShellBot.InlineKeyboardMarkup -b 'menu2')"
  1766. #LISTA MUNU SUB REVENDEDOR
  1767. unset menu3
  1768. menu3=''
  1769. ShellBot.InlineKeyboardButton --button 'menu3' --line 1 --text 'CRIAR USUARIO' --callback_data '_criaruser3'
  1770. ShellBot.InlineKeyboardButton --button 'menu3' --line 1 --text 'CRIAR TESTE' --callback_data '_criarteste3'
  1771. ShellBot.InlineKeyboardButton --button 'menu3' --line 2 --text 'REMOVER' --callback_data '_deluser3'
  1772. ShellBot.InlineKeyboardButton --button 'menu3' --line 2 --text 'USUARIOS ONLINE' --callback_data '_monitor3'
  1773. ShellBot.InlineKeyboardButton --button 'menu3' --line 3 --text 'ALTERAR LIMITE' --callback_data '_altlimite3'
  1774. ShellBot.InlineKeyboardButton --button 'menu3' --line 3 --text 'INFO USUARIOS' --callback_data '_verusers3'
  1775. ShellBot.InlineKeyboardButton --button 'menu3' --line 4 --text 'ALTERAR SENHA' --callback_data '_altsenha3'
  1776. ShellBot.InlineKeyboardButton --button 'menu3' --line 4 --text 'EXPIRADOS' --callback_data '_expirados3'
  1777. ShellBot.InlineKeyboardButton --button 'menu3' --line 5 --text 'ALTERAR DATA' --callback_data '_altdata3'
  1778. ShellBot.InlineKeyboardButton --button 'menu3' --line 5 --text 'AJUDA' --callback_data '_ajuda3'
  1779. ShellBot.regHandleFunction --function fun_adduser --callback_data _criaruser3
  1780. ShellBot.regHandleFunction --function fun_add_teste --callback_data _criarteste3
  1781. ShellBot.regHandleFunction --function fun_deluser --callback_data _deluser3
  1782. ShellBot.regHandleFunction --function alterar_senha --callback_data _altsenha3
  1783. ShellBot.regHandleFunction --function alterar_limite --callback_data _altlimite3
  1784. ShellBot.regHandleFunction --function alterar_data --callback_data _altdata3
  1785. ShellBot.regHandleFunction --function monitor_ssh --callback_data _monitor3
  1786. ShellBot.regHandleFunction --function ver_users --callback_data _verusers3
  1787. ShellBot.regHandleFunction --function fun_exp_user --callback_data _expirados3
  1788. ShellBot.regHandleFunction --function fun_ajuda --callback_data _ajuda3
  1789. unset keyboard3
  1790. keyboard3="$(ShellBot.InlineKeyboardMarkup -b 'menu3')"
  1791. #LISTA MENU OPCOES REVENDA
  1792. unset menu4
  1793. menu4=''
  1794. ShellBot.InlineKeyboardButton --button 'menu4' --line 1 --text 'ADICIONAR REVENDA' --callback_data '_addrev'
  1795. ShellBot.InlineKeyboardButton --button 'menu4' --line 2 --text 'REMOVER REVENDA' --callback_data '_delrev'
  1796. ShellBot.InlineKeyboardButton --button 'menu4' --line 3 --text 'ALTERAR LIMITE REVENDA' --callback_data '_limrev'
  1797. ShellBot.InlineKeyboardButton --button 'menu4' --line 4 --text 'ALTERAR DATA REVENDA' --callback_data '_datrev'
  1798. ShellBot.InlineKeyboardButton --button 'menu4' --line 5 --text 'LISTAR REVENDA' --callback_data '_listrev'
  1799. ShellBot.InlineKeyboardButton --button 'menu4' --line 6 --text 'SUSPENDER REVENDA' --callback_data '_susprevendas'
  1800. ShellBot.regHandleFunction --function fun_add_revenda --callback_data _addrev
  1801. ShellBot.regHandleFunction --function fun_del_rev --callback_data _delrev
  1802. ShellBot.regHandleFunction --function fun_lim_rev --callback_data _limrev
  1803. ShellBot.regHandleFunction --function fun_dat_rev --callback_data _datrev
  1804. ShellBot.regHandleFunction --function fun_list_rev --callback_data _listrev
  1805. ShellBot.regHandleFunction --function fun_susp_rev --callback _susprevendas
  1806. unset keyboard4
  1807. keyboard4="$(ShellBot.InlineKeyboardMarkup -b 'menu4')"
  1808. while :; do
  1809. [[ -e "/etc/SSHPlus/backups/backup.vps" ]] && {
  1810. backup_auto
  1811. }
  1812. #Obtem as atualizações
  1813. ShellBot.getUpdates --limit 100 --offset $(ShellBot.OffsetNext) --timeout 35
  1814. #Lista o índice das atualizações
  1815. for id in $(ShellBot.ListUpdates); do
  1816. #Inicio thread
  1817. (
  1818. ShellBot.watchHandle --callback_data ${callback_query_data[$id]}
  1819. # Requisições somente no privado.
  1820. [[ ${message_chat_type[$id]} != 'private' ]] && continue
  1821. [[ ${message_text[$id]} ]] || restaure_backup
  1822. CAD_ARQ=/tmp/cad.${message_from_id[$id]}
  1823. if [[ ${message_entities_type[$id]} == bot_command ]]; then
  1824. #Verifica se a mensagem enviada pelo usuário é um comando válido.
  1825. case ${message_text[$id]} in
  1826. *)
  1827. :
  1828. #comandos
  1829. comando=(${message_text[$id]})
  1830. [[ "${comando[0]}" = "/start" ]] && msg_bot
  1831. [[ "${comando[0]}" = "/start" ]] && msg_bem_vindo
  1832. [[ "${comando[0]}" = "/menu" ]] && fun_menu
  1833. [[ "${comando[0]}" = "/info" ]] && infouserbot
  1834. [[ "${comando[0]}" = "/hrlp" || "${comando[0]}" = "/ajuda" ]] && fun_ajuda
  1835. [[ "${comando[0]}" = "/bot" || "${comando[0]}" = "/sobre" ]] && sobremim
  1836. ;;
  1837. esac
  1838. fi
  1839. if [[ ${message_reply_to_message_message_id[$id]} ]]; then
  1840. # Analisa a interface de resposta.
  1841. case ${message_reply_to_message_text[$id]} in
  1842. '👤 CRIAR USUARIO 👤\n\nNome do usuario:')
  1843. verifica_acesso
  1844. [[ "$_erro" == '1' ]] && break
  1845. [[ "$(awk -F : '$3 >= 1000 { print $1 }' /etc/passwd | grep -w ${message_text[$id]} | wc -l)" != '0' ]] && {
  1846. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1847. --text "$(echo -e "❌ Erro! USUARIO INVALIDO ❌\n\n⚠️ Informe Outro Nome..")" \
  1848. --parse_mode html
  1849. >$CAD_ARQ
  1850. break
  1851. }
  1852. [ "${message_text[$id]}" == 'root' ] && {
  1853. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1854. --text "$(echo -e "❌ ERRO! USUARIO INVALIDO ❌\n\n⚠️ Informe Outro Nome..")" \
  1855. --parse_mode html
  1856. >$CAD_ARQ
  1857. break
  1858. }
  1859. sizemin=$(echo -e ${#message_text[$id]})
  1860. [[ "$sizemin" -lt '4' ]] && {
  1861. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1862. --text "$(echo -e "❌ Erro !\n\nUse no mínimo 4 caracteres\n[EX: test]")" \
  1863. --parse_mode html
  1864. >$CAD_ARQ
  1865. break
  1866. }
  1867. sizemax=$(echo -e ${#message_text[$id]})
  1868. [[ "$sizemax" -gt '10' ]] && {
  1869. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1870. --text "$(echo -e "❌ Erro !\n\nUse no maximo 8 caracteres\n[EX: vpn]")" \
  1871. --parse_mode html
  1872. >$CAD_ARQ
  1873. break
  1874. }
  1875. echo "Nome: ${message_text[$id]}" >$CAD_ARQ
  1876. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1877. --text 'Senha:' \
  1878. --reply_markup "$(ShellBot.ForceReply)" # Força a resposta.
  1879. ;;
  1880. 'Senha:')
  1881. sizepass=$(echo -e ${#message_text[$id]})
  1882. verifica_acesso
  1883. [[ "$_erro" == '1' ]] && break
  1884. [[ "$sizepass" -lt '4' ]] && {
  1885. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1886. --text "$(echo -e "❌ Erro !\n\nUse no mínimo 4 caracteres\n[EX: 1234]")" \
  1887. --parse_mode html
  1888. >$CAD_ARQ
  1889. break
  1890. }
  1891. echo "Senha: ${message_text[$id]}" >>$CAD_ARQ
  1892. # Próximo campo.
  1893. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1894. --text 'Limite:' \
  1895. --reply_markup "$(ShellBot.ForceReply)"
  1896. ;;
  1897. 'Limite:')
  1898. verifica_acesso
  1899. [[ "$_erro" == '1' ]] && break
  1900. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  1901. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1902. --text "$(echo -e "❌ Erro ! \n\nUltilize apenas numeros [EX: 1]")" \
  1903. --parse_mode html
  1904. >$CAD_ARQ
  1905. break
  1906. }
  1907. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  1908. _limTotal=$(grep -w "${message_from_username}" $ativos | awk '{print $4}')
  1909. fun_verif_limite_rev ${message_from_username}
  1910. _limsomarev2=$(echo "$_result + ${message_text[$id]}" | bc)
  1911. [[ "$_limsomarev2" -gt "$_limTotal" ]] && {
  1912. _restant1=$(($_limTotal - $_result))
  1913. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1914. --text "$(echo -e "❌ Vc nao tem limite suficiente\n\nLimite disponivel: $_restant1 ")" \
  1915. --parse_mode html
  1916. >$CAD_ARQ
  1917. break
  1918. }
  1919. }
  1920. echo "Limite: ${message_text[$id]}" >>$CAD_ARQ
  1921. # Próximo campo.
  1922. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1923. --text 'Validade em dias: ' \
  1924. --reply_markup "$(ShellBot.ForceReply)"
  1925. ;;
  1926. 'Validade em dias:')
  1927. verifica_acesso
  1928. [[ "$_erro" == '1' ]] && break
  1929. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  1930. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1931. --text "$(echo -e "❌ Erro ! \n\nUltilize apenas numeros [EX: 30]")" \
  1932. --parse_mode html
  1933. >$CAD_ARQ
  1934. break
  1935. }
  1936. info_data=$(date '+%d/%m/%C%y' -d " +${message_text[$id]} days")
  1937. echo "Validade: $info_data" >>$CAD_ARQ
  1938. criar_user $CAD_ARQ
  1939. [[ "(grep -w ${message_text[$id]} /etc/passwd)" = '0' ]] && {
  1940. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1941. --text "$(echo -e ❌ Erro ao criar usuario !)" \
  1942. --parse_mode html
  1943. >$CAD_ARQ
  1944. break
  1945. }
  1946. [[ "$(ls /etc/bot/arquivos | wc -l)" != '0' ]] && {
  1947. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1948. --text '📥 ARQUIVOS DISPONIVEIS 📥\n\nDeseja baixar? Sim ou Nao?:' \
  1949. --reply_markup "$(ShellBot.ForceReply)"
  1950. } || {
  1951. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1952. --text "<b>✅ CRIADO COM SUCESSO ✅</b>\n\nUSUARIO: <code>$(awk -F " " '/Nome/ {print $2}' $CAD_ARQ)</code>\nSENHA: <code>$(awk -F " " '/Senha/ {print $2}' $CAD_ARQ)</code>\nLIMITE: $(awk -F " " '/Limite/ {print $2}' $CAD_ARQ)\nEXPIRA EM: $(awk -F " " '/Validade/ {print $2}' $CAD_ARQ)" \
  1953. --parse_mode html
  1954. break
  1955. }
  1956. ;;
  1957. '📥 ARQUIVOS DISPONIVEIS 📥\n\nDeseja baixar? Sim ou Nao?:')
  1958. verifica_acesso
  1959. [[ "$_erro" == '1' ]] && break
  1960. [[ ${message_text[$id]} != ?(+|-)+([A-Za-z]) ]] && {
  1961. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1962. --text "$(echo -e "❌ Opcao Invalida ❌\n\n⚠️ Ultilize apenas letras [EX: sim ou nao]")" \
  1963. --parse_mode html
  1964. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1965. --text "<b>✅ CRIADO COM SUCESSO ✅</b>\n\nUSUARIO: <code>$(awk -F " " '/Nome/ {print $2}' $CAD_ARQ)</code>\nSENHA: <code>$(awk -F " " '/Senha/ {print $2}' $CAD_ARQ)</code>\nLIMITE: $(awk -F " " '/Limite/ {print $2}' $CAD_ARQ)\nEXPIRA EM: $(awk -F " " '/Validade/ {print $2}' $CAD_ARQ)" \
  1966. --parse_mode html
  1967. break
  1968. }
  1969. [[ "${message_text[$id]}" = @(Sim|sim|SIM) ]] && {
  1970. msg_cli="≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠\n"
  1971. msg_cli+="<b>ARQUIVOS PRE-CONFIGURADOS </b>❗\n"
  1972. msg_cli+="≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠\n\n"
  1973. for _file in $(ls /etc/bot/arquivos); do
  1974. i=$(($i + 1))
  1975. msg_cli+="<b>[$i]</b> - $_file\n"
  1976. done
  1977. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1978. --text "$(echo -e "$msg_cli")" \
  1979. --parse_mode html
  1980. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1981. --text 'Informe o Numero do Arquivo:' \
  1982. --reply_markup "$(ShellBot.ForceReply)"
  1983. } || {
  1984. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1985. --text "<b>✅ CRIADO COM SUCESSO ✅</b>\n\nUSUARIO: <code>$(awk -F " " '/Nome/ {print $2}' $CAD_ARQ)</code>\nSENHA: <code>$(awk -F " " '/Senha/ {print $2}' $CAD_ARQ)</code>\nLIMITE: $(awk -F " " '/Limite/ {print $2}' $CAD_ARQ)\nEXPIRA EM: $(awk -F " " '/Validade/ {print $2}' $CAD_ARQ)" \
  1986. --parse_mode html
  1987. }
  1988. ;;
  1989. 'Informe o Numero do Arquivo:')
  1990. verifica_acesso
  1991. [[ "$_erro" == '1' ]] && break
  1992. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  1993. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  1994. --text "$(echo -e "❌ Opcao Invalida ❌ \n\n⚠️ Ultilize apenas numeros [EX: 1]")" \
  1995. --parse_mode html
  1996. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  1997. --text "<b>✅ CRIADO COM SUCESSO ✅</b>\n\nUSUARIO: <code>$(awk -F " " '/Nome/ {print $2}' $CAD_ARQ)</code>\nSENHA: <code>$(awk -F " " '/Senha/ {print $2}' $CAD_ARQ)</code>\nLIMITE: $(awk -F " " '/Limite/ {print $2}' $CAD_ARQ)\nEXPIRA EM: $(awk -F " " '/Validade/ {print $2}' $CAD_ARQ)" \
  1998. --parse_mode html
  1999. >$CAD_ARQ
  2000. break
  2001. }
  2002. fun_download ${message_text[$id]} $CAD_ARQ
  2003. # Limpa o arquivo temporário.
  2004. >$CAD_ARQ
  2005. break
  2006. ;;
  2007. '🗑 REMOVER USUARIO 🗑\n\nNome do usuario:')
  2008. verifica_acesso
  2009. [[ "$_erro" == '1' ]] && break
  2010. fun_del_user ${message_text[$id]}
  2011. [[ "$_erro" == '1' ]] && break
  2012. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2013. --text "✅ *Removido com sucesso.* 🚮" \
  2014. --parse_mode markdown
  2015. ;;
  2016. '🔐 Alterar Senha 🔐\n\nNome do usuario:')
  2017. verifica_acesso
  2018. [[ "$_erro" == '1' ]] && break
  2019. fun_verif_user ${message_text[$id]}
  2020. echo "$_erro"
  2021. [[ "$_erro" == '1' ]] && break
  2022. echo "${message_text[$id]}" >/tmp/name-s
  2023. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2024. --text 'Nova senha:' \
  2025. --reply_markup "$(ShellBot.ForceReply)"
  2026. ;;
  2027. 'Nova senha:')
  2028. sizepass=$(echo -e ${#message_text[$id]})
  2029. verifica_acesso
  2030. [[ "$_erro" == '1' ]] && break
  2031. [[ "$sizepass" -lt '4' ]] && {
  2032. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2033. --text "$(echo -e "❌ Erro !\n\n⚠️ Use mínimo 4 caracteres [EX: 1234]")" \
  2034. --parse_mode html
  2035. break
  2036. }
  2037. alterar_senha_user $(cat /tmp/name-s) ${message_text[$id]}
  2038. [[ "$_erro" == '1' ]] && break
  2039. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2040. --text "$(echo -e "=×=×=×=×=×=×=×=×=×=×=×\n<b>✅ SENHA ALTERADA !</b> !\n=×=×=×=×=×=×=×=×=×=×=×\n\n<b>Usuario:</b> $(cat /tmp/name-s)\n<b>Nova senha:</b> ${message_text[$id]}")" \
  2041. --parse_mode html
  2042. rm /tmp/name-s >/dev/null 2>&1
  2043. ;;
  2044. '👥 Alterar Limite 👥\n\nNome do usuario:')
  2045. verifica_acesso
  2046. [[ "$_erro" == '1' ]] && break
  2047. echo $_erro segundo
  2048. fun_verif_user ${message_text[$id]}
  2049. echo "$_erro"
  2050. [[ "$_erro" == '1' ]] && break
  2051. echo "${message_text[$id]}" >/tmp/name-l
  2052. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2053. --text 'Novo limite:' \
  2054. --reply_markup "$(ShellBot.ForceReply)"
  2055. ;;
  2056. 'Novo limite:')
  2057. verifica_acesso
  2058. [[ "$_erro" == '1' ]] && break
  2059. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  2060. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2061. --text "$(echo -e "❌ Erro ! \n\n⚠️ Ultilize apenas numeros [EX: 1]")" \
  2062. --parse_mode html
  2063. break
  2064. }
  2065. alterar_limite_user $(cat /tmp/name-l) ${message_text[$id]}
  2066. [[ "$_erro" == '1' ]] && break
  2067. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2068. --text "$(echo -e "=×=×=×=×=×=×=×=×=×=×=×\n<b>✅ LIMITE ALTERADO !</b> !\n=×=×=×=×=×=×=×=×=×=×=×\n\n<b>Usuario:</b> $(cat /tmp/name-l)\n<b>Novo Limite:</b> ${message_text[$id]}")" \
  2069. --parse_mode html
  2070. rm /tmp/name-l >/dev/null 2>&1
  2071. ;;
  2072. '⏳ Alterar Data ⏳\n\nNome do usuario:')
  2073. verifica_acesso
  2074. [[ "$_erro" == '1' ]] && break
  2075. fun_verif_user ${message_text[$id]}
  2076. [[ "$_erro" == '1' ]] && break
  2077. echo "${message_text[$id]}" >/tmp/name-d
  2078. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2079. --text 'informe os dias ou data:' \
  2080. --reply_markup "$(ShellBot.ForceReply)"
  2081. ;;
  2082. 'informe os dias ou data:')
  2083. verifica_acesso
  2084. [[ "$_erro" == '1' ]] && break
  2085. [[ ${message_text[$id]} != ?(+|-)+([0-9/]) ]] && {
  2086. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2087. --text "$(echo -e "❌ Erro! Siga o exemplo\n\nDias formato [EX: 30]\nData formato [EX: 30/12/2019]")" \
  2088. --parse_mode html
  2089. break
  2090. }
  2091. alterar_data_user $(cat /tmp/name-d) ${message_text[$id]}
  2092. [[ "$_erro" == '1' ]] && break
  2093. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2094. --text "$(echo -e "=×=×=×=×=×=×=×=×=×=×=×\n<b>✅ DATA ALTERADA !</b> !\n=×=×=×=×=×=×=×=×=×=×=×\n\n<b>Usuario:</b> $(cat /tmp/name-d)\n<b>Nova Data:</b> $udata")" \
  2095. --parse_mode html
  2096. rm /tmp/name-d >/dev/null 2>&1
  2097. ;;
  2098. '[1] - ADICIONAR ARQUIVO\n[2] - EXCLUIR ARQUIVO\n\nInforme a opcao [1-2]:')
  2099. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  2100. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2101. --text "$(echo -e "❌ Erro ! \n\n⚠️ Ultilize apenas numeros [EX: 1 ou 2]")" \
  2102. --parse_mode html
  2103. break
  2104. }
  2105. if [[ "${message_text[$id]}" = '1' ]]; then
  2106. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2107. --text "📤 HOSPEDAR ARQUIVOS 📤\n\nEnvie-me o arquivo:" \
  2108. --reply_markup "$(ShellBot.ForceReply)"
  2109. elif [[ "${message_text[$id]}" = '2' ]]; then
  2110. [[ $(ls /etc/bot/arquivos | wc -l) != '0' ]] && {
  2111. msg_cli1="≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠\n"
  2112. msg_cli1+="🚀<b> ARQUIVOS HOSPEDADOS </b>\n"
  2113. msg_cli1+="≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠\n\n"
  2114. for _file in $(ls /etc/bot/arquivos); do
  2115. i=$(($i + 1))
  2116. msg_cli1+="<b>[$i]</b> - $_file\n"
  2117. done
  2118. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2119. --text "$(echo -e "$msg_cli1")" \
  2120. --parse_mode html
  2121. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2122. --text "🗑Excluir Arquivo\nInforme o Numero do Arquivo:" \
  2123. --reply_markup "$(ShellBot.ForceReply)"
  2124. } || {
  2125. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2126. --text "$(echo -e "Nao existe arquivos disponiveis")" \
  2127. --parse_mode html
  2128. break
  2129. }
  2130. else
  2131. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2132. --text "$(echo -e "❌ Opcao Invalida")" \
  2133. --parse_mode html
  2134. break
  2135. fi
  2136. ;;
  2137. '🗑Excluir Arquivo\nInforme o Numero do Arquivo:')
  2138. [[ "${message_from_id[$id]}" != "$id_admin" ]] && break
  2139. Opc1=${message_text[$id]}
  2140. echo $Opc1
  2141. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  2142. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2143. --text "$(echo -e "❌ Erro ao Excluir arquivo ! \n\n⚠️ Ultilize apenas numeros [EX: 1]")" \
  2144. --parse_mode html
  2145. break
  2146. } || {
  2147. echo "opcao $Opc1"
  2148. _DirArq=$(ls /etc/bot/arquivos)
  2149. i=0
  2150. unset _Pass
  2151. while read _Arq; do
  2152. i=$(expr $i + 1)
  2153. _oP=$i
  2154. [[ $i == [1-9] ]] && i=0$i && oP+=" 0$i"
  2155. echo -e "[$i] - $_Arq"
  2156. _Pass+="\n${_oP}:${_Arq}"
  2157. done <<<"${_DirArq}"
  2158. _file=$(echo -e "${_Pass}" | grep -E "\b$Opc1\b" | cut -d: -f2)
  2159. [[ -e /etc/bot/arquivos/$_file ]] && {
  2160. rm /etc/bot/arquivos/$_file
  2161. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2162. --text "✅ *Excluido com sucesso* ✅" \
  2163. --parse_mode markdown
  2164. break
  2165. } || {
  2166. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2167. --text "$(echo -e "❌ Opcao invalida")"
  2168. break
  2169. }
  2170. }
  2171. ;;
  2172. '📤 HOSPEDAR ARQUIVOS 📤\n\nEnvie-me o arquivo:')
  2173. if [ "${update_id[$id]}" ]; then
  2174. # Monitora o envio de arquivos
  2175. [[ ${message_document_file_id[$id]} ]] && file_id=${message_document_file_id[$id]} && download_file=1
  2176. # Verifica se o download está ativado.
  2177. [[ $download_file -eq 1 ]] && {
  2178. file_id=($file_id)
  2179. ShellBot.getFile --file_id "${file_id[0]}"
  2180. ShellBot.downloadFile --file_path ${return[file_path]} --dir "/tmp/file" && {
  2181. msg='*✅ Arquivo hospedado com sucesso.*\n\n'
  2182. msg+="*📤 Informações*\n\n"
  2183. msg+="*Nome*: ${message_document_file_name}\n"
  2184. msg+="*Salvo em*: /etc/bot/arquivos"
  2185. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2186. --text "$(echo -e "$msg")" \
  2187. --parse_mode markdown
  2188. mv /tmp/file/$(ls -1rt /tmp/file | tail -n1) /etc/bot/arquivos/${message_document_file_name}
  2189. break
  2190. }
  2191. } || {
  2192. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2193. --text "$(echo -e "❌ Erro ao receber arquivo ❌")" \
  2194. --parse_mode markdown
  2195. break
  2196. }
  2197. fi
  2198. ;;
  2199. 'Deseja restaurar ? [sim | nao]')
  2200. Resp=${message_text[$id]}
  2201. [[ ${message_from_id[$id]} != ${id_admin} ]] && break
  2202. [[ $Resp != ?(+|-)+([a-z]) ]] && {
  2203. ShellBot.sendMessage --chat_id ${id_admin} \
  2204. --text "$(echo -e "❌ Erro ! \n\n⚠️ Ultilize apenas sim ou nao")" \
  2205. --parse_mode html
  2206. break
  2207. }
  2208. [[ "$Resp" = @(Sim|sim|SIM) ]] && {
  2209. filebkp=$(ls /tmp | grep '.vps')
  2210. [[ -e /tmp/$filebkp ]] && {
  2211. mv /tmp/$filebkp /backup.vps
  2212. cd /
  2213. tar -xvf backup.vps
  2214. rm /backup.vps
  2215. ShellBot.sendMessage --chat_id ${id_admin} \
  2216. --text "$(echo -e "✅ Backup restaurado\ncom sucesso!")" \
  2217. --parse_mode html
  2218. break
  2219. }
  2220. }
  2221. break
  2222. ;;
  2223. # FUNCOES DE GESTAO REVENDA
  2224. #
  2225. # Adicionar, remover, limite, data, suspencao, relatorio
  2226. #
  2227. '👥 ADICIONAR REVENDEDOR 👥\n\nInforme o nome:')
  2228. verifica_acesso
  2229. [[ "$_erro" == '1' ]] && break
  2230. echo "Nome: ${message_text[$id]}" >$CAD_ARQ
  2231. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2232. --text 'Informe o user dele [Ex: @Nome Do Usuario]:' \
  2233. --reply_markup "$(ShellBot.ForceReply)"
  2234. ;;
  2235. 'Informe o user dele [Ex: @Nome Do Usuario]:')
  2236. verifica_acesso
  2237. [[ "$_erro" == '1' ]] && break
  2238. _VAR1=$(echo -e ${message_text[$id]} | awk -F '@' {'print $2'})
  2239. [[ -z $_VAR1 ]] && {
  2240. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2241. --text "$(echo -e "❌ Erro \n\n⚠️ Informe o user [EX: @Nome Do Usuario]")" \
  2242. --parse_mode html
  2243. break
  2244. }
  2245. [[ -d /etc/bot/revenda/$_VAR1 ]] && {
  2246. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2247. --text "$(echo -e "❌ O Revendedor ${message_text[$id]} ja existe")" \
  2248. --parse_mode html
  2249. break
  2250. }
  2251. echo "User: ${message_text[$id]}" >>$CAD_ARQ
  2252. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2253. --text 'Quantas SSH ele pode criar:' \
  2254. --reply_markup "$(ShellBot.ForceReply)"
  2255. ;;
  2256. 'Quantas SSH ele pode criar:')
  2257. verifica_acesso
  2258. [[ "$_erro" == '1' ]] && break
  2259. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  2260. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2261. --text "$(echo -e "❌ Erro ! \n\n⚠️ Ultilize apenas numeros [EX: 10]")" \
  2262. --parse_mode html
  2263. break
  2264. }
  2265. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  2266. _limTotal=$(grep -w "${message_from_username}" $ativos | awk '{print $4}')
  2267. fun_verif_limite_rev ${message_from_username}
  2268. _limsomarev=$(echo "$_result + ${message_text[$id]}" | bc)
  2269. [[ "$_limsomarev" -gt "$_limTotal" ]] && {
  2270. _restant1=$(($_limTotal - $_result))
  2271. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2272. --text "$(echo -e "❌ Vc nao tem limite suficiente\n\nLimite disponivel: $_restant1 ")" \
  2273. --parse_mode html
  2274. break
  2275. }
  2276. }
  2277. echo "Limite: ${message_text[$id]}" >>$CAD_ARQ
  2278. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2279. --text 'Quantos dias de acesso:' \
  2280. --reply_markup "$(ShellBot.ForceReply)"
  2281. ;;
  2282. 'Quantos dias de acesso:')
  2283. verifica_acesso
  2284. [[ "$_erro" == '1' ]] && break
  2285. echo "Validade: ${message_text[$id]}" >>$CAD_ARQ
  2286. _clientrev=$(cat $CAD_ARQ)
  2287. criar_rev $CAD_ARQ
  2288. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2289. --text "✅ CRIADO COM SUCESSO. ✅\n\n$(<$CAD_ARQ)\n\nBOT: @${message_reply_to_message_from_username}" \
  2290. --parse_mode html
  2291. ;;
  2292. # REMOVE REVENDEDOR
  2293. '🗑 REMOVER REVENDEDOR 🗑\n\nInforme o user dele [Ex: @Nome Do Usuario]:')
  2294. echo -e "${message_text[$id]}" >$CAD_ARQ
  2295. _Var=$(sed -n '1 p' $CAD_ARQ | awk -F '@' {'print $2'})
  2296. [[ -z $_Var ]] && {
  2297. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2298. --text "$(echo -e "❌ User invalido")" \
  2299. --parse_mode html
  2300. break
  2301. }
  2302. del_rev $_Var
  2303. break
  2304. ;;
  2305. # ALTERAR LIMITE
  2306. '♾ ALTERAR LIMITE REVENDA ♾\n\nInforme o user dele [Ex: @Nome Do Usuario]:')
  2307. verifica_acesso
  2308. [[ "$_erro" == '1' ]] && break
  2309. echo -e "Revendedor: ${message_text[$id]}" >$CAD_ARQ
  2310. _Var1=$(sed -n '1 p' $CAD_ARQ | awk -F '@' {'print $2'})
  2311. [[ -z $_Var1 ]] && {
  2312. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2313. --text "$(echo -e "❌ Nome invalido !")" \
  2314. --parse_mode html
  2315. break
  2316. }
  2317. [[ "${message_from_id[$id]}" == "$id_admin" ]] && {
  2318. [[ $(grep -wc $_Var1 $ativos) != '0' ]] && {
  2319. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2320. --text 'Informe o Limite SSH:' \
  2321. --reply_markup "$(ShellBot.ForceReply)"
  2322. } || {
  2323. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2324. --text "$(echo -e "❌ Revendedor ${message_text[$id]} nao existe")" \
  2325. --parse_mode html
  2326. break
  2327. }
  2328. }
  2329. [[ $(grep -w ${message_from_username} $ativos | awk '{print $NF}') == 'revenda' ]] && {
  2330. [[ "$(grep -wc "$_Var1" /etc/bot/revenda/${message_from_username}/${message_from_username})" != '0' ]] && {
  2331. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2332. --text 'Informe o Limite SSH:' \
  2333. --reply_markup "$(ShellBot.ForceReply)"
  2334. } || {
  2335. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2336. --text "$(echo -e "❌ O Sub-revendedor nao existe")" \
  2337. --parse_mode html
  2338. break
  2339. }
  2340. }
  2341. ;;
  2342. 'Informe o Limite SSH:')
  2343. verifica_acesso
  2344. [[ "$_erro" == '1' ]] && break
  2345. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  2346. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2347. --text "$(echo -e "❌ Erro ! \n\nUltilize apenas numeros [EX: 1]")" \
  2348. --parse_mode html
  2349. break
  2350. }
  2351. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  2352. _limTotal=$(grep -w "${message_from_username}" $ativos | awk '{print $4}')
  2353. fun_verif_limite_rev ${message_from_username}
  2354. _limsomarev=$(echo "$_result + ${message_text[$id]}" | bc)
  2355. [[ $(grep -wc 'SUBREVENDA' /etc/bot/revenda/${message_from_username}/${message_from_username}) != '0' ]] && {
  2356. _limsomarev2=$(echo "$(grep -w 'SUBREVENDA' /etc/bot/revenda/${message_from_username}/${message_from_username} | awk {'print $4'} | paste -s -d + | bc)" + "${message_text[$id]}" | bc)
  2357. } || {
  2358. _limsomarev2='0'
  2359. }
  2360. [[ "$_limsomarev2" -ge "$_limTotal" ]] && {
  2361. echo $_limsomarev2
  2362. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2363. --text "$(echo -e "❌ Vc nao tem limite suficiente")" \
  2364. --parse_mode html
  2365. break
  2366. }
  2367. [[ "$_limsomarev" -gt "$_limTotal" ]] && {
  2368. [[ "$_limTotal" == "$(($_limTotal - $_result))" ]] && _restant1='0' || _restant1=$(($_limTotal - $_result))
  2369. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2370. --text "$(echo -e "❌ Vc nao tem limite suficiente\n\nLimite restante: $_restant1 ")" \
  2371. --parse_mode html
  2372. break
  2373. }
  2374. }
  2375. echo -e "Limite: ${message_text[$id]}" >>$CAD_ARQ
  2376. lim_rev $CAD_ARQ
  2377. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2378. --text "$(echo -e "=×=×=×=×=×=×=×=×=×=×=×\n<b>✅ LIMITE REVENDA ALTERADO !</b> !\n=×=×=×=×=×=×=×=×=×=×=×\n\n$(<$CAD_ARQ)")" \
  2379. --parse_mode html
  2380. # ALTERAR DATA
  2381. ;;
  2382. '📆 ALTERAR DATA REVENDA 📆\n\nInforme o user dele [Ex: @Nome Do Usuario]:')
  2383. verifica_acesso
  2384. [[ "$_erro" == '1' ]] && break
  2385. _VAR1=$(echo -e ${message_text[$id]} | awk -F '@' {'print $2'})
  2386. [[ -z $_VAR1 ]] && {
  2387. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2388. --text "$(echo -e "Revendedor ${message_text[$id]} nao existe")" \
  2389. --parse_mode html
  2390. break
  2391. }
  2392. [[ "${message_from_id[$id]}" == "$id_admin" ]] && {
  2393. [[ $(grep -wc $_VAR1 $ativos) != '0' ]] && {
  2394. echo -e "Revendedor: ${message_text[$id]}" >$CAD_ARQ
  2395. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2396. --text 'Dias de acesso [Ex: 30]:' \
  2397. --reply_markup "$(ShellBot.ForceReply)"
  2398. } || {
  2399. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2400. --text "$(echo -e "❌ O Revendedor ${message_text[$id]} nao existe")" \
  2401. --parse_mode html
  2402. break
  2403. }
  2404. } || {
  2405. [[ $(grep -w ${message_from_username} $ativos | awk '{print $NF}') == 'revenda' ]] && {
  2406. [[ "$(grep -wc "$_VAR1" /etc/bot/revenda/${message_from_username}/${message_from_username})" != '0' ]] && {
  2407. echo -e "Revendedor: ${message_text[$id]}" >$CAD_ARQ
  2408. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2409. --text 'Dias de acesso [Ex: 30]:' \
  2410. --reply_markup "$(ShellBot.ForceReply)"
  2411. } || {
  2412. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2413. --text "$(echo -e "❌ O SubRevendedor ${message_text[$id]} nao existe")" \
  2414. --parse_mode html
  2415. break
  2416. }
  2417. }
  2418. }
  2419. ;;
  2420. 'Dias de acesso [Ex: 30]:')
  2421. verifica_acesso
  2422. [[ "$_erro" == '1' ]] && break
  2423. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  2424. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2425. --text "$(echo -e "❌ Erro ! \n\nUltilize apenas numeros [EX: 30]")" \
  2426. --parse_mode html
  2427. break
  2428. }
  2429. echo -e "Data: ${message_text[$id]}" >>$CAD_ARQ
  2430. dat_rev $CAD_ARQ
  2431. [[ "$_erro" == '1' ]] && break
  2432. ShellBot.sendMessage --chat_id ${message_from_id[$id]} \
  2433. --text "$(echo -e "=×=×=×=×=×=×=×=×=×=×=×\n<b>✅ DATA REVENDA ALTERADA !</b> !\n=×=×=×=×=×=×=×=×=×=×=×\n\n$(<$CAD_ARQ)")" \
  2434. --parse_mode html
  2435. ;;
  2436. # SUSPENDER REVENDEDOR
  2437. '🔒 SUSPENDER REVENDEDOR 🔒\n\nInforme o user dele [Ex: @Nome Do Usuario]:')
  2438. _VAR1=$(echo -e ${message_text[$id]} | awk -F '@' {'print $2'})
  2439. [[ -z $_VAR1 ]] && {
  2440. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2441. --text "$(echo -e "❌ Revendedor ${message_text[$id]} nao existe")" \
  2442. --parse_mode html
  2443. break
  2444. }
  2445. susp_rev $_VAR1
  2446. break
  2447. ;;
  2448. '👤 CRIAR TESTE 👤\n\nQuantas horas deve durar EX: 1:')
  2449. verifica_acesso
  2450. echo $_erro
  2451. [[ "$_erro" == '1' ]] && break
  2452. [[ ${message_text[$id]} != ?(+|-)+([0-9]) ]] && {
  2453. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2454. --text "$(echo -e "❌ Erro ! \n\nUltilize apenas numeros [EX: 1]")" \
  2455. --parse_mode html
  2456. >$CAD_ARQ
  2457. break
  2458. }
  2459. [[ "${message_from_id[$id]}" != "$id_admin" ]] && {
  2460. _limTotal=$(grep -w "${message_from_username}" $ativos | awk '{print $4}')
  2461. fun_verif_limite_rev ${message_from_username}
  2462. _limsomarev2=$(echo "$_result + 1" | bc)
  2463. [[ "$_limsomarev2" -gt "$_limTotal" ]] && {
  2464. ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
  2465. --text "$(echo -e "❌ Vc nao tem limite suficiente")" \
  2466. --parse_mode html
  2467. >$CAD_ARQ
  2468. break
  2469. }
  2470. }
  2471. fun_teste ${message_text[$id]}
  2472. ;;
  2473. esac
  2474. fi
  2475. ) &
  2476. done
  2477. done
  2478. #FIM