From c160203072ff2f37fc431f96b16c0c28b798553d Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Mon, 25 Oct 2021 00:42:50 +0200 Subject: [PATCH] mkupl.py - create a uniq upload link --- mkupl.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 mkupl.py diff --git a/mkupl.py b/mkupl.py new file mode 100755 index 0000000..79898ce --- /dev/null +++ b/mkupl.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +import sys, os, pg, uuid, shutil + +""" +Generates a uniq uploadlink +""" +try: + datenbank = pg.connect( + # dbname="datenpunk", host="somehost", user="donald", passwd="blablabla" + dbname="wn" + ) +except: + sys.exit("\nCan't find my database. Doing nothing :(\n") + +dbtable = "uploadlinks" +prefix = "uplgenid-" +sourcedir = os.path.expanduser("~/") +sourcefile = sourcedir + "up.php" +targetdir = os.path.expanduser("~/www/i21k.de/") +targetfilename = prefix + str(uuid.uuid4()) + ".php" +targetfile = targetdir + targetfilename + +uploaduser = input("Bitte gib einen Kontext an, z.B. einen Usernamen: ") +print("Copying ", sourcefile, "to", targetfile) +shutil.copy(sourcefile, targetfile) +print("Generating databaseentry for user", uploaduser) +dbuploadquery = "insert into " + dbtable + " (benutzer, phpfile) values ('" + uploaduser + "','" + targetfilename + "');" +print(dbuploadquery) + +try: + dbentry = datenbank.query(dbuploadquery) +except: + sys.exit("\nError bei Abfrage: " + dbuploadquery) + +datenbank.close()