HEX
Server: Apache
System: Linux hz.vslconceptsdomains.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: dkfounda (3233)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/local/mailchannels/storage/file/SSHFileStorage.php
<?php

namespace MailChannels;

require_once(dirname(__FILE__) . "/FileStorage.php");

class SSHFileStorage extends FileStorage {
    private $ip;
    private $sshKey;

    public function __construct($ip, $sshKey, $folder='tmp') {
        $this->ip = $ip;
        $this->sshKey = $sshKey;

        parent::__construct($folder);
    }

    public function setInboundConfig(InboundConfig $config) {
        parent::setInboundConfig($config);

        $this->uploadFile(self::INBOUND_CONFIG_FILE);
    }

    public function getInboundConfig() {
        $this->downloadFile(self::INBOUND_CONFIG_FILE);

        return parent::getInboundConfig();
    }

    protected function uploadFile($file) {
        $filePath = "$this->folder/$file";
        $remoteFolderPath = Config::FILE_STORAGE_FOLDER;

        exec("scp -i $this->sshKey $filePath ec2-user@$this->ip:/tmp");
        exec("ssh -i $this->sshKey ec2-user@$this->ip sudo mv /tmp/$file $remoteFolderPath");
    }

    protected function downloadFile($file) {
        $remoteFolderPath = Config::FILE_STORAGE_FOLDER;
        $remoteFilePath = "$remoteFolderPath/$file";

        exec("ssh -i $this->sshKey ec2-user@$this->ip sudo cp $remoteFilePath /tmp");
        exec("scp -i $this->sshKey ec2-user@$this->ip:/tmp/$file $this->folder");
        exec("ssh -i $this->sshKey ec2-user@$this->ip sudo rm /tmp/$file");
    }
}