Beispiel #1
0
 /**
  * Delete layout
  */
 public function delete()
 {
     //! check input
     if (empty($this->id)) {
         throw new \Exception(L('No layout id'));
     }
     if (empty(Core::$user->id) || !Core::$user->has("siteadm")) {
         throw new \Exception(L('No user id'));
     }
     Core::log('A', sprintf("Layout %s deleted by %s", $this->id, Core::$user->name), "cmsaudit");
     DS::exec("DELETE FROM " . static::$_table . " WHERE id=?", [$this->id]);
     DS::exec("DELETE FROM " . Page::$_table . "_list WHERE page_id IN (SELECT id FROM pages WHERE template=?)", [$this->id]);
     DS::exec("DELETE FROM " . Page::$_table . " WHERE template=?", [$this->id]);
 }
Beispiel #2
0
 function init($cfg)
 {
     //! defaults
     if (empty($cfg["sqldir"])) {
         $cfg["sqldir"] = "data/temp";
     }
     if (empty($cfg["pagesdir"])) {
         $cfg["pagesdir"] = "pages";
     }
     $this->pagesdir = $cfg["pagesdir"];
     //! if it's a special sql refresh request
     if (Core::$core->url == "sqlrefresh" || isset($_REQUEST["sqlrefresh"])) {
         //look data source
         if (!DS::db()) {
             die("ERROR: no db");
         }
         //read the changes
         $sqlFiles = @glob($cfg["sqldir"] . "/sqlchanges-*.sql");
         foreach ($sqlFiles as $sf) {
             //get sql commands from file
             $sqls = str_getcsv(@file_get_contents($sf), ";");
             @unlink($sf);
             //execute one by one
             foreach ($sqls as $query) {
                 DS::exec($query);
             }
         }
         die("OK");
     }
     //! check if there's a CMS generated file for the url
     //! if so, add route for it
     $c = @explode("/", Core::$core->url);
     while (!empty($c)) {
         $f = implode("-SLASH-", $c);
         if (file_exists($cfg["pagesdir"] . "/" . $f . ".php")) {
             self::$page = $cfg["pagesdir"] . "/" . $f . ".php";
             Http::route(Core::$core->url, "\\PHPPE\\EplosCMS");
             break;
         }
         //if not found, put last part in parameters array
         self::$params[] = array_pop($c);
     }
     //reverse the parameters as they were popped in reverse order
     self::$params = @array_reverse(self::$params);
     return true;
 }
Beispiel #3
0
 /**
  * Cron job to read mails from queue and send them out
  */
 public function cronMinute($item)
 {
     //! get real mailer backend ($core->mailer points to db queue backend)
     // @codeCoverageIgnoreStart
     if (empty(Core::$core->realmailer)) {
         Core::log('C', L('Real mailer backend not configured!'));
     }
     // @codeCoverageIgnoreEnd
     //! get items from database
     $lastId = 0;
     while ($row = DS::fetch('*', 'email_queue', 'id>?', '', 'id ASC', [$lastId])) {
         $email = new self($row['data']);
         $lastId = $row['id'];
         try {
             if (!$email->send(Core::$core->realmailer)) {
                 // @codeCoverageIgnoreStart
                 throw new \Exception('send() returned false');
             }
             DS::exec('DELETE FROM email_queue WHERE id=?;', [$row['id']]);
         } catch (\Exception $e) {
             Core::log('E', sprintf(L('Unable to send #%s from queue'), $row['id']) . ': ' . $e->getMessage());
         }
         // @codeCoverageIgnoreEnd
         sleep(1);
     }
 }
Beispiel #4
0
 public static function arr2str($o, $s = '', $c = ' ')
 {
     if (!is_array($s)) {
         $s = str_getcsv($s, ',');
     }
     $r = '';
     $d = DS::db();
     if (is_string($o)) {
         $o = [$o];
     }
     foreach ($o as $k => $v) {
         if (!in_array($k, $s)) {
             $r .= ($r ? $c : '') . $k . '=' . ($c == ',' && !empty($d) ? $d->quote($v) : "'" . str_replace(["\r", "\n", "\t", ""], ['\\r', '\\n', '\\t', '\\x1a'], addslashes($v)) . "'");
         }
     }
     return $r;
 }
Beispiel #5
0
 static function cleanUp($pages = null)
 {
     //! check input
     if (!empty(Core::lib("CMS")->revert)) {
         return;
     }
     if (empty(Core::$user->id) || !Core::$user->has("siteadm|pubadm")) {
         throw new \Exception(L('No user id'));
     }
     if (empty($pages)) {
         $pages = self::getPages();
     }
     //! write audit log
     Core::log('A', sprintf("Purge page history by %s", Core::$user->name), "cmsaudit");
     //! purge old records
     foreach ($pages as $p) {
         if ($p['versions'] > 1) {
             DS::exec("DELETE FROM " . static::$_table . " WHERE id=? AND (lang='' OR lang=?) AND created!=?", [$p['id'], $p['lang'], $p['created']]);
         }
     }
     //! make it published (without history that feature is off)
     DS::exec("UPDATE " . static::$_table . " SET publishid=? WHERE publishid=0", [Core::$user->id]);
 }
Beispiel #6
0
 /**
  * Function to save image lists
  *
  * @param name
  * @param array of image urls
  */
 static function saveImageList($name, $imgs)
 {
     //! check input
     if (empty($name)) {
         throw new \Exception(L('No imglist name'));
     }
     if (is_string($imgs)) {
         $imgs = str_getcsv($imgs, ",");
     }
     DS::exec("DELETE FROM img_list WHERE list_id=?", [$name]);
     foreach ($imgs as $k => $v) {
         if (!empty($v) && trim($v) != "null") {
             DS::exec("INSERT INTO img_list (list_id,id,ordering) values (?,?,?)", [$name, $v, intval($k)]);
         }
     }
     return true;
 }
Beispiel #7
0
 public function bindcfg()
 {
     try {
         $nodes = DS::query("*", self::$_table, "", "", "type, created");
     } catch (\Exception $e) {
         $nodes = [];
     }
     // generate bind config
     $sd = $this->_loadbalancer;
     if (!is_array($sd) || empty($sd)) {
         $sd = ["www"];
     }
     View::assign("nodes", $nodes);
     View::assign("subdomains", $sd);
     return preg_replace("|<br[\\ \\/]*>[\n]?|i", "\n", View::template("bind"));
 }
Beispiel #8
0
 /**
  * Execute a query and return number of affected rows (commands) or data set (select query).
  *
  * @param array             arguments array, values for placeholders
  * @param integer           data source selector
  *
  * @return integer/array    number of affected rows or result set (array of assoc arrays)
  */
 public function execute($arguments = [], $ds = -1)
 {
     //! set data source if requested
     if ($ds != -1) {
         $old_ds = DS::ds();
         DS::ds($ds);
     }
     //! get sql sentance
     $sql = $this->sql();
     if (strpos($sql, '?') !== false && empty($arguments)) {
         throw new DBException(L('Placeholder(s) in SQL without argument') . ': ' . $sql);
     }
     //! execute the query with PHPPE Core
     try {
         $ret = DS::exec($sql, $arguments);
         // @codeCoverageIgnoreStart
     } catch (\Exception $e) {
         throw new DBException(L($e->getMessage()) . ': ' . $sql);
         // @codeCoverageIgnoreEnd
     }
     //! restore data source if changed
     if ($ds != -1) {
         DS::ds($old_ds);
     }
     //! return result
     return $ret;
 }
Beispiel #9
0
 /**
  * Remove a parameter from registry.
  *
  * @param string    key
  */
 public static function del($key)
 {
     //sanitize key
     $key = preg_replace('/[^a-zA-Z0-9_]/', '', $key);
     //remove both database record as well as file
     try {
         @DS::exec('DELETE FROM registry WHERE name=?', [$key]);
     } catch (\Exception $e) {
     }
     @unlink('data/registry/' . $key);
 }
Beispiel #10
0
 public function update()
 {
     DB::query("\r\n                UPDATE users\r\n                INNER JOIN roles\r\n                ON roles.id = users.role_id\r\n                SET users.username='******', " . (!empty($this->password) ? "password='******', " : "") . "users.avatar='" . DB::esc($this->avatar) . "',\r\n                users.role_id=roles.id" . "WHERE users.id=" . DB::esc($this->id) . (empty($this->role) ? "AND roles.id=" . DS::esc($this . role_id) : "AND roles.name='" . DS::esc($this . role_id) . "'"));
 }
Beispiel #11
0
    $TIME_ZONE = (string) $xml->parameters->timezone;
    $CONF_MYSQL_HOST = (string) $xml->parameters->mysql->host;
    $CONF_MYSQL_USERNAME = (string) $xml->parameters->mysql->username;
    $CONF_MYSQL_PASSWORD = (string) $xml->parameters->mysql->password;
    $CONF_MYSQL_DBNAME = (string) $xml->parameters->mysql->dbname;
} else {
    die("config not found");
}
if (isset($TIME_ZONE)) {
    date_default_timezone_set($TIME_ZONE);
} else {
    date_default_timezone_set('Europe/Kiev');
}
$data = array();
$mysqldb = new PDO("mysql:host={$CONF_MYSQL_HOST};dbname={$CONF_MYSQL_DBNAME}", $CONF_MYSQL_USERNAME, $CONF_MYSQL_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$ds = new DS('./DS/' . 'store');
$QUERY = "SELECT swid, nameswitch, ip FROM switches WHERE ip != ''";
$res = $mysqldb->query($QUERY, PDO::FETCH_LAZY);
foreach ($res as $row) {
    $sw_id = $row["swid"];
    $sw_name = $row["nameswitch"];
    $sw_ip = $row["ip"];
    $date = date('Y-m-d H:i:s');
    $sw_ping = 0;
    $ping = Net_Ping::factory();
    if (PEAR::isError($ping)) {
        echo $ping->getMessage();
    } else {
        $ping->setArgs(array('count' => 1, 'timeout' => 2));
        $result = $ping->ping($sw_ip);
    }
Beispiel #12
0
 /**
  * Function to save document lists
  *
  * @param name
  * @param array of image urls
  */
 static function saveDocumentList($name, $docs)
 {
     //! check input
     if (empty($name)) {
         throw new \Exception(L('No doclist name'));
     }
     if (is_string($docs)) {
         $docs = str_getcsv($docs, ',');
     }
     DS::exec("DELETE FROM doc_list WHERE list_id=?", [$name]);
     foreach ($docs as $k => $v) {
         if (!empty($v) && trim($v) != "null") {
             DS::exec("INSERT INTO doc_list (list_id,id,ordering) values (?,?,?)", [$name, $v, intval($k)]);
         }
     }
     return true;
 }
    $TIME_ZONE = (string) $xml->parameters->timezone;
    $CONF_MYSQL_HOST = (string) $xml->parameters->mysql->host;
    $CONF_MYSQL_USERNAME = (string) $xml->parameters->mysql->username;
    $CONF_MYSQL_PASSWORD = (string) $xml->parameters->mysql->password;
    $CONF_MYSQL_DBNAME = (string) $xml->parameters->mysql->dbname;
} else {
    die("config not found");
}
if (isset($TIME_ZONE)) {
    date_default_timezone_set($TIME_ZONE);
} else {
    date_default_timezone_set('Europe/Kiev');
}
$data = array();
$mysqldb = new PDO("mysql:host={$CONF_MYSQL_HOST};dbname={$CONF_MYSQL_DBNAME}", $CONF_MYSQL_USERNAME, $CONF_MYSQL_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$ds = new DS('./DS/' . 'store');
$QUERY = "SELECT id, nasname, shortname FROM radnas WHERE nasname != ''";
$res = $mysqldb->query($QUERY, PDO::FETCH_LAZY);
foreach ($res as $row) {
    $sw_id = $row["id"];
    $sw_name = $row["shortname"];
    $sw_ip = $row["nasname"];
    $date = date('Y-m-d H:i:s');
    $sw_ping = 0;
    $ping = Net_Ping::factory();
    if (PEAR::isError($ping)) {
        echo $ping->getMessage();
    } else {
        $ping->setArgs(array('count' => 1, 'timeout' => 2));
        $result = $ping->ping($sw_ip);
    }
Beispiel #14
0
 function deployworker($arg)
 {
     $id = $arg['id'];
     $rootdir = $arg['rootdir'];
     $dirs = $arg['dirs'];
     $remote = $arg['remote'];
     //! call rsync
     $files = [];
     if (substr($rootdir, -1) != "/") {
         $rootdir .= "/";
     }
     foreach ($dirs as $d) {
         $files[$rootdir . $d] = 1;
     }
     Core::$user->data['remote'] = $remote;
     $files = array_keys($files);
     $path = !empty($remote['path']) ? $remote['path'] : "/var/www/";
     if (!empty($arg['rsync'])) {
         $ret = Tools::ssh("rsync", $files, $path);
     } else {
         $ret = Tools::copy($files, $path);
     }
     //! update status
     DS::exec("UPDATE " . self::$_table . " SET console=?,syncd=CURRENT_TIMESTAMP WHERE id=?", [$id]);
 }
Beispiel #15
0
 /**
  * Logout user
  */
 public function logout()
 {
     DS::exec("UPDATE " . static::$_table . " SET logoutd=CURRENT_TIMESTAMP WHERE id=?", [$this->id]);
 }