Skip to content

Commit

Permalink
#60, #13 | Settings Updates, Cleanup
Browse files Browse the repository at this point in the history
- Changed the way settings were handled in preparation for more. Now they check if encrypted and auto use the encrypted function if so. This will make it so that most settings can be added without needing a new section in the settings widget.

- Added Setting Display Names & Setting Type Definitions. use the `display_name_` prefix in settings to set the display name for a setting. Use the `hidden_` prefix to create a hidden input. Display Name definition can be anywhere before the setting value.

- Fixed bug where s3 settings couldn't be updated.

- Updated Guide to show new encrypted setting access process.

- Lots of cleanup

- Added initial variable for global mention IDs & Mention Tag start/ends.
  • Loading branch information
VenomStyx committed Apr 23, 2022
1 parent 418a718 commit d55def6
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Docs/Reading Encrypted Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ If you ever find yourself in need of reading the encrypted settings, open up `Py
from resources.config import settings_core
settings = settings_core()
# Read encrypted setting
decrypted_setting = settings.read_encrypted_setting("CATEGORY","SETTING")
decrypted_setting = settings.get_setting_value("CATEGORY","SETTING")
print(decrypted_setting)
```
2 changes: 1 addition & 1 deletion resources/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def load_data(self):
data_loaded = False

## Load Account Data from Settings
accounts = string_to_list_of_dictionaries(settings.read_encrypted_setting("accounts", "media_accounts"))
accounts = string_to_list_of_dictionaries(settings.get_setting_value("accounts", "media_accounts"))

for account in accounts:
if account["name"] == self.data['name']:
Expand Down
34 changes: 22 additions & 12 deletions resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@




# _____ _
# / __ \ |
# | / \/ | __ _ ___ ___ ___ ___
Expand Down Expand Up @@ -83,7 +82,7 @@ def __init__(self):


##### ENCRYPTION
self.key_location = cfg.get("encryption","key_location")
self.key_location = cfg.get("encryption","hidden_key_location")
self.crypt = None

## Has encryption been setup?
Expand Down Expand Up @@ -113,19 +112,23 @@ def __init__(self):
##### ACCOUNTS
media_accounts_temp = cfg.get("accounts","media_accounts")
if media_accounts_temp != "None":
self.media_accounts = string_to_list_of_dictionaries(self.read_encrypted_setting("accounts", "media_accounts"))
self.media_accounts = string_to_list_of_dictionaries(self.get_setting_value("accounts", "media_accounts"))
else:
self.media_accounts = None


##### S3 CREDENTIALS
self.s3_access = self.read_encrypted_setting("accounts", "s3_access")
self.s3_secret = self.read_encrypted_setting("accounts", "s3_secret")
self.s3_endpoint = self.read_encrypted_setting("accounts", "s3_endpoint")
self.s3_bucket = self.read_encrypted_setting("accounts", "s3_bucket")
self.s3_access = self.get_setting_value("accounts", "hidden_s3_access")
self.s3_secret = self.get_setting_value("accounts", "hidden_s3_secret")
self.s3_endpoint = self.get_setting_value("accounts", "hidden_s3_endpoint")
self.s3_bucket = self.get_setting_value("accounts", "hidden_s3_bucket")

self.storage = Storage(self.s3_access, self.s3_secret, self.s3_endpoint, self.s3_bucket)


##### Global Mention IDs
self.global_mention_ids = self.get_setting_value("posting", "global_mention_ids")

else:
self.media_accounts = None
self.storage = None
Expand All @@ -137,6 +140,7 @@ def __init__(self):
self.no_posts_title = cfg.get("app","no_posts_title")
self.no_posts_description = cfg.get("app","no_posts_description")
self.post_not_scheduled_for_reason_time_in_past = cfg.get("app","post_not_scheduled_for_reason_time_in_past")
self.value_redaction_message = cfg.get("app", "value_redaction_message")


##### PERFORMANCE
Expand All @@ -158,11 +162,9 @@ def reload_config(self):
cfg.read(configpath)


def read_encrypted_setting(self, category, setting):
def read_encrypted_setting(self, setting_value):
try:
encrypted_setting = self.get_setting_value(category, setting)
setting = self.crypt.decrypt(encrypted_setting.encode()).decode()
return setting
return self.crypt.decrypt(setting_value.encode()).decode()
except Exception as e:
print(e)
return None
Expand Down Expand Up @@ -190,7 +192,14 @@ def get_all_settings_in_category(self,category):

##### GET SETTING VALUE
def get_setting_value(self,category,setting):
return cfg.get(category,setting)

value = cfg.get(category,setting)

## Decrypt if encrypted
if list(value)[-1] == "=":
value = self.read_encrypted_setting(value)

return value


##### SET SETTING VALUE
Expand All @@ -201,6 +210,7 @@ def set_setting_value(self,category,setting,value):

self.reload_config()


##### CREATE NEW SETTING
def create_new_setting(self,category,setting,value):
cfg.add_section(category)
Expand Down
74 changes: 68 additions & 6 deletions settings_template.cfg
Original file line number Diff line number Diff line change
@@ -1,38 +1,100 @@
########## APPLICATION
#####
[accounts]
## Display Names
display_name_media_accounts = Media Accounts
display_name_supported_media_platforms = Supported Platforms
display_name_hidden_s3_access = Access
display_name_hidden_s3_secret = Secret
display_name_hidden_s3_endpoint = Endpoint
display_name_hidden_s3_bucket = Bucket

## Values
media_accounts = None
supported_media_platforms = Discord,Twitter,Reddit,Facebook,Instagram,Telegram,Signal,RSS
s3_access = None
s3_secret = None
s3_endpoint = None
s3_bucket = None
hidden_s3_access = None
hidden_s3_secret = None
hidden_s3_endpoint = None
hidden_s3_bucket = None

[posting]
## Display Names
display_name_local_mention_tag_start = Local Mention Tag Start
display_name_local_mention_tag_end = Local Mention Tag End
display_name_global_mention_ids = Global Mention IDs
display_name_utc_timezones = UTC Timezones
display_name_default_timezone = Default Timezone

## Values
local_mention_tag_start = None
local_mention_tag_end = None
global_mention_ids = None
utc_timezones = +1400,+1300,+1200,+1100,+1000,+0900,+0800,+0700,+0600,+0500,+0400,+0300,+0200,+0100,+0000,-0100,-0200,-0300,-0400,-0500,-0600,-0700,-0800,-0900,-1000,-1100,-1200
default_timezone = +0000

[encryption]
key_location = /path/to/key.pem
## Display Names
display_name_hidden_key_location = Key Location
display_name_block_size = Block Size

## Values
hidden_key_location = /path/to/key.pem
block_size = None

[app]
## Display Names
display_name_no_posts_title = Warning | Title - No Posts Found
display_name_no_posts_description = Warning | Description - No Posts Found
display_name_post_not_scheduled_for_reason_time_in_past = Warning | Attempt to Schedule Post in the Past
display_name_value_redaction_message = Info | Hidden Value Redacted Message

## Values
no_posts_title = No Pending Posts
no_posts_description = No posts here yet!
post_not_scheduled_for_reason_time_in_past = WARNING. Your post could not be scheduled. Please pick a date in the future above.
value_redaction_message = REDACTED

[storage]
## Display Names
display_name_posts_file = Posts File Name
display_name_scheduled_posts_file = Scheduled Posts File Name
display_name_uploaded_media_dir = Uploaded Media Directory

## Values
posts_file = published_posts.dat
scheduled_posts_file = scheduled_posts.dat
uploaded_media_dir = uploaded_media

[media]
## Display Names
display_name_supported_image_types = Supported Image Types
display_name_supported_video_types = Supported Video Types
display_name_supported_audio_types = Supported Audio Types

## Values
supported_image_types = jpg,jpeg,png,gif
supported_video_types = mp4,mov,avi,wmv,flv,mpg,mpeg
supported_audio_types = mp3,wav,ogg

[performance]
## Display Names
display_name_posts_cache_time = Posts Cache Time
display_name_page_cache_time = Page Cache time

## Values
posts_cache_time = 3600
page_cache_time = 3600

# Server settings need to be set on the device running the server. Changing them here will not affect the server unless you're running it locally.

########## SERVER
#####

## Server settings need to be set on the device running the server.
## Changing them here will not affect the server unless you're running it locally.

[server]
## Display Names
display_name_processing_delay_in_seconds = Processing Delay in Seconds

## Values
processing_delay_in_seconds = 60
Loading

0 comments on commit d55def6

Please sign in to comment.