Esempio n. 1
0
function DNS($host)
{
    global $config;
    if ($config['cache']['enabled'] && ($ip_addr = cache::get('dns_' . $host))) {
        return $ip_addr != '?' ? $ip_addr : false;
    }
    if (!$config['dns_system']) {
        $ip_addr = gethostbyname($host);
        if ($ip_addr == $host) {
            $ip_addr = false;
        }
    } else {
        $resp = shell_exec_error('host -W 1 ' . $host);
        if (preg_match('/has address ([^\\s]+)$/', $resp, $m)) {
            $ip_addr = $m[1];
        } else {
            $ip_addr = false;
        }
    }
    if ($config['cache']['enabled']) {
        cache::set('dns_' . $host, $ip_addr !== false ? $ip_addr : '?');
    }
    return $ip_addr;
}
Esempio n. 2
0
 public function resize()
 {
     global $config;
     if ($this->temp) {
         // remove old
         $this->destroy();
     }
     $this->temp = tempnam($config['tmp'], 'convert');
     $config['thumb_keep_animation_frames'] = (int) $config['thumb_keep_animation_frames'];
     if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '') && $config['thumb_keep_animation_frames'] > 1) {
         if ($this->gifsicle) {
             if (($error = shell_exec("gifsicle -w --unoptimize -O2 --resize {$this->width}x{$this->height} < " . escapeshellarg($this->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" -o " . escapeshellarg($this->temp))) || !file_exists($this->temp)) {
                 $this->destroy();
                 error(_('Failed to resize image!'), null, $error);
             }
         } else {
             if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) {
                 $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
             } elseif ($config['convert_manual_orient']) {
                 $convert_args = str_replace('-auto-orient', '', $config['convert_args']);
             } else {
                 $convert_args =& $config['convert_args'];
             }
             if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, $this->height, escapeshellarg($this->src), $this->width, $this->height, escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
                 $this->destroy();
                 error(_('Failed to resize image!'), null, $error);
             }
             if ($size = $this->get_size($this->temp)) {
                 $this->width = $size[0];
                 $this->height = $size[1];
             }
         }
     } else {
         if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) {
             $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
         } elseif ($config['convert_manual_orient']) {
             $convert_args = str_replace('-auto-orient', '', $config['convert_args']);
         } else {
             $convert_args =& $config['convert_args'];
         }
         if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, $this->height, escapeshellarg($this->src . '[0]'), $this->width, $this->height, escapeshellarg('jpg:' . $this->temp)))) || !file_exists($this->temp)) {
             if (strpos($error, "known incorrect sRGB profile") === false && strpos($error, "iCCP: Not recognizing known sRGB profile that has been edited") === false) {
                 $this->destroy();
                 error(_('Failed to resize image!') . " " . _('Details: ') . nl2br(htmlspecialchars($error)), null, array('convert_error' => $error));
             }
             if (!file_exists($this->temp)) {
                 $this->destroy();
                 error(_('Failed to resize image!'), null, $error);
             }
         }
         if ($size = $this->get_size($this->temp)) {
             $this->width = $size[0];
             $this->height = $size[1];
         }
     }
 }
Esempio n. 3
0
         $file['thumbheight'] = $size[1];
     } elseif ($config['minimum_copy_resize'] && $image->size->width <= $config['thumb_width'] && $image->size->height <= $config['thumb_height'] && $file['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'])) {
         // Copy, because there's nothing to resize
         copy($file['tmp_name'], $file['thumb']);
         $file['thumbwidth'] = $image->size->width;
         $file['thumbheight'] = $image->size->height;
     } else {
         $thumb = $image->resize($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'], $post['op'] ? $config['thumb_op_width'] : $config['thumb_width'], $post['op'] ? $config['thumb_op_height'] : $config['thumb_height']);
         $thumb->to($file['thumb']);
         $file['thumbwidth'] = $thumb->width;
         $file['thumbheight'] = $thumb->height;
         $thumb->_destroy();
     }
     if ($config['redraw_image'] || !@$file['exif_stripped'] && $config['strip_exif'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')) {
         if (!$config['redraw_image'] && $config['use_exiftool']) {
             if ($error = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= ' . escapeshellarg($file['tmp_name']))) {
                 error(_('Could not strip EXIF metadata!'), null, $error);
             }
         } else {
             $image->to($file['file']);
             $dont_copy_file = true;
         }
     }
     $image->destroy();
 } else {
     // not an image
     //copy($config['file_thumb'], $post['thumb']);
     $file['thumb'] = 'file';
     $size = @getimagesize(sprintf($config['file_thumb'], isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']));
     $file['thumbwidth'] = $size[0];
     $file['thumbheight'] = $size[1];
Esempio n. 4
0
function mod_config($board_config = false)
{
    global $config, $mod, $board;
    if ($board_config && !openBoard($board_config)) {
        error($config['error']['noboard']);
    }
    if (!hasPermission($config['mod']['edit_config'], $board_config)) {
        error($config['error']['noaccess']);
    }
    $config_file = $board_config ? $board['dir'] . 'config.php' : 'inc/instance-config.php';
    if ($config['mod']['config_editor_php']) {
        $readonly = !(is_file($config_file) ? is_writable($config_file) : is_writable(dirname($config_file)));
        if (!$readonly && isset($_POST['code'])) {
            $code = $_POST['code'];
            // Save previous instance_config if php_check_syntax fails
            $old_code = file_get_contents($config_file);
            file_put_contents($config_file, $code);
            $resp = shell_exec_error('php -l ' . $config_file);
            if (preg_match('/No syntax errors detected/', $resp)) {
                header('Location: ?/config' . ($board_config ? '/' . $board_config : ''), true, $config['redirect_http']);
                return;
            } else {
                file_put_contents($config_file, $old_code);
                error($config['error']['badsyntax'] . $resp);
            }
        }
        $instance_config = @file_get_contents($config_file);
        if ($instance_config === false) {
            $instance_config = "<?php\n\n// This file does not exist yet. You are creating it.";
        }
        $instance_config = str_replace("\n", '&#010;', utf8tohtml($instance_config));
        mod_page(_('Config editor'), 'mod/config-editor-php.html', array('php' => $instance_config, 'readonly' => $readonly, 'boards' => listBoards(), 'board' => $board_config, 'file' => $config_file, 'token' => make_secure_link_token('config' . ($board_config ? '/' . $board_config : ''))));
        return;
    }
    require_once 'inc/mod/config-editor.php';
    $conf = config_vars();
    foreach ($conf as &$var) {
        if (is_array($var['name'])) {
            $c =& $config;
            foreach ($var['name'] as $n) {
                $c =& $c[$n];
            }
        } else {
            $c = @$config[$var['name']];
        }
        $var['value'] = $c;
    }
    unset($var);
    if (isset($_POST['save'])) {
        $config_append = '';
        foreach ($conf as $var) {
            $field_name = 'cf_' . (is_array($var['name']) ? implode('/', $var['name']) : $var['name']);
            if ($var['type'] == 'boolean') {
                $value = isset($_POST[$field_name]);
            } elseif (isset($_POST[$field_name])) {
                $value = $_POST[$field_name];
            } else {
                continue;
            }
            // ???
            if (!settype($value, $var['type'])) {
                continue;
            }
            // invalid
            if ($value != $var['value']) {
                // This value has been changed.
                $config_append .= '$config';
                if (is_array($var['name'])) {
                    foreach ($var['name'] as $name) {
                        $config_append .= '[' . var_export($name, true) . ']';
                    }
                } else {
                    $config_append .= '[' . var_export($var['name'], true) . ']';
                }
                $config_append .= ' = ';
                if (@$var['permissions'] && isset($config['mod']['groups'][$value])) {
                    $config_append .= $config['mod']['groups'][$value];
                } else {
                    $config_append .= var_export($value, true);
                }
                $config_append .= ";\n";
            }
        }
        if (!empty($config_append)) {
            $config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n";
            if (!is_file($config_file)) {
                $config_append = "<?php\n\n{$config_append}";
            }
            if (!@file_put_contents($config_file, $config_append, FILE_APPEND)) {
                $config_append = htmlentities($config_append);
                if ($config['minify_html']) {
                    $config_append = str_replace("\n", '&#010;', $config_append);
                }
                $page = array();
                $page['title'] = 'Cannot write to file!';
                $page['config'] = $config;
                $page['body'] = '
					<p style="text-align:center">Tinyboard could not write to <strong>' . $config_file . '</strong> with the ammended configuration, probably due to a permissions error.</p>
					<p style="text-align:center">You may proceed with these changes manually by copying and pasting the following code to the end of <strong>' . $config_file . '</strong>:</p>
					<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" readonly>' . $config_append . '</textarea>
				';
                echo Element('page.html', $page);
                exit;
            }
        }
        header('Location: ?/config' . ($board_config ? '/' . $board_config : ''), true, $config['redirect_http']);
        exit;
    }
    mod_page(_('Config editor') . ($board_config ? ': ' . sprintf($config['board_abbreviation'], $board_config) : ''), 'mod/config-editor.html', array('boards' => listBoards(), 'board' => $board_config, 'conf' => $conf, 'file' => $config_file, 'token' => make_secure_link_token('config' . ($board_config ? '/' . $board_config : ''))));
}
Esempio n. 5
0
         $post['thumbheight'] = $size[1];
     } elseif ($config['minimum_copy_resize'] && $image->size->width <= $config['thumb_width'] && $image->size->height <= $config['thumb_height'] && $post['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'])) {
         // Copy, because there's nothing to resize
         copy($upload, $post['thumb']);
         $post['thumbwidth'] = $image->size->width;
         $post['thumbheight'] = $image->size->height;
     } else {
         $thumb = $image->resize($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'], $post['op'] ? $config['thumb_op_width'] : $config['thumb_width'], $post['op'] ? $config['thumb_op_height'] : $config['thumb_height']);
         $thumb->to($post['thumb']);
         $post['thumbwidth'] = $thumb->width;
         $post['thumbheight'] = $thumb->height;
         $thumb->_destroy();
     }
     if ($config['redraw_image'] || !@$post['exif_stripped'] && $config['strip_exif'] && ($post['extension'] == 'jpg' || $post['extension'] == 'jpeg')) {
         if (!$config['redraw_image'] && $config['use_exiftool']) {
             if ($error = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= ' . escapeshellarg($upload))) {
                 error(_('Could not strip EXIF metadata!'), null, $error);
             }
         } else {
             $image->to($post['file']);
             $dont_copy_file = true;
         }
     }
     $image->destroy();
 } else {
     // not an image
     //copy($config['file_thumb'], $post['thumb']);
     $post['thumb'] = 'file';
     $size = @getimagesize(sprintf($config['file_thumb'], isset($config['file_icons'][$post['extension']]) ? $config['file_icons'][$post['extension']] : $config['file_icons']['default']));
     $post['thumbwidth'] = $size[0];
     $post['thumbheight'] = $size[1];
Esempio n. 6
0
 public function resize()
 {
     global $config;
     if ($this->temp) {
         // remove old
         $this->destroy();
     }
     $this->temp = tempnam($config['tmp'], 'convert');
     $config['thumb_keep_animation_frames'] = (int) $config['thumb_keep_animation_frames'];
     if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '') && $config['thumb_keep_animation_frames'] > 1) {
         if ($this->gifsicle) {
             if (($error = shell_exec("gifsicle -w --unoptimize -O2 --resize {$this->width}x{$this->height} < " . escapeshellarg($this->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" -o " . escapeshellarg($this->temp))) || !file_exists($this->temp)) {
                 $this->destroy();
                 error(_('Failed to resize image!'), null, $error);
             }
         } else {
             if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) {
                 $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
             } elseif ($config['convert_manual_orient']) {
                 $convert_args = str_replace('-auto-orient', '', $config['convert_args']);
             } else {
                 $convert_args =& $config['convert_args'];
             }
             if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, $this->height, escapeshellarg($this->src), $this->width, $this->height, escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
                 $this->destroy();
                 error('Failed to resize image!', null, $error);
             }
             if ($size = $this->get_size($this->temp)) {
                 $this->width = $size[0];
                 $this->height = $size[1];
             }
         }
     } else {
         if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) {
             $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
         } elseif ($config['convert_manual_orient']) {
             $convert_args = str_replace('-auto-orient', '', $config['convert_args']);
         } else {
             $convert_args =& $config['convert_args'];
         }
         if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, $this->height, escapeshellarg($this->src . '[0]'), $this->width, $this->height, escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
             $this->destroy();
             error('Failed to resize image!', null, $error);
         }
         if ($size = $this->get_size($this->temp)) {
             $this->width = $size[0];
             $this->height = $size[1];
         }
     }
 }