Beispiel #1
0
 public function diag()
 {
     foreach (["frozen" => "modifyd<CURRENT_TIMESTAMP-120", "unused" => "viewd<CURRENT_TIMESTAMP-600", "overloaded" => "load>=1.0"] as $k => $v) {
         $res = DS::query("id", self::$_table, $v);
         if (!empty($res)) {
             echo "DIAG-E: cluster: " . count($res) . " " . $k . " node(s): " . implode(", ", array_column($res, "id")) . "\n";
         }
     }
     foreach (["check" => "#!/bin/sh\n\n# Check if this server still has all the master resources\n", "start" => "#!/bin/sh\n\n# Grab all resources for master (eg. OpenVPN tunnels)\n", "stop" => "#!/bin/sh\n\n# Release all resources (eg. OpenVPN tunnels)\n", "reload" => "#!/bin/sh\n\n# reload all resources and clear caches\n", "worker" => "#!/bin/sh\n\n# Use ISP command to start a new worker instance\n# aws ec2 run-instances --image-id...\n"] as $f => $d) {
         $fn = "vendor/bin/cluster_" . $f . ".sh";
         if (!file_exists($fn)) {
             file_put_contents($fn, $d);
             chmod($fn, 0750);
         }
     }
 }
Beispiel #2
0
 public static function getDDS(&$app)
 {
     try {
         $F = DS::fetch('data,dds', 'pages', "id='frame' AND " . (ClassMap::has("PHPPE\\CMS") && get_class(View::getval('app')) == "PHPPE\\Content" && Core::$user->has("siteadm|webadm") ? "" : "publishid!=0 AND ") . "(lang='' OR lang=?)", '', 'id DESC,created DESC', [Core::$client->lang]);
         $E = $F ? json_decode($F['data'], true) : null;
         View::assign('frame', $E);
         $D = $F ? json_decode($F['dds'], true) : null;
         if (is_array($D)) {
             self::$dds += $D;
         }
     } catch (\Exception $e) {
     }
     $o = [];
     foreach (self::$dds as $k => $c) {
         if (!in_array($k, ['dds', 'id', 'title', 'mimetype'])) {
             try {
                 $o[$k] = @DS::query($c[0], @$c[1], strtr(@$c[2], ['@ID' => $k, '@SHA' => sha1($k)]), @$c[3], @$c[4], @$c[5], View::getval(@$c[6]));
                 foreach ($o[$k] as $i => $v) {
                     $d = @json_decode($v['data'], true);
                     if (is_array($d)) {
                         $o[$k][$i] += $d;
                     }
                     unset($o[$k][$i]['data']);
                 }
             } catch (\Exception $e) {
                 Core::log('W', $k . ' ' . $e->getMessage() . ' ' . implode(' ', $c), 'dds');
             }
         }
     }
     if (!empty($o)) {
         foreach ($o as $k => $v) {
             $app->{$k} = $v;
         }
     }
 }
Beispiel #3
0
 static function publish($ids)
 {
     if (empty(Core::lib("CMS")->revert)) {
         return;
     }
     if (empty(Core::$user->id) || !Core::$user->has("siteadm|pubadm")) {
         throw new \Exception(L('No user id'));
     }
     $ids[] = "frame";
     $pages = DS::query("id,lang,max(created) as created", static::$_table, "publishid=0 AND ownerid=0 AND id IN ('" . implode("','", $ids) . "')", "id,lang");
     foreach ($pages as $p) {
         //! write audit log
         Core::log('A', sprintf("Publicate page %s (%s,%s) by %s", $p['id'], $p['lang'], $p['created'], Core::$user->name), "cmsaudit");
         // mark newest as active
         DS::exec("UPDATE " . static::$_table . " SET publishid=? WHERE id=? AND lang=? AND created=?", [Core::$user->id, $p['id'], $p['lang'], $p['created']]);
         // purge old active records
         DS::exec("DELETE FROM " . static::$_table . " WHERE id=? AND lang=? AND publishid!=0 AND created not in (SELECT created FROM " . static::$_table . " WHERE id=? AND lang=? ORDER BY created desc limit " . max([intval(Core::lib("CMS")->purge), 1]) . ")", [$p['id'], $p['lang'], $p['id'], $p['lang']]);
     }
     // delete intermediate versions
     DS::exec("DELETE FROM pages WHERE publishid=0 AND id IN ('" . implode("','", $ids) . "')");
 }
Beispiel #4
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"));
 }