Skip to content

Commit

Permalink
Added environment variable input as first option (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
heindrichpaul authored and simao-silva committed Oct 9, 2023
1 parent f84403c commit 2675381
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,5 @@ deprecated/
.idea
debug
test.sh
.vscode/settings.json
.scannerwork
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ or
```shell script
docker run --rm -it simaofsilva/noip-renewer:<TAG> <EMAIL> <PASSWORD>
```
or
```shell script
docker run --rm --env NO_IP_USERNAME=<EMAIL> --env NO_IP_PASSWORD=<PASSWORD> simaofsilva/noip-renewer:<TAG>
```

## Known issues / limitations
* The script assumes that the No-IP account language is set to english. For other languages it depends on the translation provided by [googletrans](https://pypi.org/project/googletrans/) so it might not work in other languages ([#11](https://github.com/simao-silva/noip-renewer/issues/11));
Expand Down
42 changes: 33 additions & 9 deletions renew.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import random
from getpass import getpass
from sys import argv
Expand Down Expand Up @@ -40,18 +41,40 @@ def exit_with_error(message):
exit(1)


def get_credentials():
"""
Retrieves the credentials required for authentication.
Returns:
- email (str): The email address associated with the credentials.
- password (str): The password associated with the credentials.
Notes:
- The function first checks if the email and password are already set as environment variables.
- If the email or password is not set, it checks if the command line arguments were passed.
- If the email or password is still not set, it prompts the user to enter the values interactively.
"""

email = os.getenv("NO_IP_USERNAME", "")
password = os.getenv("NO_IP_PASSWORD", "")

if len(email) == 0 or len(password) == 0:
if len(argv) == 3:
email = argv[1]
password = argv[2]
else:
email = str(input("Email: ")).replace("\n", "")
password = getpass("Password: ").replace("\n", "")

return email, password


if __name__ == "__main__":
LOGIN_URL = "https://www.noip.com/login?ref_url=console"
HOST_URL = "https://my.noip.com/dynamic-dns"
LOGOUT_URL = "https://my.noip.com/logout"

# ASK CREDENTIALS
if len(argv) == 3:
email = argv[1]
password = argv[2]
else:
email = str(input("Email: ")).replace("\n", "")
password = getpass("Password: ").replace("\n", "")
email, password = get_credentials()

# OPEN BROWSER
print("Opening browser")
Expand Down Expand Up @@ -108,16 +131,17 @@ def exit_with_error(message):
confirmed_hosts = 0

for host in hosts:
current_host = host.find_element(by=By.TAG_NAME, value="a").text
print("Checking if host [\"" + current_host + "\"] needs confirmation")
try:
button = host.find_element(by=By.TAG_NAME, value="button")
except NoSuchElementException as e:
break

if button.text == "Confirm" or translate(button.text) == "Confirm":
button.click()
confirmed_host = host.find_element(by=By.TAG_NAME, value="a").text
confirmed_hosts += 1
print("Host \"" + confirmed_host + "\" confirmed")
print("Host [\"" + current_host + "\"] confirmed")
sleep(0.25)

if confirmed_hosts == 1:
Expand Down

0 comments on commit 2675381

Please sign in to comment.