Discuz 3.2, 3.3, 3.4 直接利用SQL创建新用户

我们的网站要和Discuz整合到一起,有个新用户同步的需求,网络上很多的做法是用 UCenter的接口来做,反正最后都是插入SQL,笔者使用了直接操作数据库的方式,把操作的表和SQL整理了下,后面如果有时间做个SSO就省事了

版本:dz 3.2版本 ucenter1.6版本
目标:插入普通用户,最小可用就行了,可以登录

SQL记录:

注意:表名称前缀根据配置可能不同, 一共有8张表

SELECT *FROM pre_ucenter_members;
-- UCenter用户数据表 uid, username, password, email, regip(默认写一个值), regdate(时间戳), salt(随机6位字母数字)

SELECT *FROM pre_ucenter_memberfields;
-- UCenter用户扩展信息数据表 插入 uid

SELECT *FROM pre_common_member;
-- 主用户表 插入的字段 email, username, password, emailstatus, regdate(时间戳)
-- 得到uid再插入其它表

SELECT *FROM pre_common_member_count;
-- 用户数据统计 各种积分,动态等 插入 uid

SELECT *FROM pre_common_member_field_forum;
-- 用户论坛设置数据表 插入 uid

SELECT *FROM pre_common_member_field_home;
-- 用户家园设置数据表 插入 uid

SELECT *FROM pre_common_member_profile;
-- 用户个人资料数据表 插入 uid

SELECT *FROM pre_common_member_status;
-- 用户状态数据表 插入 uid


-- 下面是插入一个普通用户的测试, 这里根据id自增,自己算出了uid,便于sql书写 
-- lzz, 邮箱 [email protected], 密码 xyz2541 
-- 需要计算的密码 pre_common_member 密码为 md5(password) 2cf5c897f58ca21cac9bec93f46f6f53
-- pre_ucenter_members salt yyy111 密码为 md5(md5(password)+salt) 4fab791987738fce5f11504a0fe2a342
-- MYSQL mode 设置的比较严格,所以很多默认值要自己加上。。

INSERT INTO pre_ucenter_members SET uid=7, username='lzz', `password`='4fab791987738fce5f11504a0fe2a342', email='[email protected]', regip='127.0.0.1', regdate=UNIX_TIMESTAMP(), salt='yyy111';

INSERT INTO pre_ucenter_memberfields SET uid=7, blacklist='';

INSERT INTO pre_common_member SET uid=7, username='lzz', `password`='2cf5c897f58ca21cac9bec93f46f6f53', email='[email protected]', emailstatus=1, regdate=UNIX_TIMESTAMP();

INSERT INTO pre_common_member_count SET uid=7;

INSERT INTO pre_common_member_field_forum SET uid=7, `medals`='', `sightml`='', `groupterms`='', `groups`='';

INSERT INTO pre_common_member_field_home SET uid=7, `spacecss`='', `blockposition`='', 
`recentnote`='', `spacenote`='', `privacy`='', `feedfriend`='', `acceptemail`='', `magicgift`='', `stickblogs`='';

INSERT INTO pre_common_member_profile SET uid=7, `bio`='', `interest`='', `field1`='', `field2`='',
`field3`='', `field4`='', `field5`='', `field6`='', `field7`='', `field8`='';

INSERT INTO pre_common_member_status SET uid=7;

在Discuz的数据库中插入到数据库之后,web端就能登录了

Ucenter中的用户批量导入到discuz中的办法

这个代码是搜索到的,主要看一下需要在数据库里更新哪些表格.

将下面的代码复制到一个php中,并在浏览器中输入地址执行:

<?php
$dbserver =’localhost’; //此处改成数据库服务器地址
$dbuser =’root’;//此处写数据库用户名
$dbpwd =’1234′;//数据库密码
$dbname =’disucz’;//数据库名称
$charset =’gbk’;//此处写字符集gbk或者utf8
$uc_pre =’pre_ucenter_’;//UC表前缀
$dx_pre =’pre_’;//Discuz! X2表前缀
//此行开始向下不要改动
set_time_limit(0); //0为无限制
$connect=mysql_connect($dbserver,$dbuser,$dbpwd) or die(“无法连接数据库”);
@mysql_select_db($dbname,$connect);
mysql_query(“set names $charset”);
$query = mysql_query(“SELECT * FROM `{$uc_pre}members` WHERE `uid` not in(select `uid` from `{$dx_pre}common_member`) “,$connect);
while($user = mysql_fetch_array($query)) {
$password=$user[password];
mysql_query(” replace INTO `{$dx_pre}common_member` (uid,username,password,adminid,groupid,regdate,email) VALUES (‘$user[uid]’, ‘$user[username]’, ‘$password’,’0′,’10’,’$user[regdate]’,’$user[email]’) “);
mysql_query(” replace INTO `{$dx_pre}common_member_field_forum` (uid) VALUES (‘$user[uid]’)”);
mysql_query(” replace INTO `{$dx_pre}common_member_field_home` (uid) VALUES (‘$user[uid]’)”);
mysql_query(” replace INTO `{$dx_pre}common_member_count` (uid) VALUES (‘$user[uid]’)”);
mysql_query(” replace INTO `{$dx_pre}common_member_profile` (uid) VALUES (‘$user[uid]’)”);
mysql_query(” replace INTO `{$dx_pre}common_member_status` (uid) VALUES (‘$user[uid]’)”);
}
echo “已从UC批量导入激活成功”;
?>

注释: 连接到数据库后,PHP会比对UC和DZ用户表的数据,发现不存在于DZ但是存在于UC的用户,就会把用户导入到DZ,但是这一注册不会设置其他内容,比如用户填写的详细信息,由于以前是存储在DZ数据库中,所以还是丢失了

这样子用户已经全部导入,用户数也恢复了正常

下一步,将用户的邮箱验证全部设置为已验证

数据库执行:

update pre_common_menber set emailstatus="1";

注释:这是更新数据库中emailstatus字段,1为验证 pre记得改为你的论坛的前缀

 

 

GV和环聊该使用哪个?

Google Voice 有两个app,一个是google voice,一个是hangouts, 这两个app相比较来说肯定是hangouts好用很多

但是这个只是在苹果手机上而言, 在苹果手机上你可以使用hangouts来接发短信和拨收电话,确实很方便

但是在安卓手机上,hangouts 只能接受和发短信,无法拨打电话,需要一个叫做环聊拨号器的app,也是google开发的,但是

环聊拨号器这个app 早在2015年就停止更新了

因此在苹果手机上使用hangouts,在安卓手机上使用GV apps 是最好的选择

Centos 7 通过openresty repo 安装openresty 解析

通过openresty repo 安装的文档可以看这里:

https://openresty.org/en/linux-packages.html

目前用yum安装的过程中,安装的组件版本如下:

Installing:
openresty x86_64 1.17.8.2-1.el7 openresty 1.1 M
Installing for dependencies:
openresty-openssl111 x86_64 1.1.1g-3.el7 openresty 1.6 M
openresty-pcre x86_64 8.44-1.el7 openresty 164 k
openresty-zlib x86_64 1.2.11-3.el7.centos openresty 54 k

安装openresty resty的话,版本如下:

openresty-resty-1.17.8.2-1.el7.noarch

openresty 的bin 安装路径为:

/usr/bin/openresty

查看一下使用repo安装的openresty的详细配置:

[root@centos ~]# openresty -V
nginx version: openresty/1.17.8.2
built by gcc 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
built with OpenSSL 1.1.1g 21 Apr 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.17 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../ngx_stream_lua-0.0.8 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' --with-cc='ccache gcc -fdiagnostics-color=always' --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-stream_ssl_preread_module --with-http_ssl_module

可以看到基本上配置的非常全面的,非常好了

看一下本机的openssl version:

[root@centos ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017

查看一下openresty service配置:

[Unit]
Description=The OpenResty Application Platform
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Openresty 默认的nginx conf 位于:

/usr/local/openresty/nginx/conf/nginx.conf

配置为:

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

Zabbix Agent的安装和使用

最近需要在服务器集群上监控服务器们的CPU和RAM的使用情况,zabbix 主服务器在US, agent 安装在监控的服务器上.

总的来说其实很简单,主要就是两个步骤:

  1. 安装zabbix agent 组件并且设置好conf文件
  2. 防火墙打开10050端口或者直接whitelist zabbix主服务器的IP

 

下面是详细的步骤:

1 安装组件

4.4 for centos and debian

Centos 7: 

rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm

yum install zabbix-agent

Centos 8:

rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/8/x86_64/zabbix-release-4.4-1.el8.noarch.rpm

yum install zabbix-agent

Debian 9:

# wget https://repo.zabbix.com/zabbix/4.4/debian/pool/main/z/zabbix-release/zabbix-release_4.4-1+stretch_all.deb
# dpkg -i zabbix-release_4.4-1+stretch_all.deb
# apt update

#apt install zabbix-agent

Debian 10:

# wget https://repo.zabbix.com/zabbix/4.4/debian/pool/main/z/zabbix-release/zabbix-release_4.4-1+buster_all.deb
# dpkg -i zabbix-release_4.4-1+buster_all.deb
# apt update

#apt install zabbix-agent

zabbix 5.0 LTS for debian 9

# wget https://repo.zabbix.com/zabbix/5.0/debian/pool/main/z/zabbix-release/zabbix-release_5.0-1+stretch_all.deb
# dpkg -i zabbix-release_5.0-1+stretch_all.deb
# apt update

# apt install zabbix-agent

zabbix 5.0 LTS for centos 7

# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

# yum install zabbix-agent

2 修改配置文件

无论centos 还是debian,都是在/etc/zabbix/zabbix-agentd.conf

agent 可以以两种模式运行: passive 和 active,我们一般使用passive 模式就可以,也最简单,只需要修改

Passive checks related下面的Server IP就可以

默认的是Server=127.0.0.1, 把127.0.0.1改成你的zabbix 主服务器的IP就可以了

3 防火墙打开10050 端口或者直接whitelist 你的zabbix主服务器的IP就可以了

Priceonomics:美国买房最实惠和最不实惠的城市排行榜

一直有在美国买房的打算,刚好看到这个统计,就转过来

美国最实惠的地方是俄亥俄州的扬斯敦,紧随其后的是密西西比州的杰克逊。在这两个地方,家庭收入中位数都高于一套房子的购买价格。最实惠城市排行榜上的每个城市都位于南部或中西部。在美国的609个地方中只有50个的负担能力得分超过36%。美国的绝大多数地方的房价都很难负担得起。

接下来,我们来看看美国最负担不起的住房市场。以下图表显示了地方收入对购房影响不大的地方:

美国最负担不起的地方是加利福尼亚州的纽波特海滩,紧随其后的是加利福尼亚州的圣莫尼卡。在这些地方,典型的年收入仅占房屋购买价格的5.3%。事实上,在最负担不起的城市排行榜25名中有24个位于加利福尼亚州。

对于购房者来说,美国最实惠的州是密西西比州,紧随其后的是俄亥俄州和俄克拉何马州。最负担得起的12个州中的每一个都在南部和中西部。最负担不起的州是夏威夷、华盛顿特区和加利福尼亚州。最负担不起的地方都在这个国家的西部和东部。

在美国最大的50个市场中,密歇根州的底特律是最实惠的,因为一个家庭的工资与房屋购买价格的比率为83.4%。排名前5位的城市都在南部或中西部。旧金山是美国最负担不起的大城市,紧随其后的是洛杉矶和奥克兰。排名前十的城市中有6个位于加利福尼亚州,纽约、火奴鲁鲁、波士顿和迈阿密也跻身最负担不起的主要城市之列。

/bin/bash^M: bad interpreter: No such file or directory

好久没有写bash脚本了,这两天在写一个网站受到攻击自动开始CF五秒盾的bash脚本,利用CF的API可以很轻松的写完这个脚本,可是测试的时候出问题了,提示

/bin/bash^M: bad interpreter: No such file or directory

以前我遇到过好多次这个问题,依稀记得是windows 和unix的编码不一样,换行符的标志也不一样. windows 是CR LF表示一行结尾,而unix用LF表示一行的结尾。

知道了问题的原因,解决起来就好说多了.

  1. 直接将windows下的编辑器的脚本编码转换,转换为unix格式,然后再去unix下执行. 对于ultraedit来说,路径是 File–>Conversions–>DOS->UNIX;对于notepad++来说,路径是setting-> Preferences-> New Document -> Unix, 或者在正在编辑的文件上,点击Edit -> EOL Conversion -> Unix

2) 在unix服务器上,直接运行dos2unix命令,将bash文件转化为unix下的文件

3) vi 命令解决. 首先可以用”vi -b cloudflare.sh”命令,来查看这个bash文件里面隐藏的字符,然后用”vi cloudflare.sh”打开,按下ESC键进入命令行模式,输入下面的命令:

:set ff=unix

:wq

将文本格式设置为unix格式