2020年5月1日 星期五

duplicacy backup to google drive

1.Installation

sudo wget -O /opt/duplicacy https://github.com/gilbertchen/duplicacy/releases/download/v2.5.0/duplicacy_linux_x64_2.5.0


2.取得token

3.設定參數

sudo ln -s /opt/duplicacy /usr/local/bin/duplicacy
cd u
到要備份的資料夾
$ cd path/to/your/repository $ duplicacy init mywork sftp://user@192.168.1.100/path/to/storage

duplicacy init mywork gcs://bucket/path/to/storage

儲存地點&方式參考:

SFTP
sftp://username@server/path/to/storage (path relative to the home directory)
sftp://username@server//path/to/storage (absolute path)

Amazon S3
s3://amazon.com/bucket/path/to/storage (default region is us-east-1)
s3://region@amazon.com/bucket/path/to/storage (other regions must be specified)

Google Cloud Storage
gcs://bucket/path/to/storage
You must first obtain a credential file by authorizing.  
Duplicacy to access your Google Cloud Storage account or by downloading a service account credential file.
https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts
You can also use the s3 protocol to access Google Cloud Storage. To do this, you must enable the s3 interoperability  in your Google Cloud Storage settings and set the storage url as s3://storage.googleapis.com/bucket/path/to/storage.

--------------------------------------------------------------------





2020年4月23日 星期四

rewrite 規則


資料來源: https://blog.hinablue.me/apache-note-about-some-rewrite-note-2011-05/

  • <CondPattern:按照單字順序比對(升冪比對)。
  • >CondPattern:按照單字順序比對(降冪比對)。
  • =CondPattern:按照單字順序比對(完全相同)。
  • -d:比對 CondPattern 為路徑(資料夾)。
  • -f:比對 CondPattern 為檔案。
  • -s:比對 CondPattern 為檔案,但是檔案大小要大於 0。
  • -F:比對 CondPattern 為檔案,但是會檢查伺服器配置,確認該檔案有存取權限。
  • -U:比對 CondPattern 為路徑,但是會檢查伺服器配置,確認該路徑有存取權限。
CondPattern 後面可以追加兩組標籤:
  • [OR]:請把他當作是條件式的 AND 來看。
  • [NC]:就是 No Case 的意思,不管大小寫比對。
最後會回到 RewriteRule 的 Substitution,這裡就是最後輸出的網址樣式。他也可以是減號(-),直接輸出比對結果,不做任何處理。最後可以附加一組標籤,這組標籤是用來做最後判別用。這組標籤請謹慎,不然小心掉入無限重寫轉址地獄喔(啾咪)。
  • C:這是很有趣的標籤,倘若你的測試條件不符合,那往後的條件就不會被發生。意思就是,如果第一條寫了 [C],那倘若第一條符合,就不會發生任何事情繼續比對下去。但是倘若第一條不符合,那麼接下來的第二條就會跳過不執行比對了。
  • CO=NAME:VAL:domain[:lifetime[:path]]: 設定一組 cookie 用的。
  • E=VAR:VAL:設定系統環境變數用的。
  • F:吐回 403,就是否嗶等啦!
  • G:吐回 401,就是這網址已經不存在了。
  • L最後一支舞(喂)最後一個條件,表示之前的測試到了這裡倘若符合就會結束,不會往下做。
  • N:下一回合(噹噹噹)。讓測試重頭開始,請小心不要掉入無窮迴圈。
  • NC:就是 No Case,僅此而已。
  • NE:對所測試的網址輸出不做跳脫處理(escape)。
  • NS:不使用內部請求處理。所謂內部請求,大抵上是指這個網址不需要由伺服器端的執行程式處理(像是 .php 結尾,是由伺服器 PHP Engine 處理)。所以,像是 Apache 所擁有的 server-status 這種,我就可以使用 NS 讓他不會透過 PHP Engine 來處理這類輸出(這是我對官方的解釋的理解,如果覺得不對,請參考官方的說明
  • P:強制使用 Proxy,這個需要 mod_proxy 這個套件喔!
  • PT:取代部份的請求網址,可以搭配 mod_alias 使用。
  • QSA:傳回網址後面的 QUERY STRING。就是 ?a=xxx&b=xxx&c=xxx 這一段。
  • R[=code]:強制轉址。後面可以加上 HTTP Status Code,常用的大概就是 302 吧,告訴人家說你已經搬家了(笑)。
  • S=num:跳過往後 num 條的規則。
  • T:強制使用某個 MIME-Type 來處理目前的轉址。

2020年3月26日 星期四

LINE ID_TOKEN 解析

$url = 'https://api.line.me/oauth2/v2.1/token';  
$params = array(
 'grant_type' => 'authorization_code',  
 'code' => $code,
 'redirect_uri' => $this->strategy['redirect_uri'],
 'client_id' => $this->strategy['channel_id'],
 'client_secret' => $this->strategy['channel_secret']   
);
$option = array('http' => array('header' => 'Content-Type: application/x-www-form-urlencoded'));
$response = $this->serverPost($url, $params,$option, $headers);
$results = json_decode($response);

//$userEmail = $this->_userEmail($results->id_token); 
$id_token = $results->id_token; 

//JWT 驗證 id token
$remainder = strlen($id_token) % 4;
if ($remainder)
{
 $padlen = 4 - $remainder;
 $id_token .= str_repeat('=', $padlen);
}
$response=base64_decode(strtr($id_token, '-_', '+/'));
$cc=preg_match('/({.+})({.+})/',$response,$res);
$results = json_decode($res[2], true);
if(empty($results['email'])) return 'empty';
else return $results['email'];

參考:
http://www.zzv.cn/index.php?c=content&a=show&id=132
https://hotexamples.com/examples/-/JWT/urlsafeB64Decode/php-jwt-urlsafeb64decode-method-examples.html
https://jwt.io/