public static function loadSettings($settings) { $error = FALSE; static $ktr = array('-' => ''); foreach ($settings as $k => $v) { $k = strtolower(strtr($k, $ktr)); if ($k === 'config') { $k = 'configfile'; } if ($k === 'user' || $k === 'group') { if ($v === '') { $v = NULL; } } if (array_key_exists($k, Daemon::$settings)) { if ($k === 'maxmemoryusage') { Daemon::$parsedSettings[$k] = Daemon::parseSize($v); } elseif ($k === 'maxrequests') { Daemon::$parsedSettings[$k] = Daemon::parseNum($v); } elseif ($k === 'autogc') { Daemon::$parsedSettings[$k] = Daemon::parseNum($v); } elseif ($k === 'maxidle') { Daemon::$parsedSettings[$k] = Daemon::parseTime($v); } elseif ($k === 'autoreload') { Daemon::$parsedSettings[$k] = Daemon::parseTime($v); } elseif ($k === 'maxconcurrentrequestsperworker') { Daemon::$parsedSettings[$k] = Daemon::parseNum($v); } elseif ($k === 'keepalive') { Daemon::$parsedSettings[$k] = Daemon::parseTime($v); } elseif ($k === 'mpmdelay') { Daemon::$parsedSettings[$k] = Daemon::parseTime($v); } elseif ($k === 'chunksize') { Daemon::$parsedSettings[$k] = Daemon::parseSize($v); } if (is_int(Daemon::$settings[$k])) { Daemon::$settings[$k] = (int) $v; } else { Daemon::$settings[$k] = $v; } } elseif (strpos($k, 'mod') === 0) { Daemon::$settings[$k] = $v; } else { Daemon::log('Unrecognized parameter \'' . $k . '\''); $error = TRUE; } } if (isset($settings['path'])) { if (isset(Daemon::$settings['chroot'])) { Daemon::$pathReal = realpath(Daemon::$settings['chroot'] . (substr(Daemon::$settings['chroot'], -1) != '/' ? '/' : '') . Daemon::$settings['path']); } else { Daemon::$pathReal = realpath(Daemon::$settings['path']); } } return !$error; }
public function update() { Daemon::$parsedSettings['mod' . $this->modname . 'maxallowedpacket'] = Daemon::parseSize(Daemon::$settings['mod' . $this->modname . 'maxallowedpacket']); }
public function parseStdin() { do { if ($this->boundary === FALSE) { break; } $continue = FALSE; if ($this->mpartstate === 0) { if (($p = strpos($this->attrs->stdinbuf, $ndl = '--' . $this->boundary . "\r\n", $this->mpartoffset)) !== FALSE) { // we have found the nearest boundary at position $p $this->mpartoffset = $p + strlen($ndl); $this->mpartstate = 1; $continue = TRUE; } } elseif ($this->mpartstate === 1) { $this->mpartcondisp = FALSE; if (($p = strpos($this->attrs->stdinbuf, "\r\n\r\n", $this->mpartoffset)) !== FALSE) { $h = explode("\r\n", binarySubstr($this->attrs->stdinbuf, $this->mpartoffset, $p - $this->mpartoffset)); $this->mpartoffset = $p + 4; $this->attrs->stdinbuf = binarySubstr($this->attrs->stdinbuf, $this->mpartoffset); $this->mpartoffset = 0; for ($i = 0, $s = sizeof($h); $i < $s; ++$i) { $e = explode(':', $h[$i], 2); $e[0] = strtr(strtoupper($e[0]), Request::$htr); if (isset($e[1])) { $e[1] = ltrim($e[1]); } if ($e[0] == 'CONTENT_DISPOSITION' && isset($e[1])) { parse_str(strtr($e[1], Request::$hvaltr), $this->mpartcondisp); if (!isset($this->mpartcondisp['form-data'])) { break; } if (!isset($this->mpartcondisp['name'])) { break; } $this->mpartcondisp['name'] = trim($this->mpartcondisp['name'], '"'); if (isset($this->mpartcondisp['filename'])) { $this->mpartcondisp['filename'] = trim($this->mpartcondisp['filename'], '"'); if (!ini_get('file_uploads')) { break; } $this->attrs->files[$this->mpartcondisp['name']] = array('name' => $this->mpartcondisp['filename'], 'type' => '', 'tmp_name' => '', 'error' => UPLOAD_ERR_OK, 'size' => 0); $tmpdir = ini_get('upload_tmp_dir'); if ($tmpdir === FALSE) { $this->attrs->files[$this->mpartcondisp['name']]['fp'] = FALSE; $this->attrs->files[$this->mpartcondisp['name']]['error'] = UPLOAD_ERR_NO_TMP_DIR; } else { $this->attrs->files[$this->mpartcondisp['name']]['fp'] = @fopen($this->attrs->files[$this->mpartcondisp['name']]['tmp_name'] = tempnam($tmpdir, 'php'), 'w'); if (!$this->attrs->files[$this->mpartcondisp['name']]['fp']) { $this->attrs->files[$this->mpartcondisp['name']]['error'] = UPLOAD_ERR_CANT_WRITE; } } $this->mpartstate = 3; } else { $this->attrs->post[$this->mpartcondisp['name']] = ''; } } elseif ($e[0] == 'CONTENT_TYPE' && isset($e[1])) { if (isset($this->mpartcondisp['name']) && isset($this->mpartcondisp['filename'])) { $this->attrs->files[$this->mpartcondisp['name']]['type'] = $e[1]; } } } if ($this->mpartstate === 1) { $this->mpartstate = 2; } $continue = TRUE; } } elseif ($this->mpartstate === 2 || $this->mpartstate === 3) { if (($p = strpos($this->attrs->stdinbuf, $ndl = "\r\n--" . $this->boundary . "\r\n", $this->mpartoffset)) !== FALSE || ($p = strpos($this->attrs->stdinbuf, $ndl = "\r\n--" . $this->boundary . "--\r\n", $this->mpartoffset)) !== FALSE) { if ($this->mpartstate === 2 && isset($this->mpartcondisp['name'])) { $this->attrs->post[$this->mpartcondisp['name']] .= binarySubstr($this->attrs->stdinbuf, $this->mpartoffset, $p - $this->mpartoffset); } elseif ($this->mpartstate === 3 && isset($this->mpartcondisp['filename'])) { if ($this->attrs->files[$this->mpartcondisp['name']]['fp']) { fwrite($this->attrs->files[$this->mpartcondisp['name']]['fp'], binarySubstr($this->attrs->stdinbuf, $this->mpartoffset, $p - $this->mpartoffset)); } $this->attrs->files[$this->mpartcondisp['name']]['size'] += $p - $this->mpartoffset; } if ($ndl === "\r\n--" . $this->boundary . "--\r\n") { $this->mpartoffset = $p + strlen($ndl); $this->mpartstate = 0; // we done at all } else { $this->mpartoffset = $p; $this->mpartstate = 1; // let us parse the next part $continue = TRUE; } $this->attrs->stdinbuf = binarySubstr($this->attrs->stdinbuf, $this->mpartoffset); $this->mpartoffset = 0; } else { $p = strrpos($this->attrs->stdinbuf, "\r\n", $this->mpartoffset); if ($p !== FALSE) { if ($this->mpartstate === 2 && isset($this->mpartcondisp['name'])) { $this->attrs->post[$this->mpartcondisp['name']] .= binarySubstr($this->attrs->stdinbuf, $this->mpartoffset, $p - $this->mpartoffset); } elseif ($this->mpartstate === 3 && isset($this->mpartcondisp['filename'])) { if ($this->attrs->files[$this->mpartcondisp['name']]['fp']) { fwrite($this->attrs->files[$this->mpartcondisp['name']]['fp'], binarySubstr($this->attrs->stdinbuf, $this->mpartoffset, $p - $this->mpartoffset)); } $this->attrs->files[$this->mpartcondisp['name']]['size'] += $p - $this->mpartoffset; if (Daemon::parseSize(ini_get('upload_max_filesize')) < $this->attrs->files[$this->mpartcondisp['name']]['size']) { $this->attrs->files[$this->mpartcondisp['name']]['error'] = UPLOAD_ERR_INI_SIZE; } if (isset($this->attrs->post['MAX_FILE_SIZE']) && $this->attrs->post['MAX_FILE_SIZE'] < $this->attrs->files[$this->mpartcondisp['name']]['size']) { $this->attrs->files[$this->mpartcondisp['name']]['error'] = UPLOAD_ERR_FORM_SIZE; } } $this->mpartoffset = $p; $this->attrs->stdinbuf = binarySubstr($this->attrs->stdinbuf, $this->mpartoffset); $this->mpartoffset = 0; } } } } while ($continue); }