示例#1
0
 function action($item = null)
 {
     if (Core::$client->ip != "CLI") {
         Http::redirect("403");
     }
     $node = Core::lib("ClusterCli");
     echo chr(27) . "[96mThis node is: " . chr(27) . "[0m" . $node->id . " " . (!empty($node->loadbalancer) ? "LOADBALANCER" : "WORKER") . "\n";
 }
示例#2
0
文件: layouts.php 项目: bztsrc/phppe3
 /**
  * default action
  */
 function action($item)
 {
     //! create a fake page parameter
     $name = "layoutadd";
     $_SESSION['cms_param'][sha1("layoutadd_")] = new \PHPPE\AddOn\layoutadd([], $name, $name);
     //! if layout not given
     if (empty($item)) {
         //! check if we have to activate a sitebuild
         if (!empty($_REQUEST['set'])) {
             DS::exec("UPDATE " . Views::$_table . " SET id=sitebuild WHERE sitebuild!='' AND id='frame'");
             DS::exec("UPDATE " . Views::$_table . " SET id='frame' WHERE sitebuild=?", trim($_REQUEST['set']));
             Http::redirect();
         }
         //! load layouts and sitebuilds
         $this->layouts = Views::find([], "sitebuild=''", "name");
         $this->sitebuilds = Views::find([], "sitebuild!=''", "name");
     } else {
         //! load layout
         $this->layout = new Views($item);
         if (!empty($this->layout->jslib)) {
             foreach ($this->layout->jslib as $j) {
                 View::jslib($j);
             }
         }
         if (!empty($this->layout->css)) {
             foreach ($this->layout->css as $c) {
                 View::css($c);
             }
         }
         $this->numPages = Page::getNum($item);
         //! get user input
         $layout = Core::req2arr("layout");
         //! merge the new data with the loaded layout's properties
         if (!empty($this->layout->sitebuild) && !empty($layout)) {
             Core::$core->noframe = 1;
             $layout['sitebuild'] = $layout['id'];
         }
         if (Core::isTry("layout")) {
             //! delete a layout
             if (!empty($layout['delete'])) {
                 $this->layout->delete();
             } else {
                 unset($layout['delete']);
                 //! renamed?
                 if ($this->layout->id != $layout['id']) {
                     DS::exec("UPDATE " . Views::$_table . " SET id=? WHERE id=?", [$layout['id'], $this->layout->id]);
                     Core::log('A', sprintf("Layout %s renamed to %s by %s", $this->layout->id, $layout['id'], Core::$user->name), "cmsaudit");
                 }
                 //! save new data
                 foreach ($layout as $k => $v) {
                     $this->layout->{$k} = $v;
                 }
                 $this->layout->save();
             }
             Http::redirect("cms/layouts");
         }
     }
 }
示例#3
0
 public function testMultilingual()
 {
     $cnt = count(Core::$l);
     $this->assertNotEmpty(Core::$l, "Translations");
     //try to load fake language for Developer
     Core::$client->lang = "xx";
     Core::lang("Developer");
     //check if there's a new entry
     $this->assertNotEquals('teststr', L('teststr'), "Loading new");
 }
示例#4
0
文件: cmsmeta.php 项目: bztsrc/phppe3
 function edit()
 {
     $m = Core::lib("CMS")->metas;
     $v = is_array($this->value) ? $this->value : json_decode($this->value, true);
     $r = "";
     foreach ($m as $k) {
         $r .= "<div style='width:20%;'><span><i>" . ucfirst(L($k)) . "</i></span></div><div style='width:80%;'><input class='input form-control' name='" . $this->fld . "[" . $k . "]' value='" . htmlspecialchars(!empty($v[$k]) ? $v[$k] : '') . "'></div>";
     }
     return $r;
 }
示例#5
0
文件: pageadd.php 项目: bztsrc/phppe3
 function edit()
 {
     if (!Core::isTry()) {
         $page = new Page();
         $page->template = "simple";
         View::assign("page", $page);
     }
     $quickhelp = !Core::lib("CMS")->expert;
     View::assign("quickhelp", $quickhelp);
     return View::template("cms_pageinfo");
 }
示例#6
0
 function edit()
 {
     $m = Core::lib("CMS")->metas;
     $v = is_array($this->value) ? $this->value : json_decode($this->value, true);
     $r = "<div class='infobox' style='padding:5px;overflow:auto;'>";
     foreach ($m as $k) {
         $r .= "<b>" . ucfirst(L($k)) . "</b><br><input class='input form-control' name='" . $this->fld . "[" . $k . "]' value='" . htmlspecialchars(!empty($v[$k]) ? $v[$k] : '') . "'>";
     }
     $r .= "</div>";
     return $r;
 }
示例#7
0
 function save($params)
 {
     $v = new Views();
     $v->id = $params['layoutid'];
     $v->name = $params['layoutname'];
     try {
         if ($v->save(true)) {
             die("<script>top.document.location.href='" . url("cms/layouts/" . $params['layoutid']) . "';</script>");
         }
     } catch (\Exception $e) {
         Core::error($e->getMessage());
     }
 }
示例#8
0
 function __construct()
 {
     //! common check for all action handlers
     if (!Core::$user->has("install")) {
         Http::redirect("login", true);
     }
     //! if bootstrap extension not installed, use cdn version
     if (!Core::isInst("bootstrap")) {
         View::css("http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css");
     }
     View::css("extensions.css");
     View::jslib("sha256.js");
     View::jslib("extensions.js");
 }
示例#9
0
 public function testFilters()
 {
     //! default filters
     $this->assertFalse(\PHPPE\Core::cf("csrf"), "CSRF");
     $is = @$_SERVER['REQUEST_METHOD'] == "GET" ? true : false;
     $this->assertEquals($is, \PHPPE\Core::cf("get"), "GET");
     $is = @$_SERVER['REQUEST_METHOD'] == "POST" ? true : false;
     $this->assertEquals($is, \PHPPE\Core::cf("post"), "POST");
     //! Access Control Entry
     $this->assertEquals(\PHPPE\Core::$user->has("loggedin"), \PHPPE\Core::cf("@loggedin"), "ACE");
     $old = \PHPPE\Core::$user->id;
     \PHPPE\Core::$user->id = 1;
     $this->assertTrue(\PHPPE\Core::cf("loggedin"), "loggedin");
     \PHPPE\Core::$user->id = $old;
 }
示例#10
0
文件: pages.php 项目: bztsrc/phppe3
 /**
  * default action
  */
 function action($item)
 {
     //! page history enabled?
     $this->revert = Core::lib("CMS")->revert;
     //! delete a page with all versions
     if (!empty($_REQUEST['pagedel'])) {
         Page::delete($_REQUEST['pagedel']);
         unset($_SESSION['cms_url']);
         Http::redirect();
     }
     //! publicate a page
     if (isset($_REQUEST['publish']) && $this->revert) {
         $this->ispublish = true;
         $publish = array_keys(Core::req2arr('publish'));
         if (!empty($publish)) {
             Page::publish($publish);
             Http::redirect("cms/pages");
         }
     }
     //! load languages
     $this->langs[''] = "*";
     foreach (!empty($_SESSION['pe_ls']) ? $_SESSION['pe_ls'] : ['en' => 1] as $l => $v) {
         $this->langs[$l] = $l . " " . L($l);
     }
     //! unlock old pages for this user if any
     Page::unLock(Core::$user->id);
     //! get list of pages
     $pages = Page::getPages(intval(@$_REQUEST['order']));
     $needcleanup = false;
     foreach ($pages as $p) {
         if ($this->ispublish && ($p['publishid'] != 0 || $p['ownerid'] != 0)) {
             continue;
         }
         if ($this->revert && $p['publishid'] == 0) {
             $this->needpublish = true;
         }
         if (!$this->revert && $p['versions'] > 1) {
             $needcleanup = true;
         }
         $this->pages[empty($_REQUEST['order']) ? 0 : (empty($p['template']) ? $p['tid'] : $p['template'])][] = $p;
     }
     //! this is required once after page history turned off
     if ($needcleanup) {
         Page::cleanUp($pages);
     }
 }
示例#11
0
 public function testConvert()
 {
     setlocale(LC_NUMERIC, 'en_US.utf-8');
     \PHPPE\Core::validate("obj.phone", "phone", false);
     \PHPPE\Core::validate("obj.chk.me", "check", true);
     \PHPPE\Core::validate("obj.file", "file", false);
     $_FILES['obj_file']['error'] = 1;
     $_REQUEST['obj_phone'] = "+361234567";
     $obj = \PHPPE\Core::req2obj("obj");
     $this->assertInstanceOf("stdClass", $obj, "req2obj");
     $this->assertFalse(\PHPPE\Core::isError("obj.phone"), "validator");
     $_REQUEST['obj_phone'] = "abc";
     $obj2 = \PHPPE\Core::req2arr("obj");
     $this->assertInternalType("array", $obj2, "req2arr");
     $this->assertTrue(\PHPPE\Core::isError("obj.chk.me"), "validator");
     $obj = new \stdClass();
     $obj->field1 = "field1";
     $obj->field2 = "field2's";
     $obj->field3 = 3;
     $obj->field4 = 1.2;
     $this->assertEmpty(\PHPPE\Core::arr2str("aaa"), "arr2str str");
     $this->assertEquals("field1='field1' field2='field2\\'s' field3='3' field4='1.2'", \PHPPE\Core::arr2str($obj), "arr2str");
     $this->assertEquals("field1='field1' field2='field2\\'s' field3='3' field4='1.2'", \PHPPE\Core::obj2str($obj), "obj2str space");
     $this->assertEquals("field1='field1',field2='field2\\'s',field3='3',field4='1.2'", str_replace("''", "\\'", \PHPPE\Core::obj2str($obj, "", ",")), "obj2str comma");
     $this->assertEquals("field1='field1' field4='1.2'", \PHPPE\Core::obj2str($obj, "field2,field3"), "obj2str skip");
     $obj2 = new \stdClass();
     $obj2->test = "a:b:c";
     $obj2->test2 = ["a", "b", "c"];
     \PHPPE\View::assign("obj2", $obj2);
     $this->assertEquals("[\"a:b:c\"]", json_encode(\PHPPE\Core::val2arr("obj2.test")), "val2arr #1");
     $this->assertEquals("[\"a\",\"b\",\"c\"]", json_encode(\PHPPE\Core::val2arr("obj2.test2")), "val2arr #2");
     $this->assertEquals("[1,2]", json_encode(\PHPPE\Core::val2arr([1, 2])), "val2arr #3");
     $this->assertEquals("[\"a\",\"b\",\"c\"]", json_encode(\PHPPE\Core::val2arr("obj2.test", ":")), "val2arr #4");
     $this->assertEquals("[]", json_encode(\PHPPE\Core::val2arr("")), "val2arr #5");
     $tree = [["id" => 1, "name" => "1"], ["id" => 2, "name" => "2", "_" => [["id" => 21, "name" => "21"], ["id" => 22, "name" => "22", "_" => [["id" => 221, "name" => "221"], ["id" => 222, "name" => "222"]]], ["id" => 23, "name" => "23"], ["id" => 24, "name" => "24"]]]];
     $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2"},{"id":21,"name":"  21"},{"id":22,"name":"  22"},{"id":221,"name":"    221"},{"id":222,"name":"    222"},{"id":23,"name":"  23"},{"id":24,"name":"  24"}]', json_encode(\PHPPE\Core::tre2arr($tree)), "tre2arr selectbox #1");
     $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2"},{"id":21,"name":"&nbsp;21"},{"id":22,"name":"&nbsp;22"},{"id":221,"name":"&nbsp;&nbsp;221"},{"id":222,"name":"&nbsp;&nbsp;222"},{"id":23,"name":"&nbsp;23"},{"id":24,"name":"&nbsp;24"}]', json_encode(\PHPPE\Core::tre2arr($tree, "&nbsp;")), "tre2arr selectbox #2");
     $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2\\n<div id=\'tree2_1\' style=\'padding-left:10px;\'>"},{"id":21,"name":"21"},{"id":22,"name":"22\\n<div id=\'tree2_3\' style=\'padding-left:10px;\'>"},{"id":221,"name":"221"},{"id":222,"name":"222\\n<\\/div>"},{"id":23,"name":"23"},{"id":24,"name":"24\\n<\\/div>"}]', json_encode(\PHPPE\Core::tre2arr($tree, "<div id='tree2_%d' style='padding-left:10px;'>", "</div>")), "tre2arr DOM");
     $tree = json_decode('[{"id":1,"name":"1"},{"id":2,"name":"2","_":[{"id":3,"name":"3"}]}]');
     $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2"},{"id":3,"name":"  3"}]', json_encode(\PHPPE\Core::tre2arr($tree)), "tre2arr stdClass selectbox");
     $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2\\n<div id=\'tree2_1\' style=\'padding-left:10px;\'>"},{"id":3,"name":"3\\n<\\/div>"}]', json_encode(\PHPPE\Core::tre2arr($tree, "<div id='tree2_%d' style='padding-left:10px;'>", "</div>")), "tre2arr stdClass DOM");
 }
示例#12
0
文件: mkrepo.php 项目: bztsrc/phppe3
 function __construct()
 {
     //! check if executed from CLI
     if (Core::$client->ip != "CLI") {
         Http::redirect("403");
     }
     //! run tests
     if (in_array("--tests", $_SERVER['argv'])) {
         echo "Running tests: ";
         ob_start();
         $tests = Testing::doTests();
         $d = ob_get_clean();
         if (!$tests) {
             die("FAILED\n{$d}");
         }
         echo "OK\n";
         unset($d);
     }
     //! *** MKREPO Event ***
     Core::event("mkrepo");
     //! create repository
     Repository::make();
     die;
 }
示例#13
0
 public function testLog()
 {
     $s = Core::$core->syslog;
     $t = Core::$core->trace;
     Core::$core->syslog = true;
     Core::$core->trace = true;
     Core::log("B", "Should be Audit", "phpunit");
     $o = Core::$core->runlevel;
     Core::$core->runlevel = 0;
     Core::log("D", "Should be skipped", "phpunit");
     Core::$core->runlevel = $o;
     Core::$core->syslog = $s;
     Core::$core->trace = $t;
 }
示例#14
0
文件: boolean.php 项目: bztsrc/phppe3
 function init()
 {
     Core::addon("boolean", "Boolean", "", "*obj.field");
 }
示例#15
0
 function edit()
 {
     $quickhelp = !Core::lib("CMS")->expert;
     View::assign("quickhelp", $quickhelp);
     return View::template("cms_pageinfo");
 }
示例#16
0
        if ($_FILES['upload']['type'] == "text/plain") {
            $choose = @file_get_contents($_FILES['upload']['tmp_name']);
        } elseif ($_FILES['upload']['type'] == "text/html") {
            $d = @file_get_contents($_FILES['upload']['tmp_name']);
            preg_match_all("|<body[^>]*>(.*?)<\\/body|ims", $d, $b, PREG_SET_ORDER);
            $choose = !empty($b[0][1]) ? $b[0][1] : $d;
        } else {
            $err = L("wyswyg_htmlonly");
        }
    }
    die("<html><head><meta charset='utf-8'/></head><body>" . ($choose ? "<div>" . $choose . "</div><script type='text/javascript'>parent.pe.wyswyg.importdone(\"" . $_REQUEST['impform'] . "\");</script>" : View::_t("<!form>") . "<input type='hidden' name='impform' value='" . $_REQUEST['impform'] . "'>" . "<input type='file' name='upload' onchange='this.form.submit();' id='" . $_REQUEST['impform'] . ":import'>" . ($err ? "alert('" . $err . "');" : "") . "</form>") . "</body></html>");
}
$bs = Core::isInst("bootstrap");
//! get toolbars
$toolbar = [];
$libs = Core::lib();
foreach ($libs as $l) {
    if (!empty($l->wyswyg_toolbar)) {
        $toolbar = array_merge($toolbar, $l->wyswyg_toolbar);
    }
}
?>
pe.wyswyg = {
<?php 
if ($bs) {
    ?>
    classes: {
    "toggle": "glyphicon glyphicon-eye",
    "import": "glyphicon glyphicon-open",
    "font": "glyphicon glyphicon-font",             //L("wyswyg_font") L("wyswyg_style") L("wyswyg_style<h2>") L("wyswyg_style<h3>") L("wyswyg_style<h4>") L("wyswyg_style<h5>") L("wyswyg_style<pre>")
    "bold": "glyphicon glyphicon-bold",             //L("wyswyg_bold")
示例#17
0
 /**
  * default action, loaded via AJAX
  */
 function action($item)
 {
     //! assets
     if (!empty($_REQUEST['assetn'])) {
         list($d, $f) = explode("/", $_REQUEST['assetn']);
         $fn = ".tmp/" . session_id() . "/" . $d . "/" . $f;
         if (file_exists($fn)) {
             header("Content-type: " . ($d == "i" ? "image/png" : ($d == "c" ? "text/css" : ($d == "j" ? "text/javascript" : "application/octet-stream"))));
             die(file_get_contents($fn) . "");
         }
     }
     //! sitebuild import
     Core::$core->noframe = true;
     $import = Core::req2arr("import");
     //! uncompress uploaded archive
     if (!empty($import['file']['tmp_name'])) {
         @Tools::rmdir(".tmp/" . session_id());
         @mkdir(".tmp/" . session_id() . "/i", 0750, true);
         @mkdir(".tmp/" . session_id() . "/c", 0750, true);
         @mkdir(".tmp/" . session_id() . "/j", 0750, true);
         @mkdir(".tmp/" . session_id() . "/f", 0750, true);
         @mkdir(".tmp/" . session_id() . "/h", 0750, true);
         Tools::untar($import['file']['tmp_name'], function ($name, $body) {
             $fn = "";
             if (substr($name, -4) == ".htm" || substr($name, -5) == ".html") {
                 self::$success = true;
                 $fn = "h/" . basename($name);
             } else {
                 if (in_array(substr($name, -4), [".gif", ".png", ".pnm", ".jpg", ".svg"])) {
                     $fn = "i/" . basename($name);
                 } else {
                     if (in_array(substr($name, -4), [".eot", ".ttf"]) || substr($name, -5) == ".woff" || substr($name, -6) == ".woff2") {
                         $fn = "f/" . basename($name);
                     } else {
                         if (substr($name, -4) == ".css") {
                             $fn = "c/" . basename($name);
                         } else {
                             if (substr($name, -3) == ".js") {
                                 $fn = "j/" . basename($name);
                             }
                         }
                     }
                 }
             }
             if (!empty($fn)) {
                 file_put_contents(".tmp/" . session_id() . "/" . $fn, $body);
             }
         });
         if (!self::$success) {
             Core::error("Bad archive");
             return;
         }
     }
     //! choose a html
     $this->htmls = glob(".tmp/" . session_id() . "/h/*");
     if (count($this->htmls) == 1) {
         $item = 1;
     }
     if (intval($item) > 0 && !empty($this->htmls[$item - 1])) {
         $html = $this->htmls[$item - 1];
         unset($this->htmls);
     }
     if (empty($html)) {
         if (intval($item) > 0) {
             Core::error("Bad archive");
         }
         return;
     }
     //! choose application area
     $data = preg_replace("/<script.*?\\/script>/ims", "", file_get_contents($html));
     $files = glob(".tmp/" . session_id() . "/*/*");
     $assets = ["i" => "images", "c" => "css", "j" => "js", "f" => "fonts"];
     //! replace urls with temporary ones for the uploaded files
     foreach ($files as $f) {
         if (!empty($assets[basename(dirname($f))])) {
             $data = preg_replace("/[^=\\ \t\r\n\\'\",\\(\\[]+" . basename($f) . "/ims", url("cms/sitebuild") . "?assetn=" . basename(dirname($f)) . "/" . basename($f), $data);
         }
         if (basename(dirname($f)) == "c") {
             View::css(url("cms/sitebuild") . "?assetn=" . basename(dirname($f)) . "/" . basename($f));
         } else {
             if (basename(dirname($f)) == "j") {
                 View::jslib(url("cms/sitebuild") . "?assetn=" . basename(dirname($f)) . "/" . basename($f));
             }
         }
     }
     //! get the main application tag
     $this->content = CMS::taghtml($data);
     if (empty($_REQUEST['chooseid']) && preg_match("/(<[^<>]*?id=[\\'\"]?content[^>]*?>)/ims", $this->content, $m) && !empty($m[0]) && preg_match("/data\\-chooseid=[\\'\"]?([0-9]+)/ims", $m[0], $M)) {
         $_REQUEST['chooseid'] = $M[1];
     }
     if (!empty($_REQUEST['chooseid'])) {
         //! replace with <!app>
         $t = CMS::splithtml($this->content, $_REQUEST['chooseid'], 0) . "<!app>" . CMS::splithtml($this->content, $_REQUEST['chooseid'], 2);
         //! replace temporary urls with final ones
         preg_match_all("/[^=\\ \t\r\n\\'\",\\(\\[]+\\?assetn=([a-z])\\/([^=\\ \t\r\n\\'\",\\)\\]]+)/ims", $t, $m, PREG_SET_ORDER);
         foreach ($m as $M) {
             $t = str_replace($M[0], $assets[$M[1]] . "/" . $M[2], $t);
         }
         //! figure out sitebuild name
         $name = strtr(basename($html), [".html" => "", ".htm" => ""]);
         if ($name == "index" || $name == "frame" || $name == "simple" || $name == "default") {
             $name = "sitebuild" . Core::$core->now;
         }
         $views = Views::find($name);
         if (!empty($views)) {
             $name .= Core::$core->now;
         }
         //! save sitebuild
         $view = new Views();
         $view->id = $name;
         $view->name = $name;
         $view->sitebuild = $name;
         $view->data = preg_replace("/<!\\-\\-.*?\\-\\->/ms", "", $t);
         $view->created = date("Y-m-d H:i:s", Core::$core->now);
         foreach ($files as $f) {
             if (empty($assets[basename(dirname($f))])) {
                 continue;
             }
             if (basename(dirname($f)) == "c") {
                 $view->css[] = basename($f);
             }
             if (basename(dirname($f)) == "j") {
                 $view->jslib[] = basename($f);
             }
         }
         if ($view->save(true)) {
             //! copy temporary files to public directory
             foreach ($assets as $k => $v) {
                 chdir(".tmp/" . session_id() . "/" . $k);
                 Tools::copy(glob("*"), "public/" . $v);
                 chdir("../../..");
             }
             //! clean up
             @Tools::rmdir(".tmp/" . session_id());
             //! redirect user to the fresh new sitebuild layout
             Http::redirect("cms/layouts/" . $name);
         }
         Core::error("Unable to save sitebuild!");
     }
 }
示例#18
0
文件: test2.php 项目: bztsrc/phppe3
 function init()
 {
     \PHPPE\Core::addon("test2", "Test AddOn 2", "test1", "*configuration");
 }
示例#19
0
文件: index.php 项目: bztsrc/phppe3
 public function edit()
 {
     $t = $this;
     $e = Core::isError($t->name);
     return '<input' . @View::v($t, $t->attrs[1], $t->attrs[0], $t->args) . " type='file' style='display:inline;' title='" . round(Core::$core->fm / 1048576) . "Mb'>";
 }
示例#20
0
 *   PHP Portal Engine v3.0.0
 *   https://github.com/bztsrc/phppe3/
 *
 *   Copyright LGPL 2016 bzt
 *
 *   PHPPE Extension Manager
 *
 */
pe.extensions = {
/*PRIVATE VARS*/
    installed:[ <?php 
echo Core::lib("Extensions")->getInstalled();
?>
 ],
    pkgs:[ <?php 
echo Core::lib("Extensions")->getPkgs();
?>
 ],
    licenses:[],
    tmr:null, me:false, lastcmd:"", param:"",return:"",url:"",

/*PUBLIC METHODS*/
    search:function(str,installed)
    {
        var t="",up=false,down=false;
        if(str==""||str==null||str==undefined)str=document.getElementById("search").value;
        if(str=="<?php 
echo L("installed");
?>
"<?php 
echo L("installed") != "installed" ? "||str==\"installed\"" : "";
示例#21
0
 /**
  * Action handler
  */
 function action($item)
 {
     setlocale(LC_NUMERIC, "C");
     $lib = Core::lib("ClusterSrv");
     $nodes = DS::query("*", self::$_table, "", "", "type,load DESC,id");
     $master = DS::field("id", self::$_table, "type='master' AND modifyd>CURRENT_TIMESTAMP-120");
     //! check if executed from CLI
     if (Core::$client->ip != "CLI") {
         header("Content-type:application/json");
         $loadavg = 0.0;
         $waspeek = 0;
         $minSync = "";
         if (!empty($nodes)) {
             $minSync = reset($nodes)['syncd'];
             foreach ($nodes as $k => $node) {
                 unset($nodes[$k]["cmd"]);
                 $loadavg += floatval($node['load']);
                 if ($node['load'] >= 0.5) {
                     $waspeek = 1;
                 }
                 if ($node['load'] >= 0.75) {
                     $waspeek = 2;
                 }
                 if ($node['syncd'] < $minSync) {
                     $minSync = $node['syncd'];
                 }
             }
             $loadavg /= count($nodes);
         }
         date_default_timezone_set('UTC');
         $minSync = strtotime($minSync);
         $D = [];
         $d = $lib->_skeleton;
         if (substr($d, -1) != "/") {
             $d .= "/";
         }
         foreach (['vendor/*', 'vendor/*/*', 'vendor/*/*/*', 'vendor/*/*/*/*', 'vendor/*/*/*/*/*'] as $v) {
             $D += array_fill_keys(@glob($d . $v, GLOB_NOSORT), 0);
         }
         $newfiles = 0;
         foreach ($D as $d => $v) {
             $t = filemtime($d);
             if ($t != 0 && $t > $minSync) {
                 $newfiles = 1;
                 break;
             }
         }
         die(json_encode(["status" => $loadavg < 0.1 ? "idle" : ($loadavg > 0.5 || $waspeek ? $loadavg > 0.75 || $waspeek == 2 ? "error" : "warn" : "ok"), "loadavg" => $loadavg, "peek" => $waspeek, "master" => $master, "newfiles" => $newfiles, "id" => Core::lib("ClusterSrv")->id, "nodes" => $nodes]));
     } else {
         echo chr(27) . "[96mThis node is: " . chr(27) . "[0m" . $lib->id . " " . chr(27) . "[" . (strtolower(trim($lib->id)) == strtolower(trim($master)) ? "91mMASTER" : "92mSLAVE") . chr(27) . "[0m\n" . chr(27) . "[96mCluster nodes:\n";
         echo chr(27) . "[96m Id              Type        Load  Last seen            Last viewed          Name\n --------------  ---------  -----  -------------------  -------------------  -----------------------------" . chr(27) . "[0m\n";
         foreach ($nodes as $node) {
             echo sprintf("%s%-16s%-8s%8s", strtolower(trim($node['id'])) == strtolower(trim($master)) ? chr(27) . "[93m*" : " ", $node['id'], $node['type'], $node['load']) . "  " . (!empty($node['modifyd']) ? $node['modifyd'] : sprintf("%-19s", L("booting"))) . "  " . (!empty($node['viewd']) ? $node['viewd'] : "????-??-?? ??:??:??") . "  " . $node['name'] . chr(27) . "[0m\n";
         }
         echo "\n";
         if (Core::$core->action == "action") {
             $this->help();
         }
     }
 }
示例#22
0
文件: param.php 项目: bztsrc/phppe3
 /**
  * default action
  */
 function action($item)
 {
     //! omit frame and panel and disable cache
     Core::$core->noframe = true;
     Core::$core->nopanel = true;
     Core::$core->nocache = true;
     //! if not called as it should, return
     if (empty($item) || $item != sha1("pageadd_") && (empty($_SESSION['cms_url']) || empty($_SESSION['cms_param'][$item]))) {
         Core::$core->template = "403";
         return;
     }
     //! get height
     $this->height = intval(@$_REQUEST['height']);
     $this->adjust = intval(@$_REQUEST['adjust']);
     //! save current scroll position to session so that on next
     //! page load pe.cms.init() will use it
     if (isset($_REQUEST['scrx'])) {
         $_SESSION['cms_scroll'] = [$_REQUEST['scrx'], $_REQUEST['scry']];
     }
     //! get available access control entries
     $this->ace = ClassMap::ace();
     foreach ($this->ace as $k => $v) {
         $this->ace[$k] = "@" . $v;
     }
     $this->ace[] = "@siteadm|webadm";
     $this->ace[] = "loggedin";
     $this->ace[] = "csrf";
     $this->ace[] = "get";
     $this->ace[] = "post";
     //! get the field we're editing
     $F = clone $_SESSION["cms_param"][$item];
     $F->fld = "page_value";
     if (get_class($F) == "PHPPE\\AddOn\\wyswyg") {
         $F->args = [0, "pe.cms.image"];
     }
     if (method_exists($F, 'init')) {
         $F->init();
     }
     $this->fieldTitle = $F->name;
     $this->heightClass = @$F->heightClass;
     $this->boxHeight = $this->height - @$F->headerHeight;
     //! get the page we're editing
     //! if parameter name starts with "frame", load frame page instead
     $page = new Page(substr($F->name, 0, 6) == "frame." ? "frame" : @$_SESSION['cms_url']);
     $this->editable = $page->lock();
     View::assign("page", $page);
     $n = substr($F->name, 0, 6) == "frame." ? substr($F->name, 6) : (substr($F->name, 0, 4) == "app." ? substr($F->name, 4) : $F->name);
     if (!empty($page->data[$n])) {
         $F->value = $page->data[$n];
     }
     //! load extra data if any
     if (method_exists($F, 'load')) {
         $F->load($this);
     }
     //! save page parameter
     $param = Core::req2arr("page");
     if (!empty($param) && $this->editable) {
         //! if there was no validation error
         if (!Core::isError()) {
             if (method_exists($F, "save")) {
                 //! if it's a special field with it's own save mechanism
                 $param['pageid'] = $page->id;
                 if (!$F->save($param)) {
                     Core::error(L("Unable to save page!"));
                 }
             } else {
                 //! otherwise standard page parameter
                 $page->setParameter($F->name, $param['value']);
                 if (!$page->save()) {
                     Core::error(L("Unable to save page!"));
                 }
             }
             //! close the modal if save was successful
             if (!Core::isError()) {
                 //! release the page lock
                 $page->release();
                 die("<html><script>parent.pe.cms.close(true);</script></html>");
             }
         }
         //! copy the form data. normally you don't need to do that
         //! but here form name and object name differs, so it's not automatic
         foreach ($param as $k => $v) {
             $page->{$k} = $v;
         }
     }
     //! get the input(s)
     if (method_exists($F, 'edit')) {
         $this->field = $F->edit();
     } else {
         //! fallback to a simple input field. Should never happen
         $this->field = "<input type='text' class='input" . (Core::isError("page.value") ? " errinput" : "") . "' name='page_value' value=\"" . htmlspecialchars($F->value) . "\">";
     }
     //! focus first input
     View::js("init()", "var inp=document.querySelector('.reqinput,.input');if(inp!=null){inp.focus();inp.selectionStart=inp.selectionEnd=(inp.value!=null?inp.value:inp.innerHTML).length;}", true);
 }
示例#23
0
文件: archive.php 项目: bztsrc/phppe3
 /**
  * default action
  */
 function action($item)
 {
     //! check access rights
     if (!Core::$user->has("siteadm|webadm")) {
         Http::redirect("403");
     }
     //! if we have to delete a page version
     if (isset($_REQUEST['pagedel'])) {
         if (!empty($_REQUEST['created'])) {
             Page::delete($item, $_REQUEST['created']);
         }
         Http::redirect($item);
     }
     //! revert to an old version of the page
     if (isset($_REQUEST['revert'])) {
         if (!empty($_REQUEST['created'])) {
             Core::log('A', sprintf("Page %s reverted to %s by %s", $item, $_REQUEST['created'], Core::$user->name), "cmsaudit");
             DS::exec("UPDATE pages set created=CURRENT_TIMESTAMP,modifyd=CURRENT_TIMESTAMP,modifyid=? WHERE id=? AND (lang='' OR lang=?) AND created=?", [Core::$user->id, $item, Core::$client->lang, $_REQUEST['created']]);
         }
         Http::redirect($item);
     }
     //! get the latest public version's date
     if (empty($_REQUEST['created'])) {
         $_REQUEST['created'] = DS::field("created", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?) AND publishid!=0", "", "id DESC,created DESC", [$item, $item, Core::$client->lang]);
         if (empty($_REQUEST['created'])) {
             $_REQUEST['created'] = DS::field("created", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?)", "", "id DESC,created ASC", [$item, $item, Core::$client->lang]);
         }
     }
     //! load frame page for page parameters and dds
     $frame = DS::fetch("data,dds", "pages", "id='frame' AND (lang='' OR lang=?) AND created<=?", "", "", [Core::$client->lang, $_REQUEST['created']]);
     $frame['dss'] = @json_decode($frame['dds'], true);
     $frame['data'] = @json_decode($frame['data'], true);
     View::assign("frame", $frame['data']);
     //! load archive version
     //! normally you would use Model, but that would only return the latest version
     $page = DS::fetch("*", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?) AND created=?", "", "id DESC,created DESC", [$item, $item, Core::$client->lang, $_REQUEST['created']]);
     $this->title = $page['name'];
     $title = L("ARCHIVE") . " " . $page['name'];
     if (is_string($page['data'])) {
         $page['data'] = @json_decode($page['data'], true);
     }
     if (is_array($page['data'])) {
         foreach ($page['data'] as $k => $v) {
             $this->{$k} = $v;
         }
     }
     foreach (["id", "name", "lang", "filter", "template", "pubd", "expd", "dds", "ownerid", "created"] as $k) {
         $this->{$k} = $page[$k];
     }
     $p = @array_merge($frame['dds'], @json_decode($page['dds'], true));
     if (is_array($p)) {
         foreach ($p as $k => $c) {
             if ($k != "dds") {
                 try {
                     $this->{$k} = DS::query($c[0], $c[1], @$c[2], @$c[3], @$c[4], @$c[5], View::getval(@$c[6]));
                 } catch (\Exception $e) {
                     Core::log("E", $item . " " . $e->getMessage() . " " . implode(" ", $c), "dds");
                 }
             }
         }
     }
     $old = View::template($this->template);
     //! if we have to compare to an older (or the latest) version
     if (isset($_REQUEST['diff'])) {
         include_once "vendor/phppe/CMS/libs/simplediff.php";
         //! load current version
         $frame = DS::fetch("data,dds", "pages", "id='frame' AND (lang='' OR lang=?) AND publishid!=0", "", "created DESC", [Core::$client->lang]);
         $frame['dss'] = @json_decode($frame['dds'], true);
         $frame['data'] = @json_decode($frame['data'], true);
         View::assign("frame", $frame['data']);
         $page = DS::fetch("*", "pages", "id=? OR ? LIKE id||'/%'", "", "id DESC,created DESC", [$item, $item]);
         if (is_string($page['data'])) {
             $page['data'] = @json_decode($page['data'], true);
         }
         if (is_array($page['data'])) {
             foreach ($page['data'] as $k => $v) {
                 $this->{$k} = $v;
             }
         }
         foreach (["id", "name", "lang", "filter", "template", "pubd", "expd", "dds", "ownerid", "created"] as $k) {
             $this->{$k} = $page[$k];
         }
         $p = @array_merge($frame['dds'], @json_decode($page['dds'], true));
         if (is_array($p)) {
             foreach ($p as $k => $c) {
                 if ($k != "dds") {
                     try {
                         $this->{$k} = DS::query($c[0], $c[1], @$c[2], @$c[3], @$c[4], @$c[5], View::getval(@$c[6]));
                     } catch (\Exception $e) {
                         Core::log("E", $item . " " . $e->getMessage() . " " . implode(" ", $c), "dds");
                     }
                 }
             }
         }
         $this->title = $page['name'];
         $curr = View::template($this->template);
         //! make sure diff splits on tag end
         $this->result = htmlDiff(preg_replace("/>([^\\ \t\n])/m", "> \\1", $old), preg_replace("/>([^\\ \t\n])/m", "> \\1", $curr));
         //! remove diff inside tags
         $this->result = preg_replace("/(<[^<>]+)<ins>.*?<\\/ins>([^<>]*>)/ims", "\\1\\2", $this->result);
         $this->result = preg_replace("/(<[^<>]+)<del>(.*?)<\\/del>([^<>]*>)/ims", "\\1\\2\\3", $this->result);
     } else {
         $this->result = $old;
     }
     $this->title = $title;
 }