[projects/pld-ftp-admin] Drop the www interface

arekm arekm at pld-linux.org
Sat Nov 21 10:42:42 CET 2026


commit 790d8c04e1933536d111b325fc02d7dc1e80e874
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sat Nov 21 01:11:47 2026 +0100

    Drop the www interface
    
    The cgi-bin page was never finished: its Commit button did nothing
    and no code set the Mv/Rm marks it showed. Gone with it: ftpiod's
    public socket and its logins, the package list the page asked for,
    and the info:move mark read when a package is loaded.

 cgi-bin/index.py       |  31 ---------------
 ftpiod/ftpiod.py       |   5 +--
 html/footer.html       |   3 --
 html/header.html       |  10 -----
 html/layout.css        |  82 --------------------------------------
 html/loggedinmenu.html |   1 -
 html/menufooter.html   |   2 -
 html/regform.html      |   8 ----
 modules/cmds.py        | 106 +------------------------------------------------
 modules/common.py      |   5 +--
 modules/config.py      |   7 +---
 modules/cons.py        |  11 +----
 modules/ftpio.py       |  53 +------------------------
 modules/ftptree.py     |   5 ---
 modules/user.py        |  34 ----------------
 modules/wwwcmds.py     |  26 ------------
 modules/wwwiface.py    |  57 --------------------------
 17 files changed, 9 insertions(+), 437 deletions(-)
---
diff --git a/cgi-bin/index.py b/cgi-bin/index.py
deleted file mode 100755
index c729c66..0000000
--- a/cgi-bin/index.py
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/env python3
-# vi: ts=8 sts=4 sw=4 et
-
-import sys
-from wsgiref.handlers import CGIHandler
-
-sys.path.insert(0, '../modules')
-
-import user
-import wwwcmds
-import wwwiface
-
-
-def application(environ, start_response):
-    opts, cks = wwwiface.getopts(environ)
-    page = wwwiface.Page()
-    u = user.User(cks, opts, page)
-
-    if u.loggedin:
-        page.addheader('Logged in: ' + u.login)
-        page.addmenu(file='loggedinmenu')
-        wwwcmds.handlecmds(opts, page)
-    else:
-        page.addheader('Login form')
-        page.addcontent(file='regform')
-
-    start_response('200 OK', page.headers)
-    return [page.render()]
-
-
-CGIHandler().run(application)
diff --git a/ftpiod/ftpiod.py b/ftpiod/ftpiod.py
index 4b71cec..d25b923 100755
--- a/ftpiod/ftpiod.py
+++ b/ftpiod/ftpiod.py
@@ -26,10 +26,7 @@ while True:
     for readable in cons.readables():
         if readable==cons.privlistener:
             newsock,addr=readable.accept()
-            cons.add(cons.Connection(newsock, True))
-        elif readable==cons.publistener:
-            newsock,addr=readable.accept()
-            cons.add(cons.Connection(newsock, False))
+            cons.add(cons.Connection(newsock))
         else:
             readable.handleinput()
 
diff --git a/html/footer.html b/html/footer.html
deleted file mode 100644
index 69aae56..0000000
--- a/html/footer.html
+++ /dev/null
@@ -1,3 +0,0 @@
-</body>
-</html>
-
diff --git a/html/header.html b/html/header.html
deleted file mode 100644
index b1491da..0000000
--- a/html/header.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html>
-
-<head>
-<meta http-equiv="content-type" content="text/html; charset=utf-8" />
-<title>PLD ftp manager - Th</title>
-<style type="text/css" media="all">@import "../html/layout.css";</style>
-</head>
-
-<body>
-
diff --git a/html/layout.css b/html/layout.css
deleted file mode 100644
index d7ead8a..0000000
--- a/html/layout.css
+++ /dev/null
@@ -1,82 +0,0 @@
-body {
-	margin:0px;
-	padding:0px;
-	font-family:verdana, arial, helvetica, sans-serif;
-	color:#333;
-	background-color:white;
-	}
-h1 {
-	margin:0px 0px 15px 0px;
-	padding:0px;
-	font-size:28px;
-	line-height:28px;
-	font-weight:900;
-	color:#ccc;
-	}
-p {
-	font:11px/20px verdana, arial, helvetica, sans-serif;
-	margin:0px 0px 16px 0px;
-	padding:0px;
-	}
-#Content>p {margin:0px;}
-#Content>p+p {text-indent:30px;}
-
-a {
-	color:#09c;
-	font-size:11px;
-	text-decoration:none;
-	font-weight:600;
-	font-family:verdana, arial, helvetica, sans-serif;
-	}
-a:link {color:#09c;}
-a:visited {color:#07a;}
-a:hover {background-color:#eee;}
-
-#Header {
-	margin:25px 0px 10px 0px;
-	padding:17px 0px 0px 20px;
-	/* For IE5/Win's benefit height = [correct height] + [top padding] + [top and bottom border widths] */
-	height:33px; /* 14px + 17px + 2px = 33px */
-	border-style:solid;
-	border-color:black;
-	border-width:1px 0px; /* top and bottom borders: 1px; left and right borders: 0px */
-	line-height:11px;
-	background-color:#eee;
-
-/* Here is the ugly brilliant hack that protects IE5/Win from its own stupidity. 
-Thanks to Tantek Celik for the hack and to Eric Costello for publicizing it. 
-IE5/Win incorrectly parses the "\"}"" value, prematurely closing the style 
-declaration. The incorrect IE5/Win value is above, while the correct value is 
-below. See http://glish.com/css/hacks.asp for details. */
-	voice-family: "\"}\"";
-	voice-family:inherit;
-	height:14px; /* the correct height */
-	}
-/* I've heard this called the "be nice to Opera 5" rule. Basically, it feeds correct 
-length values to user agents that exhibit the parsing error exploited above yet get 
-the CSS box model right and understand the CSS2 parent-child selector. ALWAYS include
-a "be nice to Opera 5" rule every time you use the Tantek Celik hack (above). */
-body>#Header {height:14px;}
-
-#Content {
-	margin:0px 50px 50px 200px;
-	padding:10px;
-	}
-
-#Menu {
-	position:absolute;
-	top:100px;
-	left:20px;
-	width:172px;
-	padding:10px;
-	background-color:#eee;
-	border:1px dashed #999;
-	line-height:17px;
-/* Again, the ugly brilliant hack. */
-	voice-family: "\"}\"";
-	voice-family:inherit;
-	width:150px;
-	}
-/* Again, "be nice to Opera 5". */
-body>#Menu {width:150px;}
-
diff --git a/html/loggedinmenu.html b/html/loggedinmenu.html
deleted file mode 100644
index cd63ab1..0000000
--- a/html/loggedinmenu.html
+++ /dev/null
@@ -1 +0,0 @@
-<a href="index.py?action=logout">Logout</a><br/>
diff --git a/html/menufooter.html b/html/menufooter.html
deleted file mode 100644
index c1f08de..0000000
--- a/html/menufooter.html
+++ /dev/null
@@ -1,2 +0,0 @@
-<a href="http://bugs.pld-linux.org/index.php?tasks=all&project=3">Th bugs</a><br/>
-<a href="http://buildlogs.pld-linux.org/">Buildlogs</a><br/>
diff --git a/html/regform.html b/html/regform.html
deleted file mode 100644
index dde6db4..0000000
--- a/html/regform.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<form action="index.py" method="post">
-<input type="hidden" name="action" value="register">
-<label for="login">Username:</label>
-<input type="text" name="login"><br>
-<label for="pass">Password:</label>
-<input type="password" name="pass"><br>
-<input type="submit" value="Log in">
-</form>
diff --git a/modules/cmds.py b/modules/cmds.py
index e0632cd..131726c 100644
--- a/modules/cmds.py
+++ b/modules/cmds.py
@@ -1,12 +1,10 @@
 # vi: ts=8 sts=4 sw=4 et
 
-import hashlib
 import os
 import time
 
 import common
 import config
-import ftptree
 
 
 class BailOut(Exception):
@@ -21,9 +19,6 @@ def parse(con):
     for cmd in cmds:
         con.data=con.data[len(cmd)+1:]
         cmdname=cmd[:4]
-        if not con.authorized and cmdname not in ('linp', 'linc', 'name'):
-            raise BailOut()
-            # TODO: log unauthorized access
         if cmdname in cmdlist_noargs:
             if len(cmd)==4:
                 cmdlist_noargs[cmdname](con)
@@ -94,111 +89,14 @@ def cmd_log(con, msg):
 def cmd_name(con, name):
     con.name=name
 
-def load_creds():
-    global users, cookies
-    users={}
-    cookies={}
-    if not common.fileexists(common.ftpadmdir+'/var/passwd'):
-        return
-    else:
-        with open(common.ftpadmdir+'/var/passwd') as f:
-            for line in f:
-                x=line.strip().split(':')
-                if len(x)>=2:
-                    users[x[0]]=x[1]
-    if not common.fileexists(common.ftpadmdir+'/var/cookies'):
-        return
-    else:
-        with open(common.ftpadmdir+'/var/cookies') as f:
-            for line in f:
-                x=line.strip().split(':')
-                if len(x)>=2:
-                    cookies[x[0]]=x[1]
-
-def write_cookies():
-    with open(common.ftpadmdir+'/var/cookies', 'w') as f:
-        f.writelines(f'{key}:{login}\n' for key, login in cookies.items())
-
-def cmd_login_passwd(con, data):
-    tmp=data.split('\n')
-    if len(tmp)!=2:
-        raise BailOut()
-    login=tmp[0]
-    passwd=tmp[1]
-    md5pass=hashlib.md5(passwd.encode('utf-8')).hexdigest()
-    if login in users and users[login] == md5pass:
-        fullpass = md5pass+salt
-        cookie=repr(time.time()).split('.')[0]+'_'+hashlib.md5(fullpass.encode('utf-8')).hexdigest()
-        cookies[cookie]=login
-        write_cookies()
-        con.cookie=cookie
-        con.username=login
-        con.authorized=True
-        con.sock.send(bytearray('OK '+cookie, encoding='utf-8'))
-    else:
-        # TODO: log this
-        con.sock.send(bytearray('FAIL', encoding='utf-8'))
-        raise BailOut()
-
-def cmd_login_cookie(con, cookie):
-    if cookie in cookies:
-        con.cookie=cookie
-        con.authorized=True
-        con.username=cookies[cookie]
-        con.sock.send(bytearray('OK '+cookies[cookie], encoding='utf-8'))
-    else:
-        # TODO: log this (or not)
-        con.sock.send(bytearray('FAIL', encoding='utf-8'))
-
-def cmd_logout(con):
-    if con.cookie in cookies:
-        del cookies[con.cookie]
-        write_cookies()
-
-def reloadftptree():
-    global srctree
-    srctree=ftptree.FtpTree(config.value['default_to'], loadall=True)
-
-def cmd_gettree(con):
-    # the tree changes under the daemon: reread the names, but keep loaded packages with their marks
-    srctree.pkgnames=ftptree.FtpTree(config.value['default_to']).pkgnames
-    buf=''
-    for pkgnvr in sorted(srctree.keys()):
-        # TODO: show only user's own pkgs
-        pkg=srctree.loadedpkgs.get(pkgnvr)
-        line=pkgnvr
-        if pkg and pkg.marked4moving:
-            line=line+'\n1'
-        else:
-            line=line+'\n0'
-        if pkg and pkg.marked4removal:
-            line=line+'\n1'
-        else:
-            line=line+'\n0'
-        buf=buf+'\0'+line
-    data=buf[1:].encode('utf-8')
-    # the socket is non-blocking and a long list does not fit its buffer
-    con.sock.settimeout(10)
-    try:
-        con.sock.sendall(f'{len(data):010d}'.encode() + data)
-    except OSError:
-        raise BailOut()
-    finally:
-        con.sock.setblocking(False)
-
-
 cmdlist_args={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock,
-         'log1':cmd_log, 'name':cmd_name, 'linp':cmd_login_passwd,
-         'linc':cmd_login_cookie}
+         'log1':cmd_log, 'name':cmd_name}
 
-cmdlist_noargs={'lout':cmd_logout, 'gett':cmd_gettree, 'slck':cmd_show_locks}
+cmdlist_noargs={'slck':cmd_show_locks}
 
 # Global stuff and initializations
 
 locks={}
 # open for the daemon's lifetime
 logfile=open(common.ftpadmdir+'/var/log', 'a')  # noqa: SIM115
-load_creds()
-reloadftptree()
-salt=hashlib.md5(repr(time.time()).encode('utf-8')).hexdigest()
 
diff --git a/modules/common.py b/modules/common.py
index 46375de..27188b3 100644
--- a/modules/common.py
+++ b/modules/common.py
@@ -22,10 +22,7 @@ def checkdir(dir, metadata = True):
         print('ERR: ' + config.value['ftp_dir']+'/' + dir + " is not an ftp tree, it has no SRPMS/.metadata", file=sys.stderr)
         sys.exit(1)
 
-if 'HOME' in os.environ:
-    ftpadmdir = os.environ['HOME'] + '/pld-ftp-admin'
-else:
-    ftpadmdir = '..'
+ftpadmdir = os.environ['HOME'] + '/pld-ftp-admin'
 
 # noarchcachedir is dir where noarch files contents are stored for AI
 # XXX: file reference where the AI resides
diff --git a/modules/config.py b/modules/config.py
index ed79f20..bd6946d 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -4,12 +4,7 @@ import os
 
 value = {}
 
-if 'HOME' in os.environ:
-    path = os.environ['HOME']
-else:
-    path = '../../' # cgi-bin interface
-
-with open(path + '/.ftpadmrc') as f:
+with open(os.environ['HOME'] + '/.ftpadmrc') as f:
     lines = f.readlines()
 
 for line in lines:
diff --git a/modules/cons.py b/modules/cons.py
index 86b5fb2..add0cd8 100644
--- a/modules/cons.py
+++ b/modules/cons.py
@@ -12,16 +12,14 @@ from common import fileexists
 
 
 class Connection:
-    def __init__(self, sock, authorized):
+    def __init__(self, sock):
         sock.setblocking(False)
         self.sock=sock
-        self.authorized=authorized
         self.fileno=sock.fileno
         # the pid of the client process, as the kernel reports it for a unix socket
         self.pid=struct.unpack('3i', sock.getsockopt(socket.SOL_SOCKET, socket.SO_PEERCRED, struct.calcsize('3i')))[0]
         self.name=""
         self.data=""
-        self.cookie=None
 
     def destroy(self):
         self.sock.close()
@@ -57,7 +55,6 @@ def rm(con):
 def readables():
     lst=cons[:]
     lst.append(privlistener)
-    lst.append(publistener)
     return select.select(lst, [], [], 0.1)[0]
 
 def createlistener(path):
@@ -67,17 +64,13 @@ def createlistener(path):
     s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     s.setblocking(False)
     s.bind(path)
-    if path==ftpio.pubsock:
-        os.chmod(path, 0o606)
-    else:
-        os.chmod(path, 0o600)
+    os.chmod(path, 0o600)
     s.listen(3)
     return s
 
 cons=[]
 
 privlistener=createlistener(ftpio.privsock)
-publistener=createlistener(ftpio.pubsock)
 
 
 
diff --git a/modules/ftpio.py b/modules/ftpio.py
index 31a6e2a..82dc15e 100644
--- a/modules/ftpio.py
+++ b/modules/ftpio.py
@@ -5,45 +5,16 @@ import socket
 import sys
 import time
 
-import config
-
-pubsock=config.value['pubsock']
-
-if 'HOME' in os.environ:
-    privsock=os.environ['HOME']+'/pld-ftp-admin/var/privsock'
-    socketname=privsock
-else:
-    socketname=pubsock
+privsock=os.environ['HOME']+'/pld-ftp-admin/var/privsock'
 
 def connect(name=None):
     global sock
     sock=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-    sock.connect(socketname)
+    sock.connect(privsock)
     if not name:
         name = f"pid_{os.getpid()}_name_{sys.argv[0]}"
     sock.send(bytearray(f'name {name}\0', encoding='utf-8'))
 
-def login_passwd(login, passwd):
-    'Return cookie if ok'
-    sock.send(bytearray(f'linp {login}\n{passwd}\0', encoding='utf-8'))
-    retval=sock.recv(256).decode("utf-8")
-    if retval=='FAIL':
-        return ''
-    else:
-        return retval[3:]
-
-def login_cookie(cookie):
-    'Return login if ok'
-    sock.send(bytearray(f'linc {cookie}\0', encoding='utf-8'))
-    retval=sock.recv(256).decode('utf-8')
-    if retval=='FAIL':
-        return ''
-    else:
-        return retval[3:]
-
-def logout():
-    sock.send(bytearray('lout\0', encoding='utf-8'))
-
 # the holder of the lock lock() last did not get, see locked_by()
 holder = ''
 
@@ -92,23 +63,3 @@ def locks_dump():
 #    nbytes = int(ret.split("BLOB:")[1])
 #    ret = sock.recv(nbytes).decode("utf-8")
     return ret
-
-def recvall(size):
-    data=b''
-    while len(data) < size:
-        chunk=sock.recv(size - len(data))
-        if not chunk:
-            raise ConnectionError('ftpiod closed the connection')
-        data+=chunk
-    return data
-
-def gettree():
-    sock.send(bytearray('gett\0', encoding='utf-8'))
-    pkgs=[]
-    len=int(recvall(10).decode("utf-8"))
-    if len:
-        for pkg in recvall(len).decode("utf-8").split('\0'):
-            tmp=pkg.split('\n')
-            pkgs.append((tmp[0], int(tmp[1]), int(tmp[2])))
-    return pkgs
-
diff --git a/modules/ftptree.py b/modules/ftptree.py
index d2e6281..a13e381 100644
--- a/modules/ftptree.py
+++ b/modules/ftptree.py
@@ -194,11 +194,6 @@ class Pkg(BasePkg):
         if not quietmode:
             pwarning(f'{self.nvr} {msg}')
 
-    def load(self, content=None):
-        BasePkg.load(self, content)
-        if 'move' in self.info:
-            self.mark4moving()
-
     def writeinfo(self):
         with open(self.tree.basedir+'/SRPMS/.metadata/'+self.nvr+'.src.rpm.info', 'w') as f:
             f.writelines(f"info:build:{bid}:requester:{build.requester}\ninfo:build:{bid}:requester_email:{build.requester_email}\n" for bid, build in self.build.items())
diff --git a/modules/user.py b/modules/user.py
deleted file mode 100644
index 65135ed..0000000
--- a/modules/user.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# vi: ts=8 sts=4 sw=4 et
-
-import ftpio
-
-
-class User:
-    def __init__(self, cookies, options, page):
-        self.loggedin=False
-        self.page=page
-        ftpio.connect('wwwiface')
-        if cookies.get('ftpsessid'):
-            self.login=ftpio.login_cookie(cookies['ftpsessid'])
-            if self.login:
-                self.loggedin=True
-
-        if 'action' in options:
-            if options['action'] == 'register':
-                self.checkloginpass(options)
-            elif options['action'] == 'logout':
-                self.logout()
-
-    def checkloginpass(self, options):
-        if 'login' not in options or 'pass' not in options:
-            return
-        self.cookie=ftpio.login_passwd(options['login'], options['pass'])
-        if self.cookie:
-            self.login=options['login']
-            self.loggedin=True
-            self.page.setcookie('ftpsessid', self.cookie)
-
-    def logout(self):
-        self.loggedin=False
-        ftpio.logout()
-        self.page.setcookie('ftpsessid', '', expires=-31536000)
diff --git a/modules/wwwcmds.py b/modules/wwwcmds.py
deleted file mode 100644
index 004797f..0000000
--- a/modules/wwwcmds.py
+++ /dev/null
@@ -1,26 +0,0 @@
-# vi: ts=8 sts=4 sw=4 et
-
-import ftpio
-
-
-def handlecmds(options, page):
-    def chkbox(pkgname, value):
-        retval=f'<input type="checkbox" name="{pkgname}"'
-        if value:
-            retval=retval+' checked="yes"'
-        retval=retval+'>'
-        return retval
-
-    if 'action' in options and options['action'] in actions:
-        pass
-    else:
-        page.addcontent('<form action="index.py" method="post"><table border="1">')
-        page.addcontent('<tr><td>Mv</td><td>Rm</td><td>Package</td></tr>')
-        for pkg in ftpio.gettree():
-            page.addcontent(f'<tr><td>{chkbox(f"mv:{pkg[0]}", pkg[1])}</td><td>{chkbox(f"rm:{pkg[0]}", pkg[2])}</td><td>{pkg[0]}</td></tr>')
-        page.addcontent('<tr><td> </td><td> </td><td><input type="submit" value="Commit"></td></tr>')
-        page.addcontent('</table></form>')
-
-
-actions={}
-
diff --git a/modules/wwwiface.py b/modules/wwwiface.py
deleted file mode 100644
index cfdc01f..0000000
--- a/modules/wwwiface.py
+++ /dev/null
@@ -1,57 +0,0 @@
-# vi: ts=8 sts=4 sw=4 et
-
-from http.cookies import SimpleCookie
-from urllib.parse import parse_qsl
-
-# html/header.html declares it, so browsers also send form data in it
-CHARSET = 'utf-8'
-
-
-def getfile(file):
-    with open("../html/" + file + ".html") as f:
-        return f.read()
-
-def getopts(environ):
-    'Return (form fields, cookies) of a WSGI request'
-    fields = parse_qsl(environ.get('QUERY_STRING', ''), encoding=CHARSET)
-    if environ['REQUEST_METHOD'] == 'POST':
-        length = int(environ.get('CONTENT_LENGTH') or 0)
-        # the body is percent-encoded ASCII; latin-1 can't fail on stray bytes
-        fields += parse_qsl(environ['wsgi.input'].read(length).decode('latin-1'), encoding=CHARSET)
-
-    cookies = {}
-    for key, morsel in SimpleCookie(environ.get('HTTP_COOKIE', '')).items():
-        cookies[key] = morsel.value
-
-    return (dict(fields), cookies)
-
-class Page:
-    def __init__(self):
-        self.headers = [('Content-Type', f'text/html; charset={CHARSET}')]
-        self.header = []
-        self.menu = []
-        self.content = []
-
-    def setcookie(self, name, value, expires=None):
-        c = SimpleCookie()
-        c[name] = value
-        if expires is not None:
-            c[name]['expires'] = expires
-        self.headers.append(('Set-Cookie', c[name].OutputString()))
-
-    def addmenu(self, text=None, file=None):
-        self.menu.append(text or getfile(file))
-
-    def addheader(self, text=None, file=None):
-        self.header.append(text or getfile(file))
-
-    def addcontent(self, text=None, file=None):
-        self.content.append(text or getfile(file))
-
-    def render(self):
-        lines = [getfile('header'),
-                 '<div id="Header">', *self.header, '</div>',
-                 '<div id="Menu">', *self.menu, getfile('menufooter'), '</div>',
-                 '<div id="Content">', *self.content, '</div>',
-                 getfile('footer')]
-        return ''.join(line + '\n' for line in lines).encode(CHARSET, 'xmlcharrefreplace')
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/a049a512859eaede288d71649a2320e16c959476



More information about the pld-cvs-commit mailing list