Programming

Tentang sedjat1.dx.am

Awalnya, saya cuma punya 1 blog di sedjat1.zz.mu, pada suatu saat saya gak bisa akses web itu sama sekali. Sesudah beberapa jam saya gak bisa akses akhirnya saya putuskan untuk bikin blog lagi di hosting gratis yang lain. Dengan berbekal backup database yang ada di notebook, akhirnya saya bisa menduplikasi sedjat1.zz.mu ke blog.sedjat1.dx.am.

Di tempat baru saya sengaja bikin sub domain sendiri untuk blog karena niatnya, saya bikin blog yang aneh bin ajaib, beda dari yang lain. Blog yang bentuknya seperti terminal console, yang kalo mau liat isinya, harus ngetik perintah dulu, biar kaya jaman DOS.

Penampilan sedjat1.dx.am, bar putih yang paling bawah itu ngedip kaya kursor terminal.

Rencananya kalo ngasih perintah dir baru muncul list entri blognya, terus ada perintah open untuk baca entry blog. Dan rencananya juga, engine blog nyimpen berkas blognya bukan di database. Karena ini buatan jaman dulu banget, jadi scriptnya juga masih cupu (klik READ MORE untuk source codenya).

Tapi ternyata, sesudah blog baru selesai diinstall, ternyata hosting lama saya masih bisa di akses, akhirnya jadi punya 2 blog. Dan yang ini jadi blog ketiga. Uhuy.

index.html

<html>
    <head>
        <title>Shell</title>
        <style type="text/css">
			@font-face {font-family: LatinModernMono; src: url(lmmonoltcond10-regular.otf);}
            .curputih { color:#fff; }
            .curitem { color:#000; }
            .merah { color:#f00; }
            .ijo { color:#0f0; }
            .kedip { text-decoration: blink; }
            pre { font-family: LatinModernMono; font-size: 16pt; }
        </style>
        <script type="text/javascript" src="ajaxObject.js"></script>
        <script type="text/javascript" src="ajaxParam.js"></script>
        <script type="text/javascript">
            var lcol = true;
            var reqInput = false;
            var tmr;
            var CMD = "";
            var PRO = "<span class='ijo'>\\❯ </span>";
            function $$(id) { return document.getElementById(id); }
            
            var objWish;
            var jxWish = new ajaxObject("wish.php");
            jxWish.callback = function (responseText, responseStatus) {
                if (responseStatus == 200) {
                    try { 
                        eval("objWish=" + responseText); 
                    } catch(e) { 
                        $$('cons').innerHTML += '<b>0#'+e.description+'</b>\n'+responseText; 
                        prompt(PRO); 
                        return; 
                    }
                    try {
                        if (objWish.mode=="replace") { 
                            $$('cons').innerHTML = objWish.answer; 
                        } else { 
                            $$('cons').innerHTML += objWish.answer; 
                        }
                    } catch (e) {
                        $$('cons').innerHTML += '<b>1#'+e.description+'</b>\n'+responseText; 
                    }
                } else { 
                    $$('cons').innerHTML += 'Ajax Error\n' + responseText; 
                }
                prompt(PRO);
            }   
            function roll() {
                var ofh = document.body.offsetHeight;
                var wii = window.innerHeight;
                if (wii<ofh) { window.scroll(0,ofh-wii+40); }
            }
            function prompt(teks) { 
                CMD = "";
                $$('prom').innerHTML = "<span class='ijo' id='blt'>" + teks + "</span><span id='blc'></span><span id='bl'>▌</span>"; 
                reqInput=true;
                roll(); 
            }
            function alterColor() {
                if ($$('bl')!=undefined) {
                    if (lcol) { $$('bl').className = 'curputih'; lcol = false; }
                    else { $$('bl').className = 'curitem'; lcol = true; }
                }
            }
            
            function jalanin(tmp) {
                tmp = tmp || false;
                reqInput = false;
                $$("prom").innerHTML = "";
                if (!tmp) $$('cons').innerHTML += '\n'+PRO+CMD+'\n';
                if (CMD != '') {
                    var prm = new ajaxParam();
                    prm.addParam('wish',CMD);
                    jxWish.update(prm.toString());
                } else { prompt(PRO); }
                
            }
            function startup() { tmr = setInterval(alterColor, 300); CMD='logo'; jalanin(true); }

            function kipres(evt) {
                if (reqInput) {
                    evt = evt || window.event;
                    var charCode = typeof evt.which == "number" ? evt.which : evt.keyCode;
                    if (charCode) {
                        switch (charCode) {
                        	case 8:
			                    var pj = CMD.length-1;
			                    CMD = CMD.substr(0,pj);
			                    roll();
			                    evt.preventDefault();
                        		break;
                            case 13:
                                jalanin();
                                break;
                            default:
                                CMD += String.fromCharCode(charCode);
                                roll();
                                break;
                        }
                    }
                    $$('blc').innerHTML = CMD;
                }
            }
            
            function kidon(evt) {
                var ka;
                if (window.event) { 
                	ka = window.event.keyCode;
                } else { 
                	ka = event.which;
                }
                if (ka==8) {
                    var pj = CMD.length-1;
                    CMD = CMD.substr(0,pj);
                    $$('blc').innerHTML = CMD;
                    roll();
					//event.preventDefault();
                }
            }
        </script>
    </head>
<body style="background-color:#000; color:#fff;" onload="startup()" onkeypress="kipres(event)" onkeydown="kidon(event)">
<pre><span id="cons"></span>
<span id="prom"></span>
</pre>
</body>
</html>

ajaxObject.js

function ajaxObject(url, callbackFunction) {
  var that=this;
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(passData,postMethod) {
    if (that.updating) { return false; }
    that.AJAX = null;
    if (window.XMLHttpRequest) {
      that.AJAX=new XMLHttpRequest();
    } else {
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (that.AJAX==null) {
      return false;
    } else {
      that.AJAX.onreadystatechange = function() {
        if (that.AJAX.readyState==4) {
          that.updating=false;
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);
          that.AJAX=null;
        }
      }
      that.updating = new Date();
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } else {
        var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());
        that.AJAX.open("GET", uri, true);
        that.AJAX.send(null);
      }
      return true;
    }
  }
  var urlCall = url;
  this.callback = callbackFunction || function () { };
}

function launchJavascript(responseText) {
  // RegExp from prototype.sonio.net
  var ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:</script>)';
           
  var match    = new RegExp(ScriptFragment, 'img');
  var scripts  = responseText.match(match);

    if(scripts) {
        var js = '';
        for(var s = 0; s < scripts.length; s++) {
            var match = new RegExp(ScriptFragment, 'im');
            js += scripts[s].match(match)[1];
        }
        eval(js);
    }
}

ajaxParam.js

function ajaxParam() {
    this.value = [];
    this.clear = function() { this.value = []; }
    this.addParam = function(strParam, strValue) { this.value[strParam] = encodeURIComponent(strValue); }
    this.toString = function() {
        var hasil = "";
        for (prms in this.value) {
            if (hasil!="") hasil += "&";
            hasil += prms + "=" + this.value[prms];
        }
        return hasil;
    }
}

wish.php

<?php
$wishper = $_GET["wish"];
$arrwish = explode(" ", $wishper);
$msg = "";
$exitcode = "";
$mode = "add";
$msg = strtolower($arrwish[0]);

switch ($msg) {
    case "cls":
        $mode = "replace";
    case "logo":
        $jawab = "dMoron'<span class='merah'>s</span>HELL version 1.0\\n".
        				"I'll grant you three wishes.\\n";
        break;
    case "about":
        $jawab = "dMoron'<span class='merah'>s</span>HELL version 1.0\\n".
        				"I'll grant you three wishes.\\n".
        				"If you know the right wish, I'll reveal secrets of life.\\n";
        break;
    case "whoami":
        $jawab = "I am me, I'm always me.\\n";
        break;
    case "help":
    case "?":
        $jawab = "Available wishes:\\n".
            "<b>ABOUT</b>\\n".
            "";
        break;
    default:
        $jawab = "That's not a valid wish.\\n";
        break;
}
date_default_timezone_set("Asia/Jakarta");
$servertime = date("Y-m-d H:i:s");
echo "{\"serverTime\": \"$servertime\", \"mode\":\"$mode\", \"answer\":\"$jawab\", \"msg\":\"$msg\", \"exitCode\":\"$exitcode\"}";
?>

Udah segitu doang, belom ada apa-apanya. Silahkan kalo mau utak-atik.