2022-08-25 17:03:56 +00:00
|
|
|
"""Class representing Nextcloud service."""
|
|
|
|
import base64
|
|
|
|
import subprocess
|
|
|
|
import typing
|
|
|
|
from selfprivacy_api.jobs import Job, Jobs
|
|
|
|
from selfprivacy_api.services.generic_service_mover import FolderMoveNames, move_service
|
|
|
|
from selfprivacy_api.services.generic_status_getter import get_service_status
|
|
|
|
from selfprivacy_api.services.service import Service, ServiceDnsRecord, ServiceStatus
|
2023-04-19 11:34:14 +00:00
|
|
|
from selfprivacy_api.services.owned_path import OwnedPath
|
2022-08-25 17:03:56 +00:00
|
|
|
from selfprivacy_api.utils import ReadUserData, WriteUserData, get_domain
|
|
|
|
from selfprivacy_api.utils.block_devices import BlockDevice
|
|
|
|
import selfprivacy_api.utils.network as network_utils
|
|
|
|
from selfprivacy_api.services.pleroma.icon import PLEROMA_ICON
|
|
|
|
|
|
|
|
|
|
|
|
class Pleroma(Service):
|
|
|
|
"""Class representing Pleroma service."""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_id() -> str:
|
|
|
|
return "pleroma"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_display_name() -> str:
|
|
|
|
return "Pleroma"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_description() -> str:
|
|
|
|
return "Pleroma is a microblogging service that offers a web interface and a desktop client."
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_svg_icon() -> str:
|
|
|
|
return base64.b64encode(PLEROMA_ICON.encode("utf-8")).decode("utf-8")
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_url() -> typing.Optional[str]:
|
|
|
|
"""Return service url."""
|
|
|
|
domain = get_domain()
|
|
|
|
return f"https://social.{domain}"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_movable() -> bool:
|
|
|
|
return True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_required() -> bool:
|
|
|
|
return False
|
|
|
|
|
2023-06-29 11:27:08 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_backup_description() -> str:
|
|
|
|
return "Your Pleroma accounts, posts and media."
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def is_enabled() -> bool:
|
|
|
|
with ReadUserData() as user_data:
|
|
|
|
return user_data.get("pleroma", {}).get("enable", False)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_status() -> ServiceStatus:
|
|
|
|
return get_service_status("pleroma.service")
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def enable():
|
|
|
|
with WriteUserData() as user_data:
|
|
|
|
if "pleroma" not in user_data:
|
|
|
|
user_data["pleroma"] = {}
|
|
|
|
user_data["pleroma"]["enable"] = True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def disable():
|
|
|
|
with WriteUserData() as user_data:
|
|
|
|
if "pleroma" not in user_data:
|
|
|
|
user_data["pleroma"] = {}
|
|
|
|
user_data["pleroma"]["enable"] = False
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def stop():
|
|
|
|
subprocess.run(["systemctl", "stop", "pleroma.service"])
|
|
|
|
subprocess.run(["systemctl", "stop", "postgresql.service"])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def start():
|
|
|
|
subprocess.run(["systemctl", "start", "pleroma.service"])
|
|
|
|
subprocess.run(["systemctl", "start", "postgresql.service"])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def restart():
|
|
|
|
subprocess.run(["systemctl", "restart", "pleroma.service"])
|
|
|
|
subprocess.run(["systemctl", "restart", "postgresql.service"])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_configuration(config_items):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def set_configuration(config_items):
|
|
|
|
return super().set_configuration(config_items)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_logs():
|
|
|
|
return ""
|
|
|
|
|
2023-04-17 13:47:49 +00:00
|
|
|
@staticmethod
|
2023-04-19 11:34:14 +00:00
|
|
|
def get_owned_folders() -> typing.List[OwnedPath]:
|
|
|
|
"""
|
|
|
|
Get a list of occupied directories with ownership info
|
|
|
|
pleroma has folders that are owned by different users
|
|
|
|
"""
|
|
|
|
return [
|
|
|
|
OwnedPath(
|
|
|
|
path="/var/lib/pleroma",
|
|
|
|
owner="pleroma",
|
|
|
|
group="pleroma",
|
|
|
|
),
|
|
|
|
OwnedPath(
|
|
|
|
path="/var/lib/postgresql",
|
|
|
|
owner="postgres",
|
|
|
|
group="postgres",
|
|
|
|
),
|
|
|
|
]
|
2023-04-17 13:47:49 +00:00
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
|
|
|
return [
|
|
|
|
ServiceDnsRecord(
|
|
|
|
type="A",
|
|
|
|
name="social",
|
|
|
|
content=network_utils.get_ip4(),
|
|
|
|
ttl=3600,
|
2023-11-24 10:57:52 +00:00
|
|
|
display_name="Pleroma",
|
2022-08-25 17:03:56 +00:00
|
|
|
),
|
|
|
|
ServiceDnsRecord(
|
|
|
|
type="AAAA",
|
|
|
|
name="social",
|
|
|
|
content=network_utils.get_ip6(),
|
|
|
|
ttl=3600,
|
2023-11-24 10:57:52 +00:00
|
|
|
display_name="Pleroma (IPv6)",
|
2022-08-25 17:03:56 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
def move_to_volume(self, volume: BlockDevice) -> Job:
|
2022-10-27 14:01:11 +00:00
|
|
|
job = Jobs.add(
|
2022-08-25 17:03:56 +00:00
|
|
|
type_id="services.pleroma.move",
|
|
|
|
name="Move Pleroma",
|
|
|
|
description=f"Moving Pleroma to volume {volume.name}",
|
|
|
|
)
|
|
|
|
move_service(
|
|
|
|
self,
|
|
|
|
volume,
|
|
|
|
job,
|
2023-04-19 12:43:47 +00:00
|
|
|
FolderMoveNames.default_foldermoves(self),
|
2022-08-25 17:03:56 +00:00
|
|
|
"pleroma",
|
|
|
|
)
|
|
|
|
return job
|