Integrating Facebook Connect with Hotspot Login / Authent ..

To ahmad210993.

Yes! I can translate script coments and other text.

You can be free to use this script and my name on MUM.

You already can use my scripts discussed in this forum branch:Automatically clean expired User-Manager accounts
( It must be usefull)

The script in archive code.rar have mistakes which corrected in next edition You can see below:

This script allow to activate registered demo account after actual-profile expired, and for security reasons use method POST instead of GET


api/login.php

<?php
$mac=$_POST['mac'];
$ip=$_POST['ip'];
$username=$_POST['username'];
if ($username === 'undefined') {
$username = '';
}
$linklogin=$_POST['link-login'];
$linkorig=$_POST['link-orig'];
$linkloginonly=$_POST['link-login-only'];
$chapid = $_POST['chap-id'];
$chapchallenge = $_POST['chap-challenge'];
//$chapid=clear($_POST['chap-id']);
//$chapchallenge=clear($_POST['chap-challenge']);
$linkorigesc=$_POST['link-orig-esc'];
$macesc=$_POST['mac-esc'];
$trial=$_POST['trial'];
$error=$_POST['error'];
function clear($code) { return str_replace('\\\\', '\\', $code); } 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv='Content-Language' content='lt' />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<title>Free HotSpot | Login Facebook</title>
<link rel="shortcut icon" href="../images/favicon.ico" type="image/x-icon">
<link rel="icon" href="../images/favicon.ico" type="image/x-icon">
<link href="css/style.css" type="text/css" rel="stylesheet" />
<style type="text/css">
            .button
            {
            background: url(fb.png) no-repeat;
	    width: 100px;
		height: 30px;
            cursor:pointer;
                        border: none;
            }
        </style>
</head>
<body>
<div id="fb-root"></div>
<div id="user-info"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
 appId: '{YOUR API ID}',
 channelUrl : '//YOUR HOST NAME/api/channel.html',
 status: true,
 cookie: true,
 xfbml: true,
 oauth: true});
  function updateButton(response) {
    var button = document.getElementById('fb-auth');
    if (response.authResponse) {
      //user is already logged in and connected
      var userInfo = document.getElementById('user-info');
      FB.api('/me', function(response) {
old_pass = response.email; 
temp_pass = replace_string(old_pass,'@','A') ;
new_pass = replace_string(temp_pass,'.','T') ;
//    userInfo.innerHTML = '<iframe src="http://YOUR HOST NAME/api/user.php?mac=<?php echo $_POST['mac']; ?>&user=' + response.email + '&nama=' + response.name + '" width="1" height="1"></iframe>';
//   userInfo.innerHTML = '<iframe src="http://YOUR HOST NAME/api/user-um.php?mac=<?php echo $_POST['mac']; ?>&user=' + response.email + '&nama=' + response.name + '&password=' + new_pass + '" width="1" height="1"></iframe>';
document.useradd.user.value = response.email;
document.useradd.nama.value = response.name;
document.useradd.password.value = response.name;
document.useradd.submit();
			  wait(8000);
//self.location ='<?php echo $linkloginonly; ?>?dst=<?php echo $linkorig; ?>&password=' + response.name + '&username=' + response.email ;
document.login.username.value = response.email;
document.login.password.value = response.name;
document.login.submit()
});
      button.onclick = function() {
        FB.logout(function(response) {
          var userInfo = document.getElementById('user-info');
         userInfo.innerHTML="";
 });
      };
    } else {
      //user is not connected to your app or logged out
      button.onclick = function() {
        FB.login(function(response) {
   if (response.authResponse) {
            FB.api('/me', function(response) {
       var userInfo = document.getElementById('user-info');
     });   
          } else {
            //user cancelled login or did not grant authorization
          }
        }, {scope:'email'});   
      }
    }
  }
  // run once with current status and whenever the status changes
  FB.getLoginStatus(updateButton);
  FB.Event.subscribe('auth.statusChange', updateButton); 
};
(function() {
  var e = document.createElement('script'); e.async = true;
  e.src = document.location.protocol+ 'all.js';
  document.getElementById('fb-root').appendChild(e);
}());
function wait(msecs)
{
var start = new Date().getTime();
var cur = start
while(cur - start < msecs)
{
cur = new Date().getTime();
}	
};
function replace_string(txt,cut_str,paste_str)
{ 
var f=0;
var ht='';
ht = ht + txt;
f=ht.indexOf(cut_str);
while (f!=-1){ 
f=ht.indexOf(cut_str);
if (f>0){
ht = ht.substr(0,f) + paste_str + ht.substr(f+cut_str.length);
};
};
return ht
}
</script>
</center>
<div id="content">
<p><h4><font color="#000000">Hotspot Free with Facebook.</font></h4></p>
<button id="fb-auth" class="button"></button>
<br />
<br />
<font color="#000000" size="-1"><i>Working on pc/laptop</i></font><br />
<!-- $(if error) -->
<div style="color: #FF8080; font-size: 11px"><?php echo $error; ?></div>
<!-- $(endif) -->
</div>
<br />
<div id="footer">
<font color="#000000">Auksela Free Net © 2013.</font></a>
</div>
</div>
<!-- $(if chap-id) -->
	<form name="sendin" id="sendin" action="<?php echo $_POST['link-login-only']; ?>" method="post">
		<input type="hidden" name="username" />
		<input type="hidden" name="password" />
<!--
		<input type="hidden" name="error" />
-->
		<input type="hidden" name="dst" value="<?php echo $_POST['link-orig']; ?>" />
		<input type="hidden" name="popup" value="true" />
	</form>
	<script type="text/javascript" src="./md5.js"></script>
	<script type="text/javascript">
	<!--
	    function doLogin() {
                <?php if(strlen($chapid) < 1) echo "return true;\n"; ?>
		document.sendin.username.value = document.login.username.value;
		document.sendin.password.value = hexMD5('<?php echo $_POST['chap-id']; ?>' + document.login.password.value + '<?php echo $_POST['chap-challenge']; ?>');
		document.sendin.submit();
		return false;
	    }
	//-->
	</script>
<!-- $(endif) -->
<!-- removed $(if chap-id) $(endif)  around OnSubmit -->
	<form name="login" id="login" action="<?php echo $_POST['link-login-only'];?>" method="post" onSubmit="return doLogin()" >
		<input type="hidden" name="dst" value="<?php echo $_POST['link-orig']; ?>" />
		<input type="hidden" name="popup" value="true" />
<!--	
		<input type="hidden" name="error" value="<?php echo $_POST['error']; ?>" />
-->
        <input type="hidden" name="username" value=""/>
	    <input type="hidden" name="password" value=""/>
<!--			
        <input type="submit" value="Connect" />
-->
</form>
	<form name="useradd" id="useradd" action="user-um.php" method="post">
        <input type="hidden" name="user" value=""/>
		<input type="hidden" name="nama" value=""/>
		<input type="hidden" name="mac" value="<?php echo $_POST['mac']; ?>" />
	    <input type="hidden" name="password" value=""/>
<!--			
        <input type="submit" value="Connect" />
-->
</form>
// path below is commented , uncoment it if you want popup windows error.php which show links to register and activate permanent account
<!--
<script type="text/javascript">
<!--
var a = "<?php echo $_POST['error'] ?>";
if(a !== "")
{
window.open('http://YOUR HOST NAME/erros/error.php?mac=<?php echo $mac; ?>&link=<?php echo $linkloginonly; ?>&user=<?php echo $username; ?>&error=<?php echo $error; ?>','','width=500,height=350,scrollbars=yes');
}
//-->
<!--
</script>
-->
</body>
</html>

api/user-um.php

next edition…


<?php
namespace PEAR2\Net\RouterOS;
include_once '../src/php/PEAR2/Autoload.php';
include 'param.common.php';
//../include_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';
?>
 <?php
$user=$_POST['user'];
$mac=$_POST['mac'];
$nama=$_POST['nama'];
//$password=md5(md5($_POST['user']));
//$password=$_POST['user'];
$password=$_POST['password'];
//$password=$_POST['nama'];
$txt1 = ' ';
$profile = 'Trial';
$location = 'Your location';
$location = $location.$txt1.$mac;
$customer = 'facebook';
$comment = $nama.$txt1.$mac;
$comment1 = 'Added by Facebook';
$client = new Client($host,$admin,$pass);
//------------------
 try {$printRequest = new Request('/system clock print');
//------
	$array=$client->sendSync($printRequest)->getAllArguments(array(
	'date' => 'date',
	'time'=> 'time'));
//------
$comment1 = $array['date'].$txt1.$array['time'].$txt1.$comment1;
$comment = $array['date'].$txt1.$array['time'].$txt1.$comment;
$printRequest = new Request('/tool user-manager user print');
	$printRequest->setQuery(Query::where('name',$user));
	$array=$client->sendSync($printRequest)->getAllArguments(array('.id' => '.id',
	'actual-profile' => 'actual-profile',
	'last-seen' => 'last-seen',
	'uptime-used' =>'uptime-used',
	'download-used' => 'download-used',
	'upload-used' => 'upload-used',
	'comment' => 'comment'));
//----
if (null !== $array['.id'] ) {
echo "User {$user} already registered in system!<br>";
if (null !== $array['actual-profile'] ) {
echo "User {$user} reached time limit!<br>";
} else {
//--- Reset counters
$setRequest = new Request('/tool user-manager user reset-counters');
$setRequest->setArgument('numbers',$array['.id']);
$client->sendSync($setRequest);
echo "All counters for {$user} Id {$array['.id']}successfully reseted!!!<br>";
//--- Create and activate profile
$addRequest = new Request('/tool user-manager user create-and-activate-profile');
$addRequest->setArgument('customer',$customer);
$addRequest->setArgument('numbers',$array['.id'] );
$addRequest->setArgument('profile',$profile);
$client->sendSync($addRequest);
//---add comment
$setRequest = new Request('/tool user-manager user comment');
$setRequest->setArgument('numbers',$array['.id']);
$setRequest->setArgument('comment',$comment1);
if ($client->sendSync($setRequest)->getType() !== Response::TYPE_FINAL) {
echo "Error when aactivated  '{$user}'.<br>";
} else {
echo "User {$user} successfully activated!!!<br>";
}
}
} else {
//--- Add user
$addRequest = new Request('/tool user-manager user add');
$addRequest->setArgument('customer', $customer);
$addRequest->setArgument('name', $user);
$addRequest->setArgument('first-name', $nama);
$addRequest->setArgument('last-name', $nama);
$addRequest->setArgument('location', $location);
$addRequest->setArgument('email', $user);
$addRequest->setArgument('password', $password);
$addRequest->setArgument('phone','370');
$addRequest->setArgument('disabled', no);
$addRequest->setArgument('comment', $comment);
$addRequest->setArgument('shared-users', 1);
if ($client->sendSync($addRequest)->getType() !== Response::TYPE_FINAL) {
echo "Error when added user for '{$nama}'.<br>";
} else {
echo "Comment: '{$comment}'. User'{$user}' successfully added!.";
}
//--- Create and activate profile
$printRequest = new Request('/tool user-manager user print');
$printRequest->setArgument('.proplist', '.id');
$printRequest->setQuery(Query::where('name', $user));
$userId = $client->sendSync($printRequest)->getArgument('.id');
$addRequest = new Request('/tool user-manager user create-and-activate-profile');
$addRequest->setArgument('customer', $customer);
$addRequest->setArgument('numbers', $userId );
$addRequest->setArgument('profile', $profile);
$client->sendSync($addRequest);
$setRequest = new Request('/tool user-manager user comment');
$setRequest->setArgument('numbers',  $userId );
$setRequest->setArgument('comment', $comment1);
if ($client->sendSync($setRequest)->getType() !== Response::TYPE_FINAL) {
echo "Error when aactivated  '{$user}'.<br>";
} else {
echo "Comment: '{$comment}'. User'{$user}' successfully added!!.";
echo "User {$user} successfully activated!!!<br>";
}
}
} catch(Exception $e) {
echo $e;
}
 ?>

errors/error.php

This page, in my case, show links to create, activate and check permanent user.

EXAMPLE

<?php
   $link=$_GET['link'];
   $error=$_GET['error'];
 ?>
<head>
<meta name="verify-webtopay" content="{Your pass in payment system}">
<meta http-equiv='Content-Language' content='lt' />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<link rel="stylesheet" type="text/css" href="css.css">
<font color=red size="5" ><b><?php echo $error; ?>!</b></font>
<br />
<font color=red><b>For permanent use online,</b></font>
<br> 
<font color=red><b>*1.</b></font>You must to create user, see link below,<br>
complete form and click "Add user".<br>
<font color=red><b>*2.</b></font>After user creation it must be activated: link<br>
"User activation", read all instruction and follow it.<br>
<font color=red><b>*3.</b></font>If If Your user already exist and you have no credits,<br>
follow link "Buy credits",<br>
read all instruction and follow it..<br />
<!--
<font color=red><b>Important!</b></font> If you do not use a long time, it is necessary to check <br>
account via a link on the bottom, <br>
as subscribers inactive over 60 days are removed from the system <br>
automatically. <br />
-->
<?php 

include "links.php";

?>
<body>
<script type="text/javascript" charset="utf-8">
                        	    var wtpQualitySign_projectId  = {YOUR ID IN PAYMENT SYSTEM};
                        	    var wtpQualitySign_language   = "lt";
                            	</script>
                            	<script src="https://www.webtopay.com/new/js/project/wtpQualitySigns.js" type="text/javascript" charset="utf-8"></script>
</body>

and

errors/links.php

<br>
<a href="#" style="text-decoration:none; font-family: Tahoma;" onclick="window.open('../reg/check-user.php?mac=<?php echo $_GET['mac'];?>&phone=Your phone number.','','width=500,height=420,scrollbars=yes');return false;" title="User add"><b style='color:white'>* User add.</b><br></a>
<a href="#" style="text-decoration:none; font-family: Tahoma;" onclick="window.open('./redirect.php?link=<?php echo $link; ?>&phone=Your phone number.','','width=500,height=420,scrollbars=yes');return false;" title="User add"><b style='color:white'>* Create automatic connection.</b><br></a>
<!--
<a href="#" style="text-decoration:none; font-family: Tahoma;" onclick="window.open('../check/index.php?phone=37000000000&user=<?php echo $_GET['user']; ?>','','width=500,height=420,scrollbars=yes');return false;" title="Check user"><b style='color:white'>* Check user.</b><br></a>
-->
<a href="#" style="text-decoration:none; font-family: Tahoma;" onclick="window.open('../payment/svitch.php?phone=37000000000&mac=<?php echo $_GET['mac'];?>&user=<?php echo $_GET['user'];?>','','width=500,height=420,scrollbars=yes');return false;" title="Activate user or Buy credit"> <b style='color:white'>* Activate user or Buy credit.</b> </a><br>

links in this example:

../reg/check-user.php
./redirect.php
../check/index.php
../payment/svitch.php

I dont explain for you how this links work. You can be free do this transaction yourself.

File error.txt - standart from MT.

You must create porofile “Trial” in UM.

File login/pclogin.php from archive code.rar - standard login.php file from mikrotik wiki - external login page.
To this file added this fragments (1,2,3,4):

//------1-----
Login by "Facebook":
<a href="#" style="text-decoration:none; font-family: verdana; color: #FF0000" onclick="select();return false;" title="Facebook."> Click here</a>
</p>
//-----1 end---
//-----2----
// and function select() - redirect non hotspot user ( external ) to another page insted facebook login
<script type="text/javascript">
<!--
function select()
{
var link = "<?php echo $_POST['link-login-only'] ?>";
if(link !== "")
{
document.redirect.submit();
} else {
window.open('/facebook.html','','width=500,height=350,scrollbars=yes');
}
}
//-->
</script>
//----2 end---
//----3-------
// and hidden form which call facebook login.php  page in directory apy
<form name="redirect" action="../api/login.php" method="post">
<input type="hidden" name="mac" value="<?php echo $_POST['mac']; ?>">
<input type="hidden" name="ip" value="<?php echo $_POST['ip']; ?>">
<input type="hidden" name="username" value="<?php echo $_POST['username']; ?>">
<input type="hidden" name="link-login" value="<?php echo $_POST['link-login']; ?>">
<input type="hidden" name="link-orig" value="<?php echo $_POST['link-orig']; ?>">
<input type="hidden" name="error" value="<?php echo $_POST['error']; ?>">
<input type="hidden" name="chap-id" value="<?php echo $_POST['chap-id']; ?>">
<input type="hidden" name="chap-challenge" value="<?php echo $_POST['chap-challenge']; ?>">
<input type="hidden" name="link-login-only" value="<?php echo $_POST['link-login-only']; ?>">
<input type="hidden" name="link-orig-esc" value="<?php echo $_POST['link-orig-esc']; ?>">
<input type="hidden" name="mac-esc" value="<?php echo $_POST['mac-esc']; ?>">
//------3 end---------
//------4------------
//this path open popup window if error occured and show useful links: create, activate and check permanent user. - see abow in my post.
<script type="text/javascript">
<!--
var a = "<?php echo $_POST['error'] ?>";
if(a !== "")
{
window.open('http://YOUR HOST NAME/errors/error.php?mac=<?php echo $mac; ?>&link=<?php echo $linkloginonly; ?>&user=<?php echo $username; ?>&error=<?php echo $error; ?>','','width=500,height=350,scrollbars=yes');
}
//-->
</script>
//-------4 end-------

I use login/moblogin.php and logun/pclogin.php files for automatic selection login from PC or mobile device, but it is another theme…

I think, my explanation enough to do it work… :slight_smile:

You can test it in our site Free Net

But external user redirected to error page insted Facebook login page.

P.S. In this version Facebook’s user name used as password
and e-mail as username.