private function write_file($filepath, $buf) { if (!file_exists($filepath)) { // new file, check path exists if (!PathTool::createFile("{$filepath}.new", $err)) { error_log("failed to create file {$filepath} : {$err} \n"); return FALSE; } } $fd = fopen("{$filepath}.new", 'w'); if (!$fd) { error_log("failed to open in write mode for {$filepath}.new"); return FALSE; } if (fwrite($fd, $buf) === FALSE) { error_log("failed to write temp config for {$filepath}.new"); return FALSE; } fclose($fd); @unlink("{$filepath}.bak"); if (file_exists($filepath) && !rename($filepath, "{$filepath}.bak")) { error_log("failed to rename {$filepath} to {$filepath}.bak"); return FALSE; } if (!rename("{$filepath}.new", $filepath)) { error_log("failed to rename {$filepath}.new to {$filepath}"); return FALSE; } return TRUE; }
public function chkAttr_file_val($attr, $val, &$err) { //this is public clearstatcache(); $err = NULL; if ($attr->_type == 'filep') { $path = substr($val, 0, strrpos($val, '/')); } else { $path = $val; if ($attr->_type == 'file1') { $pos = strpos($val, ' '); if ($pos > 0) { $path = substr($val, 0, $pos); } } } $res = $this->chk_file1($attr, $path, $err); if ($attr->_type == 'filetp') { $pathtp = SERVER_ROOT . 'conf/templates/'; if (strstr($path, $pathtp) === FALSE) { $err = ' Template file must locate within $SERVER_ROOT/conf/templates/'; $res = -1; } else { if (substr($path, -5) != '.conf') { $err = ' Template file name needs to be ".conf"'; $res = -1; } } } elseif ($attr->_type == 'filevh') { $pathvh = SERVER_ROOT . 'conf/vhosts/'; if (strstr($path, $pathvh) === FALSE) { $err = ' VHost config file must locate within $SERVER_ROOT/conf/vhosts/, suggested value is $SERVER_ROOT/conf/vhosts/$VH_NAME/vhconf.conf'; $res = -1; } else { if (substr($path, -5) != '.conf') { $err = ' VHost config file name needs to be ".conf"'; $res = -1; } } } if ($res == -1 && $_POST['file_create'] == $attr->GetKey() && $this->allow_create($attr, $path)) { if (PathTool::createFile($path, $err, $attr->GetKey())) { $err = "{$path} has been created successfully."; } $res = 0; // make it always point to curr page } return $res; }