2016年5月30日 星期一

Cenet OS 6.X 預設 php 5.3 提升至 5.6版備註

緣由是CentOS 6 預設的5.3.3無法使用 mcrypt_encrypt ,因此需要提升PHP版本。過程如下:

1. 先移除原先的PHP,貌似移除這幾個其他有關聯的會一併移除。
  yum remove php php-common php-mysql  ...

2. 新增yum repository information
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

3. 安裝 php 5.6w 底下是會用到的套件
yum install php56w php56w-common php56w-mbstring php56w-mcrypt php56w-mysql php56w-opcache php56w-xml php56w-gd ...

On ubuntu:
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt
sudo service apache2 restart


PHP簡單的加解密如下,不過在加密結果傳遞時%20會造成CI在URL傳遞參數辨識上異常,需要特別置換處理以免失敗,目前還沒想到更好的方式就盡量選擇不易出現的字元組合即可。

function encrypt_key($str, $key)
{
  $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
  $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);  
  return base64_encode(trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB, $iv)));  
}

function decrypt_key($str, $key)
{
  $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
  $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($str), MCRYPT_MODE_ECB, $iv));  
}

在$str傳入的資料中,若干字元組合會造成無法解密回來的困境,例如裡面有ll. ii 的組合,最後使用的呼叫法為
加密
$security = encrypt_key(base64_encode($str), md5($key));
解密
$rtnstr = decrypt_key(base64_decode($security), md5($key));

2016年5月24日 星期二

Jenkins + TortoiseSVN + RYNC 機制

Jenkins 很方便,公司使用SVN不是GIT所以跟在保哥課程提到的方式不一樣,當然環境也是相異的(保哥是以MSBuild環境介紹),在LAMP中套用也沒有太多相異點,以此做個紀錄...

PS. 在Azure基本型A0安裝Jenkins貌似會自己Shutdown,改成A1後就正常了~很傻眼但正常就好,不曉得是1/4 CPU關係還是750M記憶體太少,總之改了很多地方都沒改善,機器等級提升就FIX囉。

Installation

wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -

sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'

sudo apt-get update

sudo apt-get install jenkins

Upgrade

sudo apt-get update

sudo apt-get install jenkins

Plugin

Once installed like this, you can update to the later version of Jenkins (when it comes out) by running the following commands:

install Subversion Plug-in

Authorized

sudo su jenkins -s /bin/bash

ssh-keygen -t rsa

 scp /var/lib/jenkins/.ssh/id_rsa.pub account@remoteServer:jenkins.pub

 cat /home/account/jenkins.pub >> /root/.ssh/authorized_keys

 chmod 600 /root/.ssh/authorized_keys

TEST

rsync -vzucPrl --delete-after -e ssh /SourcePath/ account@remoteServerIP:/TargetPath/

最近的雲端主機認證改成pem檔,所以rsync指令得改改如下,好處是上述的Authorized的程序可以免了
:

rsync -vzucPrl -e "ssh -i 'remoteserver.pem' -o 'StrictHostKeyChecking=no'" /SourcePath/ account@remoteServerIP:/TargetPath/

補充: 執行後發現若檔案存在但變更資料是少量的RSYNC會跳過該檔,所以加上-c做checksum雖然會比較慢但總比沒更新到好,畢竟FIX Bug有時候改的只是幾個BYTE而已。

2016年5月20日 星期五

awesomium 自建瀏覽器備忘 ...

Resource URL:http://www.awesomium.com/download/

備註:使用這核心封裝出來的安裝檔,在Windown 10中的Windows Defender會警示有"Trojan: Win32/Fathale.B!plock"或"Trojan: Win32/Gatrid.E!cl"兩種...XD哩,拿了PCCillin、ESET、AVG跟spyhunter掃描都顯示無異常,結果爬文估狗大師說問題出在awesomium這個OpenSource包的Dll上面,看來它的若干行為跟特洛伊很像吧,被封鎖ㄌ...

Visual Studio 2015 Memo:
  1. 將下載回來的執行檔安裝。
  2. 於Visual Studio "選擇工具箱項目"將awsomium開頭的打勾,有Core Windows.Controls Windows.Forms。
  3. 新增一個Form,然後加入一個TabControl,其餘的背景Code參考如下。
  4. Sample Code可以參考 Awesomium_in_WF 專案。
Awesomium.Windows.Forms.WebControl myBrowser;
#region TabControl 增加 Browser
private void createNewTab() {

 this.SuspendLayout();
 var ws = WebCore.CreateWebSession(new WebPreferences() { Javascript = true });
 myBrowser = new Awesomium.Windows.Forms.WebControl() { WebSession = ws };
 myBrowser.Dock = DockStyle.Fill;
 page.Controls.Add(myBrowser);
 tabControl1.TabPages.Add(page);

 myBrowser.LoadingFrameComplete += new Awesomium.Core.FrameEventHandler(LoadingFrameComplete);
 myBrowser.Source = new Uri("https://www.google.com");
 myBrowser.Update();
 this.ResumeLayout(false);
}

private void LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e) {
  if (myBrowser.IsLoading || !myBrowser.IsLive)
    return;
  this.tabControl1.TabPages[tabControl1.SelectedIndex].Text = "   " + myBrowser.Title;                          
  myBrowser.LoadingFrameComplete -= new Awesomium.Core.FrameEventHandler(LoadingFrameComplete);
}

#endregion

#region TabControl 增加 Close Button
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) {
  Rectangle r = e.Bounds;
  r = tabControl1.GetTabRect(e.Index);
  r.Offset(2, 2);
  r.Width = 5;
  r.Height = 5;
  Brush b = new SolidBrush(Color.Black);
  Pen p = new Pen(b);
  e.Graphics.DrawLine(p, r.X, r.Y, r.X + r.Width, r.Y + r.Height);
  e.Graphics.DrawLine(p, r.X + r.Width, r.Y, r.X, r.Y + r.Height);
  string titel = this.tabControl1.TabPages[e.Index].Text;
  Font f = this.Font;
  e.Graphics.DrawString(titel, f, b, new PointF(r.X + 5, r.Y));
}
private void tabControl1_MouseClick(object sender, MouseEventArgs e) {
  Point p = e.Location;
  for (int i = 0; i < this.tabControl1.TabPages.Count; i++)  {
     Rectangle r = tabControl1.GetTabRect(i);
     r.Offset(2, 2);
     r.Width = 5;
     r.Height = 5;
     if (r.Contains(p)) {
       CloseTab(i);
     }
   }
}
private void CloseTab(int i) {
  this.tabControl1.TabPages.Remove(this.tabControl1.TabPages[i]);
}
#endregion

2016年5月6日 星期五

OrangeHRM 3.1.1 Upgrade to 3.3.2 備忘

1. 下載3.3.2的SourceCode並安裝...
2. 修改 config_databases.yml.php 設定原3.1.1的DB
3. 執行底下的SQL

如果有變更資料夾路徑時,需調整 Catch中的
1. config_factories.yml.php
2. config_autoload.yml.php