diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 83c50df..8ba407a 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1,5 @@ # Bu araç @keyiflerolsun tarafından | @KekikAkademi için yazılmıştır. -github: keyiflerolsun -custom: ['https://keyiflerolsun.me/Kahve'] \ No newline at end of file +github : keyiflerolsun +buy_me_a_coffee : keyiflerolsun +custom : ["https://keyiflerolsun.me/Kahve"] \ No newline at end of file diff --git a/.github/workflows/pypiYukle.yml b/.github/workflows/pypiYukle.yml index 2934702..99d2941 100644 --- a/.github/workflows/pypiYukle.yml +++ b/.github/workflows/pypiYukle.yml @@ -2,7 +2,12 @@ name: KekikAkademi PyPI Yükleyici +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} + cancel-in-progress: true + on: + workflow_dispatch: push: branches: - "main" @@ -13,27 +18,30 @@ jobs: strategy: matrix: - python-version: ["3.10.8"] + python-version: ["3.11.8"] steps: - - name: Depo Kontrolü - uses: actions/checkout@v2 + - name : Depo Kontrolü + uses : actions/checkout@v4 - - name: Python ${{ matrix.python-version }} Sürümü Yükleniyor - uses: actions/setup-python@v2 - with: + - name : Python ${{ matrix.python-version }} Sürümü Yükleniyor + uses : actions/setup-python@v5 + with : python-version: ${{ matrix.python-version }} - - name: Python Sürümünü Göster - run: python -c "import sys; print(sys.version)" + - name : Python Sürümünü Göster + run : python -c "import sys; print(sys.version)" + + - name : Gereksinimleri Yükle + run : | + python -m pip install --upgrade pip + pip install -U setuptools wheel twine - - name: Kütüphaneyi PyPI'ye Yükle - env: + - name : Kütüphaneyi PyPI'ye Yükle + env : TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine + run : | python setup.py bdist_wheel sdist twine check dist/* python -m twine upload dist/* diff --git a/KeeneticPy/__init__.py b/KeeneticPy/__init__.py index 95e6be4..56640ed 100644 --- a/KeeneticPy/__init__.py +++ b/KeeneticPy/__init__.py @@ -149,4 +149,74 @@ def backup(self, maksimum_yedek=5) -> str: konsol.log(f"[green][+] {zip_dosyasi} başarıyla oluşturuldu!") - return zip_dosyasi \ No newline at end of file + return zip_dosyasi + + def get_static_routes(self) -> list[dict[str, str]]: + return self.__oturum.get( + url = f"{self.__rci}", + json = {"show":{"ip":{"route":{}}}} + ).json().get("ip", {}).get("route", []) + + def add_static_route(self, comment:str, host:str=None, network:str=None, mask:str=None, interface:str="Wireguard2") -> bool: + payload = None + + if host: + payload = { + "comment" : comment, + "interface" : interface, + "host" : host + } + + if network and mask: + payload = { + "comment" : comment, + "interface" : interface, + "network" : network, + "mask" : mask + } + + if not payload: + assert False, "Lütfen host ya da network ve mask bilgisini girin." + + istek = self.__oturum.post( + url = f"{self.__rci}", + json = [ + {"ip":{"route":payload}}, + {"system":{"configuration":{"save":{}}}} + ] + ) + + return istek.status_code == 200 + + def del_static_route(self, comment:str, host:str=None, network:str=None, mask:str=None, interface:str="Wireguard2") -> bool: + payload = None + + if host: + payload = { + "comment" : comment, + "interface" : interface, + "host" : host + } + + if network and mask: + payload = { + "comment" : comment, + "interface" : interface, + "network" : network, + "mask" : mask + } + + if not payload: + assert False, "Lütfen host ya da network ve mask bilgisini girin." + + payload["no"] = True + print(payload) + istek = self.__oturum.post( + url = f"{self.__rci}", + json = [ + {"ip":{"route":payload}}, + {"system":{"configuration":{"save":{}}}} + ] + ) + + return istek.status_code == 200 \ No newline at end of file diff --git a/README.md b/README.md index a6db085..4f95e99 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,25 @@ # KeeneticPy -![Repo Boyutu](https://img.shields.io/github/repo-size/keyiflerolsun/KeeneticPy?logo=git&logoColor=white) -![Görüntülenme](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https://github.com/keyiflerolsun/KeeneticPy&title=Görüntülenme) +[![Boyut](https://img.shields.io/github/repo-size/keyiflerolsun/KeeneticPy?logo=git&logoColor=white&label=Boyut)](#) +[![Görüntülenme](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https://github.com/keyiflerolsun/KeeneticPy&title=Görüntülenme)](#) -![Python Version](https://img.shields.io/pypi/pyversions/KeeneticPy?logo=python&logoColor=white) -![License](https://img.shields.io/pypi/l/KeeneticPy?logo=gnu&logoColor=white) -![Status](https://img.shields.io/pypi/status/KeeneticPy?logo=windowsterminal&logoColor=white) +[![PyPI](https://img.shields.io/pypi/v/KeeneticPy?logo=pypi&logoColor=white&label=PyPI)](https://pypi.org/project/KeeneticPy) +[![PyPI - Yüklenme](https://img.shields.io/pypi/dm/KeeneticPy?logo=pypi&logoColor=white&label=Yüklenme)](https://pypi.org/project/KeeneticPy) +[![PyPI - Wheel](https://img.shields.io/pypi/wheel/KeeneticPy?logo=pypi&logoColor=white&label=Wheel)](https://pypi.org/project/KeeneticPy) -![PyPI](https://img.shields.io/pypi/v/KeeneticPy?logo=pypi&logoColor=white) -![PyPI - Downloads](https://img.shields.io/pypi/dm/KeeneticPy?logo=pypi&logoColor=white) -![PyPI - Wheel](https://img.shields.io/pypi/wheel/KeeneticPy?logo=pypi&logoColor=white) +[![Python Version](https://img.shields.io/pypi/pyversions/KeeneticPy?logo=python&logoColor=white&label=Python)](#) +[![Lisans](https://img.shields.io/pypi/l/KeeneticPy?logo=gnu&logoColor=white&label=Lisans)](#) +[![Durum](https://img.shields.io/pypi/status/KeeneticPy?logo=windowsterminal&logoColor=white&label=Durum)](#) + +[![PyPI Yükle](https://github.com/keyiflerolsun/KeeneticPy/actions/workflows/pypiYukle.yml/badge.svg)](https://github.com/keyiflerolsun/KeeneticPy/actions/workflows/pypiYukle.yml) **Python Lib for Keenetic Routers** > _`RCI` / `PROC`_ -[![ForTheBadge made-with-python](http://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/) -[![ForTheBadge built-with-love](http://ForTheBadge.com/images/badges/built-with-love.svg)](https://GitHub.com/keyiflerolsun/) +[![ForTheBadge made-with-python](https://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/) +[![ForTheBadge built-with-love](https://ForTheBadge.com/images/badges/built-with-love.svg)](https://GitHub.com/keyiflerolsun/) ## 🚀 Kurulum @@ -35,23 +37,39 @@ pip install -U KeeneticPy from Kekik.cli import konsol from KeeneticPy import Keenetic -hero = Keenetic(sifre="cokomellisifre") +modem = Keenetic(sifre="cokomellisifre") + +modem.backup(maksimum_yedek=2) + +konsol.print(modem.system()) +konsol.print(modem.version()) + +konsol.print(modem.interface()["Dsl0"]) +konsol.print(modem.interface()["PPPoE0"]) + +konsol.print(modem.global_ip()) + +konsol.print("\n".join(modem.dsl_stats()["parse"]["message"])) + +konsol.print(modem.hosts()) -hero.backup(maksimum_yedek=2) +konsol.print(modem.dsl_reset()) -konsol.print(hero.system()) -konsol.print(hero.version()) +konsol.print(modem.get_static_routes()) -konsol.print(hero.interface()["Dsl0"]) -konsol.print(hero.interface()["PPPoE0"]) +konsol.print(modem.add_static_route(comment="bakalim.io", host="145.53.10.71", interface="Wireguard2")) -konsol.print(hero.global_ip()) +konsol.print(modem.add_static_route(comment="bakalim.io", network="145.53.10.0", mask="255.255.255.0", interface="Wireguard2")) -konsol.print("\n".join(hero.dsl_stats()["parse"]["message"])) +konsol.print(modem.del_static_route(comment="bakalim.io", network="145.53.10.0", mask="255.255.255.0", interface="Wireguard2")) -konsol.print(hero.hosts()) +konsol.print(modem.del_static_route(comment="bakalim.io", host="145.53.10.71", interface="Wireguard2")) -konsol.print(hero.dsl_reset()) +for route in modem.get_static_routes(): + konsol.log(route) + if route.get("comment") == "bakalim.io": + konsol.print(modem.del_static_route(**route)) + break ``` ## 💸 Bağış Yap @@ -69,4 +87,4 @@ konsol.print(hero.dsl_reset()) ## -> **[@KekikAkademi](https://t.me/KekikAkademi)** *için yazılmıştır..* +> **[@KekikAkademi](https://t.me/KekikAkademi)** *için yazılmıştır..* \ No newline at end of file diff --git a/setup.py b/setup.py index 61488da..24aa4b6 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( # ? Genel Bilgiler name = "KeeneticPy", - version = "0.6", + version = "0.7", url = "https://github.com/keyiflerolsun/KeeneticPy", description = "Python Lib for Keenetic Routers", keywords = ["KeeneticPy", "KekikAkademi", "keyiflerolsun"],