public function init($config) { if (!empty($config['ip'])) { $this->id = $config['ip']; } elseif (!empty($config['interface'])) { exec("ip addr sh " . escapeshellarg($config['interface']) . "|grep inet", $ips); if (!empty($ips[0]) && preg_match("/inet ([0-9a-f\\:\\.]+)/", $ips[0], $m)) { $this->id = $m[1]; } } if (empty($this->id)) { exec("ip addr sh|grep inet", $ips); if (!empty($ips[0]) && preg_match("/inet ([0-9a-f\\:\\.]+)/", $ips[0], $m)) { $this->id = $m[1]; } } if (!empty($config['keepalive']) && intval($config['keepalive']) > 3) { $this->_keepalive = intval($config['keepalive']); } if (!empty($config['deploy']) && is_array($config['deploy'])) { $this->_deploy = $config['deploy']; } if (!empty($config['skeleton']) && is_dir($config['skeleton'])) { $this->_skeleton = $config['skeleton']; } if (!empty($config['skeleton']) && is_dir($config['skeleton'])) { $this->_rsync = true; } $master = DS::field("id", self::$_table, "type='master' AND modifyd>CURRENT_TIMESTAMP-120"); $this->_master = strtolower(trim($this->id)) == strtolower(trim($master)); View::jslib("cluster.js", "pe.cluster.init();"); }
/** * Read a parameter value for key from registry. Will return default if key not found. * * @param string key * @param mixed optional default value * * @return mixed value */ public static function get($key, $default = '') { //sanitize key $key = preg_replace('/[^a-zA-Z0-9_]/', '', $key); $value = null; //try to read from database... try { $value = DS::field('data', 'registry', 'name=?', '', '', [$key]); } catch (\Exception $e) { //...fallback to files $v = trim(@file_get_contents('data/registry/' . $key)); $value = json_decode($v); if (!is_array($value) && !is_object($value)) { $value = $v; } } return $value == null ? $default : $value; }
/** * Get number of pages for a given template * * @param string template */ static function getNum($template) { return DS::field("SUM(1)", static::$_table, "template=?", "", "", [$template]); }