PHP-Nuke and other installers

Discussion in 'Developers' Forum' started by danf.1979, Dec 23, 2005.

  1. danf.1979

    danf.1979 ISPConfig Developer

    I'm developing a PHP-nuke installer in the "Tools" section. I think most installers would be very similar.
    If I have a client that owns more than one web, I need a way to "know" in which site he wants to install php-nuke. From what variable can I get this info?
    Also I need the user and pass to write in the database. How can I get this values? What scripts should I read?
    Thanks
     
  2. danf.1979

    danf.1979 ISPConfig Developer

    What I really need right now is to save the username of the user who executes the tool in $username. How can I accomplish this?
     
  3. till

    till Super Moderator

    I dont that it will work this way, because if you know the username you cannot know in which website phpnuke should be installed. Every user can have an unlimited number of websites in ISPConfig.

    You will have to let the user select in which website phpnuke shall be installed. Have a look at the backup tool, this tool shows a list of all sites the user is allowd to backup and the list to delect the phpnuke destination may be similar. Dont forget that you have also an admin and resellers and they might have to install packages for their clients too, but how to get the available sites for a user / admin / reseller this is all handled in the code for the site backups and you can copy it from there.

    No, dont write your own database functions. ISPCOnfig uses an database wrapper, if you use native mysql functions your extension might be incompatible to future ISPConfig releases. The database wrapper is in the class /home/admispconfig/ispconfig/lib/classes/ispconfig_mysql.lib.php (or similar name in this directory, dont have the sources here currently).

    The database wrapper is already initialized if you have included the two main includes as shown in the other tools. You can call the query function e.g. by: $go_api->db->query("Here comes your SQL");

    I recommend having a look at the other tools, they show you how to use the db wrapper for querys and inserts.
     
    Last edited: Dec 24, 2005
  4. till

    till Super Moderator

    You can get the username from the $go_info array. Just insert print_r($go_info); in your code and you get a list of all variables available in the session.
     
  5. danf.1979

    danf.1979 ISPConfig Developer

    OK, I love you. I'm making progress, and getting more used to the api.
     
  6. danf.1979

    danf.1979 ISPConfig Developer

    I'm having problems creating the folders with the right permissions. The owner and group is admispconfig, I need it to be user:web[id].
    This doesnt seem to work:
    Code:
    exec("chown $username:web1 $php_nuke_path");
    
    Dont know why. From a console it works OK, but from the php script dont. Does this have something to do with a php feature? (i.e. security?)
    How can I get to create the folder with the right permissions? I dont seem able to find the piece of code that generates de /var/www/web[ID] folder when creating a new customer. I think this code could help me. Not sure though.
    I'm creating the phpnuke install folder with:
    Code:
    exec("mkdir $php_nuke_path");
    
    Is this aproach the correct one?
    Maybe thereis another way with the ispconfig api. Dont know for sure. I'm just starting to get used to the api.
     
  7. danf.1979

    danf.1979 ISPConfig Developer

    Ok, progress, but still no gold.
    I'm using now:
    Code:
    chown($php_nuke_path, $username);
    
    But, i get this:
    Code:
    Warning: chown() [function.chown]: Operation not permitted in /home/admispconfig/ispconfig/web/tools/tools/test/install.php on line 66
    
    Command was:
    Code:
    chown user:web1 /var/www/web1/web/bbb
    
    Change "user" with my real user (it exists).
    When I created the web directory "bbb" with mkdir, the owner and group was admispconfig. I dont seem capable o changing that, at least no from a php script.
    May be I could do so with a Python script.
     
    Last edited: Dec 25, 2005
  8. danf.1979

    danf.1979 ISPConfig Developer

    Ok, I had posted something in here, but I'll just wait for help on the last matter because I' learned already about the "->" thingy.
     
    Last edited: Dec 25, 2005
  9. falko

    falko Super Moderator

    This code is in /root/ispconfig/scripts/lib/config.lib.php. This script is run as root so you shouldn't have permission problems if you put your code in there.
     
  10. danf.1979

    danf.1979 ISPConfig Developer

    Ok, so i put my function in /root/ispconfig/scripts/lib/config.lib.php, inside class isp_web right? but then how do I call the function from my tool?
    Thank you.
     
  11. danf.1979

    danf.1979 ISPConfig Developer

    Will I have to "include" it in my tool?
    Code:
    include("/root/ispconfig/scripts/lib/config.lib.php");
    
    Or there is another way in the api to do this?
     
    Last edited: Dec 26, 2005
  12. danf.1979

    danf.1979 ISPConfig Developer

    Ok, OK. I have been progressing a lot in the php-nuke installer.
    Here you have a screenshot:
    [​IMG]
    What the script does till now, is:
    Create directories and copy the all necessary files to run php-nuke in any given web. Admin, a reseller or a client can use it.
    I have a problem though...
    This is how my config.lib.php looks right now:
    Code:
    # php-nuke install function
    function make_install_phpnuke($web_id, $username, $path_to_create) {
           
    	$web_id = intval($web_id);	
    	exec("mkdir $path_to_create");
    	system("cp -R /var/www/installers/php-nuke/html/* $path_to_create");
    	system("chown -R $username:web$web_id $path_to_create");
    }
    
    class isp_web
    {
    
    var $FILE = "/root/ispconfig/scripts/lib/config.lib.php";
    var $directory_mode = "0755";
    var $web_doctype_id = 1013;
    var $user_doctype_id = 1014;
    .
    .
    .
    etc
    
    I have included config.lib.php in /home/admispconfig/.../tools/test2/install.php that process the form (the picture)
    install.php runs fine, but I think that when included in install.php the function make_install_phpnuke() does not run with root priviledges, so the code
    Code:
    	system("chown -R $username:web$web_id $path_to_create");
    
    does not work. Am I right about this?

    Then, I know that when you create an email user that will be the administrator, the directory permissions are changed, and you told me (falko) that only config.lib.php runned with root priviledges, so I guess the code is that changed permissions is in there. I cant find it though.
    Can you help me with this?
    I'm almost there... almost. And good news is that developing new installers will be very similar.
    Thank you.
     
    Last edited: Dec 26, 2005
  13. danf.1979

    danf.1979 ISPConfig Developer

    Uhm, I was looking at write.conf. I think it's structure does what I want. I found a code that teached me I had to put my function inside the class isp_web() and then make a new instance of the class in tools/test2/install.php and then call my function as a method of that class (am I right?).

    Now my make_install_phpnuke() function is inside class isp_web()
    Code:
    class isp_web
    {
    
    var $FILE = "/root/ispconfig/scripts/lib/config.lib.php";
    var $directory_mode = "0755";
    var $web_doctype_id = 1013;
    var $user_doctype_id = 1014;
    var $domain_doctype_id = 1015;
    var $dns_doctype_id = 1016;
    var $a_record_doctype_id = 1018;
    var $cname_record_doctype_id = 1019;
    var $mx_record_doctype_id = 1020;
    var $dienste_doctype_id = 1023;
    var $monitor_doctype_id = 1024;
    var $firewall_doctype_id = 1025;
    var $slave_doctype_id = 1028;
    var $datenbank_doctype_id = 1029;
    var $spf_record_doctype_id = 1031;
    var $vhost_conf;
    var $ftp_conf;
    var $apache_user;
    
    function make_install_phpnuke($web_id, $username, $path_to_create) {
           
    	$web_id = intval($web_id);	
    	print_r(" $web_id ");
    	exec("mkdir $path_to_create");
    	system("cp -R /var/www/installers/php-nuke/html/* $path_to_create");
    	print_r("chown -R $username:web$web_id $path_to_create");
    	system("chown -R $username:web$web_id $path_to_create");
    
    	// chown($path_to_create, $username);
    	// chgrp ($path_to_create, $web_id);
    
    }
    
    //Constructor
    function isp_web() {
      global $mod;
    .
    .
    etc
    
    My install.php has (only important code to my problem is seen)
    Code:
    include_once("/root/ispconfig/scripts/lib/config.lib.php");
    .
    .
    foreach($webs as $web_id => $val) {
    
    	$query = "SELECT * from isp_nodes, sys_user where isp_nodes.doc_id = '$web_id' and isp_nodes.doctype_id = 1013 and sys_user.doc_id = isp_nodes.userid";
            $get_web = $go_api->db->queryOneRecord($query);
    	
    	$username = $get_web["username"];
    	print_r(" $username ");
    
    	$path_to_create = $httpd_root ."/web".$web_id."/web/".$install_path;
    	print_r(" $path_to_create ");
    
    	// NEW, call instance an method of the class (my function)
            $isp_web = new isp_web;
    	$isp_web->make_install_phpnuke($web_id, $username, $path_to_create);
            // END NEW
    
    //	if ($val==1) make_install_phpnuke($web_id, $username, $path_to_create);        
    
    }
    
    But I execute a test a I get this:
    Code:
    Fatal error: Call to a member function find_includes() on a non-object in /root/ispconfig/scripts/lib/config.lib.php on line 1772
    
    This is line 1772 (last one):
    Code:
    function apache_user(){
      global $mod;
      $httpd_conf = $mod->system->server_conf["dist_httpd_conf"];
      $includes = $mod->file->find_includes($httpd_conf);
    .
    .
    etc
    
    Why? How do I fix this? I think this is the solution, but dont know why this error occurs...
    Thanks, and sorry for the several post, but I make progress from post to post, so new problems arise, and some get fixed.
     
    Last edited: Dec 26, 2005
  14. danf.1979

    danf.1979 ISPConfig Developer

    I commented the line
    // $this->apache_user = $this->apache_user();
    in function isp_web() in class isp_web, file config.lib.php, and now it gives me no error, but no permission changes either! :eek:
    Code:
    //Constructor
    function isp_web() {
      global $mod;
    
      $this->vhost_conf = $mod->system->server_conf["server_path_httpd_conf"]."/".'vhosts'."/".'Vhosts_ispconfig.conf';
      if($mod->system->server_conf["server_ftp_typ"] == "proftpd"){
        $this->ftp_conf = "/etc/proftpd_ispconfig.conf";
      } else {
        $this->ftp_conf = "";
      }
      // $this->apache_user = $this->apache_user();
    }
    
     
  15. falko

    falko Super Moderator

    You must not include /root/ispconfig/scripts/lib/config.lib.php in your install.php because then ti will not run with root privileges.

    /root/ispconfig/scripts/lib/config.lib.php is called by /root/ispconfig/writeconf.php which itself is called by the /root/ispconfig/sv/ispconfig_wconf daemon which runs as root. This /root/ispconfig/sv/ispconfig_wconf daemon checks every 10 seconds if a file /home/admispconfig/ispconfig/.run exists; if it does, it calls the writeconf.php script.

    So you have to modify /root/ispconfig/scripts/lib/config.lib.php and/or /root/ispconfig/scripts/writeconf.php, and whenever your install script is called, it should create /home/admispconfig/ispconfig/.run (add
    PHP:
    touch /home/admispconfig/ispconfig/.run;
    to your PHP code) so that writeconf.php is called.
     
  16. danf.1979

    danf.1979 ISPConfig Developer

    uhm, I have a very big doubt. If I cant include config.lib.php, then how can I access my function in the class isp_web?
    Is there some "api" way that I'm not aware of?
    Thank you for your time.
     
  17. danf.1979

    danf.1979 ISPConfig Developer

    Do you mean I have to put my function inside config.lib.php isp_web class and then put de touch .run in that code so the deamon knows it has to run my function inside config.lib.php as root? Ok, this is what I understood from your explanation, but I dont know how to call my function from config.lib.php, since I cannot include it. I can't figure out the method to do it.
    I'm really sorry if I'm being to newbie in this, but my experience is limited (I have only modified phpnuke scripts, but I know google and I dont want to give up). I think I need some guidance on this.
    Thank you all.
     
  18. falko

    falko Super Moderator

    Yes.

    You can call your function from /root/ispconfig/scripts/writeconf.php or from any other function in the config.lib.php that you know of that it gets executed.
     
  19. till

    till Super Moderator

    Maybe some general informations on the structure of ISPConfig will help you to get things clearer. ISPConfig consistsn of 2 parts.

    1) The web interface. All files for the webinterface are in the directories /home/admispconfig/ispconfig/ and above. The scripts in the webinterface run as user admispconfig. his user has limited rights and it is not allowed to change files etc.

    2) The other part are the scripts in /root/ispconfig. These where executed as root user. They where executed when the run file is set "touch /home/admispconfig/ispconfig/.run".
     
  20. danf.1979

    danf.1979 ISPConfig Developer

    Ok! It worked! (but I have a new problem)
    I did put my function on config.lib.php inside isp_web class
    this is the function:
    Code:
    function make_install_phpnuke($web_id, $username, $path_to_create) {
    
    	$web_id = intval($web_id);	
    	exec("mkdir $path_to_create");
    	system("cp -R /var/www/installers/php-nuke/html/* $path_to_create");
    	system("chown -R $username:web$web_id $path_to_create");
    }
    
    writeconf.php has now:
    Code:
    $isp_web = new isp_web;
    
    $web_id = "8";
    $username = "mundohosting";
    $path_to_create = "/var/www/web8/web/phpnuke";
    $isp_web->make_install_phpnuke($web_id, $username, $path_to_create); 
    
    And my install.php has the touch .run file.
    Everything works as espected, BUT, as you have noticed, in writeconf.php I have defined all the functions variables...
    Code:
    $web_id = "8";
    $username = "mundohosting";
    $path_to_create = "/var/www/web8/web/phpnuke";
    
    Because I dont know how to pass those values from install.php to writeconf.php... I cant think in a simple way to do this, but is there any? Maybe I should create a plain text file with the install data and read it from writeconf.php IF there is another touched file? like for example /home/admispconfig/.install
    Is there any other way?
    thank you!!
     

Share This Page