Вход Регистрация
Файл: billing/_rootfuncs.php
Строк: 998
<?php

function adminlogon( $log, $pas )
{
    global 
$_SESSION;
    
$adminLogin = getsetting( "admin_login" );
    
$adminPass = getsetting( "admin_password" );
    if ( 
$log == $adminLogin && crypt( $pas, $adminPass ) == $adminPass )
    {
        
$_SESSION['adminLogin'] = $adminLogin;
        return 
1;
    }
    else
    {
        return 
0;
    }
}

function 
adminlogout( )
{
    global 
$_SESSION;
    unset( 
$_SESSION['adminLogin'] );
    return 
1;
}

function 
validateuser( )
{
    global 
$_SESSION;
    if ( 
$_SESSION['userId'] )
    {
        if ( !( 
$r = @mysql_query( @"select * from users where id='".@$_SESSION['userId']."'" ) ) )
        {
            exit( 
mysql_error( ) );
        }
        if ( 
mysql_num_rows( $r ) == 0 )
        {
            
userlogout( );
        }
    }
}

function 
isuserloggedin( )
{
    if ( 
$_SESSION['userId'] )
    {
        return 
true;
    }
    else
    {
        return 
false;
    }
}

function 
userlogon( $u, $p )
{
    global 
$_SESSION;
    global 
$ip;
    
$u = strtolower( $u );
    
mconnect( );
    if ( !( 
$r = @mysql_query( @"select * from users where login='{$u}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $r ) )
    {
        
$r = mysql_fetch_object( $r );
        if ( 
crypt( $p, $r->password ) == $r->password )
        {
            
$_SESSION['userLogin'] = $r->login;
            
$_SESSION['userId'] = $r->id;
            
$_SESSION['userEmail'] = $r->email;
            
adduserlog( $r->id, "auth", "OK [{$ip}]" );
            return 
1;
        }
        else
        {
            
adduserlog( $r->id, "auth", "BAD PASSWORD [{$ip}]" );
            return 
0;
        }
    }
    else
    {
        return -
1;
    }
}

function 
userlogout( )
{
    global 
$_SESSION;
    unset( 
$_SESSION['userId'] );
    unset( 
$_SESSION['userLogin'] );
    unset( 
$_SESSION['userEmail'] );
    return 
1;
}

function 
mconnect( )
{
    global 
$dbhost;
    global 
$dbuser;
    global 
$dbpass;
    global 
$dbname;
    if ( !@
mysql_connect( @$dbhost, @$dbuser, @$dbpass ) )
    {
        exit( 
mysql_error( ) );
    }
    @
mysql_query( "SET NAMES cp1251" );
    if ( !@
mysql_select_db( @"{$dbname}" ) )
    {
        exit( 
mysql_error( ) );
    }
}

function 
mclose( )
{
    if ( @
mysql_ping( ) )
    {
        @
mysql_close( );
    }
}

function 
getfont( )
{
    global 
$font_row;
    global 
$font_row1;
    global 
$font_row2;
    if ( 
$font_row == $font_row1 )
    {
        
$font_row = $font_row2;
    }
    else
    {
        
$font_row = $font_row1;
    }
}

function 
valid_email( $eemail )
{
    if ( 
eregi( "^([_\.0-9a-z-]+)@([0-9a-z][0-9a-z\.-]+)\.([a-z]{2,4}$)", $eemail, $check ) )
    {
        return 
1;
    }
    else
    {
        return 
0;
    }
}

function 
sendmail( $msgto, $msgfrom, $msgsubj, $msgtext, $contenttype = "text" )
{
    if ( 
$contenttype == "text" )
    {
        
$contenttype = "text/plain";
    }
    if ( 
$contenttype == "html" )
    {
        
$contenttype = "text/html";
    }
    if ( @
mail( @"{$msgto}", @"{$msgsubj}", @"{$msgtext}", @"From: <{$msgfrom}>nMIME-Version: 1.0nContent-Type: {$contenttype}; charset=Windows-1251nContent-Transfer-Encoding: 8bitn" ) )
    {
        return 
1;
    }
    else
    {
        return 
0;
    }
}

function 
generatepassword( $length = 8 )
{
    
$password = "";
    
$possible = "0123456789bcdfghjkmnpqrstvwxyz";
    
$i = 0;
    while ( 
$i < $length )
    {
        
$char = substr( $possible, mt_rand( 0, strlen( $possible ) - 1 ), 1 );
        if ( !
strstr( $password, $char ) )
        {
            
$password .= $char;
            ++
$i;
        }
    }
    return 
$password;
}

function 
gensid( )
{
    
$schet = md5( uniqid( rand( ) ) );
    
$schet = substr( $schet, 0, 8 );
    
$schet = strtoupper( $schet );
    return 
$schet;
}

function 
gettpl( $tpl )
{
    
mconnect( );
    if ( !( 
$r = @mysql_query( @"select * from templates where param='{$tpl}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $r ) )
    {
        
$r = mysql_fetch_object( $r );
        return 
stripslashes( $r->template );
    }
}

function 
getsetting( $set )
{
    
mconnect( );
    if ( !( 
$r = @mysql_query( @"select * from settings where param='{$set}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $r ) )
    {
        
$r = mysql_fetch_object( $r );
        return 
stripslashes( $r->value );
    }
}

function 
setsetting( $param, $value )
{
    
mconnect( );
    
$value = addslashes( $value );
    if ( !@
mysql_query( @"update settings set value='{$value}' where param='{$param}'" ) )
    {
        exit( 
mysql_error( ) );
    }
}

function 
getaddons( )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( "select * from addons where active='1'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        return 
$z;
    }
}

function 
getaddonbyid( $id )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from addons where id='{$id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
getarraynotnullcount( $arr )
{
    
$cnt = 0;
    
$v = each( $arr )[1];
    
$k = each( $arr )[0];
    while ( 
each( $arr ) )
    {
        if ( 
$v )
        {
            ++
$cnt;
        }
    }
    
reset( $arr );
    return 
$cnt;
}

function 
gettarifbyid( $id )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from tarifs where id='{$id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
getbillbyid( $id )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from bills where id='{$id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
getzonebyzone( $zone )
{
    
mconnect( );
    if ( !( 
$z = mysql_query( "select * from zones where zone='{$zone}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
getzonebydomain( $domain )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select t1.* from zones as t1, orders_domains as t2 where t1.id=t2.zone_id and t2.domain='{$domain}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
getdomainbydomain( $domain )
{
    
mconnect( );
    if ( !( 
$z = mysql_query( "select * from orders_domains where domain='{$domain}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
getzonesnamesactive( )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( "select zone from zones where active='1' order by zone" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        while ( 
$zz = mysql_fetch_object( $z ) )
        {
            
$result[] = $zz->zone;
        }
        return 
$result;
    }
}

function 
getzonesnamesforwhois( )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( "select zone from zones where useinwhois='1' order by zone" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        while ( 
$zz = mysql_fetch_object( $z ) )
        {
            
$result[] = $zz->zone;
        }
        return 
$result;
    }
}

function 
getzonesactive( )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( "select * from zones where active='1' order by zone" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        return 
$z;
    }
}

function 
getzonesall( )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( "select * from zones order by zone" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        return 
$z;
    }
}

function 
iszoneinuse( $id )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from orders_domains where zone_id='{$id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        return 
true;
    }
    else
    {
        return 
false;
    }
}

function 
iszoneactive( $zone )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from zones where zone='{$zone}' and active='1'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        return 
true;
    }
    else
    {
        return 
false;
    }
}

function 
istarifinuse( $id )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from orders where tarif='{$id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        return 
true;
    }
    else
    {
        return 
false;
    }
}

function 
mydate( $date )
{
    
$date = split( "-", $date );
    return 
$date[2].".".$date[1].".".$date[0];
}

function 
frommydate( $date )
{
    
$date = split( "\.", $date );
    return 
$date[2]."-".$date[1]."-".$date[0];
}

function 
datenow( )
{
    return 
date( "d.m.Y" );
}

function 
makepages( $page, $rows )
{
    global 
$_SESSION;
    global 
$do;
    
$perPage = getsetting( "perpage_".$do );
    
$pages = ceil( $rows / $perPage );
    if ( !
$page )
    {
        if ( 
$_SESSION[$do."Page"] )
        {
            
$page = $_SESSION[$do."Page"];
        }
        else
        {
            
$page = 1;
        }
    }
    if ( 
$pages < $page )
    {
        
$page = 1;
    }
    
$start = ( $page - 1 ) * $perPage;
    
$_SESSION[$do."Page"] = $page;
    if ( 
$pages )
    {
        
$txt = "Страницы:";
    }
    if ( 
1 < $page )
    {
        
$txt .= " <A href=?do={$do}&page=".( $page - 1 )."><</a>";
    }
    else if ( 
0 < $pages )
    {
        
$txt .= " <";
    }
    
$i = 1;
    for ( ; 
$i <= $pages; ++$i )
    {
        if ( 
$page != $i )
        {
            
$newTxt = " <A href=?do={$do}&page={$i}>{$i}</a>";
        }
        else
        {
            
$newTxt = " <B>{$i}</B>";
        }
        
$txt = $txt.$newTxt;
    }
    if ( 
$page < $pages )
    {
        
$txt .= " <A href=?do={$do}&page=".( $page + 1 ).">></a>";
    }
    else if ( 
0 < $pages )
    {
        
$txt .= " >";
    }
    return array( 
$start, $perPage, $txt );
}

function 
adduserlog( $uid, $operation, $comment )
{
    
mconnect( );
    if ( !@
mysql_query( @"INSERT INTO users_logs (uid,dt,operation,comment) values('{$uid}',NOW(),'{$operation}', '{$comment}')" ) )
    {
        exit( 
mysql_error( ) );
    }
}

function 
getnews( $num = 0 )
{
    
mconnect( );
    if ( 
$num )
    {
        if ( !( 
$r = @mysql_query( @"select * from news order by data desc, id desc limit 0,{$num}" ) ) )
        {
            exit( 
mysql_error( ) );
        }
    }
    else
    {
        if ( !( 
$r = @mysql_query( "select * from news order by data desc, id desc" ) ) )
        {
            exit( 
mysql_error( ) );
        }
    }
    if ( 
0 < mysql_num_rows( $r ) )
    {
        return 
$r;
    }
}

function 
getnewsbyid( $id )
{
    if ( 
$id )
    {
        
mconnect( );
        if ( !( 
$r = @mysql_query( @"select * from news where id='{$id}'" ) ) )
        {
            exit( 
mysql_error( ) );
        }
        if ( 
0 < mysql_num_rows( $r ) )
        {
            return 
mysql_fetch_object( $r );
        }
    }
}

function 
makebillpayed( $id, $status = 1 )
{
    
$bill = getbillbyid( $id );
    if ( 
$bill && !$bill->status )
    {
        if ( !@
mysql_query( @"update bills set payed=NOW(),status='{$status}' where id='{$id}'" ) )
        {
            exit( 
mysql_error( ) );
        }
        if ( 
$bill->host_id && !$bill->status )
        {
            if ( !( 
$t = @mysql_query( @"select * from orders where id='{$bill->host_id}'" ) ) )
            {
                exit( 
mysql_error( ) );
            }
            
$t = mysql_fetch_object( $t );
            if ( 
$t->startdate == "0000-00-00" )
            {
                if ( !@
mysql_query( @"update orders set startdate=NOW(), todate=DATE_ADD(NOW(),INTERVAL {$bill->host_srok} MONTH) where id='{$bill->host_id}'" ) )
                {
                    exit( 
mysql_error( ) );
                }
                
$order = getorderbyid( $bill->host_id );
                
$tarif = gettarifbyid( $order->tarif );
                if ( 
$tarif->autocreate )
                {
                    
dacreateuser( $bill->host_id );
                }
                if ( 
$tarif->autocreatecpanel )
                {
                    
cpanelcreateuser( $bill->host_id );
                }
            }
            else
            {
                if ( !@
mysql_query( @"update orders set todate=DATE_ADD(todate,INTERVAL {$bill->host_srok} MONTH) where id='{$bill->host_id}'" ) )
                {
                    exit( 
mysql_error( ) );
                }
            }
        }
        if ( 
$bill->domain_id && !$bill->status )
        {
            if ( !( 
$d = @mysql_query( @"select * from orders_domains where id='{$bill->domain_id}'" ) ) )
            {
                exit( 
mysql_error( ) );
            }
            
$d = mysql_fetch_object( $d );
            if ( 
$d->startdate == "0000-00-00" )
            {
                if ( !@
mysql_query( @"update orders_domains set startdate=NOW(), todate=DATE_ADD(NOW(),INTERVAL {$bill->domain_srok} MONTH) where id='{$bill->domain_id}'" ) )
                {
                    exit( 
mysql_error( ) );
                }
            }
            else
            {
                if ( !@
mysql_query( @"update orders_domains set todate=DATE_ADD(todate,INTERVAL {$bill->domain_srok} MONTH) where id='{$bill->domain_id}'" ) )
                {
                    exit( 
mysql_error( ) );
                }
            }
        }
        return 
true;
    }
    return 
false;
}

function 
isloginexists( $login )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from users where login='{$login}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        return 
true;
    }
}

function 
getuserbyid( $id )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from users where id='{$id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
getuserbylogin( $login )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from users where login='{$login}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
getuserslogins( )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( "select login from users order by login" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        while ( 
$zz = mysql_fetch_object( $z ) )
        {
            
$result[] = $zz->login;
        }
        return 
$result;
    }
}

function 
getusersbyordertype( $orderType )
{
    
mconnect( );
    if ( 
$orderType == "hosting" || $orderType == "reseller" || $orderType == "vds" || $orderType == "dedicated" )
    {
        if ( !( 
$r = @mysql_query( @"select DISTINCT t2.login, t2.* from orders as t1, users as t2, tarifs as t3 where t1.tarif=t3.id and t3.vid='{$orderType}' and t2.id=t1.uid order by t2.login" ) ) )
        {
            exit( 
error( ) );
        }
    }
    else if ( 
$orderType == "domains" )
    {
        if ( !( 
$r = @mysql_query( "select DISTINCT t2.login, t2.* from orders_domains as t1, users as t2 where t2.id=t1.uid order by t2.login" ) ) )
        {
            exit( 
error( ) );
        }
    }
    if ( 
0 < mysql_num_rows( $r ) )
    {
        return 
$r;
    }
}

function 
getusersall( )
{
    
mconnect( );
    if ( !( 
$r = @mysql_query( "select * from users order by login" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $r ) )
    {
        return 
$r;
    }
}

function 
getorderbyid( $id )
{
    
mconnect( );
    if ( !( 
$z = @mysql_query( @"select * from orders where id='{$id}'" ) ) )
    {
        exit( 
mysql_error( ) );
    }
    if ( 
0 < mysql_num_rows( $z ) )
    {
        
$z = mysql_fetch_object( $z );
        return 
$z;
    }
}

function 
head( )
{
    include( 
"./_rootheader.php" );
    if ( 
$_SESSION['userId'] )
    {
        
menu( );
    }
}

function 
menu( )
{
    echo 
"t<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><font size="5"><b><font size="3">Биллинг панель</font></b></font><hr size="1"></td></tr></table>rnt";
    print 
"<B>Меню:</b> <a href=billing.php?do=bills>Счета</a>, <a href=billing.php?do=orders>Заказы</a>, <a href=billing.php?do=domains>Домены</a>, <a href=billing.php?do=profile>Профайл</a>, <a href=reg_domain.php?zone=org>Заказать домен</a>, <a href=billing.php?do=logout>Выйти</a>.<BR><BR>";
}

function 
menu_vertical( )
{
    print 
"<B>Меню:</b><BR><BR>rnt&nbsp;&nbsp;&nbsp;&nbsp;<a href=billing.php?do=bills>Счета</a><BR>rnt&nbsp;&nbsp;&nbsp;&nbsp;<a href=billing.php?do=orders>Заказы</a><BR>rnt&nbsp;&nbsp;&nbsp;&nbsp;<a href=billing.php?do=domains>Домены</a><BR>rnt&nbsp;&nbsp;&nbsp;&nbsp;<a href=billing.php?do=profile>Профайл</a><BR>rnt&nbsp;&nbsp;&nbsp;&nbsp;<a href=reg_domain.php?zone=org>Заказать домен</a><BR>rnt&nbsp;&nbsp;&nbsp;&nbsp;<a href=billing.php?do=logout>Выйти</a>";
}

function 
foot( )
{
    global 
$version;
    include( 
"./_rootfooter.php" );
    print 
"<!-- Powered by RootPanel v{$version} [ wwww.root-host.net | www.zeoshost.ru ] -->";
}

function 
menu_admin_client( $uid )
{
    
$user = getuserbyid( $uid );
    print 
"[ <B>{$user->login}</B> ] : [ <B><A href=?do=bills&param=uid&search={$uid}>счета</a></B> - <B><a href=?do=orders&param=uid&search={$uid}>заказы</a></B> - <B><a href=?do=domains&param=uid&search={$uid}>домены</a></B> - <B><a href=?do=profile&id={$uid}>профайл</a></B> - <B><a href=?do=history&uid={$uid}>история</a></B> - <B><A href=?do=fullinfo&id={$uid}>полное инфо</a></b> ]<BR><BR>";
}

function 
printwhoisform( )
{
    global 
$domain;
    global 
$checkedzones;
    global 
$zone;
    echo 
"t<form action="whois.php" method="post">rnt<Table><tr><Td>rntДоменное имя: <input type=text name=domain value="";
    echo 
$domain;
    echo "" size=15>&nbsp;rnt"
;
    
$whoistype = getsetting( "whoistype" );
    
$zones = getzonesnamesforwhois( );
    if ( 
$whoistype == "check" )
    {
        print 
"<select disabled><option value=''>выберите зоны:</select><BR><BR>";
        
$cnt = 0;
        if ( 
$zone && !$checkedzones )
        {
            
$checkedzones[$zone] = "{$zone}";
        }
        print 
"<table>";
        
$v = each( @$zones )[1];
        
$k = each( @$zones )[0];
        while ( @
each( @$zones ) )
        {
            ++
$cnt;
            if ( 
$cnt == 1 )
            {
                print 
"<tr><td>";
            }
            else
            {
                print 
"<td>";
            }
            if ( 
$checkedzones && in_array( $v, $checkedzones ) )
            {
                
$addon = "checked";
            }
            else
            {
                
$addon = "";
            }
            print 
"<input type=checkbox name=checkedzones[{$v}] value='{$v}' {$addon}>.{$v}";
            if ( 
$cnt == 6 )
            {
                
$cnt = 0;
                print 
"</td></tr>";
            }
            else
            {
                print 
"</td>";
            }
        }
        print 
"</table>";
    }
    else if ( 
$whoistype == "select" )
    {
        print 
"<select name=zone><option value=''>выберите зону:";
        
$v = each( @$zones )[1];
        
$k = each( @$zones )[0];
        while ( @
each( @$zones ) )
        {
            if ( 
$zone == $v )
            {
                
$addon = "selected";
            }
            else
            {
                
$addon = "";
            }
            print 
"<option value='{$v}' {$addon}>.{$v}";
        }
        print 
"</select>";
    }
    echo 
"t</td><Td valign=bottom><input type=submit value=Проверить></Td></tr></table>rnt</form>rnt";
}

function 
dacreateuser( $orderid, $sendErrorEmail = 1 )
{
    global 
$DAerror;
    
$da_user = getsetting( "da_user" );
    
$da_password = getsetting( "da_password" );
    
$da_ip = getsetting( "da_ip" );
    
$da_user_ip = getsetting( "da_user_ip" );
    if ( 
$da_user && $da_password && $da_ip && $da_user_ip )
    {
        
$order = getorderbyid( $orderid );
        if ( 
$order->id )
        {
            
$user = getuserbyid( $order->uid );
            if ( 
$user->id )
            {
                
$tarif = gettarifbyid( $order->tarif );
                if ( 
$tarif->id )
                {
                    if ( 
$tarif->daname )
                    {
                        
$pwd = generatepassword( );
                        
$login_addon = rand( );
                        
$login_addon = substr( $login_addon, 0, 3 );
                        
$login = substr( $user->login, 0, 7 ).$login_addon;
                        
$da = new directadmin( $da_ip, $da_user, $da_password );
                        if ( !
$da->s->error )
                        {
                            
$error = $da->add_user( $login, $user->email, $pwd, $order->domain, $tarif->daname, $da_user_ip );
                            if ( 
$error == "0" )
                            {
                                if ( !@
mysql_query( @"update orders set dalogin='{$login}',status='1' where id='{$orderid}'" ) )
                                {
                                    exit( 
mysql_error( ) );
                                }
                                
$error = "";
                            }
                        }
                        else
                        {
                            
$error = $da->s->error[0];
                        }
                    }
                    else
                    {
                        
$error = "В настройках тарифного плана {$tarif->name} не указано название тарифа в DirectAdmin.";
                    }
                }
                else
                {
                    
$error = "Не найден тарифный план ID #{$order->tarif}.";
                }
            }
            else
            {
                
$error = "Не найден пользователь ID #{$user->id}.";
            }
        }
        else
        {
            
$error = "Не найден заказ ID #{$orderid}.";
        }
    }
    else
    {
        
$error = "Указаны не все настройки DirectAdmin.";
    }
    
$DAerror = $error;
    if ( 
$error )
    {
        if ( 
$sendErrorEmail )
        {
            
$errormsg = "RootPanel не смог автоматически создать аккаунт в DA для заказа ID #{$orderid} ({$order->domain}) по следующей причине:nn{$error}nnВам необходимо создать аккаунт вручную, а затем заполнить поле 'Логин в DA' в редактировании заказа!";
            
$manager_email = getsetting( "manager_email" );
            
sendmail( $manager_email, $manager_email, "DA: Ошибка создания аккаунта", $errormsg );
        }
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
cpanelcreateuser( $orderid, $sendErrorEmail = 1 )
{
    global 
$CPANELerror;
    
$cpanel_user = getsetting( "cpanel_user" );
    
$cpanel_password = getsetting( "cpanel_password" );
    
$cpanel_ip = getsetting( "cpanel_ip" );
    
$cpanel_ns1 = getsetting( "cpanel_ns1" );
    
$cpanel_ns2 = getsetting( "cpanel_ns2" );
    if ( 
$cpanel_user && $cpanel_password && $cpanel_ip )
    {
        
$order = getorderbyid( $orderid );
        if ( 
$order->id )
        {
            
$user = getuserbyid( $order->uid );
            if ( 
$user->id )
            {
                
$tarif = gettarifbyid( $order->tarif );
                if ( 
$tarif->id )
                {
                    if ( 
$tarif->cpanelname )
                    {
                        
$pwd = generatepassword( );
                        
$login_addon = rand( );
                        
$login_addon = substr( $login_addon, 0, 3 );
                        
$login = substr( $user->login, 0, 5 ).$login_addon;
                        
$postdata = "sign=&plan=&domain={$order->domain}&username={$login}&password={$pwd}&quota={$tarif->quota}&cgi={$tarif->cgi}&maxftp={$tarif->ftp}&maxpop={$tarif->email}&";
                        
$postdata = $postdata."maxlst={$tarif->emaillists}&maxsql={$tarif->sql}&maxsub={$tarif->subdomains}&maxpark={$tarif->parkdomains}&maxaddon={$tarif->addondomains}&";
                        
$postdata = $postdata."bwlimit={$tarif->bandwidth}&cpmod={$tarif->theme}&customip=--Auto+Assign--&msel={$tarif->cpanelname}&contactemail={$user->email}";
                        @
set_time_limit( 120 );
                        
$url = "http://".$cpanel_ip.":2086/scripts/wwwacct";
                        
$ch = curl_init( );
                        
curl_setopt( $ch, CURLOPT_URL, $url );
                        
curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
                        
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
                        
curl_setopt( $ch, CURLOPT_TIMEOUT, 120 );
                        
curl_setopt( $ch, CURLOPT_POST, 1 );
                        
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
                        
curl_setopt( $ch, CURLOPT_USERPWD, "{$cpanel_user}:{$cpanel_password}" );
                        
$result = curl_exec( $ch );
                        
curl_close( $ch );
                        if ( 
eregi( "Sorry, that domain is already setup", $result ) )
                        {
                            
$error = "Sorry, that domain is already setup";
                        }
                        else
                        {
                            if ( 
eregi( "Sorry, a DNS entry for", $result ) )
                            {
                                
$error = "Sorry, a DNS entry already exists, please delete it first (from all servers in the dns cluster)";
                            }
                            else
                            {
                                if ( 
eregi( "Sorry that username is too long", $result ) )
                                {
                                    
$error = "Sorry that username is too long";
                                }
                                else
                                {
                                    if ( 
eregi( "New Account Info", $result ) )
                                    {
                                        if ( !@
mysql_query( @"update orders set cpanellogin='{$login}',status='1' where id='{$orderid}'" ) )
                                        {
                                            exit( 
mysql_error( ) );
                                        }
                                        
$template = gettpl( "cpanel" );
                                        
$company_name = getsetting( "company_name" );
                                        
$company_url = getsetting( "company_url" );
                                        
$manager_email = getsetting( "manager_email" );
                                        
$template = str_replace( "{company_name}", $company_name, $template );
                                        
$template = str_replace( "{company_url}", $company_url, $template );
                                        
$template = str_replace( "{domain}", $order->domain, $template );
                                        
$template = str_replace( "{ip}", $cpanel_ip, $template );
                                        
$template = str_replace( "{login}", $login, $template );
                                        
$template = str_replace( "{password}", $pwd, $template );
                                        
$template = str_replace( "{ns1}", $cpanel_ns1, $template );
                                        
$template = str_replace( "{ns2}", $cpanel_ns2, $template );
                                        
sendmail( $user->email, $manager_email, "Your account for {$order->domain} is now ready for use.", $template );
                                        
sendmail( $manager_email, $user->email, "Duplicate: Your account for {$order->domain} is now ready for use.", $template );
                                        
$error = "";
                                    }
                                    else
                                    {
                                        
$error = "Sorry, connection error.";
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        
$error = "В настройках тарифного плана {$tarif->name} не указано название тарифа в cPanel.";
                    }
                }
                else
                {
                    
$error = "Не найден тарифный план ID #{$order->tarif}.";
                }
            }
            else
            {
                
$error = "Не найден пользователь ID #{$user->id}.";
            }
        }
        else
        {
            
$error = "Не найден заказ ID #{$orderid}.";
        }
    }
    else
    {
        
$error = "Указаны не все настройки cPanel.";
    }
    
$CPANELerror = $error;
    if ( 
$error )
    {
        if ( 
$sendErrorEmail )
        {
            
$errormsg = "RootPanel не смог автоматически создать аккаунт в cPanel для заказа ID #{$orderid} ({$order->domain}) по следующей причине:nn{$error}nnВам необходимо создать аккаунт вручную, а затем заполнить поле 'Логин в cPanel' в редактировании заказа!";
            
$manager_email = getsetting( "manager_email" );
            
sendmail( $manager_email, $manager_email, "cPanel: Ошибка создания аккаунта", $errormsg );
        }
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
dadeleteuser( $orderid, $sendErrorEmail = 1 )
{
    global 
$DAerror;
    
$da_user = getsetting( "da_user" );
    
$da_password = getsetting( "da_password" );
    
$da_ip = getsetting( "da_ip" );
    
$da_user_ip = getsetting( "da_user_ip" );
    if ( 
$da_user && $da_password && $da_ip && $da_user_ip )
    {
        
$order = getorderbyid( $orderid );
        if ( 
$order->id )
        {
            if ( 
$order->dalogin )
            {
                
$tarif = gettarifbyid( $order->tarif );
                if ( 
$tarif->autodelete )
                {
                    
$da = new directadmin( $da_ip, $da_user, $da_password );
                    if ( !
$da->s->error )
                    {
                        
$result = $da->delete_user( $order->dalogin );
                        if ( !
eregi( "Users deleted", $result ) )
                        {
                            
eregi( "<p align="center"><b>Подробно<\/b><\/p>[^<]*<p align="center">([^<]*)<", $result, $ar );
                            
$error = $ar[1];
                        }
                    }
                    else
                    {
                        
$error = $da->s->error[0];
                    }
                }
                else
                {
                    
$error = "Возможность автоматического удаления аккаунтов в DA для данного тарифного плана отключена, либо тарифный план не найден.";
                }
            }
            else
            {
                
$error = "Не указан логин в DA для данного заказа.";
            }
        }
        else
        {
            
$error = "Не найден заказ ID #{$orderid}";
        }
    }
    else
    {
        
$error = "Указаны не все настройки DirectAdmin.";
    }
    
$DAerror = $error;
    if ( 
$error )
    {
        if ( 
$sendErrorEmail )
        {
            
$errormsg = "RootPanel не смог автоматически удалить аккаунт в DA для заказа ID #{$orderid} ({$order->dalogin}) по следующей причине:nn{$error}nnВам необходимо удалить аккаунт вручную!";
            
$manager_email = getsetting( "manager_email" );
            
sendmail( $manager_email, $manager_email, "DA: Ошибка удаления аккаунта", $errormsg );
        }
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
cpaneldeleteuser( $orderid, $sendErrorEmail = 1 )
{
    global 
$CPANELerror;
    
$cpanel_user = getsetting( "cpanel_user" );
    
$cpanel_password = getsetting( "cpanel_password" );
    
$cpanel_ip = getsetting( "cpanel_ip" );
    if ( 
$cpanel_user && $cpanel_password && $cpanel_ip )
    {
        
$order = getorderbyid( $orderid );
        if ( 
$order->id )
        {
            if ( 
$order->cpanellogin )
            {
                
$tarif = gettarifbyid( $order->tarif );
                if ( 
$tarif->autodeletecpanel )
                {
                    
$postdata = "domain={$order->cpanellogin}&user{$order->cpanellogin}";
                    @
set_time_limit( 120 );
                    
$url = "http://".$cpanel_ip.":2086/scripts/killacct";
                    
$ch = curl_init( );
                    
curl_setopt( $ch, CURLOPT_URL, $url );
                    
curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
                    
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
                    
curl_setopt( $ch, CURLOPT_TIMEOUT, 120 );
                    
curl_setopt( $ch, CURLOPT_POST, 1 );
                    
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
                    
curl_setopt( $ch, CURLOPT_USERPWD, "{$cpanel_user}:{$cpanel_password}" );
                    
$result = curl_exec( $ch );
                    
curl_close( $ch );
                    if ( 
eregi( "does not exist!", $result ) )
                    {
                        
$error = "Warning! System user does not exist!";
                    }
                    else
                    {
                        if ( 
eregi( "Removing User....Done", $result ) )
                        {
                            
$error = "";
                        }
                        else
                        {
                            
$error = "Sorry, connection error.";
                        }
                    }
                }
                else
                {
                    
$error = "Возможность автоматического удаления аккаунтов в cPanel для данного тарифного плана отключена, либо тарифный план не найден.";
                }
            }
            else
            {
                
$error = "Не указан логин в cPanel для данного заказа.";
            }
        }
        else
        {
            
$error = "Не найден заказ ID #{$orderid}";
        }
    }
    else
    {
        
$error = "Указаны не все настройки cPanel.";
    }
    
$CPANELerror = $error;
    if ( 
$error )
    {
        if ( 
$sendErrorEmail )
        {
            
$errormsg = "RootPanel не смог автоматически удалить аккаунт в cPanel для заказа ID #{$orderid} ({$order->dalogin}) по следующей причине:nn{$error}nnВам необходимо удалить аккаунт вручную!";
            
$manager_email = getsetting( "manager_email" );
            
sendmail( $manager_email, $manager_email, "cPanel: Ошибка удаления аккаунта", $errormsg );
        }
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
dasuspenduser( $orderid, $suspend = 1, $sendErrorEmail = 1 )
{
    global 
$DAerror;
    
$da_user = getsetting( "da_user" );
    
$da_password = getsetting( "da_password" );
    
$da_ip = getsetting( "da_ip" );
    
$da_user_ip = getsetting( "da_user_ip" );
    if ( 
$da_user && $da_password && $da_ip && $da_user_ip )
    {
        
$order = getorderbyid( $orderid );
        if ( 
$order->id )
        {
            if ( 
$order->dalogin )
            {
                
$tarif = gettarifbyid( $order->tarif );
                if ( 
$tarif->autosuspend )
                {
                    
$da = new directadmin( $da_ip, $da_user, $da_password );
                    if ( !
$da->s->error )
                    {
                        if ( 
$suspend )
                        {
                            
$result = $da->suspend_user( $order->dalogin );
                            if ( 
$result == "0" )
                            {
                                
$error = "Аккаунт уже остановлен.";
                            }
                        }
                        else
                        {
                            
$result = $da->activate_user( $order->dalogin );
                            if ( 
$result == "0" )
                            {
                                
$error = "Аккаунт уже запущен.";
                            }
                        }
                        if ( 
eregi( "error has occurred", $result ) )
                        {
                            
eregi( "<p align="center"><b>Подробно<\/b><\/p>[^<]*<p align="center">([^<]*)<", $result, $ar );
                            
$error = $ar[1];
                        }
                    }
                    else
                    {
                        
$error = $da->s->error[0];
                    }
                }
                else
                {
                    
$error = "Возможность автоматической остановки/запуска аккаунтов в DA для данного тарифного плана отключена, либо тарифный план не найден.";
                }
            }
            else
            {
                
$error = "Не указан логин в DA для данного заказа.";
            }
        }
        else
        {
            
$error = "Не найден заказ ID #{$orderid}.";
        }
    }
    else
    {
        
$error = "Указаны не все настройки DirectAdmin.";
    }
    
$DAerror = $error;
    if ( 
$error )
    {
        if ( 
$sendErrorEmail )
        {
            
$errormsg = "RootPanel не смог автоматически остановить/запустить аккаунт в DA для заказа ID #{$orderid} ({$order->dalogin}) по следующей причине:nn{$error}nnВам необходимо сделать это вручную!";
            
$manager_email = getsetting( "manager_email" );
            
sendmail( $manager_email, $manager_email, "DA: Ошибка остановки/запуска аккаунта", $errormsg );
        }
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
cpanelsuspenduser( $orderid, $suspend = 1, $sendErrorEmail = 1 )
{
    global 
$CPANELerror;
    
$cpanel_user = getsetting( "cpanel_user" );
    
$cpanel_password = getsetting( "cpanel_password" );
    
$cpanel_ip = getsetting( "cpanel_ip" );
    if ( 
$cpanel_user && $cpanel_password && $cpanel_ip )
    {
        
$order = getorderbyid( $orderid );
        if ( 
$order->id )
        {
            if ( 
$order->cpanellogin )
            {
                
$tarif = gettarifbyid( $order->tarif );
                if ( 
$tarif->autosuspendcpanel )
                {
                    if ( !
$suspend )
                    {
                        
$postdata = "domain={$order->cpanellogin}&user={$order->cpanellogin}&unsuspend-user=UnSuspend&reason=automatic+unsuspend";
                    }
                    else if ( 
$suspend )
                    {
                        
$postdata = "domain={$order->cpanellogin}&user={$order->cpanellogin}&suspend-user=Suspend&reason=automatic+suspend";
                    }
                    @
set_time_limit( 120 );
                    
$url = "http://".$cpanel_ip.":2086/scripts2/suspendacct";
                    
$ch = curl_init( );
                    
curl_setopt( $ch, CURLOPT_URL, $url );
                    
curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
                    
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
                    
curl_setopt( $ch, CURLOPT_TIMEOUT, 120 );
                    
curl_setopt( $ch, CURLOPT_POST, 1 );
                    
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
                    
curl_setopt( $ch, CURLOPT_USERPWD, "{$cpanel_user}:{$cpanel_password}" );
                    
$result = curl_exec( $ch );
                    
curl_close( $ch );
                    if ( 
eregi( "You do not have permission to suspend that account!", $result ) )
                    {
                        
$error = "You do not have permission to suspend that account!";
                    }
                    else
                    {
                        if ( 
eregi( "Account Already Suspended", $result ) )
                        {
                            
$error = "Account Already Suspended";
                        }
                        else
                        {
                            if ( 
eregi( "account is now active", $result ) || eregi( "account has been suspended", $result ) )
                            {
                                
$error = "";
                            }
                            else
                            {
                                
$error = "Sorry, connection error.";
                            }
                        }
                    }
                }
                else
                {
                    
$error = "Возможность автоматической остановки/запуска аккаунтов в cPanel для данного тарифного плана отключена, либо тарифный план не найден.";
                }
            }
            else
            {
                
$error = "Не указан логин в cPanel для данного заказа.";
            }
        }
        else
        {
            
$error = "Не найден заказ ID #{$orderid}.";
        }
    }
    else
    {
        
$error = "Указаны не все настройки cPanel.";
    }
    
$CPANELerror = $error;
    if ( 
$error )
    {
        if ( 
$sendErrorEmail )
        {
            
$errormsg = "RootPanel не смог автоматически остановить/запустить аккаунт в cPanel для заказа ID #{$orderid} ({$order->cpanellogin}) по следующей причине:nn{$error}nnВам необходимо сделать это вручную!";
            
$manager_email = getsetting( "manager_email" );
            
sendmail( $manager_email, $manager_email, "cPanel: Ошибка остановки/запуска аккаунта", $errormsg );
        }
        return 
false;
    }
    else
    {
        return 
true;
    }
}

function 
error( $err )
{
    
head( );
    print 
"<B>Ошибка</b>";
    print 
"{$err}";
    
foot( );
}

$version = "1.3.1";
$_yes[0] = "нет";
$_yes[1] = "да";
$_status[0] = "не обработан";
$_status[1] = "обработан";
$_status[2] = "приостановлен";
$_statusBill[0] = "не оплачен";
$_statusBill[1] = "оплачен";
$_statusBill[2] = "условно оплачен";
$_newreg[0] = "перенос домена";
$_newreg[1] = "новый домен";
$_newregmin[0] = "перенос";
$_newregmin[1] = "новый";
$_renew[0] = "без продления домена";
$_renew[1] = "продление домена";
$_renewmin[0] = "без продления";
$_renewmin[1] = "продление";
$_sort['asc'] = "по возрастанию";
$_sort['desc'] = "по убыванию";
$font_row = $font_row2;
$ip = getenv( "REMOTE_ADDR" );
$server_host = getenv( "HTTP_HOST" );
$server_ip = getenv( "SERVER_ADDR" );

?>
Онлайн: 3
Реклама