mkupl.py - create a uniq upload link
This commit is contained in:
commit
c160203072
1 changed files with 36 additions and 0 deletions
36
mkupl.py
Executable file
36
mkupl.py
Executable file
|
@ -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()
|
Loading…
Reference in a new issue