doubleTroub1e / nodepayai

GNU General Public License v3.0
3 stars 2 forks source link

Docker Hub Tag Name? #2

Closed Kellphy closed 4 months ago

Kellphy commented 4 months ago

Hi, just wondering why is there an image on Docker Hub tagged with my name :D We could contribute to a single open source project if you want to. Idk where else to ask this, ty! image

doubleTroub1e commented 4 months ago

Hi @Kellphy , was checking if your code is working after nodepay updates) I'm running on raspberry pi 3 and 4 so was needed a different platform to test on, thus built and push with my arch))) will remove soon))

Kellphy commented 4 months ago

Saw your arch, and built it as well for arm/v7. Sure, if you want to collab, hit me up, cheers

doubleTroub1e commented 4 months ago

well, I'm not good at programming, only bash)) but I can't make it work In headless chrome(nodeplay login) also, guess there is a change to create a virtual display and login not in headless, but it is expecting some human interaction, my attempts to do this with chat GPT failed.

Kellphy commented 4 months ago

The problem that I had was that width lower than 1024px would make the page say that "it does not work on mobile", instead of letting it login. To debug, I usually output the page source and read it so that I know what I am missing.. Ex. page did not load yet, resolution too low to view the elements, etc. Or output a screenshot, but feels pointless for just a couple of instructions.

doubleTroub1e commented 4 months ago

yeap, also saw it - but this was solved for me, issue now it is doesn't allow me to login because it knows that I'm not a real human, if I use not a headless mode - then it is working fine, in headless - failing, even undetected headless also failing

Kellphy commented 4 months ago

Ah ... I don't know then ... hopefully it was just you spamming login for a day that triggered it for 24hrs ...

doubleTroub1e commented 4 months ago

guess no, becasue I was able to login via browser does your version is working now?

Kellphy commented 4 months ago

Already deployed version, still working: 2024-06-01T12:11:39.754232288Z 2024-06-01 12:11:39,753 - INFO - Status: Connected!

Started now a new one, working: image

Try it out with your credentials https://github.com/Kellphy/Nodepay

doubleTroub1e commented 4 months ago

nice! you're right! seems they ban my IP, but this is good to have dynamic IP)) now mine and yours are working fine for me! btw, did you also farm Grass? And have yu think about farming both (grass and nodepay) in. single docker container?

Kellphy commented 4 months ago

You can run both in the same container, I would not. I would keep them separate, so each update restarts only one of them. Microservices instead of Monolith architecture. I do farm Grass too, yes.

Solana0x commented 4 months ago

Why dont you guys RUn via CLI python script why to waste so much resoruces on the Docker?

Kellphy commented 4 months ago

Because I'm running it on a raspberry pi, and a linux laptop, and on windows pc. Along with other 26 other apps.

Solana0x commented 4 months ago

But a Python Normal CLI code will be less resource consuming then a Full docker image ! ?

doubleTroub1e commented 4 months ago

I do also use it on some linux machine, sone raspberry pi3 and pi4 so I prefer using docker. Also, I do have other containers already up and running and each app requires some different python versions. and of course, it is very easy to do a rollback/update with docker image on all devices

Solana0x commented 4 months ago

Can you share the python code? i am having some errors in mine - received 1011 (internal error); then sent 1011 (internal error)

please help me out thanks

image image image

doubleTroub1e commented 4 months ago

my code is published in this repo, check src/main.py file

Solana0x commented 4 months ago

but you are using selenium for automation my code is working without selenium direct interaction with the code

doubleTroub1e commented 4 months ago

 yeap, I have no need in trying to implement it, but maybe try with Claude AI/chatGPT, it would be interesting to compare system load for both approaches

Solana0x commented 4 months ago

i have implemented the code but just having this error received 1011 (internal error); then sent 1011 (internal error)

can you help debug?

doubleTroub1e commented 4 months ago

I can give it a try, share your repo

Solana0x commented 4 months ago

https://github.com/Solana0x/getgrass

this was grasss repo to convert it into nodepay we can use nodepay socket and get th node pay User ID

image

doubleTroub1e commented 4 months ago

try this


import asyncio
import random
import ssl
import json
import time
import uuid
from loguru import logger
from websockets_proxy import Proxy, proxy_connect

async def connect_to_wss(socks5_proxy, user_id, token):
    device_id = str(uuid.uuid4())
    logger.info(device_id)
    while True:
        try:
            await asyncio.sleep(random.randint(1, 10) / 10)
            custom_headers = {
                "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
            }
            ssl_context = ssl.create_default_context()
            ssl_context.check_hostname = False
            ssl_context.verify_mode = ssl.CERT_NONE
            uri = "wss://nw.nodepay.ai:4576/websocket"
            proxy = Proxy.from_url(socks5_proxy)
            async with proxy_connect(uri, proxy=proxy, ssl=ssl_context,
                                     extra_headers=custom_headers) as websocket:
                async def send_ping():
                    while True:
                        send_message = json.dumps(
                            {"id": str(uuid.uuid4()), "version": "2.1.0", "action": "PING", "data": {}})
                        logger.debug(send_message)
                        await websocket.send(send_message)
                        await asyncio.sleep(20)
                send_ping_task = asyncio.create_task(send_ping())
                while True:
                    response = await websocket.recv()
                    message = json.loads(response)
                    logger.info(message)
                    if message.get("action") == "AUTH":
                        auth_response = {
                            "id": message["id"],
                            "origin_action": "AUTH",
                            "browser_id": device_id,
                            "user_id": user_id,
                            "user_agent": custom_headers['User-Agent'],
                            "timestamp": int(time.time()),
                            "device_type": "extension",
                            "version": "2.1.0",
                            "token": token,
                        }
                        logger.debug(auth_response)
                        await websocket.send(json.dumps(auth_response))

                    elif message.get("action") == "PONG":
                        pong_response = {"id": message["id"], "origin_action": "PONG"}
                        logger.debug(pong_response)
                        await websocket.send(json.dumps(pong_response))
        except Exception as e:
            logger.error(f"Error with proxy {socks5_proxy}: {str(e)}")
            if "[SSL: WRONG_VERSION_NUMBER]" in str(e) or "invalid length of packed IP address string" in str(e):
                logger.info(f"Removing error proxy from the list: {socks5_proxy}")
                remove_proxy_from_list(socks5_proxy)
                return None  # Return None to signal to the main loop to replace this proxy
            elif "" in str(e):
                logger.info(f"Removing error proxy from the list: {socks5_proxy}")
                remove_proxy_from_list(socks5_proxy)
                return None  # Return None to signal to the main loop to replace this 
            elif "Empty connect reply" in str(e) or "Device creation limit exceeded" in str(e):
                logger.info(f"Removing error proxy from the list: {socks5_proxy}")
                remove_proxy_from_list(socks5_proxy)
                return None  # Return None to signal to the main loop to replace this proxy
            elif "sent 1011 (internal error) keepalive ping timeout; no close frame received" in str(e):
                logger.info(f"Removing error proxy due to keepalive ping timeout: {socks5_proxy}")
                remove_proxy_from_list(socks5_proxy)
                return None  # Return None to signal to the main loop to replace this proxy
            else:
                continue  # Continue to try to reconnect or handle other errors
async def main():
    _user_id = '12439....'   # Replace Your User ID HERE 
    proxy_file = '/path/proxy' # your Path to Proxy3.txt file 
    token = 'eyJhbGciOiJIUzUxMiJ9.eyJzdW....'  # Replace with actual BAERER token

    # formate => socks5://username:pass@ip:port
    with open(proxy_file, 'r') as file:
        all_proxies = file.read().splitlines()

    active_proxies = random.sample(all_proxies, 7) # write the number of proxy you wana use
    tasks = {asyncio.create_task(connect_to_wss(proxy, _user_id, token)): proxy for proxy in active_proxies}

    while True:
        done, pending = await asyncio.wait(tasks.keys(), return_when=asyncio.FIRST_COMPLETED)
        for task in done:
            if task.result() is None:
                failed_proxy = tasks[task]
                logger.info(f"Removing and replacing failed proxy: {failed_proxy}")
                active_proxies.remove(failed_proxy)
                new_proxy = random.choice(all_proxies)
                active_proxies.append(new_proxy)
                new_task = asyncio.create_task(connect_to_wss(new_proxy, _user_id, token))
                tasks[new_task] = new_proxy  # Replace the task in the dictionary
            tasks.pop(task)  # Remove the completed task whether it succeeded or failed
        # Replenish the tasks if any have completed
        for proxy in set(active_proxies) - set(tasks.values()):
            new_task = asyncio.create_task(connect_to_wss(proxy, _user_id, token))
            tasks[new_task] = proxy

def remove_proxy_from_list(proxy):
    with open("/path/proxy", "r+") as file:
        lines = file.readlines()
        file.seek(0)
        for line in lines:
            if line.strip() != proxy:
                file.write(line)
        file.truncate()

if __name__ == '__main__':
    asyncio.run(main())
doubleTroub1e commented 4 months ago

and this is my version with which I was testing

import asyncio
import websockets
import json
import uuid
import time

WEBSOCKET_URL = "wss://nw.nodepay.ai:4576/websocket"
PING_INTERVAL = 30  # seconds

# np_token extracted from the .har file
np_token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMjQzOTI4MjQ4OTIwODMwtB_"

# Manually defined details
user_id = "124"  # Replace with actual user_id
browser_id = str(uuid.uuid4())  
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
version = "2.1.0"  # Replace with actual version

async def send_ping(ws, guid, options={}):
    while True:
        try:
            payload = {
                'id': guid,
                'action': 'PING',
                **options
            }
            await ws.send(json.dumps(payload))
            print("Sent PING:", payload)
            await asyncio.sleep(PING_INTERVAL)
        except websockets.ConnectionClosedError as e:
            print("Connection closed error while sending ping:", e)
            break
        except Exception as e:
            print("Error while sending ping:", e)
            break

async def send_pong(ws, guid):
    payload = {
        'id': guid,
        'origin_action': 'PONG',
    }
    await ws.send(json.dumps(payload))
    print("Sent PONG:", payload)

async def on_message(ws, message):
    data = json.loads(message)
    print("Received message:", data)
    if data.get('action') == 'PONG':
        await send_pong(ws, data['id'])
        await send_ping(ws, data['id'])
    elif data.get('action') == 'AUTH':
        print("AUTH action received")
        data_info = {
            'id': data['id'],
            'action': 'PING',
            'token': np_token,
            'user_id': user_id,
            'browser_id': browser_id,
            'user_agent': user_agent,
            'timestamp': int(time.time()),
            'device_type': "extension",
            'version': version,
            'origin_action': "AUTH",
        }
        await ws.send(json.dumps(data_info))

async def connect_to_wss():
    while True:
        try:
            async with websockets.connect(WEBSOCKET_URL) as ws:
                print("WebSocket connection opened")
                initial_message = {
                    "id": str(uuid.uuid4()),  # Generate a new UUID for initial ID
                    "action": "AUTH",
                    "token": np_token,
                }
                await ws.send(json.dumps(initial_message))
                async for message in ws:
                    await on_message(ws, message)
        except websockets.ConnectionClosedError as e:
            print("Connection closed error:", e)
        except Exception as e:
            print("Unexpected error:", e)
        finally:
            print("Reconnecting in 5 seconds...")
            await asyncio.sleep(5)

if __name__ == "__main__":
    asyncio.run(connect_to_wss())
doubleTroub1e commented 4 months ago

just received "Connection closed error: sent 1011 (internal error) keepalive ping timeout; no close frame received" seems it is getting once website has no activity. maybe dev team will fix it soon with new update, if not, script changes are needed to login to site and refresh tab once a 5-10mins for token to not expire

Kellphy commented 4 months ago

I will unsubscribe from this issue since it became something outside my scope, take care and cya!

Solana0x commented 4 months ago

@doubleTroub1e i am also getting same error sent 1011 (internal error) keepalive ping timeout; idk why can you try figure it out may be we are using wrong Socket method to connect or something that or may be wrong AUTH methods