XOOPS 2.7 全面升級到 Smarty 4 後,舊佈景或舊模組最容易炸掉的地方,就是樣板裡的 `<{php}>...<{/php}>`。 原因很單純:Smarty 4 已經不支援在樣板中直接執行 PHP。也就是說,舊寫法如果還把 PHP 邏輯塞在 `.tpl` 裡,升級後就會出現 unknown tag、白畫面或 SmartyCompilerException。 目前比較穩的解法,不是去 hack Smarty,也不是讓 Smarty 重新開放任意 PHP,而是把原本散落在樣板中的 PHP 程式碼收回 PHP 檔案,整理成 function,再用 `$tpl->registerPlugin()` 註冊成 Smarty 標籤,最後在樣板中用新標籤取代原本的 `<{php}>`。 簡單說: 舊寫法: .tpl 直接寫 <{php}> PHP CODE <{/php}> 新寫法: PHP 檔建立 function → registerPlugin 註冊成 Smarty function → .tpl 改用 <{php_channel}> 這樣效果接近原本 `<{php}>`,但執行入口變乾淨,也比較符合 Smarty 4 的規則。 修改方法如下說明: 一、建立相容函式檔 建議先建立一個 PHP 檔,專門收納原本樣板裡的流浪 PHP,例如: modules/模組ID/function/tpl_smarty_compat.php 示例: <?php //Smarty 4 樣板流浪 PHP 收容區 function register_smarty_compat($tpl=""){ if(empty($tpl) || !is_object($tpl)) return; if(!method_exists($tpl,'registerPlugin')) return; static $registered=array(); $tplid=function_exists('spl_object_id') ? spl_object_id($tpl) : spl_object_hash($tpl); if(!empty($regist...
話說時間過得真快,轉眼間又收到上半年度局端的伺服器「弱點管制表」通報,其中當然免不了那些PHP/Apache需要升級項目,但本次多了三個新弱點項目,做個紀錄日後就能SOP處理! 弱點名稱:備份檔案洩漏 弱點概述:It is possible to retrieve file backups from the remote web server. 弱點名稱:Web 伺服器的目錄/資料夾可被瀏覽 弱點概述:Some directories on the remote web server are browsable. 弱點名稱:Web 應用程式具有點擊劫持(ClickJacking)的弱點 弱點概述:The remote web server may fail to mitigate a class of web application vulnerabilities. 這三個弱點可以一次解決,只需要找到 HTTPS vhost,也就是 <IfModule mod_ssl.c> 裡的 <VirtualHost *:443>。 該檔案通常由 certbot 自動產生,檔案名稱多為:000-default-le-ssl.conf(通常位於 sites-available 資料夾中,並連結到 sites-enabled 啟用) sudo nano /etc/apache2/sites-available/000-default-le-ssl.conf 打開編輯 <IfModule mod_ssl.c> <VirtualHost *:443> 略........................ ServerAdmin webmaster@localhost DocumentRoot /var/www/html #防護設定加在DocumentRoot 後面 #這段解決Web 伺服器的目錄/資料夾可被瀏覽問題 <Directory /var/www/html> Options -Indexes AllowOverride All Require all granted </Directory> #這段解決備份檔案洩漏 <FilesMatch "(?i)(~$|\.bak$|\.old$|\.or...