Thursday, September 28, 2017

SCP: Sending Image Using Secure Copy

Command:

$ scp ~/Desktop/Pepe.png USERNAME@SERVERNAME:/home/USERNAME
USERNAME@SERVERNAME's password:

Result:

Pepe.png  

Coinhive: Capcha Example: Using PHP

<html>
<head></head>
<body>
<div>
<?php
if(isset($_POST["coinhive-captcha-token"])){
        $token = $_POST["coinhive-captcha-token"];
        $secret = 'bAbbbb5A9AbA0bbbA3bAAbAb8bAbAAAb';
        $url = 'https://api.coinhive.com/token/verify';

        $data = array('token'=> $token,
                      'hashes' => 1024,
                      'secret' => $secret);

        $options = array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($data)
        );
     
        $context  = stream_context_create(array('http' => $options));

        $response = json_decode(file_get_contents($url, false, $context));

        if ($result === FALSE) {
                echo "Error";
                exit;
        }
     
        $responseSuccess = $response->success;
}
?>
<?php if ($responseSuccess){ ?>
Verified<br/>
<?php } else { ?>
You must verify
<form action="?" method="post">
        <!-- other form fields -->

        <script src="https://coinhive.com/lib/captcha.min.js" async></script>
        <div class="coinhive-captcha" data-hashes="1024" data-key="AAAbAA33bAAbAbbAbAA4bA7dA4AAbA7b"></div>

        <input type="submit" value="Submit"/>
</form>
<?php } ?>
</div>
</body>
</html>

Billy Corgan - VANILLA - live from Madame ZuZu's - Sep 16, 2017

Thursday, September 21, 2017

Javascript: Prime Number Generator

HTML/Javascript Code:

<html><head>
<meta name="viewport" content="width=device-width">
<script>
var d=document;
var primes=[];

function Prime(){
   for (var i=2; i<=2000000;i++){
      if (this.check(i, primes)){
         primes.push(i);
         d.write(i+" ");
      }
   }
}

Prime.prototype.check=function(i, primes){
   var isOdd=i%2;
   var isPrime=true;
   var n=2;

   if(i==2 || isOdd){
      var to=Math.floor(i/2);

      if (primes.length>0){
         for (var j=0;j<primes.length; j++){
            n=primes[j];
            if(n>to){
               break;
            }
            if(i%n==0){
               isPrime=false;
               break;
            }
         }
      }

      for(;n<=to;n++){
         if(i%n==0){
            isPrime=false;
            break;
         }
      }
   } else {
      isPrime=false;
   }

   return isPrime;
}

function main(){
   var p=new Prime();
}
</script>
</head>
<body onload="main()">default</body>
</html>


Web Inspector:

23.51s



Monday, September 18, 2017

Tuesday, September 12, 2017

Apache HTTP Server: Redirect All HTTP Requests to HTTPS

Command:

# diff httpd.conf httpd.conf.bkup20170901


Result:

1005c1004
< <VirtualHost *:80>
---
> #<VirtualHost *:80>
1008,1009c1007
<      ServerName www.SERVERNAME.com
< Redirect / https://www.SERVERNAME.com/
---
> #    ServerName dummy-host.example.com
1012,1013c1010
< </VirtualHost>
<
---
> #</VirtualHost>


Reference:

https://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests-to-https/21798882#21798882