Memaparkan catatan dengan label web. Papar semua catatan
Memaparkan catatan dengan label web. Papar semua catatan

Ahad, November 24, 2013

LAMPP : Permision denied "/op/lampp/htdoc" - FIXED!

Bila pasang XAMPP dalam linux, semua web files akan sumbat dalam folder htdocs. Tapi masalahnya. Asyik kena recursive chmod je folder website (htdocs) dan sangat leceh bila nak buat kerja (sangat busy beb!). Jadi, cara mudah.. kita letakkan bawah user dan group komputer kita sendiri. Tak faham? Ok. Contoh lah web saya tu dalam folder "pinktube" (bukan redtube ok?), dan saya nak buat index.php dalam tu.
$ touch /opt/lampp/htdocs/pinktube/index.php
touch: cannot touch ‘/opt/lampp/htdocs/pinktube/index.php’: Permission denied
Nampak tak masalah kat atas? Bayangkan ada banyak fail dan folder. Nak chmod 755 -R pun rasa malas klau ada banyak folder lain dan kena kerap kali buat macamni. Tu belum masuk lagi kes orang yang tak tahu guna recursive chmod. Mesti kojol kalau dia chmod fail satu per satu..kah..kah..

Penyelesaian Mudah :
===================
1. Kita kenal pasti user dan group:
$ who am i
Contoh output:
syasha      pts/1        2023-14-54 01:44 (:0)
* amik output yang depan sekali untuk kenal pasti user dan group , sebagai contoh diatas ialah "syasha"

2. Set direktori /op/lampp/htdocs/ tersebut dengan permision dari output user dan group di atas
$ sudo chown -R username:username /opt/lampp/htdocs
Klu ikot contoh aku, username tu perlulah ganti dengan syasha..bergantung pada komputer korang la.

3. Edit fail httpd.conf
$ sudo nano /opt/lampp/etc/httpd.conf
Cari maklumat bawah bahagian <IfModule unixd_module>
User deamon
Group deamon
Ganti deamon tu dengan user dan group anda sendiri. Simpan dan restart lampp anda. Ok selesai.. try la buat fail atau folder, dah takde masalah lagi.

Selamat mencuba!

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)

Ahad, Ogos 18, 2013

PHP : Switch Case

<?php

$day = 'Saturday';

switch ($day) {
case 'Saturday':
case 'Sunday':
echo 'It\'s a weekend.';
break;

default:
echo 'Not a weekend.';
break;
}

?>

Khamis, Ogos 08, 2013

JavaScript : No right click

============================================================
Script:    Basic No-Right-Click Script
Functions: Blocks right-click on mouse and shows alert box
Browsers:  NS & IE 4.0 & later; degrades gracefully
Author:    etLux
============================================================

Put the following script in the head of your page:

<script language="Javascript1.2">

// (C) 2003 CodeLifter.com
// Source: CodeLifter.com
// Do not remove this header

// Set the message for the alert box
am = "This function is disabled!";

// do not edit below this line
// ===========================
bV  = parseInt(navigator.appVersion)
bNS = navigator.appName=="Netscape"
bIE = navigator.appName=="Microsoft Internet Explorer"

function nrc(e) {
   if (bNS && e.which > 1){
      alert(am)
      return false
   } else if (bIE && (event.button >1)) {
     alert(am)
     return false;
   }
}

document.onmousedown = nrc;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (bNS && bV<5) window.onmousedown = nrc;

</script>

JavaScript : No select text + No Right Click

<script type="text/javascript">

/***********************************************
* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
* Modified here to exclude form tags properly, cross browser by jscheuer1
***********************************************/

//form tags to omit:
var omitformtags=["input", "textarea", "select"]

function disableselect(e){
for (i = 0; i < omitformtags.length; i++)
if (omitformtags[i]==(e.target.tagName.toLowerCase()))
return;
return false
}

function reEnable(){
return true
}

function noSelect(){
if (typeof document.onselectstart!="undefined"){
document.onselectstart=new Function ("return false")
if (document.getElementsByTagName){
tags=document.getElementsByTagName('*')
for (j = 0; j < tags.length; j++){
for (i = 0; i < omitformtags.length; i++)
if (tags[j].tagName.toLowerCase()==omitformtags[i]){
tags[j].onselectstart=function(){
document.onselectstart=new Function ('return true')
}
if (tags[j].onmouseup!==null){
var mUp=tags[j].onmouseup.toString()
mUp='document.onselectstart=new Function (\'return false\');\n'+mUp.substr(mUp.indexOf('{')+2,mUp.lastIndexOf('}')-mUp.indexOf('{')-3);
tags[j].onmouseup=new Function(mUp);
}
else{
tags[j].onmouseup=function(){
document.onselectstart=new Function ('return false')
}
}
}
}
}
}
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}
}

window.onload=noSelect;
</script>

Selasa, Ogos 06, 2013

PHP : Bing! Domain Scanner (CLI dan UI)

<?php
/*
name: bing subdomain scanner
author: RieqyNS13
using: php bing.php domain.com
*/
$args = $_SERVER['argv'];
$url = $args[1];
scan($url);
function curl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $exec = curl_exec($ch);
    curl_close($ch);
    return $exec;
}
function scan($url){
    $i=1;
    $jum=0;
    $reg = '@^(https?\://)?(www\.)?([a-z0-9]([a-z0-9]|(\-[a-z0-9]))*\.)+[a-z]+$@i';
    if(preg_match($reg, $url)){
        while(1){
            $curl = curl("http://www.bing.com/search?q=domain:".$url."&first=".$i);
            $data = preg_match_all('#\<div class\="sb_meta"\>\<cite\>(.*?)\</cite\>#is', $curl, $m) ? $m[1] : null;
            if($data==null){
                $count=0;
                goto a;
            }
            foreach($data as $dat){
                $dat_ = preg_match("|/|i", $dat) ? strstr($dat, "/", 1) : $dat ;
                $urls[$i][] = $dat_;
            }
            $count = count($urls[$i]);
            $urls_ = array_unique($urls[$i]);
            sort($urls_);
            foreach($urls_ as $url_){
                echo $url_."\n";
                $jum++;
            }
            $i=$i+10;
            a:
            if($count<10 || $data==null){
                echo "\nJumlah subdomain terdeteksi: ".$jum;
                exit;
            }    
        }
    }else{
        echo "URL tidak valid";
        exit;
    }
}
?>


<?php
//bacoked by rieqy
ini_set("output_buffering", "Off");
set_time_limit(0);
//:dead
if(isset($_POST['submit'])){
    if(!empty($_POST['domain'])){
        $domain = trim($_POST['domain']);
    }else $domain = null;
    
}else $domain = null;
?>
<html>
<head>
<title>Bing Subdomain Scanner by RieqyNS13</title>
<meta name="author" content="RieqyNS13">
<meta name="description" content="Bing Subdomain Scanner by RieqyNS13">
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method=POST>
<label for="subdomain">Masukkan domain</label>&nbsp<input type="text" value="<?php echo $domain; ?>" name="domain" style="width:200px" placeholder="e.g. http://gay.com or gay.com"><input type="submit" name="submit" value="Scan"><br>
<textarea placeholder="subdomain akan ditampilkan di sini" rows="20" cols="35" readonly>
<?php
if(isset($domain) && !empty($domain)){
    scan($domain);
}
function curl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $exec = curl_exec($ch);
    curl_close($ch);
    return $exec;
}
function scan($url){
    $i=1;
    $jum=0;
    $reg = '@^(https?\://)?(www\.)?([a-z0-9]([a-z0-9]|(\-[a-z0-9]))*\.)+[a-z]+$@i';
    if(preg_match($reg, $url)){
        while(1){
            $curl = curl("http://www.bing.com/search?q=domain:".$url."&first=".$i);
            $data = preg_match_all('#\<div class\="sb_meta"\>\<cite\>(.*?)\</cite\>#is', $curl, $m) ? $m[1] : null;
            if($data==null){
                $count=0;
                goto a;
            }
            foreach($data as $dat){
                $dat_ = preg_match("|/|i", $dat) ? strstr($dat, "/", 1) : $dat ;
                $urls[$i][] = $dat_;
            }
            $count = count($urls[$i]);
            $urls_ = array_unique($urls[$i]);
            sort($urls_);
            foreach($urls_ as $url_){
                echo $url_."\n";
                ob_flush();flush();
                $jum++;
            }
            $i=$i+10;
            a:
            if($count<10 || $data==null){
                echo "\nJumlah subdomain terdeteksi: ".$jum;
                ob_flush();flush();
                exit;
            }    
        }
    }else{
        echo "URL tidak valid";
        ob_flush();flush();
        exit;
    }
}
?>
</textarea>
</form>
</body>
</html> 

Sabtu, Ogos 03, 2013

PHP : Secure session

<?php
session_start(); 
$_SESSION['sid'] = md5(time());
$sid = $_SESSION['sid'];
echo $sid;
?>

.htaccess : Mengurangkan bandwith dengan memampatkan data

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

.htaccess : Redirect web pada custom error pages

ErrorDocument 400 /error/badreq.html
ErrorDocument 401 /error/autherror.html
ErrorDocument 403 /error/forbidden.html
ErrorDocument 404 /error/notfound.html
ErrorDocument 500 /error/serverr.html

.htaccess : Buang WWW pada URL

RewriteEngine On
RewriteCond %{HTTP_HOST} !^mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301]

.htaccess : Buang extensi fail pada URL (Contoh : *.html)

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html