The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating New Remote Database Hosts via PHP

Discussion in 'Database Discussions' started by kloring, Aug 19, 2011.

  1. kloring

    kloring Registered

    Joined:
    Aug 19, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    PHP:
    <?php
    // Example: addHost.php?host=192.168.1.1
    // Author: Kevin Loring June 2011

    $cpuser 'cpanel_username';
    $cppass 'cpanel_password';
    $cpdomain 'cpanel_domain';
    $skin 'x3';

    function 
    getVar($name$def '') {
      if (isset(
    $_REQUEST[$name]))
        return 
    $_REQUEST[$name];
      else
        return 
    $def;
    }

    // check if overrides passed
    $ehost getVar('host''');
    $mode getVar('mode','');
    $msg '';
    if (
    $mode == "add") {
    if (!empty(
    $ehost))
    while(
    true) {
      
    $f fopen ("http://".$cpuser.":".$cppass."@".$cpdomain.":2082/frontend/x3/sql/addhost.html?host=$ehost""r");
      if (!
    $f) {
        
    $msg 'Cannot create HOST.';
        break;
      }

      
    $msg "<h2>HOST ".$ehost." created.</h2>";

      
    // Check result
      
    while (!feof ($f)) {
        
    $line fgets ($f1024);
        if (
    preg_match('~^already exsists/?$~'$line$out)) {
          
    $msg "<h2>HOST ALREADY EXSISTS!.</h2>";
          break;
        }
      }
      
    fclose($f);

      break;
    }
    }
    if (
    $mode == "delete") {
    if (!empty(
    $ehost))
    while(
    true) {
      
    $f fopen ("http://".$cpuser.":".$cppass."@".$cpdomain.":2082/frontend/".$skin."/sql/delhost.html?host=$ehost""r");
      if (!
    $f) {
        
    $msg 'Cannot delete HOST.';
        break;
      }

      
    $msg "<h2>HOST ".$ehost." deleted.</h2>";

      
    fclose($f);

      break;
    }
    }
    ?>
    <html>
    <head><title>PHP cPanel Host Manager</title></head>
    <body>
    <?php echo '<div style="color:red">'.$msg.'</div>'?>
    <h1>Manage cPanel Remote Database Hosts</h1>
    <form name="frmEmail" method="post">
    <table width="400" border="0">
    <tr><td>New Host:</td><td><input name="host" size="20" value="<?php echo htmlentities($ehost); ?>" /> <select name='mode'><option value='add'>Add Host</option><option value='delete'>Remove Host</option></select></td></tr>
    <tr><td colspan="2" align="center"><hr /><input type="submit" name="E1" value="Create HOST" /></td></tr>
    </table>
    </form>
    </body>
    </html>
     
  2. JerrySmith

    JerrySmith Active Member

    Joined:
    Apr 21, 2011
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    Hello,

    Do you mind clarifying what your question is so we can assist you?
     
Loading...

Share This Page