Ankermgmt / ankermake-m5-protocol

Ankermake M5 protocol specifications and libraries *NOT AFFILIATED WITH ANKER*
GNU General Public License v3.0
161 stars 34 forks source link

Add support for fetching configuration via login #148

Closed treitmayr closed 2 weeks ago

treitmayr commented 8 months ago

Implemented new command 'config login' to fetch the complete configuration from the server instead of relying on the configuration file created by the AnkerMake Slicer.

Features:

Open:

Help output:

$ ./ankerctl.py config login -h
Usage: ankerctl.py config login [OPTIONS] [REGION (EU/US)] [EMAIL] [PASSWORD]

  Fetch configuration by logging in with provided credentials.

Options:
  -h, --help  Show this message and exit.

Usage example:

$ ./ankerctl.py config login
Please enter your email address: my@email.com
Please enter your password: xxxxx
Please enter your region (EU/US), empty to guess:
[*] Initializing API..
[*] Using region 'EU'
[*] Logging in..
[*] Initializing API..
[*] Requesting profile data..
[*] Requesting printer list..
[*] Requesting pppp keys..
[*] Adding printer [AK75D72D24300601]
[*] Finished import
treitmayr commented 8 months ago

Unfortunately I just realized, that the IP address in the created printer config is set to an empty string. I will have to check whether it is just not part of the replies from AnkerMake's server, or there is a different issue.

treitmayr commented 8 months ago

Added a commit which preserves the printer IP addresses from a valid previous ankerctl configuration if the server replied with empty IP addresses (which it always does for me). So now, you can do ankerctl.py config login without loosing these IP addresses.

treitmayr commented 8 months ago

The third commit adds a web interface for logging in to AnkerMake's server and fetch the configuration from there. As captchas seem to be requested quite frequently, those are also supported. This should make it unnecessary to import the slicer login.json file.

Note that it is my first time working with Flask and Bootstrap, and I have tried my best (in the available amount of time) to conform to the existing code style and concepts. For the captcha functionality I had to implement Javascript HTTP requests instead of reloading the page, so this is a newly introduced concept in the ankerctl code. According to my tests it works pretty well for both initial configuration and re-configuring.

Bildschirmfoto vom 2024-02-04 03-12-03-1