RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-300562

F. Tomas's questions

Martin Hope
F. Tomas
Asked: 2022-09-06 03:54:10 +0000 UTC

无法自动装配 PasswordHasherInterface

  • 1

大家好。我正在新的 Symfony 6.1 上做一个小项目。我连接了设备,因此有必要对密码进行哈希处理。翻遍码头,发现 PasswordHasherInterface

<?php
namespace App\DataFixtures;

use App\Model\User\Entity\User\Email;
use App\Model\User\Entity\User\Id;
use App\Model\User\Entity\User\Role;
use App\Model\User\Entity\User\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\PasswordHasher\PasswordHasherInterface;

class UserFixture extends Fixture
{
    private PasswordHasherInterface $hasher;

    public function __construct(PasswordHasherInterface $hasher)
    {
        $this->hasher = $hasher;
    }
    
    public function load(ObjectManager $manager): void
    {
        $hash = $this->hasher->hash("password");

        $user = User::signUpByEmail(
            Id::next(),
            new \DateTimeImmutable(),
            new Email("admin@app.test"),
            $hash,
            "token"
        );

        $user->confirmSignUp();

        $user->changeRole(Role::admin());

        $manager->persist($user);
        $manager->flush();
    }
}

但我收到一个错误:

In DefinitionErrorExceptionPass.php line 54:
!!                                                                                 
!!    Cannot autowire service "App\DataFixtures\UserFixture": argument "$hasher"   
!!    of method "__construct()" references interface "Symfony\Component\PasswordH  
!!    asher\PasswordHasherInterface" but no such service exists. Did you create a  
!!    class that implements this interface?                                       
!!                                              

我的 services.yaml 文件:

parameters:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Model/User/Entity/'
            - '../src/Kernel.php'

如何在 Symfony 6.1 中散列密码?

php symfony
  • 1 个回答
  • 30 Views
Martin Hope
F. Tomas
Asked: 2022-06-14 06:24:33 +0000 UTC

获取按钮对象,只知道其中的 svg 类

  • 2

页面上有几个按钮。按钮内有 div 和 svg。

<button class="wpOab  " type="button"><div class="QBdTU B5bH7"><svg class="news" color="#8e8e8e" fill="#8e8e8e" height="24"
...
</svg>
</div>
</button>

这些类是随机生成的,一个区别是按钮内的 svg 具有 class="news"。你需要它通过 document.querySelector(".myclass"); 获取的不是 svg 对象,而是其父按钮对象。我怎样才能做到这一点?

javascript
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2021-12-23 21:29:49 +0000 UTC

如何过滤复杂的多维数组?

  • 0

大家好。有一个像这样的数组

    $array = array (
      0 => 
      array (
        'domain' => '.mydomain.com',
        'expirationDate' => '1671845325,529',
        'hostOnly' => false,
        'httpOnly' => false,
        'name' => 'SID',
        'path' => '/',
        'sameSite' => 'unspecified',
        'secure' => false,
        'session' => false,
        'storeId' => '0',
        'value' => '4wdY_czyOdfgd5hfgh34h870uuj7LRagEE53hV3_gghetrxC-717H5-p5ycfP_uJomw.',
        'priority' => 'high',
      ),
      1 => 
      array (
        'domain' => '.mydomain.com',
        'expirationDate' => '1671845325,529',
        'hostOnly' => false,
        'httpOnly' => true,
        'name' => '__Secure-3PSID',
        'path' => '/',
        'sameSite' => 'norestriction',
        'secure' => true,
        'session' => false,
        'storeId' => '1',
        'value' => '4wdY_czyKmbn75De2Z13H8iMhL8h870uuj7LRagEE53hV3_guZ2W7Qf-y8NKsjpLmuNkEAw.',
        'priority' => 'high',
      ),
      2 => 
      array (
        'domain' => '.mydomain.com',
        'expirationDate' => '1671845325,529',
        'hostOnly' => false,
        'httpOnly' => false,
        'name' => 'SID',
        'path' => '/',
        'sameSite' => 'unspecified',
        'secure' => false,
        'session' => false,
        'storeId' => '0',
        'value' => '4wdY_czyOdfgd5hfgh34h870uuj7LRagEE53hV3_gghetrxC-717H5-p5ycfP_uJomw.',
        'priority' => 'high',
      ),
    );

显然,在一个数组中,元素 0 和 2 是相等的(相同的数组)。过滤数组的最佳方法是什么,只留下唯一的元素?换句话说,把它带到表格中:

    $array = array (
      0 => 
      array (
        'domain' => '.mydomain.com',
        'expirationDate' => '1671845325,529',
        'hostOnly' => false,
        'httpOnly' => false,
        'name' => 'SID',
        'path' => '/',
        'sameSite' => 'unspecified',
        'secure' => false,
        'session' => false,
        'storeId' => '0',
        'value' => '4wdY_czyOdfgd5hfgh34h870uuj7LRagEE53hV3_gghetrxC-717H5-p5ycfP_uJomw.',
        'priority' => 'high',
      ),
      1 => 
      array (
        'domain' => '.mydomain.com',
        'expirationDate' => '1671845325,529',
        'hostOnly' => false,
        'httpOnly' => true,
        'name' => '__Secure-3PSID',
        'path' => '/',
        'sameSite' => 'norestriction',
        'secure' => true,
        'session' => false,
        'storeId' => '1',
        'value' => '4wdY_czyKmbn75De2Z13H8iMhL8h870uuj7LRagEE53hV3_guZ2W7Qf-y8NKsjpLmuNkEAw.',
        'priority' => 'high',
      )
    );

内置php函数

$clean = array_unique ( $array );

在这里不起作用并给出错误:

<br />
<b>Notice</b>:  Array to string conversion in <b>[...][...]</b> on line <b>52</b><br />
<br />
<b>Notice</b>:  Array to string conversion in <b>[...][...]</b> on line <b>52</b><br />
<br />
<b>Notice</b>:  Array to string conversion in <b>[...][...]</b> on line <b>52</b><br />

这个问题有解决方案吗?

php
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-05-14 06:17:12 +0000 UTC

正则表达式不适用于西里尔文搜索

  • 1

编写了一个简单的正则表达式来过滤包含俄语单词的字符串。 #^[\p{Cyrillic}\s0-9\-]+$# 我在https://regex101.com/上对其进行了测试——它有效。我将它添加到我的代码中 - 它不起作用......我不明白为什么,我找到了一个在线 PHP 编译器,测试了上面的代码 - 它真的不起作用!

$res = "вопрос";
if(preg_match("#^[\p{Cyrillic}\s0-9\-]+$#", $res)){
  echo 'Good';
} else {
  echo 'Bad';
}

它产生 Bad,虽然 $res 变量中只有俄语字符,但它应该写成 Good。为什么? http://sandbox.onlinephpfunctions.com/code/07479a932b8b77d28cb07bc36a9ad906ff1da22e

php
  • 2 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-05-13 06:46:15 +0000 UTC

不能用 yum update 更新 centos

  • 1

有一个小型KVM VPS(256MB RAM),上面安装了centos 7.0.1406,我想升级到最新版本,将命令驱动到putty,yum update但在安装过程中服务器意外断开连接。VPS 上没有数据,所以我重新安装并再次尝试 - 我再次将它放在同一个地方。再次重新安装 - 再次在同一个地方掉线。我决定尝试只更新内核yum update kernel,但它也不起作用 - VPS 断开连接。 在此处输入图像描述 可能是什么原因以及如何解决问题?

linux
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-05-07 05:13:09 +0000 UTC

我无法理解 fetch 中 POST 请求的功能

  • 0

我正在尝试通过发送 POST 请求fetch。以前我为此目的使用了 jquery。$.ajax

这是我的代码:

fetch("/", {
    method: 'POST',
    headers: {
      "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
    },
    body: 'mode=ajax&action=delete_opt&opt=' + this.arr_opt_to_delete

  })
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })

在接收代码中,在 PHP 脚本中,我输出到一个文件:

file_put_contents("/home/web/ing.txt", print_r($_POST, true), FILE_APPEND);

我得到了结果:

Array
(
    [mode] => ajax
    [action] => delete_opt
    [opt] => ite,koni,vio
)

以前,我使用 jquery$.ajax并按预期收到了一个数组。添加代码:

$.ajax("/", {
  cache: false,
  data: {
    "mode": "ajax",
    "action": "delete_opt",
    "opt": this.arr_opt_to_delete
  },
  dataType: "json",
  type: "POST",
  success: function(dt) {

    console.log(dt);

  },
  error: function() {
    alert("err55");
  }
});

正如预期的那样,我得到了:

Array
(
    [mode] => ajax
    [action] => delete_opt
    [opt] => Array
        (
            [0] => ite
            [1] => koni
            [2] => vio
        )

)

$.ajax为什么数据来自jquery [opt],因为它应该在一个数组中,并且通过fetch我得到一个字符串ite,koni,vio?如何实现它们[opt]通过数组排列fetch?

javascript
  • 2 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-04-30 19:07:10 +0000 UTC

hasOwnProperty 抛出 ReferenceError

  • 1

使用 fetch 我发出 GET 请求:

fetch("/?mode=ajax&action=gen")
      .then(response => response.json())
      .then(data => {

           console.log(data);
           console.log(typeof data);

           if ( ! data.hasOwnProperty(added_logs)) {
               throw new Error("Нет логов: поля 'added_logs' в результирующем наборе не найдено!");
           }

           })
      .catch(err => {
            $('#ajax_err span').html(err);
            $('#ajax_err').show();
      })
;

数据看起来像:

{result: "ok", added_logs: Array(24), added_count: 24}

并将对象输出到控制台但这里是代码片段:

   if ( ! data.hasOwnProperty(added_logs)) {
       throw new Error("Нет логов: поля 'added_logs' в результирующем наборе не найдено!");
   }

抛出错误:

ReferenceError: added_logs is not defined

我不明白为什么?毕竟added_logs属性是在data对象里面的,所以查错了?

fetch
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-04-26 04:48:07 +0000 UTC

帮助 MySQL 正则表达式

  • 1

在 MySQL 数据库中,在 varchar 类型字段中,一行中存储了 1 个 IP 地址或多个以逗号分隔的 IP 地址。

123.22.33.12,21.24.54.215,234.23.15.35

您需要在此行中搜索指定的 IP 地址。通过 LIKE %IP_ADRESS% 将不起作用,因为 例如,“21.24.54.2”的 IP 请求将匹配上面的字符串。但是还有另一个 IP 21.24.54.215。还是用REGEXP吧,因为表的行数不到一百,不会变慢。正则表达式的帮助,我想使用类似的东西\D123.22.33.12\D,但是字符串的开头和结尾有问题。我不擅长常客,所以我正在寻求帮助。

mysql
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-03-24 05:28:49 +0000 UTC

在 symfony 4.4 中支持类在 UserProvider 中不起作用

  • 1

升级到symfony 4.4后,发现网站上的授权被破坏了。当我尝试登录时,出现错误:

There is no user provider for user "App\Security\UserIdentity". Shouldn't the "supportsClass()" method of your user provider return true for this classname?

UserProvider 类中的 supportsClass() 方法如下所示:

namespace App\Security;

use App\ReadModel\User\AuthView;
use App\ReadModel\User\UserFetcher;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;

class UserProvider implements UserProviderInterface
{
...
    public function supportsClass($class): bool
    {
        dump($class);
        return $class instanceof UserIdentity;
        //return true;
    }

使用转储函数,我在探查器中看到 $class 参数如下所示:

"App\Security\UserIdentity"

告诉我,错在哪里?

php
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-02-01 05:17:57 +0000 UTC

symfony 更新后授权被破坏

  • 1

我正在本地开发一个小型 symfony 项目。我正在使用码头工人。我使用 symfony 4.3.8 我决定更新 symfony,在使用docker-compose run --rm manager-php-cli composer update 命令后,symfony以及所有软件包都更新到了 4.3.11

之后,之前运行良好的用户授权在尝试登录时出现错误:

There is no user provider for user "App\Security\UserIdentity". Shouldn't the "supportsClass()" method of your user provider return true for this classname?

多次清除缓存。尝试了缓存:清除和手动。

可能是什么问题呢?真的可以通过简单的更新来破坏项目吗?这是我的 security.yaml

security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
    fetcher:
        id: App\Security\UserProvider
firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        anonymous: true
        user_checker: App\Security\UserChecker
        guard:
            authenticators:
                - App\Security\LoginFormAuthenticator
                - App\Security\OAuth\FacebookAuthenticator
            entry_point: App\Security\LoginFormAuthenticator
        remember_me:
            secret: '%kernel.secret%'
            lifetime: 604800
            path: /

        form_login: true
        logout:
            path: app_logout
            # where to redirect after logout
            # target: app_any_route

        # activate different ways to authenticate
        # https://symfony.com/doc/current/security.html#firewalls-authentication

        # https://symfony.com/doc/current/security/impersonating_user.html
        # switch_user: true

role_hierarchy:
    ROLE_ADMIN:
        - ROLE_USER
        - ROLE_MANAGE_USERS
        - ROLE_WORK_MANAGE_MEMBERS
        - ROLE_WORK_MANAGE_PROJECTS

# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/signup, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/reset, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/oauth, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/, roles: ROLE_USER }

这是 UserProvider.php

declare(strict_types=1);

namespace App\Security;

use App\ReadModel\User\AuthView;
use App\ReadModel\User\UserFetcher;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;

class UserProvider implements UserProviderInterface
{

    /**
     * @var UserFetcher
     */
    private $users;

    public function __construct(UserFetcher $users)
    {
        $this->users = $users;
    }

    public function loadUserByUsername($username): UserInterface
    {
        $user = $this->loadUser($username); // $username can be useremail@gmail.com or facebook:56474756967544769
        return self::identityByUser($user, $username);
    }

    public function refreshUser(UserInterface $identity): UserInterface
    {
        if(!$identity instanceof UserIdentity){
            throw new UnsupportedUserException('Invalid user class '.get_class($identity));
        }

        $user = $this->loadUser($identity->getUsername());
        return self::identityByUser($user, $identity->getUsername());
    }

    public function supportsClass($class): bool
    {
        return $class instanceof UserIdentity;
    }

    private function loadUser($username): AuthView
    {
        $chunks = explode(":", $username); // $username can be useremail@gmail.com or facebook:56474756967544769

        if(count($chunks) === 2 && $user = $this->users->findForAuthByNetwork($chunks[0], $chunks[1])){
            return $user;
        }

        if( ! $user = $this->users->findForAuthByEmail($username) ){
            throw new UsernameNotFoundException("");
        }
        return $user;
    }

    /**
     * $username must be:
     *              facebook:56474756967544769
     *     or       useremail@gmail.com
     *
     * @param AuthView $user
     * @param string   $username - т.к. при регистрации через соц. сеть email может быть пустым, пишем сюда $username, который может быть вида: useremail@gmail.com or facebook:56474756967544769
     * @return UserIdentity
     */
    private static function identityByUser(AuthView $user, string $username): UserIdentity
    {
        return new UserIdentity(
            $user->id,
            $user->email ?: $username,
            $user->password_hash ?: '',
            $user->name ?: $username,
            $user->role,
            $user->status
        );
    }

}

这是 UserIdentity.php

declare(strict_types=1);

namespace App\Security;

use App\Model\User\Entity\User\User;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class UserIdentity implements UserInterface, EquatableInterface
{

    /**
     * @var string
     */
    private $id;

    /**
     * @var string
     */
    private $username;

    /**
     * @var string
     */
    private $password;

    /**
     * @var string
     */
    private $display;

    /**
     * @var string
     */
    private $role;

    /**
     * @var string
     */
    private $status;

    public function __construct(string $id, string $username, string $password, string $display, string $role, string $status)
    {
        $this->id = $id;
        $this->username = $username;
        $this->password = $password;
        $this->display = $display;
        $this->role = $role;
        $this->status = $status;
    }

    public function getId(): string
    {
        return $this->id;
    }

    public function getUsername(): string
    {
        return $this->username;
    }

    public function getPassword(): string
    {
        return $this->password;
    }

    public function getDisplay(): string
    {
        return $this->display;
    }

    public function getRoles(): array
    {
        return [$this->role];
    }

    public function getStatus(): string
    {
        return $this->status;
    }

    public function isActive(): bool
    {
        return $this->status === User::STATUS_ACTIVE;
    }

    public function getSalt(): ?string
    {
        return null;
    }

    public function eraseCredentials(): void
    {
        return;
    }

    public function isEqualTo(UserInterface $user): bool 
    {
        if(!$user instanceof self){
            return false;
        }

        return
            $this->id === $user->id &&
            $this->password === $user->password &&
            $this->role === $user->role &&
            $this->status === $user->status;

    }

}
php
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-10-13 05:55:33 +0000 UTC

无法在 docker 映像中挂载文件夹

  • 2

我在 Windows 8.1 上使用 Docker Toolbox for Windows 在 phpstorm 终端中,我尝试运行以下命令:

docker run --rm -v /$(pwd)/manager/public:/var/www/html -p 8080:80 php:7.2-apache

它似乎工作成功并且容器启动了。但问题是,当我访问http://192.168.99.100:8080/时,我得到一个 Apache 错误:Forbidden,这会到达终端:

[autoindex:error] [pid 17] [client 192.168.99.1:52894] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index for
bidden by Options directive

那些。/var/www/html 文件夹中没有索引文件,尽管我挂载的文件夹 ($(pwd)/manager/public) 有 index.php。检查后发现 /var/www/html 文件夹确实是空的。

我究竟做错了什么?顺便说一句/$(pwd)/manager/public:/var/www/html,我在这里 用谷歌搜索 没有斜线,容器没有启动。我还通过创建 pwd.cmd 文件,将 pwd 命令添加到自己的 Windows 中,将其添加到其中@echo %cd%并将其放入c:\windows\system32\

类似的命令

docker run --rm -v "%cd%/manager/public:/var/www/html" -p 8080:80 php:7.2-apache

报错docker: Error response from daemon: invalid mode: /var/www/html.

PS 也许 $(pwd) 或 %cd% 给出了类似 C:\Users\Alexander\ 的路径,并且与冒号冲突?但是如何解决这个问题?即使尝试使用绝对路径也不会成功 - 容器不会启动。

linux
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-09-28 19:28:40 +0000 UTC

Vue:getter 无法与 vuex 中的 find 一起使用

  • 1

大家好,刚刚在vue中练习。我在 vuex 中遇到了 getter 的一种奇怪行为——如果将 find 方法应用于其中的数组,代码将无法工作。

所以这是我来自 Vuex 的 products.js 模块:

export default {
  namespaced: true,
  state: {
    items: getProducts()
  },
  getters: {
    items(state){
      return state.items;
    },

    mapProducts(state){
      let mapArr = [];

      for(let i = 0; i < state.items.length; i++){
        mapArr[state.items[i].id_product] = state.items[i];
      }
      return mapArr;
    },

    get_product_by_id: (state, getters) => (id) => {
      return getters.items.find((elem) => {
        return elem.id_product === id;
      })
    },

    item: (state, getters) => (id) => {
      return getters.mapProducts[id];
    }
  }
}

function getProducts(){
  return [
    {
      id_product: 14,
      name: "Xiaomi Mi 9T Pro",
      desc: "Android, экран 6.39\" AMOLED (1080x2340), Qualcomm Snapdragon 855, ОЗУ 6 ГБ, флэш-память 128 ГБ, камера 48 Мп, аккумулятор 4000 мАч, 2 SIM",
      price: 520,
      img: require('../../assets/img/id14.jpg')

    },
    {
      id_product: 17,
      name: "HONOR 20",
      desc: "Android, экран 6.26\" IPS (1080x2340), HiSilicon Kirin 980, ОЗУ 6 ГБ, флэш-память 128 ГБ, камера 48 Мп, аккумулятор 3750 мАч, 2 SIM",
      img: require('../../assets/img/id17.jpeg'),
      price: 350
    }
  ]
}

这是我的 Product.vue 组件,我试图通过其 id 获取产品对象:

<template>
<div>
  <h1>{{ get_product }} - {{ get_product_id }}</h1>
</div>
</template>

<script>
  import {mapGetters} from 'vuex';

    export default {
        name: "Product",
        data() {
            return { }
        },
        computed: {
            ...mapGetters("products", {
                get_product_by_id: "get_product_by_id",
                item: "item"
            }),
            get_product_id(){
                return this.$route.params.id;
            },
            get_product(){
                console.log(this.get_product_by_id(this.get_product_id)); // В консоли undefined
                return this.get_product_by_id(this.get_product_id); // Не работает и все тут
                //return this.get_product_by_id(19); // Так работает!!!
                //return this.item(this.get_product_id); // Так тоже работает!!!
            }

        },
        methods: { }
    }
</script>

正如您从评论中看到的那样,在计算中,在 get_product 方法中,行

return this.get_product_by_id(this.get_product_id);

断然拒绝工作,当您尝试将结果输出到控制台时,它会写入未定义。

但是,如果您致电:

return this.get_product_by_id(19);

然后我成功获得了产品对象。还成功返回我一个产品对象调用:

return this.item(this.get_product_id);

解释调用问题

return this.get_product_by_id(this.get_product_id);

为什么应该工作的时候却不工作!!!

javascript
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-07-06 03:25:04 +0000 UTC

如何减少name的食欲?

  • 1

大家好。有一个资源非常有限的小型 VPS - 只有 256Mb RAM。我在这个运行 CentOS 7 操作系统的 VPS 上安装了 PHP 7.3、NginX 和绑定 9.9.4-74。检查 top 命令的输出,我注意到 named 占用了非常大的 RAM - 25.2%

PID  USER  PR NI VIRT   RES   SHR  S %CPU %MEM TIME+   COMMAND
1509 named 20 0  170804 61476 3260 S 0.0  25.2 0:00.24 named

这是 named.conf 配置

acl "trusted" {
    127.0.0.1;
    SERVER_IP;
};

// these are just a list of ip's that I consider bogus and just ignore them
acl "fakeips" {
#        0.0.0.0/8;
};

options {
    listen-on port 53 { 127.0.0.1;SERVER_IP; };
    directory   "/var/named";
    dump-file   "/var/named/data/cache_dump.db";
    statistics-file "/var/named/data/named_stats.txt";
    memstatistics-file "/var/named/data/named_mem_stats.txt";
    allow-query { any; }; // Этот параметр указывает, кому разрешается подавать запросы к нашему серверу
    allow-query-cache { none; };
    allow-recursion { trusted; };
    allow-notify { trusted; };
    allow-transfer { trusted; };
    version "not currently available";
    blackhole { fakeips; };

    dnssec-enable yes;
    dnssec-validation yes;
    dnssec-lookaside auto;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

    pid-file "/run/named/named.pid";
    session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
    type hint;
    file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

告诉我,有没有办法减少named的胃口?这样就不会影响VPS的速度。

linux
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-06-13 02:29:32 +0000 UTC

iptables 规则不适用于 vps

  • 2

大家好。有一个安装了iptables v1.4.21的VPS(OpenVZ),需要屏蔽几个无情解析网站的ip。向 iptables 添加规则,保存它们,重新启动服务器。结果,我在 /etc/sysconfig/iptables 中得到了类似的东西

# Generated by iptables-save v1.4.21 on Wed Jun 10 16:24:09 2019
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [131:11369]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 53 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 53 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 31985 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 51985 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A INPUT -s 176.122.14.0/24 -j REJECT --reject-with icmp-port-unreachable
-A INPUT -s 141.98.82.104/32 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Wed Jun 10 16:24:09 2019

重启 VPS 后检查 iptables 状态 - 活动

# systemctl status iptables
● iptables.service - IPv4 firewall with iptables
   Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
   Active: active (exited) since 
...

但是 iptables IP 阻止规则顽固地拒绝工作。我重新启动了 VPS 几次,并且 iptables 状态 - 活动,来自 iptables 中列出的 IP 的请求继续涌入 nginx 日志。我无法弄清楚这里发生了什么。我曾经在专用服务器上做类似的操作,一切正常......

centos
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-03-27 01:45:30 +0000 UTC

给定句子,如何将文本分成块?

  • 0

大家好。有必要使用 PHP 5.6 将长度超过 3000 个字符的文本分成不超过 500 个字符的片段。但与此同时,建议必须考虑在内。文本可能包含标签。例如,我们有一个 1398 个字符的文本:

Financial, commercial, legal, and intellectual factors changed the size of encyclopedias. During the <a href="/wiki/Renaissance" title="Renaissance">Renaissance</a>, middle classes had more time to read and encyclopedias helped them to learn more. Publishers wanted to increase their output so some countries like Germany started selling books missing alphabetical sections, to publish faster. Also, publishers could not afford all the resources by themselves, so multiple publishers would come together with their resources to create better encyclopedias. When publishing at the same rate became financially impossible, they turned to subscriptions and serial publications. This was risky for publishers because they had to find people that would pay all upfront or make payments. When this worked, capital would rise and there would be a steady income for encyclopedias. Later, rivalry grew, causing copyright to occur due to weak underdeveloped laws. Some publishers would copy another publisher's work to produce an encyclopedia faster and cheaper so consumers did not have to pay a lot and they would <a href="/wiki/encyclopedias" title="Renaissance">sell more</a>. Encyclopedias made it to where middle-class citizens could basically have a small library in their own house. Europeans were becoming more curious about their society around them causing them to revolt against their government.

您需要获取一个数组作为输出:

$result = [
   // 393 символа 
   0 => "Financial, commercial, legal, and intellectual factors changed the size of encyclopedias. During the <a href=\"/wiki/Renaissance\" title=\"Renaissance\">Renaissance</a>, middle classes had more time to read and encyclopedias helped them to learn more. Publishers wanted to increase their output so some countries like Germany started selling books missing alphabetical sections, to publish faster.",

    // 478 символов
    1 => "Also, publishers could not afford all the resources by themselves, so multiple publishers would come together with their resources to create better encyclopedias. When publishing at the same rate became financially impossible, they turned to subscriptions and serial publications. This was risky for publishers because they had to find people that would pay all upfront or make payments. When this worked, capital would rise and there would be a steady income for encyclopedias.",

    // 407 символов
    2 => "Later, rivalry grew, causing copyright to occur due to weak underdeveloped laws. Some publishers would copy another publisher's work to produce an encyclopedia faster and cheaper so consumers did not have to pay a lot and they would <a href=\"/wiki/encyclopedias\" title=\"Renaissance\">sell more</a>. Encyclopedias made it to where middle-class citizens could basically have a small library in their own house.",

    // Оставшаяся часть - 117 символов
    3 => "Europeans were becoming more curious about their society around them causing them to revolt against their government."
]; 

请告诉我最好的方法来做到这一点。

php
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-03-19 21:23:09 +0000 UTC

无法在 nginx 中从 https 重定向到 http

  • 1

大家好。购买了以前由另一个人拥有的域。旧域的 google 索引中有带有 https 的页面。我要上传到这个域的网站在 http 上工作,所以当我从 https 访问页面时需要重定向到 http。我搜索了互联网,尝试了很多选项 - 它不起作用。

这是我的 nginx 配置:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    access_log off;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    client_max_body_size 10M;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;


server {
    listen       myip:80;
    server_name .mysite12.com;

    location / {
        root   /home/site12;
        index  index.php;
if ($scheme = https) {
    return 301 http://$host$request_uri;
}
        if (!-e $request_filename) {
               rewrite ^ /index.php last;
               break;
        }
    }

    location ~ \.php$ {
        root           /home/site12;
        try_files $uri =404;
        fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}


}

添加

if ($scheme = https) {
    return 301 http://$host$request_uri;
}

在我看来,这是最合乎逻辑的选择,但它不起作用......帮助我从 http 重定向到 https

nginx
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-12-25 04:37:03 +0000 UTC

如何根据用户评分突出显示平均评分?

  • 2

大家好。我使用 Starability.css 库,用户可以在其中单击星标对产品/服务进行评分。 https://github.com/LunarLogic/starability 我已经有了基于用户评分的平均评分,例如 3.45,我需要在页面加载时突出显示 3.5 颗星。怎么做?我没有在文档中找到答案。或者你能告诉我一个类似的图书馆在哪里可以做到这一点。

css
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-11-18 23:56:44 +0000 UTC

Symfony 中的数据库查询问题

  • 2

symfony 3.4 上的网站

有2张桌子:

产品 在此处输入图像描述

和类别

在此处输入图像描述

有必要以下列形式显示这些表格中的信息: 在此处输入图像描述

以便显示每个产品类别中的产品数量

我编写了以下 DQL 查询:

    SELECT a.id, a.category, a.enabled, COUNT(b.id) as prcnt
    FROM AppBundle:Category a
    JOIN AppBundle:Product b WITH a.id = b.category
    WHERE a.enabled = :enabled

和调试输出:

array:1 [▼
  0 => array:4 [▼
    "id" => 1
    "category" => "Фантастика"
    "enabled" => true
    "prcnt" => "6"
  ]
]

如您所见,只找到了 1 个类别,此外,他数错了 COUNT,在“奇幻”类别中有 4 个产品,他将所有产品都统计了 - 6 个。

我的 DQL 查询中的错误在哪里?为什么输出中只有 1 个类别?编写此 DQL 查询的正确方法是什么?为什么在 DQL 中引入 WITH 而不是 ON ?

一般来说,根据 symfony 的最佳实践,是编写 DQL 查询还是使用 createQueryBuilder 收集器更好?

php
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-11-11 02:11:03 +0000 UTC

为什么 symfony 有 generateUrl 方法

  • 0

我学习 symfony,我阅读了文档。路由部分https://symfony.com/doc/3.4/routing.html#generating-urls描述了 generateUrl 方法。我无法理解它执行什么功能以及在什么情况下可能需要它?

class MainController extends Controller
{
    public function showAction($slug)
    {
        // ...

        // /blog/my-blog-post 
        // (Зачем??, если в аннотации можно указать @Route("/blog/my-blog-post", name="myblogpost"))
        $url = $this->generateUrl(
            'blog_show',
            array('slug' => 'my-blog-post')
        );
    }
}
php
  • 1 个回答
  • 10 Views
Martin Hope
F. Tomas
Asked: 2020-10-31 23:41:58 +0000 UTC

如何从动作中触发突变

  • 2

我正在使用 Vue.js 并执行以下操作:

 actions: {
     chmy(store, i){
      store.state.controls[i].isActive = true;
      store.state.controls[i].isValid = store.state.myinputs[i].regexp.test(store.state.myinputs[i].value);
   }

运行代码时,Vue.js 发誓

Error: [vuex] Do not mutate vuex store state outside mutation handlers.

编写突变的最佳方法是什么?毕竟,我仍然需要传递控件 i 数组的索引。

像这样尝试:

  actions: {
    chmy(store, i){
      store.commit('updControls', {control: store.state.controls[i].isActive, val: true});
}
}

  mutations: {
    updControls(state, obj){
      obj.control = obj.val;
    }
}

但不起作用。告诉我如何正确地做

javascript
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5