1 頁 (共 1 頁)

Harbour for Apache module

發表於 : 2019-05-24, 17:43
admin
2019.05.24: 最近比較火紅的話題,利用 Harbour 開發 for Apache module!!
話說原作者安東尼奧的版本,是在 Apache Web Server 網頁上跑整支 .prg,
然後裡面再輸出一些 html 碼的方式,在下個人認為這樣方式和 php 方式差異太大,
因此,自己研究了另一套方法,可以寫類似 php 方式,例如:
test3.prg

代碼: 選擇全部

<?prg
#xcommand HTML => #pragma __cstream | AP_RPuts(%s)
#xcommand ? <cText> => AP_RPuts(<cText>)
#define CRLF chr(13)+chr(10) // Harbour
#define WCL "<br>" // Web
public z := ''
public j := 100
public cDbf := 'E:\Temp\frswebserver\www\customer.dbf'
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>harbour for apache test!!</title>
<meta name="generator" content="Designed by WenSheng!!">
<link href="ssbbs.css" rel="stylesheet">
<link href="test3.css" rel="stylesheet">
<script src="jquery-1.12.4.min.js"></script>
</head>
<body>
<?prg
USE (cDBF) NEW ALIAS CUT SHARE
?>
<script>
function firstPage(){
  alert('First Page');
}
function prevPage(){
  alert('Prev Page');
}
function nextPage(){
  alert('Next Page');
}
function lastPage(){
  alert('last Page');
}
//
$(document).ready(function(){
  var tbl=document.getElementById('Table1');
  if(! tbl){
    alert("no Table");
    return;
  }
<?prg
c:='['
for i:= 1 to 10
    c += if(i<>1, ',', '' )
    c += '["'+CUT->FIRST+'","'+CUT->LAST+'","'+CUT->STREET+'","'+CUT->CITY+'","'+CUT->STATE+'"]'
    SKIP
next i
c+='];'+CRLF
? 'var aData='+c+';'+CRLF
?>
  var n=0;
  for(var i=0; i<10; i++){
    n=tbl.rows.length;
    tr=tbl.insertRow(n-1);
    var c='';
    for(var j=0; j<5; j++){
      if(j==4){
        c+='<td class="cell1">'+aData[i][j]+'</td>'; // insert row data
      }else{
        c+='<td class="cell0">'+aData[i][j]+'</td>'; // insert row data
      }
    }
    tr.innerHTML=c;
  }
});
</script>
<table style="position:absolute;left:0px;top:0px;width:774px;height:68px;z-index:0;" id="Table1">
<tr>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">F</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">IRST</span></td>
<td class="cell0"><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:15px;">LAST</span></td>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">S</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">TREET</span></td>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">C</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">ITY</span></td>
<td class="cell1"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">S</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">TATE</span></td>
</tr>
<tr>
<td colspan="5" class="cell2"><span style="color:#000000;font-family:Arial;font-size:13px;line-height:16px;"><a href="./test3.prg" onclick="firstPage();return false;">FirstPage</a>&nbsp; <a href="./test3.prg" onclick="prevPage();return false;">PrevPage</a>&nbsp;&nbsp; ________&nbsp;&nbsp; <a href="./test3.prg" onclick="nextPage();return false;">NextPage</a>&nbsp; <a href="./test3.prg" onclick="lastPage();return false;">LastPage</a></span></td>
</tr>
</table>

<?prg
? "TEST OK!!"
? j
? aaa()
CLOSE ALL
?>
</body>
</html><?prg
func aaa()
return 'aaa'
?>
這樣的寫法是不是和 php 一模一樣了呢?
(The code is like PHP.)

執行後的網頁 html 如下(run on Browser HTML Code):

代碼: 選擇全部

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>harbour for apache test!!</title>
<meta name="generator" content="Designed by WenSheng!!">
<link href="ssbbs.css" rel="stylesheet">
<link href="test3.css" rel="stylesheet">
<script src="jquery-1.12.4.min.js"></script>
</head>
<body>
<script>
function firstPage(){
  alert('First Page');
}
function prevPage(){
  alert('Prev Page');
}
function nextPage(){
  alert('Next Page');
}
function lastPage(){
  alert('last Page');
}
//
$(document).ready(function(){
  var tbl=document.getElementById('Table1');
  if(! tbl){
    alert("no Table");
    return;
  }
  // alert('Have Table');
var aData=[["Homer               ","Simpson             ","32179 Maiden Lane             ","Springfield                   ","IL"],["Ceci                ","Gibbard             ","9540 Raynes Park Road         ","Miami                         ","MA"],["Reg                 ","Kaczocha            ","30522 Park Ten Place          ","Scottsdale                    ","WY"],["David               ","Jochum              ","8211 Carnegie Center          ","Hingham                       ","IL"],["Simpson             ","Cafee               ","32736 Meadowbrook Drive       ","Nedlands                      ","ID"],["Tom                 ","Logan               ","6180 Roselle Street           ","West Covina                   ","CT"],["Gary                ","Brock               ","3893 Canandaigua Road         ","Senford                       ","WV"],["Frank               ","Fonseca             ","18712 Sherman Way             ","Ashby                         ","RI"],["Rick                ","Sencovici           ","13802 South University        ","Arcadia                       ","HI"],["Hugh                ","Lupton              ","16472 S. LaSalle Street       ","Tarzana                       ","AK"]];
;
  var n=0;
  for(var i=0; i<10; i++){
    n=tbl.rows.length;
    tr=tbl.insertRow(n-1);
    var c='';
    for(var j=0; j<5; j++){
      if(j==4){
        c+='<td class="cell1">'+aData[i][j]+'</td>'; // insert row data
      }else{
        c+='<td class="cell0">'+aData[i][j]+'</td>'; // insert row data
      }
    }
    tr.innerHTML=c;
  }
});
</script>
<table style="position:absolute;left:0px;top:0px;width:774px;height:68px;z-index:0;" id="Table1">
<tr>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">F</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">IRST</span></td>
<td class="cell0"><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:15px;">LAST</span></td>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">S</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">TREET</span></td>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">C</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">ITY</span></td>
<td class="cell1"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">S</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">TATE</span></td>
</tr>
<tr>
<td colspan="5" class="cell2"><span style="color:#000000;font-family:Arial;font-size:13px;line-height:16px;"><a href="./test3.prg" onclick="firstPage();return false;">FirstPage</a>&nbsp; <a href="./test3.prg" onclick="prevPage();return false;">PrevPage</a>&nbsp;&nbsp; ________&nbsp;&nbsp; <a href="./test3.prg" onclick="nextPage();return false;">NextPage</a>&nbsp; <a href="./test3.prg" onclick="lastPage();return false;">LastPage</a></span></td>
</tr>
</table>

TEST OK!!aaa</body>
</html>
執行結果如下(run screen):
圖檔

切記:test3.prg 內一定要定義:

代碼: 選擇全部

#xcommand HTML => #pragma __cstream | AP_RPuts(%s)
這個 HTML 是我用來包裝 html code 之用,沒定義就會出問題!
(note: test.prg must define

代碼: 選擇全部

#xcommand HTML => #pragma __cstream | AP_RPuts(%s)
, this code is include all html code)

download mod_harbour.so (harbour for Apache 2.4.x module compiler use vsc2017): https://app.box.com/s/9ln2wo6sibp7hjdgnzlcp6kmk2qxrb0z
test file: https://app.box.com/s/1uturyfbbrqpoycbwtzbo0qa477dvxtz

Re: Harbour for Apache module

發表於 : 2019-05-27, 23:05
admin
*2019.05.27: 玩點新花樣!!
Q1. 如何讓 mod_harbour 也能執行 .hrb 呢?
Q2. 這有何好處呢?

Come and order new tricks!
Q1. How to run .hrb on mod_harbour?
Q2. What are the benefits?

A1: 修改程式碼之後,執行順序如下:
A1: Modify main.prg and run step as:

代碼: 選擇全部

if File('xxx.hrb')
   // run 'xxx.hrb'
Else
   if File('xxx.prg')
     // run 'xxx.prg'
   Else
     // File not found
   EndIf
EndIf
A2: 優點有兩點,第一,節省每次編譯,雖說編譯花不了多少時間...
第二,程式碼保密,編譯成 .hrb 不是一般人看得懂了!!
A2: 1. don't compiler every time.
2. the .hrb is secret.

基於上述兩項優點,這次釋放新的 mod_harbour.so 提供給 Apache Web Server 載入之用,
一樣只支援 Windows/Apache 2.4.x 環境.

測試前查看目錄檔案如下:
To view folder now:
圖檔

同時存在 'test3.hrb' 與 'test3.prg' 兩支程式,
'test3.hrb' 的原始碼如下:
have 'test3.hrb' and 'test3.prg'
'test3.hrb' source code is:

代碼: 選擇全部

<?prg
#xcommand HTML => #pragma __cstream | AP_RPuts(%s)
#xcommand ? <cText> => AP_RPuts(<cText>)
#define CRLF "<br>"
public z := ''
public j := 100
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>harbour for apache test!!</title>
<meta name="generator" content="Designed by WenSheng!!">
<link href="ssbbs.css" rel="stylesheet">
<link href="test3.css" rel="stylesheet">
</head>
<body>
<div id="wb_Text1" style="position:absolute;left:0px;top:0px;width:250px;height:32px;z-index:0;">
<span style="color:#000000;font-family:Arial;font-size:13px;">This </span><span style="color:#000000;font-family:Arial;font-size:27px;">is</span><span style="color:#000000;font-family:Arial;font-size:13px;"> a </span><span style="color:#FF0000;font-family:Arial;font-size:27px;">samples</span><span style="color:#000000;font-family:Arial;font-size:13px;">!!</span></div>
<?prg
for i:= 1 to 10
    ? str(i)+CRLF 
next i
? "TEST OK!!"
? j
? aaa()
?>
</body>
</html><?prg
func aaa()
return 'aaa'
?>
利用 hbcgi.exe 編譯成 'test3.hrb',執行命令方式為:
use hbcgi.exe to compiler and create 'test3.hrb', command line is:

代碼: 選擇全部

c:\>hbcgi.exe test3.hrb -hrb
就會產生 'test3.hrb' 了!
Create 'test3.hrb'

另一支 'test3.prg' 原始碼如下:
other 'test3.prg' source code is:

代碼: 選擇全部

<?prg
#xcommand HTML => #pragma __cstream | AP_RPuts(%s)
#xcommand ? <cText> => AP_RPuts(<cText>)
#define CRLF chr(13)+chr(10) // Harbour
#define WCL "<br>" // Web
#include "fileio.ch"
extern fOpen, fClose
public z := ''
public j := 100
public cDbf := 'E:\Temp\frswebserver\www\customer.dbf'
public nH := 0
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>harbour for apache test!!</title>
<meta name="generator" content="Designed by WenSheng!!">
<link href="ssbbs.css" rel="stylesheet">
<link href="test3.css" rel="stylesheet">
<script src="jquery-1.12.4.min.js"></script>
</head>
<body>
<?prg
USE (cDBF) NEW ALIAS CUT SHARE
?>
<script>
function firstPage(){
  alert('First Page');
}
function prevPage(){
  alert('Prev Page');
}
function nextPage(){
  alert('Next Page');
}
function lastPage(){
  alert('last Page');
}
//
$(document).ready(function(){
  var tbl=document.getElementById('Table1');
  if(! tbl){
    alert("no Table");
    return;
  }
  // alert('Have Table');
<?prg
c:='['
for i:= 1 to 10
    c += if(i<>1, ',', '' )
    c += '["'+CUT->FIRST+'","'+CUT->LAST+'","'+CUT->STREET+'","'+CUT->CITY+'","'+CUT->STATE+'"]'
    SKIP
next i
c+='];'+CRLF
? 'var aData='+c+';'+CRLF
?>
  var n=0;
  for(var i=0; i<10; i++){
    n=tbl.rows.length;
    tr=tbl.insertRow(n-1);
    var c='';
    for(var j=0; j<5; j++){
      if(j==4){
        c+='<td class="cell1">'+aData[i][j]+'</td>'; // insert row data
      }else{
        c+='<td class="cell0">'+aData[i][j]+'</td>'; // insert row data
      }
    }
    tr.innerHTML=c;
  }
});
</script>
<table style="position:absolute;left:0px;top:0px;width:774px;height:68px;z-index:0;" id="Table1">
<tr>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">F</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">IRST</span></td>
<td class="cell0"><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:15px;">LAST</span></td>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">S</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">TREET</span></td>
<td class="cell0"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">C</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">ITY</span></td>
<td class="cell1"><span style="color:#000000;font-family:微軟正黑體;font-size:13px;line-height:17px;">S</span><span style="color:#000000;font-family:Calibri;font-size:13px;line-height:17px;">TATE</span></td>
</tr>
<tr>
<td colspan="5" class="cell2"><span style="color:#000000;font-family:Arial;font-size:13px;line-height:16px;"><a href="./test3.prg" onclick="firstPage();return false;">FirstPage</a>&nbsp; <a href="./test3.prg" onclick="prevPage();return false;">PrevPage</a>&nbsp;&nbsp; ________&nbsp;&nbsp; <a href="./test3.prg" onclick="nextPage();return false;">NextPage</a>&nbsp; <a href="./test3.prg" onclick="lastPage();return false;">LastPage</a></span></td>
</tr>
</table>

<?prg
? "TEST OK!!"
? j
? aaa()
CLOSE ALL
?>
</body>
</html><?prg
func aaa()
return 'aaa'
?>

現在先使用 Chrome 執行一次,http://localhost/test3.prg ,結果畫面如下:
Now use Chrome to run http://localhost/test3.prg, screen is:
圖檔
這是 'test3.hrb' 的畫面,而非 'test3.prg' 的畫面!!
The screen is 'test3.hrb' is not 'test3.prg'!!

現在將 'test3.hrb' 改名為 '_test3.hrb',這樣 mod_harbour 就找不到 'test3.hrb' 改執行 'test3.prg'!
目錄夾為:
Now change 'test3.hrb' to '_test3.hrb', than mod_harbour can't found 'test3.hrb' and run 'test3.prg'
Folder is:
圖檔

http://localhost/test3.prg ,執行結果如下:
run http://localhost/test3.prg and screen is:
圖檔

結果畫面改變了!!
就是這麼好玩!!
其實,還可以刪除 'test3.prg' 只保留 'test3.hrb' 然後再執行一次: http://localhost/test3.prg
你將會發現畫面會是 'test3.hrb' 的畫面,雖然檔案 'test3.prg' 已經不存在了,一樣會去執行 'test3.hrb',
如何?不錯吧!哈哈哈! :lol:

Now screen is change,
This is a very interesting thing.
even you can delete 'test3.prg' and hold 'test3.hrb' on the folder and run http://localhost/test3.prg again,
than you can to view screen is show 'test3.hrb' is not 'test3.prg',the mod_harbour can run 'test3.hrb' still.

新版 mod_harbour.so 與 hbcgi.exe 檔案下載(download): https://app.box.com/s/0o0amzj9bad6gf4zsmfmx2i5r37bv6xi