Jumaat, November 15, 2013

PHP : Saiz imej berdasarkan kadaran ( Proportional resizing image )

<?php
function scale_image($foto, $maxdim){
$thumb_width = $maxdim;
list($fullsize_width, $fullsize_height) = getimagesize($foto);
$thumb_height = @floor($fullsize_height/($fullsize_width/$thumb_width));
if($fullsize_width > $thumb_width){ $width = $thumb_width; $height = $thumb_height; } else { $width = $fullsize_width; $height = $fullsize_height; }

return '<img src="' . $foto . '" width="' . $width . '" height="' . $height . '" />';
}

echo scale_image('image.jpg', '500');
?>

Selasa, November 12, 2013

TUTORIAL : MINIMAL UBUNTU DESKTOP VIA UBUNTU SERVER INSTALLATION

1. Download ISO Ubuntu Server dan pasang pada komputer anda.
2. Pasang pakej "ubuntu desktop" tanpa "recommend" pada ubuntu server anda.
$ sudo apt-get install --no-install-recommends ubuntu-desktop
3. Akhir sekali, pasangkan "Desktop Enviroment" anda (pilih salah satu sahaja)
> Minimal KDE Desktop (KUBUNTU)
$ sudo apt-get install --no-install-recommends kubuntu-desktop

> Minimal XFCE Desktop (XUBUNTU)
$ sudo apt-get install --no-install-recommends xubuntu-desktop

> Minimal LXDE Desktop (LUBUNTU)
$ sudo apt-get install lubuntu-desktop

Siap! Sekarang Ubuntu anda berfungsi dengan pakej yang minimal. Seterusnya terpulang pada anda untuk membuat pemasangan aplikasi yang lain. Adios!

Linux : Semak maklumat RAM

black@b0x ~ $ sudo dmidecode -t 17
# dmidecode 2.11
SMBIOS 2.7 present.

Handle 0x0036, DMI type 17, 34 bytes
Memory Device
    Array Handle: 0x0035
    Error Information Handle: Not Provided
    Total Width: 64 bits
    Data Width: 64 bits
    Size: 4096 MB
    Form Factor: SODIMM
    Set: None
    Locator: ChannelA-DIMM0
    Bank Locator: BANK 0
    Type: DDR3
    Type Detail: Synchronous
    Speed: 1600 MHz
    Manufacturer: Samsung
    Serial Number: 00V89ED2
    Asset Tag: 9176843213
    Part Number: X971B5233DH0-CL0  
    Rank: Unknown
    Configured Clock Speed: 1600 MHz

Handle 0x0037, DMI type 17, 34 bytes
Memory Device
    Array Handle: 0x0035
    Error Information Handle: Not Provided
    Total Width: 64 bits
    Data Width: 64 bits
    Size: 4096 MB
    Form Factor: SODIMM
    Set: None
    Locator: ChannelB-DIMM0
    Bank Locator: BANK 2
    Type: DDR3
    Type Detail: Synchronous
    Speed: 1600 MHz
    Manufacturer: Samsung
    Serial Number: 0Z7U9RA3
    Asset Tag: 9876543210
    Part Number: M481BT173DH0-CL0  
    Rank: Unknown
    Configured Clock Speed: 1600 MHz

Sabtu, November 02, 2013

VB.NET : Tumblr.com login + captcha

Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Web

Public Class frmMain
#Region "Structures"
    Private Structure Sessions
  Dim recaptcha_public_key As String
  Dim form_key As String
  Dim recaptcha_challenge_field As String

  Public Sub Reset()
    recaptcha_challenge_field = String.Empty
    form_key = String.Empty
    recaptcha_public_key = String.Empty
  End Sub
    End Structure
#End Region

    Public Enum Verb
  [GET] = 0
  POST = 1
    End Enum
    Private ReadOnly Verbs() As String = New String() {"GET", "POST"}

    Dim CookieJar As New CookieContainer
    Private Session As New Sessions
    Function GetResponse(ByVal Method As Verb, ByVal Uri As String, Optional ByVal PostData As String = "")

  Dim byteData As Byte() = Nothing
  If Not String.IsNullOrEmpty(PostData.Trim) Then byteData = UTF8Encoding.UTF8.GetBytes(PostData)

  Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create(Uri), HttpWebRequest)
  postReq.Method = Verbs(Method)
  postReq.KeepAlive = True
  postReq.CookieContainer = CookieJar
  postReq.ContentType = "application/x-www-form-urlencoded"
  postReq.Referer = "https://www.tumblr.com/login"
  postReq.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"
  postReq.ContentLength = If(IsNothing(byteData), 0, byteData.Length)

  If (Method.Equals(Verb.POST)) Then
    If Not postReq.ContentLength.Equals(0) Then
    Dim dataStream As Stream = postReq.GetRequestStream()
    With dataStream
    .Write(byteData, 0, byteData.Length)
    .Close() : .Dispose()
    End With
    End If
  End If

  Dim postresponse As HttpWebResponse
  postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
  CookieJar.Add(postresponse.Cookies)

  Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
  Dim html As String = postreqreader.ReadToEnd
  Return html
    End Function

    Sub UpdateLog(ByVal text As String)
  EventLog.AppendText(String.Format("[{0}]: {1}", Date.Now.ToShortTimeString, text.Trim))
  EventLog.AppendText(Environment.NewLine)
    End Sub
    Public Shared Function ParseBetween(ByVal Html As String, ByVal Before As String, ByVal After As String, Optional Offset As Integer = 0) As String
  If Offset = 0 Then Offset = Before.Length
  If String.IsNullOrEmpty(Html) Then Return String.Empty
  If Html.Contains(Before) Then
    Dim Result As String = Html.Substring(Html.IndexOf(Before) + Offset)
    If Result.Contains(After) AndAlso Not String.IsNullOrEmpty(After) Then Result = Result.Substring(0, Result.IndexOf(After))
    Return Result
  Else
    Return String.Empty
  End If
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  UpdateLog("Logging in with: " & username_txt.Text)
  If Not captcha_txt.Text = String.Empty Or username_txt.Text = String.Empty Or password_txt.Text = String.Empty Then
    Dim PostData As New StringBuilder
    PostData.Append(HttpUtility.UrlEncode("user[email]") & "=" & HttpUtility.UrlEncode(username_txt.Text))
    PostData.Append("&" & HttpUtility.UrlEncode("user[password]") & "=" & HttpUtility.UrlEncode(password_txt.Text))
    PostData.Append("&" & HttpUtility.UrlEncode("tumblelog[name]") & "=")
    PostData.Append("&recaptcha_public_key=" & Session.recaptcha_public_key)
    PostData.Append("&recaptcha_challenge_field=" & Session.recaptcha_challenge_field)
    PostData.Append("&recaptcha_response_field=" & captcha_txt.Text)
    PostData.Append("&" & HttpUtility.UrlEncode("user[age]") & "=")
    PostData.Append("&context=login")
    PostData.Append("&version=STANDARD")
    PostData.Append("&follow=")
    PostData.Append("&http_referer=" & HttpUtility.UrlEncode("https://www.tumblr.com/login"))
    PostData.Append("&form_key=" & HttpUtility.UrlEncode(Session.form_key))
    PostData.Append("&seen_suggestion=0")
    PostData.Append("&used_suggestion=0")

    Dim html As String = GetResponse(Verb.POST, "https://www.tumblr.com/login", PostData.ToString)

    html = GetResponse(Verb.GET, "http://www.tumblr.com/dashboard")

    If html.Contains(">Log out</a>") Then
    UpdateLog("Successfully Logged in !")
    UpdateLog("Your blog is: " & ParseBetween(html, "class=""open_blog_link"" href=""", """"))
    Else
    UpdateLog("Couldn't Login. Check username/password.")

    End If

  Else
    MsgBox("Make sure you've entered all the inputs. Including the captcha")
  End If

    End Sub

    Sub GetCaptcha()
  UpdateLog("Fetching Captcha ...")
  Dim Html As String = GetResponse(Verb.GET, "https://www.tumblr.com/login")
  Session.recaptcha_public_key = ParseBetween(Html, "name=""recaptcha_public_key"" value=""", """")
  Session.form_key = ParseBetween(Html, "name=""form_key"" value=""", """")
  Dim Challenge As String = GetResponse(Verb.GET, String.Format("https://www.google.com/recaptcha/api/challenge?k={0}&ajax=1&cachestop=0.7610605780430966", Session.recaptcha_public_key))
  Challenge = ParseBetween(Challenge, "challenge : '", "',")
  Session.recaptcha_challenge_field = Challenge
  PictureBox1.ImageLocation = "https://www.google.com/recaptcha/api/image?c=" & Session.recaptcha_challenge_field
  UpdateLog("Successfully fetched Captcha !")
    End Sub

    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  GetCaptcha()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  GetCaptcha()
    End Sub
End Class 

Download : Tumblr login (mediafire)

XSS : http://mylearn.umt.edu.my (Universiti Malaysia Terengganu)