(Revision) Forum authority. The | Forum promotion

Hey folks

The site has been running for about 5 years and unfortunately has been through a lot of difficulties during that time period, although now it seems that we are more stable. Unfortunately, there is not much activity and I am aware that there are still some small bugs present on the website, however if anyone has any constructive criticism or comments regarding the Forum Authority it would be absolutely great if you can share with me below .

link: https://forumauthority.com/index.php

python – Mail Crypt Library for Encrypted Email [REVISION]

This is a revised copy of the Mail Crypt library based on the recommendations of the last post, as well as the review of the recommendations from the first post that I didn't understand.
(Last Post) Mail Crypt Library for Encrypted Email
(First post) Mail Crypt CLI Encrypted Email Container for Gmail

Registry change:
1) The try / except block was removed from the / sig tag state so that the end user gets the error.
2) Ungrouped context manager so that public and private keys are handled separately.
3) encrypted message return uses join and hex with for loop instead of .hex after each element.
4) Decrypt message now unzips each item into its own var instead of as a list.
5) Import keys are now unzipped to 2 var instead of listed.
6) get_emails unpacks what is needed in the data and the rest is to go underlined.
7) Created the recovery feature in email to replace 3 identical recovery calls in email.
(get_emails, read_encrypted, read)
8) Keys.export_keys renamed to Keys.save_keys to have symmetric naming.
9) Break the Keys class into CreateKeys, PublicKeysStore, and PersonalKeys.
10) rsa_key_length is no longer a class constant but is now an arg class, change_rsa_key_length
Method removed.
11) split load my keys into get_public and get_private.
12) removed MailCrypt private and public key arguments so keys should now be passed to
encrypt and decrypt function.
13) Decorator of static method added to decrypt the message.
14) Key update method removed from MailCrypt since MailCrypt no longer handles keys.
15) removed the aes_session_key_length constant from MailCrypt, now it's a past argument
in encrypt_msg with a default value of 32.
16) the encrypted message is now a static method.
17) The email class is divided into EmailSMTP and EmailIMAP (grouped according to the server used).
18) The SMTP port is no longer a constant, it can be passed or used by default.
19) The smtp port change method was removed since the port is now an argument.
20) fetch now replaces reading in EmailIMAP.
21) The PublicKey object must now be passed to EmailSMTP to handle public key search.

"""Library for send and receiveing encrypted emails."""

import pickle
import email
import imaplib
import smtplib
from Crypto.Hash import SHA512
from Crypto.Cipher import PKCS1_OAEP
from Crypto.Cipher import AES
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
from Crypto.Signature import pss


class MailCrypt:
    """Core compents for encryption/decryption and key generation."""
    @staticmethod
    def encrypt_msg(message, recpient_public_key, private_key, aes_session_key_length=32):
        """Generates a session key to use with AES to encrypt the message, then
            encrypts the session key with the recipients public key. Everything
            is returned in hex format to be better sent over email."""
        session_key = get_random_bytes(aes_session_key_length)
        aes_cipher = AES.new(session_key, AES.MODE_EAX)
        aes_cipher_text, tag = aes_cipher.encrypt_and_digest(message)
        pub = PKCS1_OAEP.new(recpient_public_key).encrypt(session_key)
        priv = pss.new(private_key).sign(SHA512.new(message))

        return ' '.join(
            part.hex() for part in (
                aes_cipher_text,
                tag,
                aes_cipher.nonce,
                pub,
                priv,
            )
        )

    @staticmethod
    def decrypt_msg(message, sender_public_key, private_key):
        """Splits the message into its sections
            Decrypts the session key, then decrypts the message body.
            If aes_cipher.verify throws an error that means an invalid
                tag was provided
            If pss.new throws an error that means the message signature
                is invalid"""
        aes_cipher_text, tag, nonce, enc_session_key, signature = (
            value.encode().fromhex(value)
            for value in message.split(' '))

        aes_cipher = AES.new(
            PKCS1_OAEP.new(private_key).decrypt(enc_session_key),
            AES.MODE_EAX,
            nonce=nonce,
        )
        clear_text = aes_cipher.decrypt(aes_cipher_text)

        aes_cipher.verify(tag)
        pss.new(sender_public_key).verify(SHA512.new(clear_text), signature)

        return clear_text


class PublicKey:
    """Handles public key storage and retrieval."""
    def __init__(self):
        self.key_dict = {}

    def load_keys(self):
        """Read public keys in from file. Must be in same folder
            as script is run from."""
        with open('public_key_bank.pkl', 'rb') as fpublic_key_file:
            self.key_dict = pickle.load(fpublic_key_file)

    def save_keys(self):
        """Saves key_dict to file."""
        with open('public_key_bank.pkl', 'wb') as fpublic_key_file:
            pickle.dump(self.key_dict, fpublic_key_file)

    def add_key(self, address, key):
        """Adds key to to key_dict."""
        self.key_dict(address) = key

    def retreive_key(self, address):
        """Retrieves public key based on email."""
        return RSA.import_key(self.key_dict(address))

    def remove_key(self, address):
        """Removes key from dict"""
        self.key_dict.pop(address)


class PersonalKeys:
    """Handles users public and private keys."""
    def __init__(self):
        self.my_private_key = None
        self.my_public_key = None

    def get_private(self, passwd):
        """Loads private key in from file."""
        with open('private_key.pem', 'r') as fprivate_key_save:
            self.my_private_key = RSA.import_key(fprivate_key_save.read(), passphrase=passwd)

    def get_public(self):
        """Loads public key in from file."""
        with open('my_public_key.pem', 'r') as fpublic_key_save:
            self.my_public_key = RSA.import_key(fpublic_key_save.read())


class CreateKeys:
    """Handles key pair creation and storage."""
    def __init__(self, rsa_key_length=4096):
        self.rsa_key_length = rsa_key_length

    def generate_keys(self, passwd):
        """Generates public and private key pairs and exports them as .pem files."""
        private_key = RSA.generate(self.rsa_key_length)
        public_key = private_key.publickey()

        with open('my_public_key.pem', 'wb') as fpub:
            fpub.write(public_key.export_key('PEM'))

        with open('private_key.pem', 'wb') as fpri:
            fpri.write(private_key.export_key('PEM', passphrase=passwd))

    def generate_keys_test(self):
        """"Used for testing, returns key pair."""
        private_key = RSA.generate(self.rsa_key_length)
        public_key = private_key.publickey()
        return private_key, public_key


class EmailSMTP:
    """Handles the SMTP functionality."""
    def __init__(self, username, passwd, server_address, pub_key_obj, per_key_obj, port=465):
        self.smtp = smtplib.SMTP_SSL(server_address, port)
        self.smtp.ehlo()
        self.username = username
        self.smtp.login(username, passwd)
        self.publickeys = pub_key_obj
        self.private = per_key_obj

    def close_connection(self):
        """Closes connection to server."""
        self.smtp.close()

    def send(self, recipient, message):
        """Sends plain text email."""
        self.smtp.sendmail(self.username, recipient, message)

    def send_encrypted(self, recipient, message):
        """Sends encrypted message."""
        message = MailCrypt.encrypt_msg(message.encode(),
                                        self.publickeys.retreive_key(recipient),
                                        self.private.my_private_key)

        self.smtp.sendmail(self.username, recipient, message)

    def share_public_key(self, recipient):
        """Sends public key."""
        self.send(recipient, self.private.my_public_key.export_key('PEM'))


class EmailIMAP:
    """Handles the IMAP sever funcionality"""
    def __init__(self, username, passwd, server_address):
        self.imap = imaplib.IMAP4_SSL(server_address)
        self.imap.login(username, passwd)
        self.imap.select('inbox')

    def close_connection(self):
        """Logs out and closes connection to the server"""
        self.imap.logout()
        self.imap.close()

    def get_emails(self):
        """Yeilds uid and senders address for every message
            in the inbox folder."""
        _, data, *_ = self.imap.uid('search', None, 'ALL')
        for uid in data(0).decode().split(' '):
            sender, _ = self.fetch(uid)
            yield uid, sender

    def fetch(self, uid):
        """returns sender address and message payload"""
        _, email_data = self.imap.uid('fetch', uid, '(RFC822)')
        msg = email.message_from_bytes(email_data(0)(1))
        return msg('From'), msg.get_payload()

    def read_encrypted(self, uid, sender_public, private):
        """Fetches email from given uid and returns clear text."""
        _, payload = self.fetch(uid)
        return MailCrypt.decrypt_msg(payload, sender_public, private)

    def mark_delete(self, uid):
        """Moves the specified email to trash folder. If useing email
            provider other than gmail 'Trash' needs to be changed to
            whatever folder that service uses."""
        self.imap.uid('store', uid, '+X-GM-LABELS', '(\Trash)')

    def delete_all(self):
        """Empties the trash folder."""
        self.imap.expunge()

    def import_key(self):
        """Checks message payloads for public keys, if found it
            yeilds the senders email address and the public key."""
        for uid, sender in self.get_emails():
            sender, msg_body = self.fetch(uid)
            if 'PUBLIC' in msg_body:
                yield sender, msg_body

8 – How to programmatically translate node with correct revision translation affected value?

I have a question about creating node translation programmatically.

First off, the following is the database screenshot when we use the drupal user interface to create the translation.

the revision_translation_affected it will be set to the language each time the new one is created.

For example, I create an article in English and then translate it into Chinese.

enter the image description here

We can see that the affected revision translation has been configured with the Chinese version because the translation is the latest one created.

However, I use the following code to create a node and add the translation.

$post = Drupal::entityTypeManager()->getStorage('node')->create(
        (
            'type' => 'page',
            'title' => 'test title',
            'langcode' => 'en'
        )
    );
    $post->save();
    $source_translation = $post->getTranslation('en');
    $target_translation = $post->addTranslation('zh-hant', $source_translation->toArray());
    $target_translation->save();

I got the following result from the database

enter the image description here

This result will cause confusion in the revision when we want to see the revision record of each translation.

Does anyone have experience on how to handle this problem?

svn – No such revision subversion exists

We use version svn 1.6.12. After retrieving lvm on the machine, an error occurs while connecting: svn: E160006: There is no such revision 12526. In the revs directory there is no such revision 12526 as others since 7739 and many others. I can't dump and sync, because it constantly gets interrupted on non-existent revisions. The interesting thing is that in the revprops folder there are these numbers, which are absent in revolutions. Please tell me, how can I restore the repository?
Thank you.

entities – Where to update the affected revision translation?

In a custom entity that I created, I notice that when I see your revision history, it mixes with the revisions of other languages. I noticed that the node is doing this check but finding out if revision_translation_affected is set to 1. On the node, it is set to 1 when the revision language is edited and is null when it is not.

For some reason, it is always set to 1 for my custom entity, but I have no idea where to change it.

plugins – WP is missing the first revision with wp_get_post_revisions ()

I am using native WordPress reviews and have encountered a small problem.

I want to return a list of revisions to the page, however, my first published content is lost every time I make a change.

The best way to demonstrate this is with images from the database:

When I create a note for the first time, everything looks good:

enter the description of the image here

When I edit this note in the back end, this is what changes:

enter the description of the image here

Do you see how the original content was lost with the "1"? This is not OK! How can I allow revisions to store that first bit of data too?


Note: This is what happens when I add a third party. Even so, that initial post with "1" in the content is lost:

enter the description of the image here

What can I do to avoid this?

I tried:

  1. Looking at the parameters for wp_get_post_revisions() but there is none
  2. I looked for other questions about SO, nothing.
  3. I looked for any type of add-on (the add-ons seem a bit dead in WP today!)
  4. I looked for some kind of hook, I can do something personalized, but I'm not sure about this

Is the list linked to the database a good architecture for the response and revision system when using mongodb?

I want to create a system of user comments and responses to comments on a website. There may be answers to the answers. I am using the mongodb database, which I think is an important detail.

The review document looks more or less like this:

{
  review: {
    reviewid: String,
    userid: String,
    reviewRating: Int,
    reviewContent: String,
    replies: (Reply)
  }

}

The response object looks like this:

{
  reply: {
    userid: String,
    reviewid: String,
    replyid: String,
    replyContent: String
  }
}

I am not sure which route to take with how to store user responses. On the one hand, it will be very convenient to store a variety of response objects in the review document (1). On the other hand, I think it will be more stable and organized to save the responses as separate documents in db (2).

In case 1 I get the benefit of mongodb flexibility and I won't need to do db searches.

In case 2 I thought to add previous: ObjectId Y next: ObjectId fields to each answer. Then, the review will only be linked to the first response of the chain. In case 2, there will be more searches for answers, since I will have to repeat next all the time. However, it will not take long to get the next answer because mongodb creates an index in the identification fields by default. Another disadvantage is that, to count the number of responses per review, I will have to perform as many db searches as db unless I keep the count as a field under review and make sure to increase / decrease it every time. (More complexity).

So, at first glance, the first route is better in terms of performance. The main disadvantage is that the order of the responses is a bit volatile in the sense that it is just a matrix. I also instinctively feel that the first route is "flimsy" because the answers are not a real document in the database without its own identification.

I am looking for suggestions on what would be the best practice here.

Paragraphs: How do you reorder an entity reference revision field during hook_node_presave?

I am trying to reorder some paragraphs based on a text field within them in the node save so that the author does not need to maintain the alphabetical order manually, but when I save the node all the values ​​are lost. I tried to match the array of $ node-> get (& # 39; field_paragraphs & # 39;) -> getValue (), but that doesn't seem to work.

function mymodule_node_presave(NodeInterface $node) {
  if ($node->bundle() == 'page' && $node>get('field_paragraphs')->count() > 1) {
    $values = $node->get('field_paragraphs')->getValue();
    $entities = $node->get('field_paragraphs')->referencedEntities();
    uasort($entities, function ($a, $b) {
      return Unicode::strcasecmp($a->get('field_text')->value, $b->get('field_text')->value);
    });

    $new_values = ();
    foreach ($entities as &$entity) {
    $id = $entity->id();
    $new_value = (
      'target_id' => $id,
      'target_revison_id' => $entity->getRevisionId(),
    );
    $index = array_search($id, array_column($values, 'target_id'));
    if (FALSE !== $index && isset($values($index)('subform'))) {
      $new_value('subform') = $values($index)('subform');
    }
    $new_values() = $new_value;
  }

  $node->set('field_paragraphs', $new_values);
}

8 – How do I make the custom entity create a new revision by default?

In addition to the 4k4 response here, which is very good and specific, a co-worker helped me reach another solution to cancel ContentEntityForm::buildForm function:

class MyEntityForm extends ContentEntityForm {

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form('revision') = (
      '#type' => 'value',
      '#default_value' => TRUE,
    );
  }
}

The benefit of canceling the buildForm The function is that it can have a little more form specific logic, e.g. turning it into a hidden value or a checkbox.

SpendJeffBezosMoney.com; For revision

Hello, I would love to receive comments from a new website that I just launched.

It's nothing very serious: www [DOT] pasarjeffbezosmoney [DOT] com /

The concept is very simple. I just want to know your opinions about ad placements. And maybe compare the browsing experience from the computer to the smartphone.

Also, maybe take a look at the merchandising page; www [DOT] pasarjeffbezosmoney [DOT] com / merch /

Just make sure all pages flow naturally, etc. Any comment is welcomed.

Thank you