ionCube Logo
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


 
Post new topic   Reply to topic    ionCube Forum Index -> ionCube PHP Encoder

accessing ioncube library functions

Author Message
buggedcom



Joined: 12 Feb 2005
Posts: 14

PostPosted: Tue Apr 26, 2005 7:37 pm    Post subject: accessing ioncube library functions Reply with quote

I'm not sure if this belongs in this forum or the loader forum so please feel free to move the topic.

I am trying to create a custom licensing class using php, however I am at a loss as how to get the ip address / mac address / server vars to lock the license to. the current settings are based on the $_SERVER var but this is wholly unreliable.

I was wondering if the loader libs have any functions that could be used to aid me in this process. I'm sure there must be as I'm presumming they are used to lock the encoded files.

are you able to help me out here or do you know of any exec commands that could be used cross platform to lock down a license script?
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2788

PostPosted: Wed Apr 27, 2005 10:56 am    Post subject: Reply with quote

Hi

There aren't any functions exposed at the moment that let you obtain MAC address, but you could lock your license files to MAC address with Cerberus. Running external programs with exec to obtain the MAC address would be a bad idea as it wouldn't work on all machines, even of the same type due to PHP config issues, and particularly as it would be easy to work around.
_________________
Community Admin
Back to top
View user's profile Send private message
buggedcom



Joined: 12 Feb 2005
Posts: 14

PostPosted: Wed Apr 27, 2005 11:01 am    Post subject: Reply with quote

Ok thanks, however I'm not just loooking for MAC addresses but also ip's and domains of the server. as for Cerberus, are you able to upgrade packages because i have pro at the moment?
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2788

PostPosted: Wed Apr 27, 2005 11:17 am    Post subject: Reply with quote

Certainly. There are upgrade items on the purchase products page in the members area.

You said that $_SERVER in PHP is unreliable. What do you mean by that?
_________________
Community Admin
Back to top
View user's profile Send private message
buggedcom



Joined: 12 Feb 2005
Posts: 14

PostPosted: Wed Apr 27, 2005 12:48 pm    Post subject: Reply with quote

not all servers use all of the $_SERVER vars. as stated in the PHP.net docs. to quote...

http://uk2.php.net/manual/en/reserved.variables.php#reserved.variables.server

Quote:
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the webserver. There is no guarantee that every webserver will provide any of these; servers may omit some, or provide others not listed here.


so reliying on these for a foolproof license system is not really very effective. although it does say

Quote:
That said, a large number of these variables are accounted for in the CGI 1.1 specification, so you should be able to expect those.


but again not all instances of php run through cgi. my current solution for a license system runs via the $_SERVER and checks for at least 3 parameters to match in the license.dat file which is created. for example the function that my license class, http://forums.devshed.com/t247889/s.html uses is...

Code:
function getURIS()
        {
            # get the server specific uris
            $a = array();
            if(isset($_SERVER['SERVER_ADDR']) && ($_SERVER['SERVER_ADDR']!='127.0.0.1' || $this->ALLOW_LOCAL))
            {
                $a['SERVER_ADDR'] = $_SERVER['SERVER_ADDR'];
            }
            if(isset($_SERVER['HTTP_HOST']) && ($_SERVER['HTTP_HOST']!='127.0.0.1' || $this->ALLOW_LOCAL))
            {
                $a['HTTP_HOST'] =  $_SERVER['HTTP_HOST'];
            }
            if(isset($_SERVER['PATH_TRANSLATED']))
            {
                $a['PATH_TRANSLATED'] =  substr($_SERVER['PATH_TRANSLATED'], 0, strrpos($_SERVER['PATH_TRANSLATED'], '/'));
            }
            else if(isset($_SERVER['SCRIPT_FILENAME']))
            {
                $a['SCRIPT_FILENAME'] =  substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/'));
            }
            if(isset($_SERVER['SCRIPT_URI']))
            {
                $a['SCRIPT_URI'] =  substr($_SERVER['SCRIPT_URI'], 0, strrpos($_SERVER['SCRIPT_URI'], '/'));
            }
            # if the number of different uris is less than the required amount,
            # fail the request
            return (count($a) < $this->REQUIRED_URIS) ? false : $a;
        }


so if the number of required uris do not exist then the license fails to be generated. and again the above methods are not fool proof either. so you see my predicament. I need to search for exec methods of getting the document root in order to guarentee that i can get the best out of my script.
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2788

PostPosted: Wed Apr 27, 2005 1:59 pm    Post subject: Reply with quote

Ok, this is what I thought that you meant, but wanted to check.

You are correct, different servers report information in different places. Some don't report as much as others. To provide a thorough solution, you need knowledge of the differences. This is the type of logic that from experience, is built into the Loader, and partly where there is value of using the Loader for checking information as opposed to developing it oneself.

It's a shame that there are not totally fixed standards for such information.
_________________
Community Admin
Back to top
View user's profile Send private message
buggedcom



Joined: 12 Feb 2005
Posts: 14

PostPosted: Wed Apr 27, 2005 2:01 pm    Post subject: Reply with quote

indeed it is. hopefully i'll be able to findsome on some forum somewhere who knows how to do it.
Back to top
View user's profile Send private message
buggedcom



Joined: 12 Feb 2005
Posts: 14

PostPosted: Sat Apr 30, 2005 8:14 pm    Post subject: Reply with quote

The below code was inspired by a phpaudit code. it has been tested with several variations of win, mac os x and linux, however i can't guarentee it will work all the time.

This function is taken from my opensource licensing class based in php. I will start a new thread and let people know about it when it is finished.

Code:

      /**
      * get_mac_address
      *
      * Used to get the MAC address of the host server. It works with linux
      * and darwin (mac os x).
      *
      * @access private
        * @return string MAC address if found
        * @return string ERROR_OPEN means config can't be found and thus not opened
        * @return string MAC_404 means mac adress doesn't exist in the config file
        * @return string SAFE_MODE means server is in safe mode so config can't be read
      **/
      function get_mac_address()
      {
         if(ini_get('safe_mode'))
         {
            # returns invalid because server is in safe mode thus not allowing
            # sbin reads but will still allow it to open. a bit weird that one.
            return 'SAFE_MODE';
         }
         
         # if anyone has any clues for windows environments
         # or other server types let me know
         $os = strtolower(PHP_OS);
         if(substr($os, 0, 3)=='win')
         {
            # this windows version works on xp running apache
            # based server. it has not been tested with anything
            # else, however it should work with NT, and 2000 also
            
            # execute the ipconfig
            exec('ipconfig/all', $lines);
            # seperate the lines
            foreach ($lines as $key=>$line)
            {
               # check for the mac signature in the line
               if(strpos(strtolower($line), 'physical address'))
               {
                  $trimmed_line = trim($line);
                  # take of the mac addres and return
                  return trim(substr($trimmed_line, strrpos($trimmed_line, " ")+1));
               }
            }
         }
         else
         {
            # switch between the os's
            switch($os)
            {
               # not sure if the string is correct for FreeBSD
               # not tested
               case 'freebsd' :
               # not sure if the string is correct for NetBSD
               # not tested
               case 'netbsd' :
               # not sure if the string is correct for Solaris
               # not tested
               case 'solaris' :
               # not sure if the string is correct for SunOS
               # not tested
               case 'sunos' :
               # darwin is mac os x
               # tested only on the client os
               case 'darwin' :
                  $os_var = 'ether';
                  $os_file = '/sbin/ifconfig';
                  break;
               # linux variation
               # tested on server
               case 'linux' :
                  $os_var = 'HWaddr';
                  $os_file = '/sbin/ifconfig';
                  break;
               default :
                  break;
            }
            
            # open the ipconfig
            $fp = @popen($os_file, "rb");
            if (!$fp)
            {
               # returns invalid, cannot open ifconfig
               return 'ERROR_OPEN';
            }
            
            # read the config
            $conf = @fread($fp, 4096);
            @pclose($fp);
            
            # get the pos of the os_var to look for
            $pos = strpos($conf, $os_var);
            if($pos)
            {
               # seperate out the mac address
               $str1 = trim(substr($conf, ($pos+strlen($os_var))));
               return trim(substr($str1, 0, strpos($str1, "\n")));
            }
         }
         
         return 'MAC_404'; # failed to find the mac address
      }
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2788

PostPosted: Sun May 01, 2005 12:10 am    Post subject: Reply with quote

Thanks for posting this. This will work on some versions of Linux, however do be aware that it is easily spoofed by a man in the middle attack. As an ifconfig parser though, it looks reasonable, and could be a useful starting point for others taking that route.
_________________
Community Admin
Back to top
View user's profile Send private message
buggedcom



Joined: 12 Feb 2005
Posts: 14

PostPosted: Wed May 11, 2005 6:51 pm    Post subject: Reply with quote

updated for win and re-wrote so not to use phpaudits code.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ionCube Forum Index -> ionCube PHP Encoder All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum