Bookmark Topic Watch Topic
  • New Topic

Can anyone please convert it to Java? I really need it  RSS feed

 
magvanshiirev Janchiv
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
<?php
require_once("PHPTelnet.Class.php");

class TelnetMML
{
private $telnet;
private $l_host;
private $l_user;
private $l_pass;
private $mml_user;
private $mml_pass;
private $mml_term;
private $mml_serv;
private $l_debug;

public function __construct($host, $user, $pass, $mmluser, $mmlpass, $mmlterm, $mmlserv, $debug)
{
$this->l_host = $host;
$this->l_user = $user;
$this->l_pass = $pass;
$this->mml_user = $mmluser;
$this->mml_pass = $mmlpass;
$this->mml_term = $mmlterm;
$this->mml_serv = $mmlserv;
$this->l_debug = $debug;
}

public function Connect()
{
$this->telnet = new PHPTelnet();
return $this->telnet->Connect($this->l_host, $this->l_user, $this->l_pass);
}

public function PrepareMML()
{
$this->telnet->DoCommand('su - ismpmml', $result);
if ($this->l_debug) echo $result;

$this->telnet->DoCommand('start.sh mml', $result);
if ($this->l_debug) echo $result;
$this->telnet->DoCommand('login ' . $this->mml_user . ' ' . $this->mml_pass . ' ' . $this->mml_term, $result);
if ($this->l_debug) echo $result;

if (strpos($result, 'DESC=Success') === false)
return 1;

if ($this->l_debug) echo "MML Login Successful\n";

$this->telnet->DoCommand('set serv=' . $this->mml_serv, $result);
if ($this->l_debug) echo $result;
$this->telnet->DoCommand('set term=' . $this->mml_term, $result);
if ($this->l_debug) echo $result;

return 0;
}

public function AddUserDynamicIP($loginname, $msid, $domain, $usergroupid, $paidtype, $usertype, $ipassignway, $ippoolid, $servicestop, $templateid)
{ $cmd = "ADD C330 USER: LOGINNAME=$loginname, MSID=$msid, DOMAIN=$domain, USERGROUPID=$usergroupid, PAIDTYPE=$paidtype, USERTYPE=$usertype, IPASSIGNWAY=$ipassignway, IPPOOLID=$ippoolid, SERVICESTOP=$servicestop, TEMPLATEID=$templateid;";
if ($this->l_debug) echo $cmd;
$this->telnet->DoCommand($cmd, $result);
if ($this->l_debug) echo $result;

$desc_start = strpos($result, "DESC=\"") + 6;
return substr($result, $desc_start, strpos($result, "\";") - $desc_start);
}

public function AddUserStaticIP($loginname, $msid, $domain, $usergroupid, $paidtype, $usertype, $ipassignway, $ipaddress, $ipmask, $servicestop, $templateid)
{
$cmd = "ADD C330 USER: LOGINNAME=$loginname, MSID=$msid, DOMAIN=$domain, USERGROUPID=$usergroupid, PAIDTYPE=$paidtype, USERTYPE=$usertype, IPASSIGNWAY=$ipassignway, IPADDRESS=$ipaddress, IPMASK=$ipmask, SERVICESTOP=$servicestop, TEMPLATEID=$templateid;";
if ($this->l_debug) echo $cmd;
$this->telnet->DoCommand($cmd, $result);
if ($this->l_debug) echo $result;

$desc_start = strpos($result, "DESC=\"") + 6;
return substr($result, $desc_start, strpos($result, "\";") - $desc_start);
}

public function SetUserStatus($loginname, $msid, $domain, $status, $ip_addr, $ipmask, $ipassway)
{
if ($status == 'Normal')
$status_code = 0;
else
$status_code = 1;

$cmd = "MOD C330 USER: LOGINNAME=$loginname, MSID=$msid, DOMAIN=$domain, STATUS=$status_code, IPADDRESS=$ip_addr, IPMASK=$ipmask, IPASSIGNWAY=$ipassway,;";
if ($this->l_debug) echo $cmd;
$this->telnet->DoCommand($cmd, $result);
if ($this->l_debug) echo $result;

$desc_start = strpos($result, "DESC=\"") + 6;
return substr($result, $desc_start, strpos($result, "\";") - $desc_start);
}

public function SetUserTemplate($loginname, $msid, $domain, $template_id)
{
$cmd = "MOD C330 USER: LOGINNAME=$loginname, MSID=$msid, DOMAIN=$domain, TEMPLATEID=$template_id;";
if ($this->l_debug) echo $cmd;
$this->telnet->DoCommand($cmd, $result);
if ($this->l_debug) echo $result;

$desc_start = strpos($result, "DESC=\"") + 6;
return substr($result, $desc_start, strpos($result, "\";") - $desc_start);
}

public function SetUserGroup($loginname, $msid, $domain, $group_id, $times)
{
$result='';

$cmd = "MOD C330 USER: LOGINNAME=$loginname, MSID=$msid, DOMAIN=$domain, NEWUSERGROUPID=$group_id, NEWGRPEFFECTTIME=$times,;";

$this->telnet->DoCommand($cmd, $result);
if ($this->l_debug) echo $result;

$desc_start = strpos($result, "DESC=\"") + 6;
return substr($result, $desc_start, strpos($result, "\";") - $desc_start);
}

public function SetUserRealIp($loginname, $msid, $domain, $real_ip, $ipmask, $ipassway)
{
$result='';
$cmd = "MOD C330 USER: LOGINNAME=$loginname, MSID=$msid, DOMAIN=$domain, IPADDRESS=$real_ip, IPMASK=$ipmask, IPASSIGNWAY=$ipassway;";

$this->telnet->DoCommand($cmd, $result);
if ($this->l_debug) echo $result;

$desc_start = strpos($result, "DESC=\"") + 6;
return substr($result, $desc_start, strpos($result, "\";") - $desc_start).$real_ip;
}

public function ResetUser($loginname, $msid, $domain)
{
$cmd = "RESET C330 ACCOUNT: USERNAME=$loginname, MSID=$msid, DOMAIN=$domain;";
if ($this->l_debug) echo $cmd;
$this->telnet->DoCommand($cmd, $result);
if ($this->l_debug) echo $result;

$desc_start = strpos($result, "DESC=\"") + 6;
return substr($result, $desc_start, strpos($result, "\";") - $desc_start);
}

public function DeleteUser($loginname, $domain)
{
$cmd = "DEL C330 USER: LOGINNAME=$loginname, DOMAIN=$domain, REMOVEALL=1;";
if ($this->l_debug) echo $cmd;
$this->telnet->DoCommand($cmd, $result);
if ($this->l_debug) echo $result;

$desc_start = strpos($result, "DESC=\"") + 6;
return substr($result, $desc_start, strpos($result, "\";") - $desc_start);
}

public function QueryUser($mac, $domain)
{
$this->telnet->DoCommand("QUERY C330 USER: LOGINNAME=$mac, MSID=$mac, DOMAIN=$domain;", $result);
if ($this->l_debug) echo $result;
}

public function Disconnect()
{
if ($this->telnet == null)
{
$telnet->DoCommand('exit', $result);
if ($this->l_debug) echo $result;
$telnet->DoCommand('exit', $result);
if ($this->l_debug) echo $result;
$this->telnet->Disconnect();
}
}
}
?>
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
magvanshiirev Janchiv,

Sorry but that's not how things work around here. You are expected to DoYourOwnHomework (←that's a link; please click on it and read)
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Locking this thread - duplicate of this one
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!