Welcome Guest, Not a member yet? Register   Sign In
[Updated!] Cpanel library (Supports email & Cron)
#5

[eluser]PromaneX[/eluser]
New code for the lib - wouldnt fit in first post!

Code:
<?php
if (!defined('BASEPATH'))
{
    exit('No direct script access allowed');
}
/**
* Code Igniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package        CodeIgniter
* @author        Rick Ellis
* @copyright    Copyright (c) 2006, pMachine, Inc.
* @license        http://www.codeignitor.com/user_guide/license.html
* @link        http://www.codeigniter.com
* @since        Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
class Cpanel
{
    function Cpanel()
    {
        $this->CI =& get_instance();
        log_message('debug', 'Cpanel Class Initialized');//set up cpanel access data
        $this->CI->config->load('cpanel', TRUE);
        $this->cpanel_config = $this->CI->config->item('cpanel');
    }

    function create_email($user, $pass, $quota=20)
    {
        $request='http://'.$this->cpanel_config['user'];
        $request.=':';
        $request.=$this->cpanel_config['pass'];
        $request.='@';
        $request.=$this->cpanel_config['host'];
        $request.=':2082/frontend/';
        $request.=$this->cpanel_config['skin'];
        $request.='/mail/doaddpop.html?quota=';
        $request.=$quota;
        $request.='&email;=';
        $request.=$user;
        $request.='&domain;=';
        $request.=$this->cpanel_config['host'];
        $request.='&password;=';
        $request.=$pass;
        if ($repsonse = file_get_contents($request))
        {
            if (!stristr($repsonse, 'already exists!') === FALSE)
            {
                return FALSE;
            }
            if (!stristr($repsonse, 'was successfully created') === FALSE)
            {
                return TRUE;
            }
        }
        else
        {
            return FALSE;
        }
    }

    function get_cron($search = null)
    {
        $request = 'http://' . $this->cpanel_config['user'];
        $request .= ':';
        $request .= $this->cpanel_config['pass'];
        $request .= '@';
        $request .= $this->cpanel_config['host'];
        $request .= ':2082/frontend/';
        $request .= $this->cpanel_config['skin'];
        $request .= '/cron/advcron.html';
        if ($repsonse = file_get_contents($request))
        {
            $dom = new domdocument;
            $dom->loadHTML($repsonse);
            $xpath = new domxpath($dom);
            $xNodes = $xpath->query('//input');
            foreach ($xNodes as $item)
            {
                $_n = explode('-', $item->getAttribute('name'));
                if (!stristr($item->getAttribute('name'), '-') === false)
                {
                    if ($search !== null)
                    {
                        if (!stristr($item->getAttribute('value'), $search) === false)
                        {
                            $data[$_n[0]]['accept'] = true;
                        }
                        else
                        {
                            $data[$_n[0]]['accept'] = false;
                        }
                    }
                    $data[$_n[0]][$_n[1]] = $item->getAttribute('value');
                    $data[$_n[0]]['id'] = $_n[0];
                }
            }
            unset($data[0]);
            foreach ($data as $row)
            {
                if ($search !== null)
                {
                    if (!$row['accept'])
                    {
                        unset($data[$row['id']]);
                    }
                }
                unset($data[$row['id']]['id']);
            }
            return $data;
        }
        else
        {
            return false;
        }
    }

    function set_cron($min, $hour, $day, $month, $weekday, $command, $id=0)
    {
        $url = 'http://' . $this->cpanel_config['user'].':'.$this->cpanel_config['pass'].'@'.$this->cpanel_config['host'].':2082/frontend/'.$this->cpanel_config['skin']."/cron/editcron.html?";
        $request = $id.'-minute=';
        $request .= $min;
        $request .= '&'.$id.'-hour=';
        $request .= $hour;
        $request .= '&'.$id.'-day=';
        $request .= $day;
        $request .= '&'.$id.'-month=';
        $request .= $month;
        $request .= '&'.$id.'-weekday=';
        $request .= $weekday;
        $request .= '&'.$id.'-command=';
        $request .= urlencode($command);
        $oldcron = $this->CI->cpanel->get_cron();
        foreach ($oldcron as $key=>$line)
        {
            if ($key==$id)
            {
                unset($oldcron[$key]);
            }
            else
            {
                $request .= '&'.$key.'-minute=';
                $request .= $line['minute'];
                $request .= '&'.$key.'-hour=';
                $request .= $line['hour'];
                $request .= '&'.$key.'-day=';
                $request .= $line['day'];
                $request .= '&'.$key.'-month=';
                $request .= $line['month'];
                $request .= '&'.$key.'-weekday=';
                $request .= $line['weekday'];
                $request .= '&'.$key.'-command=';
                $request .= urlencode($line['command']);
            }
        }
        if ($repsonse = file_get_contents($url.$request))
        {
            return true;
        }
    }
}// END Cpanel class
/* End of file cpanel.php */
/* Location: ./system/application/libraries/cpanel.php */


Messages In This Thread
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 10-02-2009, 08:22 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 10-21-2009, 05:18 PM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 10-22-2009, 06:00 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 10-22-2009, 08:16 PM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-29-2009, 01:58 PM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-29-2009, 01:58 PM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-29-2009, 10:07 PM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-30-2009, 05:17 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-30-2009, 06:19 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-30-2009, 06:24 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-30-2009, 06:30 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-30-2009, 06:42 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 11-30-2009, 06:49 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 12-01-2009, 05:51 AM
[Updated!] Cpanel library (Supports email & Cron) - by El Forum - 08-04-2011, 03:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB