Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    2

    Default Creating New Remote Database Hosts via PHP

    PHP Code:
    <?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. #2
    cPanel, Inc. Staff
    Join Date
    Apr 2011
    Posts
    34

    Default Re: Creating New Remote Database Hosts via PHP

    Hello,

    Do you mind clarifying what your question is so we can assist you?
    Thank you,

    Jerry Smith
    Technical Analyst I
    cPanel Inc.

Similar Threads & Tags
Similar threads

  1. not able to connect remote MySQL : Remote Database Access Hosts
    By crazyaboutlinux in forum Database Discussions
    Replies: 4
    Last Post: 10-05-2011, 03:55 PM
  2. How do I remove ALL remote database access hosts?
    By devonhosting in forum Database Discussions
    Replies: 0
    Last Post: 01-05-2011, 07:40 PM
  3. Remote Database Access Hosts
    By laxbobber in forum Feature Requests for cPanel/WHM
    Replies: 0
    Last Post: 12-02-2010, 09:11 PM
  4. Problem with Remote Database Access Hosts
    By santrix in forum Database Discussions
    Replies: 3
    Last Post: 05-11-2010, 10:55 PM
  5. Adding Remote Database Access Hosts
    By pvkrajpv in forum Database Discussions
    Replies: 0
    Last Post: 02-01-2010, 11:39 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube