PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: coreno on 20 January, 2007, 23:52:37

Title: register from web
Post by: coreno on 20 January, 2007, 23:52:37
so, i have a PHP script which will update cfg/RegisteredUsers.xml with a new registration. But, it seems that PtoakX only uses that file on startup, or it seems that way anyway. I say this because if someone registers themselves on the hub itself,  it overwrites the file to what it was before I edited it with PHP (and also appends the newly registered user). Can anyone think of some clever ways around this?
Title: Re: register from web
Post by: bastya_elvtars on 21 January, 2007, 02:20:03
coreno: woiuld you like to share that script with the rest of the world by the way? :)
Title: Re: register from web
Post by: coreno on 21 January, 2007, 04:33:28
I was kinda thinking the same thing, save to a file and have a script reg them... but, then there would be a delay... which I guess is no big deal.

And no, I don't know LUA :( So someone would have to help me out and make the script to read the file.

I will also gladly post my PHP scripts. Give me a bit to clean it up, it's a bit messy right now :p
Title: Re: register from web
Post by: coreno on 21 January, 2007, 04:50:41
Wow, a bit beefier of a script than thought it was going to be haha, thanks though :) I think this will be easier for those not so technically savvy... :p
Title: Re: register from web
Post by: 7P-Darkman on 21 January, 2007, 05:35:31
Hello friends...


I was reading here on the possibility to make the register in a HUB, through a page web, and I remembered a test that I made, times behind, with one another type of server for DC++ network. This server to possess a page web of model, that allowed to make the register in the HUB, through the site.

   
It seems that the only difficulty to use this model would be to create one profile in the Ptokax server (called "Web", in this HTML page), whom it has accepted to be able to make the register of users in the HUB.

case that it serves of inspiration for ours scripters, here code HTML of this page goes:

<html>

<head>
<title><%lua return GetHubName() lua%></title>
</head>

<body>

<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" width="837" height="104">
    <tr>
      <td width="193" height="59" bgcolor="#F48520" colspan="2">&nbsp;</td>
      <td width="680" height="59" bgcolor="#E34704" colspan="2"><p align="left"><font size="5" face="Verdana" style="italic" color="#FFFFFF"><b>&nbsp;<em>
        <%lua return "Welcome to "..GetHubName() lua%>
      </em></b></font></p></td>
    </tr>
    <tr>
      <td width="193" height="22" bgcolor="#FAAF6B" colspan="2">&nbsp;</td>
      <td width="680" height="22" bgcolor="#F88A27" colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td width="193" height="18" bgcolor="#F48520" align="center" colspan="2"><em><font color="#FFFFFF"><strong><A href="<%lua return "http://"..GetHubAddress()..":"..GetHubPortHttp().."/" lua%>">&nbsp;HOME&nbsp;</A></strong></font></em></td>
      <td width="680" height="345" colspan="2" rowspan="5" valign="top" bgcolor="#E34704">
        <p align="left"><font size="1" face="Verdana" color="#FFFFFF"><b>
<%lua
  local ok = nil
  local profile = "Web"
  local msg
  local t=GetAllProfiles()
  for i=1,table.getn(t) do
    if t[i]==profile then ok=1 end
  end
  if not ok then
    return "This server does not allow web registration because profile '"..profile.."' is not defined"
  else
    ok = nil
  end
  if POSTMSG then
    ok,_,nickname,password = string.find(POSTMSG,"nickname=(.+)&password=(.+)")
  end
  if ok then
    for i=1,table.getn(t) do
      if t[i]~="Default" then
        local u=GetAllRegisteredUsers(t[i])
        for j=1,table.getn(u) do
          if u[j] == nickname then ok=nil end
        end
      end
    end
    if ok then
      AddRegUser(nickname,password,profile)
      msg = "You are now registered as "..nickname..", go to dchub://"..db_hubconfig["dns"]..":"..db_hubconfig["tcp"].." and have fun"
    else
      msg = "Nick "..nickname.." is already taken, please choose another one<p>"
      msg = msg.."<form action=\"./reg.htm\" method=\"POST\">"
      msg = msg.."Nickname:    <input type=\"text\" name=\"nickname\"><p>"
      msg = msg.."Password:   <input type=\"text\" name=\"password\"><p>"
      msg = msg.."<input type=\"submit\">"
    end
  else
    msg = "Fill all the fields to register<p>"
    msg = msg.."Note to enter the hub you will need :<br>"
    msg = msg.."\160 - Minimum Share : "..GetShareUnit(GetMinShare(profile)).."<br>"
    msg = msg.."\160 - Maximum Share : "..GetShareUnit(GetMaxShare(profile)).."<br>"
    msg = msg.."\160 - Minimum Slots : "..GetMinSlots(profile).."<br>"
    msg = msg.."\160 - Maximum Slots : "..GetMaxSlots(profile).."<br>"
    msg = msg.."\160 - Minimum Slots/Hubs : "..GetSlotHubRatio(profile).."<br>"
    msg = msg.."\160 - Maximum Hubs : "..GetMaxHubs(profile).."<p>"
    msg = msg.."<form action=\"./reg.htm\" method=\"POST\">"
    msg = msg.."Nickname:    <input type=\"text\" name=\"nickname\"><p>"
    msg = msg.."Password:   <input type=\"text\" name=\"password\"><p>"
    msg = msg.."<input type=\"submit\">"
  end
  return msg
lua%>
<p>

</b></font></td>
    </tr>
    <tr>
      <td width="193" height="10" bgcolor="#F48520" align="center" colspan="2"><em><font color="#FFFFFF"><strong><A href="./stats.htm">&nbsp;STATISTICS&nbsp;</strong></font></em></td>
    </tr>
    <tr>
      <td width="193" height="11" bgcolor="#F48520" align="center" colspan="2"><em><font color="#FFFFFF"><strong><A href="./reg.htm">&nbsp;REGISTER&nbsp;</strong></font></em></td>
    </tr>
    <tr>
      <td width="193" height="1" bgcolor="#F48520" align="center" colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td width="193" height="257" bgcolor="#F48520" colspan="2"></td>
    </tr>
  </table>
  </center>
</div>
<p align="center"><font size="1" face="Verdana"><a href="http://www.dcsh.org/">www.dcsh.org</a></font></p>

</body>

</html>



I wait to have collaborated with the subject.

Respectfully,


7P-Darkman
Title: Re: register from web
Post by: coreno on 21 January, 2007, 07:49:53
This is for AutoReg 1.0:

function file_register($nick, $password){
/*****************
Written by coreno (coreno {at} gmail.com)
Jan. 2007
Code may be distributed feely, please leave credits intact
Please note any changes
For use with custom PtoAkX script AutoReg 1.0:
http://forum.ptokax.org/index.php?topic=6750.0

    Does not return anything.Prints out a sucessful write or not.
*****************/
$file = "C:/path/to/file.txt"; //path to addreg.txt, including filename
$type = "3";
if (is_writeable($file)){
        $data = "$nick $password $type";
if(file_put_contents($file,$data,FILE_APPEND)){
echo "<p><b>Account $nick registered.</b>";
}
}
else{
echo "<p>Unable to write to <tt>$file</tt><p>";
}
}



MISC FUNCTIONS:

function register($nick, $password){
    /*****************
Written by coreno (coreno {at} gmail.com)
Jan. 2007
Code may be distributed feely, please leave credits intact
Please note any changes
For use with PtokaX 0.3.4.x
Concept only, PtokaX will overwrite any registrations made with this
with registrations made from the hub

Returns true on sucess or false on fail
*****************/
$dir = "";      //location of PtokaX cfg folder. Include the cfg folder
//and the trailing slash. Must be forward slashes
$userlist = "RegisteredUsers.xml";

    $xml = simplexml_load_file($dir.$userlist);
   
    $RU = $xml->addChild("RegisteredUser");
$RU->addChild('Nick',$nick);
$RU->addChild('Password',$password);
$RU->addChild('Profile','3'); //Change 3 to the default profile ID.
                                    //Default: 0 = Master, 1 = Operator, 2 = VIP, 3 = Reg
if (is_writeable($dir.$userlist)){
    if(file_put_contents($dir.$userlist,$xml->asXML())){
return true;
}
}
else{
return false;
}
}




function search($search){
    /*****************
Written by coreno (coreno {at} gmail.com)
Jan. 2007
Code may be distributed feely, please leave credits intact
Please note any changes
For use with PtokaX 0.3.4.x
Searches current registrations and prints result
Accepts regular expressions

Returns true on success or false on fail
*****************/
$dir = "C:/dc_server/0.3.4.0.dbg/cfg/";
//location of PtokaX cfg folder. Include the cfg folder and the trailing slash. Must be forward slashes
$userlist = "RegisteredUsers.xml";
    $xml = simplexml_load_file($dir.$userlist);
    echo "Searching for \"<tt>$search</tt>\"...";
    $results = array();
    for ($i=0; $i<count($xml->RegisteredUser); $i++){
if(eregi($search,$xml->RegisteredUser[$i]->Nick)){
$results[] = strval($xml->RegisteredUser[$i]->Nick);
  }
}

foreach ($results as $name){
echo "$name<br />";
  }
}
Title: Re: register from web
Post by: nEgativE on 28 February, 2007, 20:08:36
Quote from: coreno on 21 January, 2007, 07:49:53
This is for AutoReg 1.0:

function file_register($nick, $password){
/*****************
Written by coreno (coreno {at} gmail.com)
Jan. 2007
Code may be distributed feely, please leave credits intact
Please note any changes
For use with custom PtoAkX script AutoReg 1.0:
http://forum.ptokax.org/index.php?topic=6750.0

    Does not return anything.Prints out a sucessful write or not.
*****************/
$file = "C:/path/to/file.txt"; //path to addreg.txt, including filename
$type = "3";
if (is_writeable($file)){
        $data = "$nick $password $type";
if(file_put_contents($file,$data,FILE_APPEND)){
echo "<p><b>Account $nick registered.</b>";
}
}
else{
echo "<p>Unable to write to <tt>$file</tt><p>";
}
}



MISC FUNCTIONS:

function register($nick, $password){
    /*****************
Written by coreno (coreno {at} gmail.com)
Jan. 2007
Code may be distributed feely, please leave credits intact
Please note any changes
For use with PtokaX 0.3.4.x
Concept only, PtokaX will overwrite any registrations made with this
with registrations made from the hub

Returns true on sucess or false on fail
*****************/
$dir = "";      //location of PtokaX cfg folder. Include the cfg folder
//and the trailing slash. Must be forward slashes
$userlist = "RegisteredUsers.xml";

    $xml = simplexml_load_file($dir.$userlist);
   
    $RU = $xml->addChild("RegisteredUser");
$RU->addChild('Nick',$nick);
$RU->addChild('Password',$password);
$RU->addChild('Profile','3'); //Change 3 to the default profile ID.
                                    //Default: 0 = Master, 1 = Operator, 2 = VIP, 3 = Reg
if (is_writeable($dir.$userlist)){
    if(file_put_contents($dir.$userlist,$xml->asXML())){
return true;
}
}
else{
return false;
}
}




function search($search){
    /*****************
Written by coreno (coreno {at} gmail.com)
Jan. 2007
Code may be distributed feely, please leave credits intact
Please note any changes
For use with PtokaX 0.3.4.x
Searches current registrations and prints result
Accepts regular expressions

Returns true on success or false on fail
*****************/
$dir = "C:/dc_server/0.3.4.0.dbg/cfg/";
//location of PtokaX cfg folder. Include the cfg folder and the trailing slash. Must be forward slashes
$userlist = "RegisteredUsers.xml";
    $xml = simplexml_load_file($dir.$userlist);
    echo "Searching for \"<tt>$search</tt>\"...";
    $results = array();
    for ($i=0; $i<count($xml->RegisteredUser); $i++){
if(eregi($search,$xml->RegisteredUser[$i]->Nick)){
$results[] = strval($xml->RegisteredUser[$i]->Nick);
  }
}

foreach ($results as $name){
echo "$name<br />";
  }
}


Sorry, but how do we use this code ?
Title: Re: register from web
Post by: plop on 02 March, 2007, 01:07:33
doesn't php have sockets?

plop
Title: Re: register from web
Post by: bastya_elvtars on 02 March, 2007, 01:45:16
It does, but it's optional, and in some cases it is compiled without socket support.
Title: Re: register from web
Post by: nEgativE on 13 March, 2007, 01:56:51
Quote from: Mutor on 01 March, 2007, 00:30:15
It is run in a php enabled web sever.
The reg data [$file] should be saved to a
folder accessible by PtokaX.

Use the AutoReg lua script to register
users from that reg data file. We have other
scripts to do this, but all require php or
similar, which the Px inbuilt web server does
not support.

Hi Mutor.. maybe i'm doing something wrong here.. but the php code on the "my php webserver" doesn't return nothing for registering.. could u help me here ? thx.