zabbix 文字化け調査 *zabbix-1.4 の古い情報 !!文字化けしている場所 !JavaScript popup_menu *http://nona.to/zabbix/overview.php のデータをクリックすると文字化けしたメニューが出る。 *ソースはutf-8 *文字化けした部分は onClick の JavaScript になっている。   *変換に失敗している。 !!コード解析 !https://nona.to/zabbix/overview.php *表示タイプをデータとトリガに切り替えられる。 *パラメータ type が SHOW_DATA ならデータ表示 *パラメータ type が SHOW_TRIGGERS ならトリガー表示 *require_once "include/items.inc.php"; *$table=get_items_data_overview(...); *$table->Show(); !include/items.inc.php *function get_items_data_overview($groupid) *$table=CTableInfo(S_NO_ITEMS_DEFINED); *$items[desc,key,host]=db("select distinct hostid, host, itemid, key, type, value ... from hosts,items,left join functions left join triggers") *foreach ($items as $descr => $ithosts) { *$table_row=array(nbsp($descr)); *$it_ov_menu=array_merge(array(name, url, (target [tw], statusbar [sb]), css, submenu)); *$it_ov_menu=array_merge(array(S_GRAPHS,null,null,array('outer'=>array('pum_oheader'),'inner'=>array('pum_iheader'))); *name = (S_GRAPHS, S_LAST_HOUR_GRAPH, S_LAST_WEEK_GRAPH, S_LAST_MONTH_GRAPH) *$it_ov_menu=new CPUMenu($it_ov_menu,170); *$value_col->OnClick($it_ov_menu->GetOnActionJS()); *array_push($table_row,$value_col); *$table->AddRow($table_row); *} *return $table; !include/classes/cpumenu.inc.php *onClick="return show_popup_menu( を出力しているのは、include/classes/cpumenu.inc.php *class CPUMenu *function GetOnActionJS() *return 'return show_popup_menu(event,'.zbx_jsvalue($this->items).','.zbx_jsvalue($this->width).');'; *$this->items を出力している !include/js.inc.php *function zbx_jsvalue *phpオブジェクトから JavaScript での変数定義コードに変換 *ここでは値を取得していない。 *別の場所で $this->items の値を出力している !include/classes/ctag.inc.php *class CTag extends CObject *function AddAction *JavaScript での OnClick などのアクションを登録するため *$this->options[$name] = htmlentities($str,ENT_COMPAT) となっている。 *htmlentities のデフォルト文字列は iso-8859-1 *utf-8 を指定すると良い. *htmlentities($str,ENT_COMPAT,"utf-8") とすると文字化けは解消した。 !国際化対応 *ユーザの文字コードは S_HTML_CHARSET として定数が定義されている *$this->options[$name] = htmlentities($str,ENT_COMPAT,S_HTML_CHARSET) とすると文字化けが解消した。 !Map *zabbix/php/map.php *zabbix/php/include/maps.inc.php *オリジナルの出力コード ImageString($im, 2, $x_info, $y_info, $info_line, $color); **$im: 画像オブジェクト **2: 文字フォント指定、最小から2つ目の大きさ **$x_info, $y_info 文字位置指定 **$info_line 出力メッセージ **ラスタフォント、ASCII文字のみ *日本語対応 **文字列描画を ImageString から ImageTTFText に切替 **True Type Font 指定: $font_path='/usr/local/share/ipa-ttfonts/fonts/ipag.ttf' **文字化け対応 $info_line=iconv('utf-8','euc-jp',$info_line); ImageTTFText( $im, 8, 0, $x_ifno, $y_info+10, $color, $font_path, $info_line); *国際化対応 **include/locales/ja_jp.inc.php は utf-8 で記述されている **出力 PNG の化け方は euc-jp 文字列を utf-8 として出力した場合に一致する。 **どこかにわざわざ出力文字列を utf-8 から euc-jp に変換している場所がある。 !メール