Search This Blog

2018/11/13

'selinux' not supported in vagrant VM

chcon -R -t httpd_sys_content_t vagrant

$ mount /dev/sda2 /vagrant/ -o defcontext="system_u:object_r:httpd_sys_content_t:s0"
apache

mount server:/export /vagrant -o context="system_u:object_r:httpd_sys_content_t:s0"

https://github.com/hashicorp/vagrant/issues/6970

2018/08/19

Mysql文字列処理

mysql> SELECT CONCAT('My', 'S', 'QL');
        -> 'MySQL'
mysql> SELECT CONCAT('My', NULL, 'QL');
        -> NULL
mysql> SELECT CONCAT(14.3);
        -> '14.3'
mysql> SELECT CONCAT_WS(',','First name','Second name','Last Name');
        -> 'First name,Second name,Last Name'
mysql> SELECT CONCAT_WS(',','First name',NULL,'Last Name');
        -> 'First name,Last Name'

2018/07/03

Get file data by axios|Vue.js

<template>
    <div class="col-lg-12" v-html="rawHtml">
</div>
</template>
axios.get('/assets/includes/test.html')
.then((res) => {
    if (res.status === 200) {
        this.rawHtml = res.data;
    } else {
        console.log(res.status);
    }
})
.catch((error) => {
    console.log(error);
});
Also can get json file.

2018/06/14

Missing the MySQL extension which is required by WordPress.

Error:
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Install below will solve. MariaDB also need.
php-mysql
php-mysqlnd

CentOS:
yum install php-mysql
yum install php-mysqlnd
# php72
yum install php72-php-mysql
yum install php72-php-mysqlnd

Ubuntu:
apt-get install php-mysql
apt-get install php-mysqlnd

2018/06/12

split in PHP

explode($findThis, $targetString);
explode("/", "ab/dvf/dfa");
> ["ab", "dvf", "dfa"]

str_split($targetString, [int length]);
str_split("dddd");
> ["d", "d", "d", "d"]

str_split("dddd", 2);
> ["dd", "dd"]

QQ mail: 550 Suspected spam ip

qq mail: 550 Suspected spam ip
mail blocked by theIP

http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=20022&&no=1001495
550 Suspected spam ip.
IP 发送大量垃圾邮件,或所发送的邮件收件人存在大量的不存在账号。

Basically It is nothing Service Provide can do, need user to set mail setting.

Solution:
Add domain into whitelist.
Setting》Spam》Set Email whitelist
Setting》Spam》Set domain whitelist
把被拒邮箱的网域加入白名单。
设置》反垃圾》设置邮件地址白名单
设置》反垃圾》设置域名白名单

2018/06/11

Vue.js Tips

Hide elements during loading using "v-cloak"]

v-if vs v-show
Generally speaking, v-if has higher toggle costs while v-show has higher initial render costs. So prefer v-show if you need to toggle something very often, and prefer v-if if the condition is unlikely to change at runtime.

Call vue function from outside third party js
third party js call back a function, like callbackFuc.
In outside js:
var functionName = function(response) {
    vue.$emit('vue_function_name', response)
}
window.callbackFuc = functionName ;
In vue:
....
created() {
    const _component = this;
    this.$root.$on('vue_function_name', (response) => {
        _component.function_name(response);
    }
},
methods: {
    function_name(res) {
        // to do something
    }
}

2018/06/08

Array sort by two keys | array_multisort() | ソート順二つ以上

// array_multisort(): $data を最後のパラメータとして渡し、同じキーでソートする。 
$data[] = ['id' => 1, 'sort_1' => 12, 'sort_2' => 2, 'sort_3' => 'gamma', 'sort_4' => 'Delta']; 
$data[] = ['id' => 2, 'sort_1' => 34, 'sort_2' => 3, 'sort_3' => 'Gamma', 'sort_4' => 'beta']; 
$data[] = ['id' => 3, 'sort_1' => 56, 'sort_2' => 5, 'sort_3' => 'Beta', 'sort_4' => 'Beta']; 
$data[] = ['id' => 4, 'sort_1' => 56, 'sort_2' => 4, 'sort_3' => 'beta', 'sort_4' => 'alpha']; 
$data[] = ['id' => 5, 'sort_1' => 34, 'sort_2' => 1, 'sort_3' => 'Alpha', 'sort_4' => 'Epsilon']; 
$data[] = ['id' => 6, 'sort_1' => 12, 'sort_2' => 6, 'sort_3' => 'alpha', 'sort_4' => 'Zeta']; 

// 列方向の配列を得る 
foreach ($data as $key => $row) {
     $sort_1[$key] = $row['sort_1'];
     $sort_2[$key] = $row['sort_2'];
     $sort_3[$key] = $row['sort_3'];
     $sort_4[$key] = $row['sort_4'];
 }

// データを sort_1 の降順、sort_2 の昇順にソートする。
array_multisort($sort_1, SORT_DESC, $sort_2, SORT_ASC, $data);
print_r("<pre>");
print_r($data);
print_r("</pre>");

// データを sort_3 大文字ではじまる昇順にソートする
array_multisort($sort_3, SORT_ASC, SORT_STRING, $data);
print_r("<pre>");
print_r($data);
print_r("</pre>");

// データを sort_4 小文字で始まる昇順にソートする
array_multisort($$sort_4, SORT_ASC, SORT_REGULAR, $data);
print_r("<pre>");
print_r($data);
print_r("</pre>");

2018/06/01

Fix phpoffice/phpspreadsheet requires ext-gd * error | php72

ENV: PHP7.2
Error message:
phpoffice/phpspreadsheet 1.2.1 requires ext-gd * -> the requested PHP extension gd is missing from your system

In centOs:
sudo yum install php72-php-gd.x86_64

In ubuntu:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2-gd

Download composer.phar and composer update modules | CentOS

cd path/to/folder/

Download:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
install
php composer-setup.php
remove
php -r "unlink('composer-setup.php');"

php composer.phar update

bash: php: command not found.
# source /opt/remi/php72/enable

2018/04/25

Host is not allowed to connect to this mysql server

原因確認:
sudo i
mysql
>select user,host from mysql.user;
User権限確認:
+---------+------------+
| user     | host       |
+---------+------------+
| root     | localhost |
|            | 127.0.0.1 |
+---------+------------+

sudo vim /etc/mysql/my.cnf
# bind-address = 127.0.0.1

User権限:
GRANT ALL PRIVILEGES ON *.* TO user@'192.168.%' IDENTIFIED BY 'password' WITH GRANT OPTION;

2018/03/21

Vagrant: VBoxManage error has terminated unexpectedly during startup with exit code 1 (0x1)

When use 'vagrant up' to start env, it show the error below.

==> controller: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["startvm", "db9a7f93-2e24-46a1-a484-aa7705fa285d", "--type", "headless"]
Stderr: VBoxManage.exe: error: The virtual machine 'php_controller_1521423965199_38765'
has terminated unexpectedly during startup with exit code 1 (0x1). More details may be available in
'\VirtualBox VMs\php_controller_1521423965199_38765\Logs\VBoxHardening.log'
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component MachineWrap,
interface IMachine

Solution:
re-install VirtualBox will fix

2018/03/10

Android: Keystore was tampered with, or password was incorrect

$keytool -list -v -keystore /Users/randinblogger/.android/debug.keystore
*Replace randinblogger with user name

Error Log:
keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect
java.io.IOException: Keystore was tampered with, or password was incorrect
        at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:772)
        at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:55)
        at java.security.KeyStore.load(KeyStore.java:1445)
        at sun.security.tools.keytool.Main.doCommands(Main.java:889)
        at sun.security.tools.keytool.Main.run(Main.java:340)
        at sun.security.tools.keytool.Main.main(Main.java:333)
Caused by: java.security.UnrecoverableKeyException: Password verification failed
        at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:770)
        ... 5 more

Solution:
For the debug.keystore, the password is android. For Eclipse, the debug keystore is typically located at ~/.android/debug.keystore

2018/02/14

ModuleNotFoundError: No module named 'requests'

When 'import request' happened to ModuleNotFoundError.

Python2:
pip install requests

Python3:
python3.6 -m pip install requests

Same as ModuleNotFoundError for BeautifulSoup4
python3.6 -m pip install BeautifulSoup4

Install python3.6 in centos

yum search python36
yum install -y python36u python36u-libs python36u-devel python36u-pip

python3.6 -V

Remove duplicate value from array

function unique(list) {
  var result = [];
  $.each(list, function(i, e) {
    if ($.inArray(e, result) == -1) result.push(e);
  });
  return result;
}

2018/02/03

How to do Cross Site Scripting Test

Set parameter value includes: "'<>()
  • "'><script>alert('XSS');</script>
Solution
  • Check every parameter.
  • Don't output parameter value in the page directly.
Example
randinblogger.blogspot.com/?m="'><script>alert('XSS');</script>

IE/Edge only show # because XSS filter(X-XSS-Protection)

IE/Edge only show # because XSS filter(X-XSS-Protection)

If a cross-site scripting attack is detected, the IE will sanitize the page and only show a "#" as default header.

X-XSS-Protection: 0

Disables XSS filtering.

X-XSS-Protection: 1

Enables XSS filtering(usually default in browsers), sanitize the page.

X-XSS-Protection: 1; mode=block

Enables XSS filtering, prevent rendering of the page if an attack is detected.

X-XSS-Protection: 1; report=<reporting-uri>

Enables XSS filtering, sanitize the page and report the violation. This uses the functionality of the CSP report-uri directive to send a report.

In PHP

header("X-XSS-Protection: 1; mode=block");

By .htaccess

<IfModule mod_headers.c>
  Header set X-XSS-Protection "1; mode=block"
</IfModule>

Controlling the XSS Filter(Microsoft)
X-XSS-Protection(MDN)

2018/01/19

how to use phpdocument使用方法

環境準備Prepare
By yum
$ sudo yum -y install php-pear php-xml
$ sudo pear channel-discover pear.phpdoc.org
$ sudo pear install -a phpdoc/phpDocumentor
$ sudo yum install php-intl
$ sudo yum install graphviz (option)
By composer
$ sudo php composer.phar require phpdocumentor/phpdocumentor


php.ini設定
date.timezone = 'Asia/Tokyo'

生成
cd /path/to/root/of/project
phpdoc -c app/phpdoc.xml --template="clean"
phpdoc -d /path/to/source/folder
phpdoc -t /path/to/file

-c: 設定ファイルを利用すること
default config: phpdoc.dist.xml

phpdoc template:list
* abstract
* checkstyle
* clean
* new-black
* old-ocean
* responsive
* responsive-twig
* xml
* zend

Sample of phpdoc.xml

2018/01/13

blogspot: data for title

site name + post title
<data:blog.pageTitle/>

post title
<data:view.title.escaped/>

2018/01/06

Mock assert function | PHPUnit

mixed is ...

メソッド 意味
assertNull($var) $varがNULLである
assertEquals($val1, $val2) $val1が$val2と等しい
assertSame($val1, $val2) $val1と$val2が型も含めて等しい
assertInternalType($type, $val) $valの型名が$typeである

number is ...

メソッド 意味
assertGreaterThan($expect, $var) $expect < $var が成立する
assertGreaterThanOrEqual($expect, $var) $expect <= $var が成立する
assertLessThan($expect, $var) $expect > $var が成立する
assertLessThanOrEqual($expect, $var) $expect >= $var が成立する

string is ...

メソッド 意味
assertJsonStringEqualsJsonString($str1, $str2) $str1と$str2がjsonとして等しい
assertRegExp($ptn, $str) $strが正規表現$ptnにマッチする

boolean is ...

メソッド 意味
assertTrue($var) $varがTRUEである
assertFalse($var) $varがFALSEである

array is ...

メソッド 意味
assertArrayHasKey($key, $array) 配列$arrayにキー$keyが存在する
assertContains($val, $array) 配列$arrayに値$valが存在する
assertContainsOnly($type, $array) 配列$arrayの値の型がすべて$typeである
assertCount($count, $array) 配列$arrayの値の数が$countである
assertEmpty($array) 配列$arrayが空である

object/class is ...

メソッド 意味
assertObjectHasAttribute($attr, $object) オブジェクト$objectにプロパティ変数$attrが存在する
assertClassHasAttribute($attr, $class) クラス名$classにプロパティ変数$attrが存在する
assertClassHasStaticAttribute($attr, $class) クラス名$classに静的プロパティ変数$attrが存在する
assertInstanceOf($class, $instance) $instanceがクラス名$classのインスタンスである

file is ...

メソッド 意味
assertFileExists($file) $fileが存在する
assertFileEquals($file1, $file2) $file1と$file2の内容が等しい
assertJsonFileEqualsJsonFile($file1, $file2) $file1と$file2の内容がjsonとして等しい
assertJsonStringEqualsJsonFile($file1, $json) $file1の内容と$jsonがjsonとして等しい