python3-cyberfusion-proftpd-support 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: python3-cyberfusion-proftpd-support
3
+ Version: 1.0
4
+ Summary: Library to manage ProFTPD.
5
+ Author-email: Cyberfusion <support@cyberfusion.io>
6
+ Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-proftpd-support
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: pydantic[dotenv]==1.10.4
9
+
10
+ # python3-cyberfusion-proftpd-support
11
+
12
+ Library to manage ProFTPD.
13
+
14
+ At the moment, this library allows you to create auto-expiring ProFTPD users (stored in an SQLite database).
15
+
16
+ # Install
17
+
18
+ ## PyPI
19
+
20
+ Run the following command to install the package from PyPI:
21
+
22
+ pip3 install python3-cyberfusion-proftpd-support
23
+
24
+ ## Debian
25
+
26
+ Run the following commands to build a Debian package:
27
+
28
+ mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
29
+ dpkg-buildpackage -us -uc
30
+
31
+ # Configure
32
+
33
+ Place settings in `/etc/proftpd-support.conf` (regular text file).
34
+
35
+ All settings must be prefixed with `PROFTPD_SUPPORT_`.
36
+
37
+ Find all available settings in `settings.py`.
38
+
39
+ Find an example config in `.env.local`.
40
+
41
+ # Usage
42
+
43
+ ```python
44
+ from cyberfusion.ProftpdSupport.users import create_proftpd_user
45
+
46
+ user = create_proftpd_user(
47
+ username="example",
48
+ password="example",
49
+ uid=1000,
50
+ gid=1000,
51
+ home_directory="/home/example",
52
+ )
53
+ ```
@@ -0,0 +1,44 @@
1
+ # python3-cyberfusion-proftpd-support
2
+
3
+ Library to manage ProFTPD.
4
+
5
+ At the moment, this library allows you to create auto-expiring ProFTPD users (stored in an SQLite database).
6
+
7
+ # Install
8
+
9
+ ## PyPI
10
+
11
+ Run the following command to install the package from PyPI:
12
+
13
+ pip3 install python3-cyberfusion-proftpd-support
14
+
15
+ ## Debian
16
+
17
+ Run the following commands to build a Debian package:
18
+
19
+ mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
20
+ dpkg-buildpackage -us -uc
21
+
22
+ # Configure
23
+
24
+ Place settings in `/etc/proftpd-support.conf` (regular text file).
25
+
26
+ All settings must be prefixed with `PROFTPD_SUPPORT_`.
27
+
28
+ Find all available settings in `settings.py`.
29
+
30
+ Find an example config in `.env.local`.
31
+
32
+ # Usage
33
+
34
+ ```python
35
+ from cyberfusion.ProftpdSupport.users import create_proftpd_user
36
+
37
+ user = create_proftpd_user(
38
+ username="example",
39
+ password="example",
40
+ uid=1000,
41
+ gid=1000,
42
+ home_directory="/home/example",
43
+ )
44
+ ```
@@ -0,0 +1,21 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "python3-cyberfusion-proftpd-support"
7
+ version = "1.0"
8
+ description = "Library to manage ProFTPD."
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Cyberfusion", email = "support@cyberfusion.io" },
12
+ ]
13
+ dependencies = [
14
+ "pydantic[dotenv]==1.10.4",
15
+ ]
16
+
17
+ [project.urls]
18
+ "Source" = "https://github.com/CyberfusionIO/python3-cyberfusion-proftpd-support"
19
+
20
+ [project.scripts]
21
+ proftpd-support-delete-expired-users = "cyberfusion.ProftpdSupport.users:delete_expire_users"
@@ -0,0 +1,12 @@
1
+ [aliases]
2
+ test = pytest
3
+
4
+ [tool:pytest]
5
+ norecursedirs = .git build dist *.egg __pycache__ .cache
6
+ testpaths = tests
7
+ junit_suite_name = python3-cyberfusion-proftpd-support
8
+
9
+ [egg_info]
10
+ tag_build =
11
+ tag_date = 0
12
+
@@ -0,0 +1,11 @@
1
+ import sqlite3
2
+
3
+ from cyberfusion.ProftpdSupport.settings import settings
4
+
5
+
6
+ def get_database_connection() -> sqlite3.Connection:
7
+ connection = sqlite3.connect(settings.database_path, isolation_level=None)
8
+
9
+ connection.row_factory = sqlite3.Row # Allow named access to columns
10
+
11
+ return connection
@@ -0,0 +1,14 @@
1
+ import datetime
2
+ from dataclasses import dataclass
3
+
4
+
5
+ @dataclass
6
+ class User:
7
+ id: int
8
+ username: str
9
+ password: str
10
+ uid: int
11
+ gid: int
12
+ home_directory: str
13
+ shell_path: str
14
+ created_at: datetime.datetime
@@ -0,0 +1,16 @@
1
+ from pydantic import BaseSettings
2
+ from pathlib import Path
3
+
4
+
5
+ class Settings(BaseSettings):
6
+ database_path: Path
7
+
8
+ user_expire_hours: int = 1
9
+
10
+ class Config:
11
+ env_prefix = "proftpd_support_"
12
+
13
+ env_file = ".env", "/etc/proftpd-support.conf"
14
+
15
+
16
+ settings = Settings()
@@ -0,0 +1,84 @@
1
+ import datetime
2
+ import os
3
+ from typing import List
4
+
5
+ from cyberfusion.ProftpdSupport.database import get_database_connection
6
+ from cyberfusion.ProftpdSupport.models import User
7
+ from cyberfusion.ProftpdSupport.settings import settings
8
+
9
+ PATH_SHELL = os.path.join(os.path.sep, "bin", "false")
10
+
11
+
12
+ def get_expire_users_ids() -> List[int]:
13
+ connection = get_database_connection()
14
+
15
+ cursor = connection.cursor()
16
+
17
+ cursor.execute(
18
+ f"SELECT * FROM `users` WHERE `created_at` < datetime('now', '-{settings.user_expire_hours} hours')"
19
+ )
20
+
21
+ return [row["id"] for row in cursor.fetchall()]
22
+
23
+
24
+ def get_user(username: str) -> User:
25
+ connection = get_database_connection()
26
+
27
+ cursor = connection.cursor()
28
+
29
+ user = cursor.execute(
30
+ "SELECT `id`, `userid`, `passwd`, `uid`, `gid`,`homedir`, `shell`, `created_at` FROM `users` WHERE `userid` = ?",
31
+ (username,),
32
+ ).fetchone()
33
+
34
+ return User(
35
+ id=user["id"],
36
+ username=user["userid"],
37
+ password=user["passwd"],
38
+ uid=user["uid"],
39
+ gid=user["gid"],
40
+ home_directory=user["homedir"],
41
+ shell_path=user["shell"],
42
+ created_at=datetime.datetime.strptime(user["created_at"], "%Y-%m-%d %H:%M:%S"),
43
+ )
44
+
45
+
46
+ def delete_expire_users() -> None:
47
+ expire_users_ids = get_expire_users_ids()
48
+
49
+ connection = get_database_connection()
50
+
51
+ cursor = connection.cursor()
52
+
53
+ for id_ in expire_users_ids:
54
+ cursor.execute("DELETE FROM `users` WHERE `id` = ?", (str(id_)))
55
+
56
+
57
+ def get_users_amount() -> int:
58
+ connection = get_database_connection()
59
+
60
+ cursor = connection.cursor()
61
+
62
+ return cursor.execute("SELECT COUNT(*) FROM `users`").fetchone()[0]
63
+
64
+
65
+ def create_proftpd_user(
66
+ *, username: str, password: str, uid: int, gid: int, home_directory: str
67
+ ) -> User:
68
+ connection = get_database_connection()
69
+
70
+ cursor = connection.cursor()
71
+
72
+ cursor.execute(
73
+ "INSERT INTO `users`(`userid`, `passwd`, `uid`, `gid`, `homedir`, `shell`) VALUES(?, ?, ?, ?, ?, ?)",
74
+ (
75
+ username,
76
+ password,
77
+ uid,
78
+ gid,
79
+ home_directory,
80
+ PATH_SHELL,
81
+ ),
82
+ )
83
+
84
+ return get_user(username)
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: python3-cyberfusion-proftpd-support
3
+ Version: 1.0
4
+ Summary: Library to manage ProFTPD.
5
+ Author-email: Cyberfusion <support@cyberfusion.io>
6
+ Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-proftpd-support
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: pydantic[dotenv]==1.10.4
9
+
10
+ # python3-cyberfusion-proftpd-support
11
+
12
+ Library to manage ProFTPD.
13
+
14
+ At the moment, this library allows you to create auto-expiring ProFTPD users (stored in an SQLite database).
15
+
16
+ # Install
17
+
18
+ ## PyPI
19
+
20
+ Run the following command to install the package from PyPI:
21
+
22
+ pip3 install python3-cyberfusion-proftpd-support
23
+
24
+ ## Debian
25
+
26
+ Run the following commands to build a Debian package:
27
+
28
+ mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
29
+ dpkg-buildpackage -us -uc
30
+
31
+ # Configure
32
+
33
+ Place settings in `/etc/proftpd-support.conf` (regular text file).
34
+
35
+ All settings must be prefixed with `PROFTPD_SUPPORT_`.
36
+
37
+ Find all available settings in `settings.py`.
38
+
39
+ Find an example config in `.env.local`.
40
+
41
+ # Usage
42
+
43
+ ```python
44
+ from cyberfusion.ProftpdSupport.users import create_proftpd_user
45
+
46
+ user = create_proftpd_user(
47
+ username="example",
48
+ password="example",
49
+ uid=1000,
50
+ gid=1000,
51
+ home_directory="/home/example",
52
+ )
53
+ ```
@@ -0,0 +1,14 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.cfg
4
+ src/cyberfusion/ProftpdSupport/__init__.py
5
+ src/cyberfusion/ProftpdSupport/database.py
6
+ src/cyberfusion/ProftpdSupport/models.py
7
+ src/cyberfusion/ProftpdSupport/settings.py
8
+ src/cyberfusion/ProftpdSupport/users.py
9
+ src/python3_cyberfusion_proftpd_support.egg-info/PKG-INFO
10
+ src/python3_cyberfusion_proftpd_support.egg-info/SOURCES.txt
11
+ src/python3_cyberfusion_proftpd_support.egg-info/dependency_links.txt
12
+ src/python3_cyberfusion_proftpd_support.egg-info/entry_points.txt
13
+ src/python3_cyberfusion_proftpd_support.egg-info/requires.txt
14
+ src/python3_cyberfusion_proftpd_support.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ proftpd-support-delete-expired-users = cyberfusion.ProftpdSupport.users:delete_expire_users