Rick Roll Script

rick-astleyThis is a simple script that I wrote as one of my first Asterisk projects. It’s a simple Click2Call script that calls the provided phone number and plays Rick Astleys “Never Gonna Give You Up”. The script requires that you have php5 + and asterisk 1.4.22. My version of the script will be back online once I’ve written a backend that can limit users to one call per hour. Keep checking for updates, they should be coming soon!

UPDATE:

I’ve recently gone back and cleaned up the code and made the script more modular so that I can build on it and make something really amazing that everyone can enjoy.

There are now two files involved with this script, the first and most important is the include file. In this case I named it rick_include.php. Create the include file with the following code (make sure to edit for your own server):

<?php
 
#first I defined the function
function rickroll () {
 
  #now some variables are assigned to connect to asterisk
  $strHost = "127.0.0.1";
  $strUser = "yourusername";
  $strSecret = "yourpassword";
  $strWaitTime = "30";
  $strPriority = "1";
  $strMaxRetry = "2";
 
  #get the value from the form in rickroll.php
  $strExten = $_POST['txtphonenumber'];
 
  #some asterisk CLI debugging stuff
  $callNumber = $strExten;
  $strCallerId = "RICKROLL <$callNumber>";
 
  #get the length of our input (giggity)
  $length = strlen($strExten);
 
  #check to make sure the input value is at least 10
  #digits, if true, send the information to
  #the "rickroll" context that is setup in extensions_custom.conf
  if ($length == 10 && is_numeric($strExten))
    {
        $oSocket = fsockopen($strHost, 5038, $errnum, $errdesc) or die("Connection to host failed");
        fputs($oSocket, "Action: login\r\n");
        fputs($oSocket, "Events: off\r\n");
        fputs($oSocket, "Username: $strUser\r\n");
        fputs($oSocket, "Secret: $strSecret\r\n\r\n");
        fputs($oSocket, "Action: originate\r\n");
        fputs($oSocket, "Channel: Local/1$callNumber@from-internal\r\n");
        fputs($oSocket, "WaitTime: $strWaitTime\r\n");
        fputs($oSocket, "CallerId: $strCallerId\r\n");
        fputs($oSocket, "Exten: s\r\n");
        fputs($oSocket, "Context: callclient\r\n");
        fputs($oSocket, "Priority: 1\r\n\r\n");
        fputs($oSocket, "Action: Logoff\r\n\r\n");
        sleep(3);
        fclose($oSocket);
    }
 
  #or else, keep telling them how to do it correctly
  else
    {
        echo ('Please enter a 10 digit number and try again');
    }
 
}
 
?>

Next, we need to create the file that will actually be loaded by the end user. This is the file that displays the form and posts it to our include file:

<html>
<head>
<title>Rick Astley is Calling You!</title>
<link rel="stylesheet" href="css/general.css" type="text/css" media="screen" />
</head>
<body>
 
<form action="<? echo $_SERVER['rick_include.php'] ?>" method="post">
 
<input type="text" size="20" maxlength="10" name="txtphonenumber"><br>
<input type="submit"
value="Rick Roll!">
 
</form>
 
<?php
include('rick_include.php');
 
rickroll();
?>
 
</body>
</html>

You’ll need to add the following to your extensions.conf file, or your extensions_custom.conf if you’re running a trixbox:

[rickroll]
exten => s,1,NoOp(inizio) ; verbose
exten => s,n,Answer
exten => s,n(message),Background(rickroll) ; "play rickroll.mp3 located in /var/lib/asterisk/sounds/"
exten => s,n,WaitExten(5)
exten => t,1,Playback(vm-goodbye)
exten => t,2,Hangup
  1. No comments yet.

  1. No trackbacks yet.

Unfortunately you don't have Adobe Flash-Player.... Klicken Sie hier fü kostenlosen Adobe Flash-Player.