text:
<?php

namespace Backend\Modules\Profiles\Actions;

use Backend\Core\Engine\Base\ActionAdd as BackendBaseActionAdd;
use Backend\Core\Engine\Form as BackendForm;
use Backend\Core\Language\Language as BL;
use Backend\Core\Engine\Model as BackendModel;
use Backend\Modules\Profiles\Engine\Model as BackendProfilesModel;
use Symfony\Component\Intl\Intl as Intl;

/**
 * This is the add-action, it will display a form to add a new profile.
 */
class Add extends BackendBaseActionAdd
{
    /**
     * @var int
     */
    private $id;

    /**
     * @var bool
     */
    private $notifyAdmin;

    /**
     * @var bool
     */
    private $notifyProfile;

    public function execute(): void
    {
        parent::execute();
        $this->getData();
        $this->loadForm();
        $this->validateForm();
        $this->parse();
        $this->display();
    }

    public function getData(): void
    {
        $this->notifyAdmin = $this->get('fork.settings')->get(
            $this->url->getModule(),
            'send_new_profile_admin_mail',
            false
        );

        $this->notifyProfile = $this->get('fork.settings')->get(
            $this->url->getModule(),
            'send_new_profile_mail',
            false
        );
    }

    private function loadForm(): void
    {
        // gender dropdown values
        $genderValues = [
            'male' => \SpoonFilter::ucfirst(BL::getLabel('Male')),
            'female' => \SpoonFilter::ucfirst(BL::getLabel('Female')),
        ];

        // birthdate dropdown values
        $days = range(1, 31);
        $months = \SpoonLocale::getMonths(BL::getInterfaceLanguage());
        $years = range(date('Y'), 1900);

        // create form
        $this->form = new BackendForm('add');

        // create elements
        $this->form
            ->addText('email')
            ->setAttribute('type', 'email')
        ;
        $this->form->addPassword('password');
        $this->form->addText('display_name');
        $this->form->addText('first_name');
        $this->form->addText('last_name');
        $this->form->addText('city');
        $this->form->addDropdown('gender', $genderValues);
        $this->form->addDropdown('day', array_combine($days, $days));
        $this->form->addDropdown('month', $months);
        $this->form->addDropdown('year', array_combine($years, $years));
        $this->form->addDropdown('country', Intl::getRegionBundle()->getCountryNames(BL::getInterfaceLanguage()));

        // set default elements dropdowns
        $this->form->getField('gender')->setDefaultElement('');
        $this->form->getField('day')->setDefaultElement('');
        $this->form->getField('month')->setDefaultElement('');
        $this->form->getField('year')->setDefaultElement('');
        $this->form->getField('country')->setDefaultElement('');
    }

    private function validateForm(): void
    {
        // is the form submitted?
        if ($this->form->isSubmitted()) {
            // cleanup the submitted fields, ignore fields that were added by hackers
            $this->form->cleanupFields();

            // get fields
            $txtEmail = $this->form->getField('email');
            $txtDisplayName = $this->form->getField('display_name');
            $txtPassword = $this->form->getField('password');
            $txtFirstName = $this->form->getField('first_name');
            $txtLastName = $this->form->getField('last_name');
            $txtCity = $this->form->getField('city');
            $ddmGender = $this->form->getField('gender');
            $ddmDay = $this->form->getField('day');
            $ddmMonth = $this->form->getField('month');
            $ddmYear = $this->form->getField('year');
            $ddmCountry = $this->form->getField('country');

            // email filled in?
            if ($txtEmail->isFilled(BL::getError('EmailIsRequired'))) {
                // valid email?
                if ($txtEmail->isEmail(BL::getError('EmailIsInvalid'))) {
                    // email already exists?
                    if (BackendProfilesModel::existsByEmail($txtEmail->getValue())) {
                        // set error
                        $txtEmail->addError(BL::getError('EmailExists'));
                    }
                }
            }

            // display name filled in?
            if ($txtDisplayName->isFilled(BL::getError('DisplayNameIsRequired'))) {
                // display name already exists?
                if (BackendProfilesModel::existsDisplayName($txtDisplayName->getValue())) {
                    // set error
                    $txtDisplayName->addError(BL::getError('DisplayNameExists'));
                }
            }

            // profile must not be notified, password must not be empty
            if (!$this->notifyProfile) {
                $txtPassword->isFilled(BL::err('FieldIsRequired'));
            }

            // one of the birthday fields are filled in
            if ($ddmDay->isFilled() || $ddmMonth->isFilled() || $ddmYear->isFilled()) {
                // valid date?
                if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) {
                    // set error
                    $ddmYear->addError(BL::getError('DateIsInvalid'));
                }
            }

            // no errors?
            if ($this->form->isCorrect()) {
                $password = ($txtPassword->isFilled()) ?
                    $txtPassword->getValue() : BackendModel::generatePassword(8);

                // build item
                $values = [
                    'email' => $txtEmail->getValue(),
                    'registered_on' => BackendModel::getUTCDate(),
                    'display_name' => $txtDisplayName->getValue(),
                    'url' => BackendProfilesModel::getUrl($txtDisplayName->getValue()),
                    'last_login' => BackendModel::getUTCDate(null, 0),
                    'password' => BackendProfilesModel::encryptPassword($password),
                ];

                $this->id = BackendProfilesModel::insert($values);

                // bday is filled in
                if ($ddmYear->isFilled()) {
                    // mysql format
                    $birthDate = $ddmYear->getValue() . '-';
                    $birthDate .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-';
                    $birthDate .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT);
                } else {
                    // not filled in
                    $birthDate = null;
                }

                // update settings
                BackendProfilesModel::setSetting($this->id, 'first_name', $txtFirstName->getValue());
                BackendProfilesModel::setSetting($this->id, 'last_name', $txtLastName->getValue());
                BackendProfilesModel::setSetting($this->id, 'gender', $ddmGender->getValue());
                BackendProfilesModel::setSetting($this->id, 'birth_date', $birthDate);
                BackendProfilesModel::setSetting($this->id, 'city', $txtCity->getValue());
                BackendProfilesModel::setSetting($this->id, 'country', $ddmCountry->getValue());

                // notify values
                $notifyValues = array_merge(
                    $values,
                    [
                        'id' => $this->id,
                        'first_name' => $txtFirstName->getValue(),
                        'last_name' => $txtLastName->getValue(),
                        'unencrypted_password' => $password,
                    ]
                );

                $redirectUrl = BackendModel::createUrlForAction('Edit') .
                               '&id=' . $this->id .
                    '&var=' . rawurlencode($values['display_name']) .
                    '&report='
                ;

                // notify new profile user
                if ($this->notifyProfile) {
                    BackendProfilesModel::notifyProfile($notifyValues);

                    $redirectUrl .= 'saved-and-notified';
                } else {
                    $redirectUrl .= 'saved';
                }

                // notify admin
                if ($this->notifyAdmin) {
                    BackendProfilesModel::notifyAdmin($notifyValues);
                }

                // everything is saved, so redirect to the overview
                $this->redirect($redirectUrl);
            }
        }
    }

    protected function parse(): void
    {
        parent::parse();

        $this->template->assign('notifyProfile', $this->notifyProfile);
    }
}


text:
/***
* Inferno Engine v4 2015-2017
* Written by Tomasz "Rex Dex" Jonarski
*
* [#filter: platform\pipe\posix #]
* [#platform: posix #]
***/

#include "build.h"
#include "process.h"
#include "base/system/include/thread.h"
#include "pipePOSIX.h"
#include <sys/stat.h>
#include <uuid/uuid.h>
#include <fcntl.h>

namespace base
{
    namespace process
    {
        namespace prv
        {

            //--

            namespace helper
            {
                static void GetSystemPipeName(const AnsiChar *pipeName, AnsiChar *fullName)
                {
                    // compose a pipe name
                    if (nullptr == pipeName)
                    {
                        uuid_t id;
                        uuid_generate_random(id);

                        strcpy_s(fullName, "/tmp/");
                        uuid_unparse_lower(id, fullName + 5);
                    }
                    else
                    {
                        sprintf(fullName, "/tmp/%s", pipeName);
                    }
                }

                static const char* GetEnginePipeName(const AnsiChar* systemPipeName)
                {
                    FATAL_ASSERT(0 == strncmp(systemPipeName, "/tmp/", 5));
                    return systemPipeName + 5;
                }
            }

            //--

            POSIXPipeWriter::POSIXPipeWriter()
                : m_handle(-1)
            {}

            POSIXPipeWriter::~POSIXPipeWriter()
            {
                close();

                FATAL_ASSERT_EX(m_handle == -1, "Pipe not closed properly");
            }

            POSIXPipeWriter* POSIXPipeWriter::Create()
            {
                // get the system name for the pipe
                char fullName[128];
                helper::GetSystemPipeName(nullptr, fullName);

                // open the fifo
                if (0 != mkfifo(fullName, 0777))
                {
                    TRACE_ERROR("Failed to create pipe '{}': {}", fullName, errno);
                    return nullptr;
                }

                // open the pipe for writing
                auto handle = open(fullName, O_RDWR | O_NONBLOCK);
                if (handle == -1)
                {
                    TRACE_ERROR("Unable to open pipe '{}' for writing: {}", fullName, errno)
                    return nullptr;
                }

                // create
                auto* ret = MemNew(POSIXPipeWriter);
                ret->m_handle = handle;
                strcpy_s(ret->m_name, fullName);

                // return
                TRACE_INFO("Created writing end of pipe '{}'", ret->getName());
                return ret;
            }

            POSIXPipeWriter* POSIXPipeWriter::Open(const AnsiChar* pipeName)
            {
                char fullName[128];
                helper::GetSystemPipeName(pipeName, fullName);

                // open the pipe for writing
                auto handle = open(fullName, O_WRONLY | O_NONBLOCK);
                if (handle == -1)
                {
                    TRACE_ERROR("Unable to open pipe '{}' for writing: {}", fullName, errno)
                    return nullptr;
                }

                // create
                auto* ret = MemNew( POSIXPipeWriter);
                ret->m_handle = handle;
                strcpy_s(ret->m_name, fullName);

                // return
                TRACE_INFO("Opened writing end of pipe '{}'", ret->getName());
                return ret;
            }

            void POSIXPipeWriter::close()
            {
                if (m_handle != -1)
                {
                    TRACE_INFO("Closed writing end of pipe '{}'", getName());
                    ::close(m_handle);
                    m_handle = -1;
                }
            }

            const AnsiChar* POSIXPipeWriter::getName() const
            {
                return helper::GetEnginePipeName(m_name);
            }

            const Bool POSIXPipeWriter::isOpened() const
            {
                return (m_handle != -1);
            }

            const Uint32 POSIXPipeWriter::write(const void* data, const Uint32 size)
            {
                if (!size)
                    return 0;

                if (m_handle == -1)
                    return 0;

                const auto ret = ::write(m_handle, data, size);
                if (ret == -1)
                {
                    TRACE_ERROR("Writing end of pipe '{}' lost", getName());
                    return 0;
                }

                return ret;
            }

            //--

            POSIXPipeReader::POSIXPipeReader()
                : m_handle(-1)
                , m_readThread(0)
                , m_requestExit(false)
                , m_callback(nullptr)
            {}

            POSIXPipeReader::~POSIXPipeReader()
            {
                close();

                FATAL_ASSERT_EX(m_handle == -1, "Pipe not closed properly");
                FATAL_ASSERT_EX(m_readThread == 0, "Pipe not closed properly");
            }

            POSIXPipeReader* POSIXPipeReader::Create(IOutputCallback* callback)
            {
                // get the system name for the pipe
                char fullName[128];
                helper::GetSystemPipeName(nullptr, fullName);

                // open the fifo
                if (0 != mkfifo(fullName, 0666))
                {
                    TRACE_ERROR("Failed to create pipe '{}': {}", fullName, errno);
                    return nullptr;
                }

                // open the pipe for writing
                return OpenNative(fullName, callback);
            }

            POSIXPipeReader* POSIXPipeReader::Open(const AnsiChar* pipeName, IOutputCallback* callback)
            {
                if (!pipeName || !*pipeName)
                {
                    TRACE_ERROR("Invalid pipe name specified");
                    return nullptr;
                }

                char fullName[128];
                helper::GetSystemPipeName(pipeName, fullName);
                return OpenNative(fullName, callback);
            }

            POSIXPipeReader* POSIXPipeReader::OpenNative(const AnsiChar* fullName, IOutputCallback* callback)
            {
                // open the pipe for writing
                auto handle = open(fullName, O_RDONLY | O_NONBLOCK);
                if (handle == -1)
                {
                    TRACE_ERROR("Unable to open pipe '{}' for reading: {}", fullName, errno)
                    return nullptr;
                }

                // create wrapper
                auto* ret = MemNew(POSIXPipeReader);
                ret->m_handle = handle;
                ret->m_requestExit = false;
                strcpy_s(ret->m_name, fullName);

                // start reading thread
                if (callback != nullptr)
                {
                    ret->m_callback = callback;

                    // create thread
                    pthread_attr_t attrs;
                    pthread_attr_init(&attrs);
                    pthread_attr_setstacksize(&attrs, 4096);
                    pthread_create(&ret->m_readThread, &attrs, &POSIXPipeReader::ThreadFunc, ret);
                    pthread_attr_destroy(&attrs);

                    // failed to create thread ?
                    if (0 == ret->m_readThread)
                    {
                        TRACE_ERROR("Unable to create reading thread for pipe '{}': {}", fullName, errno)
                        delete ret;
                        return nullptr;
                    }

                    // name the thread
                    pthread_setname_np(ret->m_readThread, "PipeReaderThread");
                }

                TRACE_INFO("Opened reading end of pipe '{}'", ret->getName());
                return ret;
            }

            void POSIXPipeReader::close()
            {
                if (m_handle != -1)
                {
                    // request exit
                    m_requestExit = true;

                    // close the handle
                    TRACE_INFO("Closed reading end of pipe '{}'", getName());
                    ::close(m_handle);
                    m_handle = -1;

                    // wait for thread
                    if (m_readThread != 0)
                    {
                        pthread_join(m_readThread, nullptr);
                        m_readThread = 0;
                    }
                }
            }

            const AnsiChar* POSIXPipeReader::getName() const
            {
                return helper::GetEnginePipeName(m_name);
            }

            const Bool POSIXPipeReader::isOpened() const
            {
                return (m_handle != -1);
            }

            const Uint32 POSIXPipeReader::read(void* data, const Uint32 size)
            {
                // we have a thread to read
                if (nullptr != m_callback)
                    return 0;

                // lost
                if (m_handle == -1)
                    return 0;

                // read
                const auto ret = ::read(m_handle, data, size);
                if (ret == -1)
                {
                    if (errno == EAGAIN)
                        return 0;

                    TRACE_ERROR("Unable to read content from pipe '{}': {}", getName(), errno)
                    ::close(m_handle);
                    m_handle = -1;
                    return 0;
                }

                // return number of bytes read
                return ret;
            }

            void* POSIXPipeReader::ThreadFunc(void* param)
            {
                auto* pipe = (POSIXPipeReader*)param;

                std::vector<Uint8> asyncBuffer;
                asyncBuffer.resize(512 * 1024);

                while (!pipe->m_requestExit)
                {
                    // wait for data
                    const auto ret = ::read(pipe->m_handle, asyncBuffer.data(), asyncBuffer.size());
                    if (ret == -1)
                    {
                        if (errno == EAGAIN)
                            continue;

                        TRACE_WARNING("Pipe '{}' abruptly closed: {}", pipe->getName(), errno);
                        break;
                    }

                    // send to callback
                    if (ret > 0)
                        pipe->m_callback->processData(asyncBuffer.data(), ret);
                }

                return nullptr;
            }

            //--

        } // prv
    } // process
} // base

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE html>

	Your organization has been declined. Please contact info@code4socialgood.org for more information.