示例#1
0
 /**
  * Initialize all variables used by Peg. Has to be called before any usage
  * of peg.
  */
 public static function Initialize()
 {
     // Initialize the plugin loader and try to load any plugins.
     self::$plugin_loader = new Plugins\Loader();
     if (self::ValidExtension()) {
         self::$plugin_loader->Start(self::GetCwd() . "/plugins");
         if (file_exists(self::GetCwd() . "/peg.conf")) {
             Settings::SetBackEnd(new Config\INI());
             Settings::Load(self::GetCwd(), "peg.conf");
         } else {
             Settings::SetBackEnd(new Config\JSON());
             Settings::Load(self::GetCwd(), "peg.json");
         }
     }
 }
*  as-is and without warranty under the MIT License. See
*  [root]/license.txt for more. This information must remain intact.
*/
require_once '../../common.php';
require_once 'class.settings.php';
if (!isset($_GET['action'])) {
    die(formatJSEND("error", "Missing parameter"));
}
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////
checkSession();
$Settings = new Settings();
//////////////////////////////////////////////////////////////////
// Save User Settings
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'save') {
    if (!isset($_POST['settings'])) {
        die(formatJSEND("error", "Missing settings"));
    }
    $Settings->username = $_SESSION['user'];
    $Settings->settings = json_decode($_POST['settings'], true);
    $Settings->Save();
}
//////////////////////////////////////////////////////////////////
// Load User Settings
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'load') {
    $Settings->username = $_SESSION['user'];
    $Settings->Load();
}
 function __construct($query, $boundary, $logpass, $shellManager, $type = "htmle", $auto = true)
 {
     global $translation;
     $this->query = $query;
     $this->files = isset($_POST['files']) ? $_POST['files'] : null;
     $this->outserver = isset($_POST['outserver']) ? $_POST['outserver'] : null;
     $this->saveInTxtLog = isset($_POST['saveLogInTxt']) && $_POST['saveLogInTxt'] == "true" ? true : false;
     if (SERVICEMODE) {
         $this->outserver = null;
     }
     $this->output = "";
     $this->shellManager = $shellManager;
     if (!$auto) {
         return;
     }
     if ($this->query == "preview") {
         if (SERVICEMODE) {
             if ($type == "text") {
                 $_POST['text'] = $translation->getWord("service-warning-text") . PHP_EOL . $_POST['text'];
             } else {
                 $_POST['text'] = "<div style='color:red;font-weight:bold;'>" . $translation->getWord("service-warning-text") . "</div>" . $_POST['text'];
             }
         }
         $email = EmailSender::makeEmail($_POST['to'], $_POST['fromname'], $_POST['frommail'], $_POST['replymail'], $_POST['tema'], $_POST['additional'], $_POST['text'], $_POST['enumer'], $this->query == "preview");
         $this->output = $email->text;
         return;
     }
     if ($this->query == "send") {
         $emailSender = new EmailSender();
         if (SERVICEMODE) {
             if ($type == "text") {
                 $_POST['text'] = $translation->getWord("service-warning-text") . PHP_EOL . $_POST['text'];
             } else {
                 $_POST['text'] = "<div style='color:red;font-weight:bold;'>" . $translation->getWord("service-warning-text") . "</div>" . $_POST['text'];
             }
         }
         $emailSender->Send($type, $this->files, $this->outserver, $boundary, array('to' => $_POST['to'], 'fromname' => $_POST['fromname'], 'frommail' => $_POST['frommail'], 'replymail' => $_POST['replymail'], 'tema' => $_POST['tema'], 'additional' => $_POST['additional'], 'text' => $_POST['text'], 'sendInBase64' => $_POST['sendInBase64'] == "true", 'enumer' => $_POST['enumer']));
         $this->output = $emailSender->getOutput();
         if ($this->saveInTxtLog) {
             $this->saveToTxtLog($this->output);
         }
         return;
     }
     if ($this->query == "sendFromTemplate") {
         if (SERVICEMODE) {
             return;
         }
         $emailSender = new EmailSender();
         $emailSender->SendFromTemplate($_POST['template'], $_POST['to'], $this->outserver, $boundary);
         $this->output = $emailSender->getOutput();
         if ($this->saveInTxtLog) {
             $this->saveToTxtLog($this->output);
         }
         return;
     }
     if ($this->query == "upload_universal") {
         $this->output = TransferIface::uploadFile(isset($_FILES['elist']) ? $_FILES['elist'] : null);
         return;
     }
     if ($this->query == "savedata") {
         $this->output = TransferIface::downloadFile(isset($_POST['savedata']) ? $_POST['savedata'] : null, $_POST['filename']);
         return;
     }
     if ($this->query == "changepass") {
         if (SERVICEMODE) {
             return;
         }
         $this->output = $this->changePass($_POST['login'], $_POST['pass'], $logpass);
         return;
     }
     if ($this->query == "pingoutserver") {
         if (SERVICEMODE) {
             return;
         }
         $this->output = Shell::check($_POST['server']);
         return;
     }
     if ($this->query == "linesinfile") {
         if (SERVICEMODE) {
             return;
         }
         $this->output = AMUtil::linesInFile($_POST['file_path']);
         return;
     }
     if ($this->query == "saveSettings") {
         if (SERVICEMODE) {
             return;
         }
         $result = Settings::Save($_POST['settings']);
         if ($result) {
             $this->output = $translation->getWord("settings-saved");
         } else {
             $this->output = $translation->getWord("settings-save-error");
         }
         return;
     }
     if ($this->query == "removeSettings") {
         if (SERVICEMODE) {
             return;
         }
         Settings::Remove();
         $this->output = $translation->getWord("settings-removed");
         return;
     }
     if ($this->query == "loadSettings") {
         $data = Settings::Load();
         if (!$data) {
             $this->output = "";
         } else {
             $this->output = $data;
         }
         return;
     }
     if ($this->query == "sendInBackground") {
         if (SERVICEMODE) {
             return;
         }
         $emailSender = new EmailSender();
         $outservers = isset($_POST['outservers']) ? explode("\n", $_POST['outservers']) : array();
         $additional = array();
         foreach ($_POST['additional'] as $n => $values) {
             $additional[$n] = explode("\n", $values);
         }
         $emailSender->sendInBackground($_POST['type'], $_POST['files'], $boundary, $outservers, $_POST['timeout'], array('to' => explode("\n", $_POST['to']), 'fromname' => explode("\n", $_POST['fromname']), 'frommail' => explode("\n", $_POST['frommail']), 'replymail' => explode("\n", $_POST['replymail']), 'subject' => explode("\n", $_POST['subject']), 'additional' => $additional, 'text' => $_POST['text'], 'sendInBase64' => $_POST['sendInBase64'], 'randomTimeout' => $_POST['randomTimeout'], 'enumer' => null));
         //NO RETURN ^_^
     }
     if ($this->query == "getBackgroundState") {
         if (SERVICEMODE) {
             return;
         }
         $this->output = json_encode(EmailSender::loadState());
         return;
     }
     if ($this->query == "setBackgroundState") {
         if (SERVICEMODE) {
             return;
         }
         $this->output = EmailSender::setState($_POST['isRunning'] == "true");
         return;
     }
     if ($this->query == "selfDiagnostics") {
         //if(SERVICEMODE) return;
         $this->output = $this->selfDiagnostics();
         return;
     }
 }
 /**
  * dbConnection::__construct()
  * Reads settings from the default settings file and creates the connection.
  * @param String $useAlternative Alternative settings file
  */
 function __construct($instanceName = 'Database')
 {
     $this->adapter = $this->getAdapter(Settings::Load()->Get($instanceName));
     $this->debug = Settings::Load()->Get($instanceName, 'debug') === '1';
 }
 /**
  * Logger::dbCheck()
  * Checks if the current database exists, and creates it if it's not there.
  */
 public function dbCheck()
 {
     if (!$this->checked) {
         $this->log[] = "checking if db exists";
         $this->checked = dbConnection::getInstance('Logger')->tableExists(Settings::Load()->Get('Logger', 'logtable'));
         if (!$this->checked) {
             $createquery = $this->createqueries[strtolower(Settings::Load()->Get('Logger', 'dbtype'))];
             $createquery = str_replace('@logtable@', Settings::Load()->Get('Logger', 'logtable'), $createquery);
             $this->checked = dbConnection::getInstance('Logger')->query($createquery);
             if (!$this->checked) {
                 die("Error creating logdatabase");
             }
             Logger::Log("Log database created.");
         }
     }
 }