Reply
Modify/make WHM account creater..
Old 04-24-2008, 01:03 PM Modify/make WHM account creater..
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
Okay so i am trying to do my self a order system and i have a budget of £0 been playing with PHPcoin but its not really what i want. and i would much prefer to build one myself so it can be bare bones.

I have the accounting file from cPanel so thats not a issue.

I want to have a script where i can post the new username, password, domain, package, email to and it will create the account.


The rest i can do.

below is a plugin for phpcoin which does the whm stuff, but i have never done it before and looks a bit confusing >< can someone help me decfer it please

PHP Code:
<?php
/****************************************************************
* File: WHM Module Admin Functions File
* Based On Code By: Jeremi Bergman (http://www.mividdesigns.com)
* Version: 1.4.3
* Author: Keith Holler (http://www.azcappy.com)
* License: DO NOT Remove this text block. See /docs/license.txt
*          Copyright © 2003-2008 phpCOIN.com
* Schema: See sql file for schema reference
* Notes:
* - Translation File: lang_whm.php
*
* Visit http://bugs.azcappy.com or send email to bugs@azcappy.com
* to report bugs or request features.
****************************************************************/
# Code to handle file being loaded by URL
IF (eregi("whm_admin.php"$_SERVER["PHP_SELF"]))
{
 require_once (
'../../coin_includes/session_set.php');
 require_once(
PKG_PATH_INCL.'redirect.php');
 
html_header_location('error.php?err=01&url=mod.php?mod=whm');
 exit;
}
# Include language file (must be after parameter load to use them)
 
require_once($_CCFG['_PKG_PATH_LANG'].'lang_whm.php');
 IF (
file_exists($_CCFG['_PKG_PATH_LANG'].'lang_whm_override.php')) {
  require_once(
$_CCFG['_PKG_PATH_LANG'].'lang_whm_override.php');
 }
/**************************************************************
*  WHM Remote Access Key
**************************************************************/
function do_get_remote_access_key(){
 
# Cannot be tabbed over
 
$rak 'WHM HASH CODE';
 return 
$rak;
}
/**************************************************************
* Module Admin Functions
**************************************************************/
function do_whm_create_acct ($adata$aret_flag=0$from_api=0)
{
 
# Assumes:  Nothing
 # Passed In:  $adata['username']  - username to add to WHM
 # Passed In:  $adata['password']  - password for username to add to WHM
 # Passed In:  $adata['domain']   - domian to add to WHM
 # Passed In:  $adata['plan']   - plan for domain to add to WHM
 # Passed In:  $adata['dom_id']   - phpCOIN Domain Id
 # Dim some Vars
 
global $_CCFG$_TCFG$_DBCFG$db_coin$_UVAR$_LANG$_SERVER$_nl$_sp;
 
$success 0;  // assume we are unsuccessful until changed
 
$rak do_get_remote_access_key();
 include_once (
$_CCFG['WHM_ACCOUNT_FILE']);
 IF (
$adata['username']!="" && $adata['password']!=""){
  
$whmresult createacct($_CCFG['DOM_DEFAULT_IP'],$_CCFG['WHM_USER'],$rak,0,$adata['domain'],$adata['username'],$adata['password'],$adata['plan']);
  IF (
$_CCFG['WHM_DEBUG_ON']) { print_r($whmresult); }
 } ELSE {
  
$_out '<center>' $_LANG['_WHM']['No_U_P'] . '</center>';
 }
 
# check result and set success string accordingly
 
IF (strstr($whmresult,'New Account Info')) { 
  
$success 1;
 } ELSE { 
  
$success=0;
 }
 IF (
$success) {
  
$_out .= '<center>'.$_LANG['_WHM']['Create_Success'].'</center>';
 } ELSEIF(
strstr($whmresult,'domain is already setup')) {
  
$_out .= '<center>'.$_LANG['_WHM']['Create_Domain_Err'].'</center>';
 } ELSEIF(
strstr($whmresult,'username is taken')) {
  
$_out .= '<center>'.$_LANG['_WHM']['Create_User_Err'].'</center>';
 } ELSEIF(
strstr($whmresult,'choose a plan')) {
  
$_out .= '<center>'.$_LANG['_WHM']['Create_Plan_Err'].'</center>';
 } ELSE {
  
$_out .= '<center>'.$_LANG['_WHM']['Create_Failure'].'</center>';
 }
 IF (
$adata['send_acc_email'] == "on" && $success) {
  include_once ( 
$_CCFG['_PKG_PATH_LANG'].'lang_domains.php');
  
do_mail_domain($adata,1);
  
$_out .= '<center>'.$_LANG['_WHM']['acc_email_sent'].'</center>';
 }
 
# Change output if from API
 
IF ($from_api) { $_out $success; }
 
# Either return output or echo here
 
IF ( $aret_flag ) { return $_out; } ELSE { echo $_out; }
}
function 
do_add_domain_from_api($adata)
{
 global 
$_CCFG$_LANG$_DBCFG$db_coin;
 
$query ""$result ""$row ""$_ret 0;
 
# Set Query for select.
 
$query .= "SELECT dom_user_name_cp,dom_user_pword_cp,dom_id";
 
$query .= " FROM ".$_DBCFG['domains'];
 
$query .= " WHERE dom_domain = '".$adata['ord_domain']."'";
 
# Do select
 
$result  $db_coin->db_query_execute($query);
 
$numrows $db_coin->db_query_numrows($result);
 
$row  $db_coin->db_fetch_array($result);
 
# Check for plan setup
 
IF (get_package_name($adata['ord_prod_id'])==null && ($_CCFG['WHM_DEBUG_ON'])) {
  echo 
'<center><b>Plan does not exist.  Please check package matching <a href="mod.php?mod=whm&mode=match_prods">here</a></b></center>';
 } ELSE {
  
# Set data
  
$data['username'] = $row['dom_user_name_cp'];
  
$data['password'] = $row['dom_user_pword_cp'];
  
$data['domain'] = $adata['ord_domain'];
  
$data['plan'] = get_package_name($adata['ord_prod_id']);
  
$data['dom_id'] = $row['dom_id'];
  
$data['send_acc_email'] = ($_CCFG['WHM_SEND_ACC_ON_AUTO'] ? "on" "off");
  
# Add
  
$_ret do_whm_create_acct($data,1,1);
 }
 return 
$_ret;
}
function 
do_whm_delete_acct ($adata$aret_flag=0)
{
 
# Assumes:  Nothing
 # Passed In:  $adata['cp_username'] - User to delete from WHM
 #                or
 #             $adata['dom_user_name_cp'] - User to delete from WHM
 # Dim some Vars
 
global $_CCFG$_LANG$_DBCFG$db_coin;
 
$rak do_get_remote_access_key();
 if (empty(
$adata['dom_user_name_cp'])) { # check for empty domain username
  
$adata['dom_user_name_cp'] = $adata['cp_username'];
  include_once (
$_CCFG['WHM_ACCOUNT_FILE']);
  
$result killacct($_CCFG['DOM_DEFAULT_IP'],$_CCFG['WHM_USER'],$rak,0,$adata['dom_user_name_cp']);
  IF (
$_CCFG['WHM_DEBUG_ON']) { $_out .= $result; }
  IF (
strstr($result,'Done')) {
   
$_out .= '<center>'.$_LANG['_WHM']['Delete_Success'].'<center>';
  } ELSEIF (
strstr($result,'unix user does not exist')) {
   
$_out .= '<center>'.$_LANG['_WHM']['Delete_User_Err'].'<center>';
  } ELSE {
   
$_out .= '<center>'.$_LANG['_WHM']['Delete_Failure'].'<center>';
  }
  IF ( 
$aret_flag ) {
   return 
$_out;
  } ELSE {
   echo 
$_out;
  }
 }
}
function 
do_whm_suspend_acct ($adata$aret_flag=0)
{
 
# Dim some Vars
 
global $_CCFG$_LANG$_DBCFG$db_coin;
 
$rak do_get_remote_access_key();
 include_once (
$_CCFG['WHM_ACCOUNT_FILE']);
 
$result suspend($_CCFG['DOM_DEFAULT_IP'],$_CCFG['WHM_USER'],$rak,0,$adata['cp_username']);
 IF (
$_CCFG['WHM_DEBUG_ON']) { $_out .= $result; }
 IF (
strstr($result,'account has been suspended')) {
  
$_out .= '<center>'.$_LANG['_WHM']['Account_Suspended'].'</center>';
 } ELSEIF (
strstr($result,'Account Already Suspended')) {
  
$_out .= '<center>'.$_LANG['_WHM']['Suspend_Fail_Already'].'</center>';
 } ELSE {
  
$_out .= '<center>'.$_LANG['_WHM']['Suspend_Fail'].'</center>';
 }
 IF ( 
$aret_flag ) { return $_out; } ELSE { echo $_out; }
}
function 
do_whm_unsuspend_acct ($adata$aret_flag=0)
{
 
# Dim some Vars
 
global $_CCFG$_LANG$_DBCFG$db_coin;
 
$rak do_get_remote_access_key();
 include_once (
$_CCFG['WHM_ACCOUNT_FILE']);
 
$result unsuspend($_CCFG['DOM_DEFAULT_IP'],$_CCFG['WHM_USER'],$rak,0,$adata['cp_username']);
 IF (
$_CCFG['WHM_DEBUG_ON']) { $_out .= $result; }
 IF (
strstr($result,'account is now active')) {
  
$_out .= '<center>'.$_LANG['_WHM']['Account_Unsuspended'].'</center>';
 } ELSE {
  
$_out .= '<center>'.$_LANG['_WHM']['UnSuspend_Fail'].'</center>';
 }
 IF ( 
$aret_flag ) { return $_out; } ELSE { echo $_out; }
}
function 
do_list_domain_table($adata$aret_flag=0)
{
 
# Get security vars
 
$_SEC get_security_flags ();
 
$_PERMS do_decode_perms_admin($_SEC[_sadmin_perms]);
 
# Dim some Vars:
 
global $_CCFG$_TCFG$_DBCFG$db_coin$_UVAR$_LANG$_SERVER$_nl$_sp;
 
$query ""$result""$numrows 0;
 
# Get WHM Version
 
include_once ($_CCFG['WHM_ACCOUNT_FILE']);
 
$rak do_get_remote_access_key();
 
$ver showversion($_CCFG['DOM_DEFAULT_IP'],$_CCFG['WHM_USER'],$rak,0);
 
# Set Query for select for current server information
 
$getserverinfo "SELECT *";
 
$getserverinfo .= " FROM ".$_DBCFG['server_info'];
 
$getserverinfo .= " WHERE si_ip = '".$_CCFG['DOM_DEFAULT_IP']."'";
 
$serverresult  $db_coin->db_query_execute($getserverinfo);
 
$servernumrows $db_coin->db_query_numrows($serverresult);
 
$serverinfo  $db_coin->db_fetch_array($serverresult);
 
 
# Set Query for select.
 
$query .= "SELECT *";
 
$query .= " FROM ".$_DBCFG['domains'];
 
$tmpStatus explode(" ",$_CCFG['WHM_DOMAIN_STATUS']);
 
$tmpStatusCount count($tmpStatus);
 if (
$tmpStatusCount 0) {
  
$query .= " WHERE ";
  
$i 1;
  foreach(
$tmpStatus as $k => $v) {
   
# Pull only the domains that match the domain status parameter field and the current server ID
   
$query .= "dom_status = '$v' && dom_si_id = '".$serverinfo['si_id']."'";
   if (
$i $tmpStatusCount) { $query .= "OR "; }
   
$i++;
  }
 }
 
$query .= " ORDER BY dom_id";
 
# Build Page menu
 # Get count of rows total for pages menu:
 
$query_ttl "SELECT COUNT(*)";
 
$query_ttl .= " FROM ".$_DBCFG['domains'];
 
$query_ttl .= $_where;
 
$result_ttl$db_coin->db_query_execute($query_ttl);
 while(list(
$cnt) = $db_coin->db_fetch_row($result_ttl)) { $numrows_ttl $cnt; }
 
# Page Loading first rec number
 # $_rec_next - is page loading first record number
 # $_rec_start - is a given page start record (which will be rec_next)
 
$_rec_page $_CCFG['WHM_NUM_PAGES'];
 
$_rec_next $adata['rec_next'];
 IF (!
$_rec_next) { $_rec_next=0; }
 
# Range of records on current page
 
$_rec_next_lo $_rec_next+1;
 
$_rec_next_hi $_rec_next+$_rec_page;
 IF ( 
$_rec_next_hi $numrows_ttl) { $_rec_next_hi $numrows_ttl; }
 
# Calc no pages,
 
$_num_pages round(($numrows_ttl/$_rec_page), 0);
 IF ( 
$_num_pages < ($numrows_ttl/$_rec_page) ) { $_num_pages $_num_pages+1; }
 
# Loop Array and Print Out Page Menu HTML
 
$_page_menu $_LANG['_WHM']['l_Pages'].$_sp;
 for (
$i 1$i <= $_num_pages$i++)
 {
  
$_rec_start = ( ($i*$_rec_page)-$_rec_page);
  IF ( 
$_rec_start == $_rec_next ){
   
# Loading Page start record so no link for this page.
   
$_page_menu .= "$i";
  } ELSE {
   
$_page_menu .= '<a href="'.$_SERVER["PHP_SELF"].'?mod=whm'.$_link_xtra.'&rec_next='.$_rec_start.'">'.$i.'</a>';
  }
  IF ( 
$i $_num_pages ) { $_page_menu .= ','.$_sp; }
 }
 
# End page menu
 # Finish out query with record limits and do data select for display and return check
 
$query  .= $_where." LIMIT $_rec_next, $_rec_page";
 
$result  $db_coin->db_query_execute($query);
 
$numrows $db_coin->db_query_numrows($result);
 
# Generate Links For Sorting
 
$_hdr_link_prefix '<a href="'.$_SERVER["PHP_SELF"].'?mod=domains&sb=';
 
$_hdr_link_suffix '&fb='.$adata['fb'].'&fs='.$adata['fs'].'&fc='.$adata['fc'].'&rec_next='.$_rec_next.'">';
 
# Build Accounts List From WHM
 
$accts do_build_acct_ary();
 
# Build Javascript To confirm Deletion
 
$_out .= '<script language="JavaScript">'.$_nl;
 
$_out .= ' function ok2delete() {'.$_nl;
 
$_out .= ' var txt = "'.$_LANG['_WHM']['DEL_CONFIRM'].'";'.$_nl;
 
$_out .= ' return confirm(txt); }'.$_nl;
 
$_out .= '</script>'.$_nl;
 
# Build Output
 
$_out .= '<div align="center">'.$_nl;
 
$_out .= '<table align="center" style="border: 1px dashed black" bgcolor="#eeeeee"><tr><td class="TP3SML_NC">'.$_nl;
 
$_out .= '<b>Quick Tip:</b> Click on the Id # to edit the details of the server or the domain within phpCOIN.'.$_nl;
 
$_out .= '</td></tr></table><br>'.$_nl;
 
# Display Title & Server Information Table
 
$_out .= '<table width="95%" border="0" cellpadding="0" cellspacing="1">'.$_nl;
 
$_out .= '<tr><td class="TP3SML_NR">'.$_nl;
 
$_out .= '<a href="http://bugs.azcappy.com" target="_blank">Bug/Dev Tracking System</a> | '.$_nl;
 
$_out .= '<a href="http://docs.phpcoin.com/index.php/WHM_Plug-In" target="_blank">Documentation</a>'.$_nl;
 
$_out .= '</td></tr></table>'.$_nl;
 
$_out .= '<table width="95%" border="0" bordercolor="'.$_TCFG['_TAG_TABLE_BRDR_COLOR'].'" bgcolor="'.$_TCFG['_TAG_TRTD_BKGRND_COLOR'].'" cellpadding="0" cellspacing="1">'.$_nl;
 
$_out .= '<tr class="BLK_DEF_TITLE"><td class="TP3MED_NC" colspan="7">'.$_nl;
 
$_out .= '<table width="100%" cellpadding="0" cellspacing="0">'.$_nl;
 
$_out .= '<tr class="BLK_IT_TITLE_TXT">'.$_nl.'<td class="TP0MED_NL">'.$_nl;
 
$_out .= '<b>Server Information</b><br>'.$_nl;
 
$_out .= '</td><td class="TP0MED_NR">'.$_nl;
 
$_out .= '</td></tr></table></td></tr>'.$_nl;
 
$_out .= '<tr class="BLK_DEF_ENTRY">'.$_nl;
 
$_out .= '<td nowrap width="5%" class="TP3SML_NC" valign="top"><b>Id</b></td>'.$_nl;
 
$_out .= '<td nowrap width="28%" class="TP3SML_NL" valign="top"><b>Server Name</b></td>'.$_nl;
 
$_out .= '<td nowrap width="17%" class="TP3SML_NC" valign="top"><b>IP Address</b></td>'.$_nl;
 
$_out .= '<td nowrap width="13%" class="TP3SML_NC" valign="top"><b>WHM Version</b></td>'.$_nl;
 
$_out .= '<td nowrap width="35%" class="TP3SML_NL" valign="top"><b>Actions</b></td></tr>'.$_nl;
 
$_out .= '<tr class="BLK_DEF_ENTRY">'.$_nl;
 
$_out .= '<td nowrap class="TP3SML_NC"><a href="admin.php?cp=server_info&op=edit&si_id='.$serverinfo['si_id'].'">'.$serverinfo['si_id'].'</a></td>'.$_nl;
 
$_out .= '<td nowrap class="TP3SML_NL">'.$serverinfo['si_name'].'</td>'.$_nl;
 
$_out .= '<td nowrap class="TP3SML_NC">'.$_CCFG['DOM_DEFAULT_IP'].'</td>'.$_nl;
 
$_out .= '<td nowrap class="TP3SML_NC">'.$ver.'</td>'.$_nl;
 
$_out .= '<td nowrap class="TP3SML_NL">'.$_nl;
 
$_out .= '<a href="http://'.$_CCFG['DOM_DEFAULT_IP'].'/whm" target="_blank">Login</a>'.$_sp.$_nl;
 
$_out .= '</td></tr></table><br>'.$_nl;
 
# Display phpCOIN Domains Compared To WHM Table
 
$_out .= '<table width="95%" border="0" bordercolor="'.$_TCFG['_TAG_TABLE_BRDR_COLOR'].'" bgcolor="'.$_TCFG['_TAG_TRTD_BKGRND_COLOR'].'" cellpadding="0" cellspacing="1">'.$_nl;
 
$_out .= '<tr class="BLK_DEF_TITLE"><td class="TP3MED_NC" colspan="7">'.$_nl;
 
$_out .= '<table width="100%" cellpadding="0" cellspacing="0">'.$_nl;
 
$_out .= '<tr class="BLK_IT_TITLE_TXT">'.$_nl.'<td class="TP0MED_NL">'.$_nl;
 
$_out .= '<b>'.$_LANG['_WHM']['TITLE'].$_sp.'</b><br>'.$_nl;
 
$_out .= '</td>'.$_nl.'<td class="TP0MED_NR">'.$_nl;
 
$_out .= '</td>'.$_nl.'</tr>'.$_nl.'</table>'.$_nl;
 
$_out .= '</td></tr>'.$_nl;
 
$_out .= '<tr class="BLK_DEF_ENTRY">'.$_nl;
 
$_out .= '<td class="TP3SML_NC" valign="top"><b>'.$_LANG['_WHM']['l_ID'].'</b></td>'.$_nl;
 
$_out .= '<td class="TP3SML_NC" valign="top"><b>'.$_LANG['_WHM']['l_In_WHM'].'</b></td>'.$_nl;
 
$_out .= '<td class="TP3SML_NL" valign="top"><b>'.$_LANG['_WHM']['l_Domain'].'</b></td>'.$_nl;
 
$_out .= '<td class="TP3SML_NL" valign="top"><b>'.$_LANG['_WHM']['l_UserName'].'</b></td>'.$_nl;
 
$_out .= '<td class="TP3SML_NL" valign="top"><b>'.$_LANG['_WHM']['l_Actions'].'</b></td></tr>'.$_nl;
 
# Process Query Results
 
IF ( $numrows ) {
  while (
$row $db_coin->db_fetch_array($result))
  {
   
$exists do_acct_exists_in_whm($accts$row['dom_domain']);
   
$suspended $accts[$row['dom_user_name_cp']][3];
   IF (
$exists) { $accts do_del_from_array($accts$row['dom_domain']); } // deletes from tmp array
   
$_out .= '<tr class="BLK_DEF_ENTRY">'.$_nl;
   
$_out .= '<td class="TP3SML_NC"><a href="mod.php?mod=domains&mode=edit&dom_id='.$row['dom_id'].'">'.$row['dom_id'].'</a></td>'.$_nl;
   
$_out .= '<td class="TP3SML_NC">';
   IF (
$exists) {
    
$_out .= "<img src=coin_modules/whm/images/checkmark.gif>";
    
$_out .= '</td>'.$_nl;
   }
   IF (
$suspended==1){
    
$_out .= '<td class="TP3SML_NL"><font color=red><b>'.$row['dom_domain'].'</b></font></td>'.$_nl;
   } ELSE {
    
$_out .= '<td class="TP3SML_NL">'.$row['dom_domain'].'</td>'.$_nl;
   }
   
$_out .= '<td class="TP3SML_NL">'.$row['dom_user_name_cp'].'</td>'.$_nl;
   
$_out .= '<td class="TP3SML_NL">'.$_nl;
   
$_out .= do_create_nav_links($row['dom_id'],$exists,$suspended);
   
$_out .= '</td></tr>'.$_nl;
  }
 }
 
# Closeout phpCOIN Domains Compared To WHM Table
 
$_out .= '<tr class="BLK_DEF_ENTRY"><td class="TP3MED_NC" colspan="7">'.$_nl;
 
$_out .= $_page_menu.$_nl;
 
$_out .= '</td></tr></table></div><br>'.$_nl;
 
# Display Domains In WHM Not In phpCOIN Table
 
$_out .= '<div align="center">'.$_nl;
 
$_out .= '<table width="95%" border="0" bordercolor="'.$_TCFG['_TAG_TABLE_BRDR_COLOR'].'" bgcolor="'.$_TCFG['_TAG_TRTD_BKGRND_COLOR'].'" cellpadding="0" cellspacing="1">'.$_nl;
 
$_out .= '<tr class="BLK_DEF_TITLE"><td class="TP3MED_NC" colspan="7">'.$_nl;
 
$_out .= '<table width="100%" cellpadding="0" cellspacing="0">'.$_nl;
 
$_out .= '<tr class="BLK_IT_TITLE_TXT">'.$_nl.'<td class="TP0MED_NL">'.$_nl;
 
$_out .= '<b>'.$_LANG['_WHM']['In_WHM'].$_sp.'</b><br>'.$_nl;
 
$_out .= '</td><td class="TP0MED_NR">'.$_nl;
 
$_out .= '</td></tr></table></td></tr>'.$_nl;
 
$_out .= '<tr class="BLK_DEF_ENTRY">'.$_nl;
 
$_out .= '<td class="TP3SML_NL" valign="top"><b>'.$_LANG['_WHM']['l_Domain'].'</b></td>'.$_nl;
 
$_out .= '<td class="TP3SML_NL" valign="top"><b>'.$_LANG['_WHM']['l_UserName'].'</b></td>'.$_nl;
 
$_out .= '<td class="TP3SML_NL" valign="top"><b>'.$_LANG['_WHM']['plan'].'</b></td>'.$_nl;
 
$_out .= '<td class="TP3SML_NL" valign="top"><b>'.$_LANG['_WHM']['l_Actions'].'</b></td></tr>'.$_nl;
 
# Process Query Results
 
FOREACH($accts as $user => $account)
 {
  
$data="";
  
$data['dom_domain']=$account[0];
  
$data['dom_user_name_cp']=$user;
  
$suspended $account[3];
  
$_out .= '<tr class="BLK_DEF_ENTRY">'.$_nl;
  
$_chk do_check_suspended($user);
  IF (
$suspended==1) {
   
$_out .= '<td class="TP3SML_NL"><font color=red><b>'.$account[0].'</b></font></td>'.$_nl;
  } ELSE {
   
$_out .= '<td class="TP3SML_NL">'.$account[0].'</td>'.$_nl;
  }
  
$_out .=