diff --git a/.gitmodules b/.gitmodules index ee67a9f..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "fritzconnection"] - path = fritzconnection - url = https://github.com/kbr/fritzconnection.git -[submodule "peewee"] - path = peewee - url = https://github.com/coleifer/peewee.git diff --git a/README.md b/README.md index 9aa5eb8..9c00218 100644 --- a/README.md +++ b/README.md @@ -10,20 +10,16 @@ TODO: Write feature list ## Requirements + - Git (only for installing from Git repository) - Python >= 3.8 - fritzconnection >= 1.3.4 - - https://pypi.org/project/fritzconnection/ - - peewee >= 3.13.3 - - https://pypi.org/project/peewee/ - - Git (Just to install the way I do. You can also install downloading a .zip file and install libraries by yourself... not what I like, so I actually will not take care of this.) - -3rd party libraries are included as Git submodule. See installation instructions below. Actually I use the current repository code. This will change but for development this is the easiest solution. I will switch to stable releases some day. + - pymysql >= 0.10.1 +Just install the 3rdf party dependencies using `pip install $PACKAGE` ## Installation git clone https://git.unixpeople.org/hanez/uplink.git cd uplink - git submodule update --init --recursive cp config.example.json config.json ### Configuration @@ -42,9 +38,14 @@ Edit config.json to your needs. #### Example { - "interval": 60, - "database": "./uplink.sqlite3", - "cron_mode": false, + "interval": 60, + "database_type": "mysql", + "database": "uplink", + "database_host": "127.0.0.1", + "database_user": "USER", + "database_password": "PASSWORD", + "cron": false, + "daemon": false, "uplinks": [ { "provider": "Cable Provider", "ip": "192.168.0.1", "password": "1234" }, { "provider": "DSL Provider", "ip": "192.168.1.1", "password": "1234" } diff --git a/fritzconnection b/fritzconnection deleted file mode 160000 index f2ed0ba..0000000 --- a/fritzconnection +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f2ed0baaaf57e4f0134c81ba4a7b0fcd8e8e9e53 diff --git a/peewee b/peewee deleted file mode 160000 index ce9375c..0000000 --- a/peewee +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ce9375cb4b3fa64560e400932d86e2632c4a0586 diff --git a/uplink b/uplink index 5df05cd..47cfd56 100755 --- a/uplink +++ b/uplink @@ -27,12 +27,12 @@ import logging import logging.handlers import os import os.path as path -import sqlite3 +import pymysql +#import sqlite3 import sys import time -from fritzconnection.fritzconnection.lib.fritzstatus import FritzStatus -from peewee import peewee +from fritzconnection.lib.fritzstatus import FritzStatus __version__ = "0.1" @@ -103,8 +103,15 @@ def parse_args(): def get_data(config): - conn = sqlite3.connect(config["database"]) - c = conn.cursor() + + #conn = sqlite3.connect(config["database"]) + #c = conn.cursor() + + con = pymysql.connect(config["database_host"], + config["database_user"], + config["database_password"], + config["database"]) + for i in range(len(config["uplinks"])): timestamp = calendar.timegm(time.gmtime()) local_time = time.localtime(timestamp) @@ -119,8 +126,11 @@ def get_data(config): 'VALUES (\"' + str(timestamp) + '\",\"' + str(d) + '\",\"' + str(t) + '\",\"' + \ str(config["uplinks"][i]["ip"]) + '\",\"' + "0" + '\",\"' + "0" + '\",\"ERROR: ' + str(err) + '\")' logging.debug(sql) - c.execute(sql) - conn.commit() + #c.execute(sql) + #conn.commit() + with con.cursor() as cur: + cur.execute(sql) + con.commit() break if fc.is_connected: @@ -141,9 +151,13 @@ def get_data(config): str(fc.str_max_linked_bit_rate[1]) + '\",\"' + str(fc.modelname) + '\",\"' + \ str(fc.fc.system_version) + '\",\"' + status + '\")' logging.debug(sql) - c.execute(sql) - conn.commit() - conn.close() + #c.execute(sql) + #conn.commit() + with con.cursor() as cur: + cur.execute(sql) + con.commit() + #conn.close() + con.close() def run(config): diff --git a/uplink.mysql.sql b/uplink.mysql.sql new file mode 100644 index 0000000..5594540 --- /dev/null +++ b/uplink.mysql.sql @@ -0,0 +1,23 @@ +CREATE TABLE `log` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `timestamp` int(11) NOT NULL, + `date` date DEFAULT NULL, + `time` time DEFAULT NULL, + `uptime` int(11) DEFAULT NULL, + `internal_ip` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL, + `external_ip` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `external_ipv6` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `is_linked` tinyint(1) DEFAULT NULL, + `is_connected` tinyint(1) DEFAULT NULL, + `str_transmission_rate_up` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `str_transmission_rate_down` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `str_max_bit_rate_up` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `str_max_bit_rate_down` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `str_max_linked_bit_rate_up` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `str_max_linked_bit_rate_down` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `modelname` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `system_version` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `message` varchar(2048) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `id_UNIQUE` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/uplink.sql b/uplink.sqlite3.sql similarity index 100% rename from uplink.sql rename to uplink.sqlite3.sql