2013年9月18日 星期三

備份系統安全性記錄檔


參考來源: http://jojochen.blog.ithome.com.tw/post/2529/77642
參考來源: http://msdn.microsoft.com/en-us/library/aa394593%28v=VS.85%29.aspx

以下為 vbs 內容:

=============================

'定義變數BackupName備份事件檢視器檔案
Dim BackupName
Set Fso = CreateObject("Scripting.FileSystemObject")

'定義當日年,月,日
dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay

'設定 WMI 取得 NameSpace 為 root\cimv2 的 Backup 方式
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Backup,Security)}!\\.\root\cimv2")

'WQL 取得 Win32_NTEventLogFile 為安全性記錄檔 security
Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile Where LogFileName='security'")
For Each objLogfile in colLogFiles
BackupName = "c:\" & strBackupName &  "_security.evt"
if (Fso.FileExists(BackupName)) then
objLogFile.BackupEventLog("c:\" & strBackupName &  "_security2.evt")
objLogFile.ClearEventLog()
WScript.Echo "File saved: " & strBackupName &  "_security2.evt"
else
objLogFile.BackupEventLog("c:\" & strBackupName &  "_security.evt")
objLogFile.ClearEventLog()
WScript.Echo "File saved: " & strBackupName &  "_security.evt"
end if
Next

Set colLogFiles = Nothing
Set objWMIService = Nothing
Set Fso = Nothing

=============================

更新:
在 windows 2000 執行時遇到 SWbemObject: Access denied 存取遭到拒絕
將 impersonationLevel=impersonate,(Backup) 改成 impersonationLevel=impersonate,(Backup,Security)


2013年9月14日 星期六

解決 sencha touch 2.2.x 在 Chrome 29.x 執行時,textfield 無法顯示的問題


參考來源:http://druckit.wordpress.com/2013/08/22/sencha-touch-2-x-and-google-chrome-29/
There’s a bug in Google Chrome 29 that prevents Sencha Touch 2.2.x apps from displaying properly. While this shouldn’t affect mobile browsers (yet), it will affect you if you use Chrome to debug your apps.
You can patch your Sencha Touch 2.2.x apps by modifying the /touch2/resources/themes/stylesheets/sencha-touch/base/mixins/_Class.scss file, replacing the st-box mixin with the following code:
1
2
3
4
5
6
7
8
9
10
11
@mixin st-box($important: no) {
    @if $important == important {
        display: flex !important;
        display: -webkit-box !important;
        display: -ms-flexbox !important;
    } @else {
        display: flex;
        display: -webkit-box;
        display: -ms-flexbox;
    }
}

2013年8月30日 星期五

response.setHeader 下載檔名遇到中文字的解決方法


response.setContentType("application/x-x509-ca-cert");
response.setContentLength(byteCert.length);
// caname 是中文字
// Safari & Firefox & Chrome
String fileName = new String(caname.getBytes(), "ISO8859-1");

String agent = request.getHeader("USER-AGENT");
if (null != agent && -1 != agent.indexOf("MSIE")) {
    // IE
    fileName = URLEncoder.encode(fileName, "UTF8").replaceAll("\\+", "%20");
}

response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".cer\"");

2013年8月23日 星期五

解決 Linux 主機使用 KeyStore 儲存 pfx 時非常慢的問題


在啟動的 shell script 中 (catalina.sh) 加上下列指令

export JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"

2013年8月22日 星期四

從 web service 取得 ServletContext 物件

// ServletContextListener Class


public void contextInitialized(ServletContextEvent sce) {
  try {
    sce.getServletContext().setAttribute("myBook", "Learning java");
  } catch (Exception ex) {
  }
}


// WebService


@Resource
WebServiceContext wsContext;

@WebMethod(operationName = "test1")
public String test1() {
  ServletContext servletContext = (ServletContext) wsContext.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
  String myBook = (String) servletContext.getAttribute("myBook");
}

2013年8月14日 星期三

Get viewport size (Nice)


var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
alert(x);
alert(y);


Reference url: http://stackoverflow.com/questions/3437786/how-to-get-web-page-size-browser-window-size-screen-size-in-a-cross-browser-wa

2013年7月31日 星期三

Post data to a new window with full screen

Javascript Example:


function postDataToNewWindow() {
var myform = document.createElement("form");
myform.setAttribute("method", "post");
myform.setAttribute("action", "verifyCredential.asp");
myform.setAttribute("target", "_custom");

var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "credential");
hiddenField.setAttribute("id", "credential");
hiddenField.setAttribute("value", "2.0");

myform.appendChild(hiddenField);
document.body.appendChild(myform);
window.open("", "_custom", "fullscreen=yes");
myform.submit();
}