Exemplo n.º 1
0
 function display($var)
 {
     if ($var === 'state') {
         if ($this->resourcepriv === '-') {
             return 'ok';
         }
         if ($this->resourceused === 'NA') {
             return 'ok';
         }
         if (isQuotaGreaterThanOrEq($this->resourceused, $this->resourcepriv)) {
             return 'exceed';
         }
         return 'ok';
     }
     if (($this->vv === 'disk' || $this->vv === 'lvm' || cse($this->vv, "usage")) && ($var === 'resourceused' || $var === 'resourcepriv')) {
         return $this->privdisplay($this->vv, $var, $this->{$var});
     }
     return $this->{$var};
 }
Exemplo n.º 2
0
function do_desc_add($object, $class, $param)
{
    global $gbl, $sgbl, $login, $ghtml;
    $quotaclass = exec_class_method($class, "getquotaclass", $class);
    $numvar = "{$quotaclass}_num";
    $qobject = $object->getClientParentO();
    dprint($qobject->getClname());
    if ($qobject->isQuotaVariable($numvar)) {
        if (isQuotaGreaterThanOrEq($qobject->used->{$numvar}, $qobject->priv->{$numvar})) {
            throw new lxException("Quota Exceeded for {$class}", 'nname', $numvar);
        }
    }
    /*
    	$list = $qobject->getQuotaVariableList();
    	foreach((array) $list as $l => $v) {
    		if (csb($l, "{$class}_m_")) {
    			$license = strtil(strfrom($l, "_n_"), "_num");
    			$licvar = strtil(strfrom($l, "_m_"), "_n_");
    			if (isset($param[$licvar]) && $param[$licvar] === $license) {
    				if (isQuotaGreaterThanOrEq($qobject->used->$l, $qobject->priv->$l)) {
    					throw new lxException("Quota Exceeded for $class $licvar.$license", 'nname', $numvar);
    				}
    			}
    		}
    	}
    */
    // Setting it here itself so that the add can override if necessary. This is done in tickets, where the parent is always the admin.
    $param['parent_clname'] = $object->getClName();
    // In the case of mailaccount, the real parent is mmail, while the object is added to client.
    if (isset($param['real_clparent_f'])) {
        $parent_class = exec_class_method($class, 'defaultParentClass', $object);
        $param['parent_clname'] = createParentName($parent_class, $param['real_clparent_f']);
    }
    $param = exec_class_method($class, 'Add', $object, $class, $param);
    // First loop to create a unique nname if applicable.... FOr the 'unique-nname-creation' to work in the second loop, the variables must be resolved before that... So this extra looping...
    foreach ($param as $k => $v) {
        if (csb($k, "__v_") || csb($k, "__m_")) {
            continue;
        }
        $object->resolve_class_differences($class, $k, $dclass, $dk);
    }
    foreach ($param as $k => $v) {
        if (csb($k, "__v_") || csb($k, "__m_")) {
            continue;
        }
        $object->resolve_class_heirarchy($class, $k, $dclass, $dk);
        $object->resolve_class_differences($class, $k, $ddclass, $ddk);
        $nnamevar = get_real_class_variable($ddclass, "__rewrite_nname_const");
        if ($nnamevar) {
            $nnamelist = null;
            foreach ($nnamevar as $n) {
                $nnamelist[] = $param[$n];
            }
            $nparam[$dclass]['nname'] = implode($sgbl->__var_nname_impstr, $nnamelist);
        }
        $nparam[$dclass][$dk] = $v;
    }
    // First Pass
    foreach ($nparam as $k => $v) {
        if (csa($k, "_s_")) {
            continue;
        }
        if ($k === 'priv') {
            $olist[$k] = new priv(null, null, $nparam[$class]['nname']);
            check_priv($object, $class, $olist[$k], $v);
            continue;
        }
        if ($k === 'used') {
            $olist[$k] = new Used(null, null, $nparam[$class]['nname']);
            $olist[$k]->create($v);
            continue;
        }
        if ($k === 'listpriv') {
            //$olist[$k] = new listpriv($object->__masterserver, null, $class . "_s_vv_p_" . $nparam[$class]['nname']);
            $olist[$k] = new listpriv($object->__masterserver, null, $class . "-" . $nparam[$class]['nname']);
            check_listpriv($object, $class, $olist[$k], $v);
            continue;
        }
        if (csa($k, "_b")) {
            $olist[$k] = new $k($object->__masterserver, null, $nparam[$class]['nname']);
        } else {
            $olist[$k] = new $k($object->__masterserver, null, $v['nname']);
        }
        $olist[$k]->inheritSyncServer($object);
        $olist[$k]->initThisDef();
        $olist[$k]->create($v);
        // The createsyncclass needs the syncserver variable to be set. Which may not be available. So we have to run this again.
        if ($olist[$k]->hasDriverClass()) {
            $olist[$k]->createSyncClass();
        }
    }
    // The main object has to inherit the masterserver here itself, so that its children will inherit it later when they are added through addobject.
    if (!cse($class, "_a") && exec_class_method($class, "isDatabase") && exists_in_db($object->__masterserver, $class, $olist[$class]->nname)) {
        // If the parent is getting added too, then that means we are in the client add page, and thus the variable is vps_name, domain_name rather than nname.
        if ($object->dbaction === 'add') {
            $vname = "{$class}_name";
        } else {
            $vname = "nname";
        }
        throw new lxException("{$olist[$class]->nname}+already+exists+in+{$class}.", $vname, $class);
    }
    //Second Pass...
    foreach ($nparam as $k => $v) {
        if (!csa($k, "_s_") && !csa($k, "-")) {
            continue;
        }
        $clist = explode("_s_", $k);
        $k = $clist[1];
        $cl = $clist[0];
        $nolist[$k] = new $k($object->__masterserver, null, $v['nname']);
        $nolist[$k]->inheritSyncServer($olist[$cl]);
        $nolist[$k]->initThisDef();
        $nolist[$k]->create($v);
        // The createsyncclass needs the syncserver variable to be set. Which may not be available. So we have to run this again.
        if ($nolist[$k]->hasDriverClass()) {
            $nolist[$k]->createSyncClass();
        }
        $olist[$cl]->addObject($k, $nolist[$k]);
    }
    foreach ($olist as $k => $v) {
        if (cse($k, "_b") || $k === 'used' || $k === 'priv' || $k === 'listpriv') {
            $olist[$class]->{$k} = $v;
            continue;
        }
        if ($k != $class) {
            $olist[$class]->addObject($k, $v);
            continue;
        }
    }
    if (isset($param['__v_priv'])) {
        $olist[$class]->priv = $param['__v_priv'];
    }
    if (isset($param['__v_listpriv'])) {
        $olist[$class]->listpriv = $param['__v_listpriv'];
    }
    //$olist[$class]->parent_clname = $object->getClName();
    $rparent = $object;
    $olist[$class]->__parent_o = $rparent;
    $olist[$class]->postAdd();
    $rparent->addToList($class, $olist[$class]);
    $olist[$class]->superPostAdd();
    //dprintr($object);
    notify_admin("add", $object, $olist[$class]);
    do_actionlog($login, $olist[$class], "add", "");
    //This shouldn't happen here. This should be done only after the synctosystem since, the sync can fail and the write may not happen at all.
    //$olist[$class]->changeUsedFromParentAll();
    dprint($olist[$class]->getParentO());
}
Exemplo n.º 3
0
 function updateBackupRestore($param, $type)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $stagevar = $type . "stage";
     if ($this->getParentO()->checkIfLockedForAction($type)) {
         $message = "{$type}_is_going_on";
         throw new lxException($message, '');
     }
     $bpath = "__path_program_home/{$this->getParentO()->get__table()}/{$this->getParentO()->nname}/__backup";
     $parent = $this->getParentO();
     if ($type === 'backup') {
         if ($parent->get__table() === 'vps') {
             $num = rl_exec_get(null, $parent->syncserver, "get_total_files_in_directory", array($bpath));
             if (isQuotaGreaterThanOrEq($num, $parent->priv->backup_num)) {
                 throw new lxException("backup_number_exceeded", '', "{$num} greater than {$parent->priv->backup_num}");
             }
         }
     }
     // There is a timing issue here. The backup.php program should be run only AFTEr the update is fully complete.
     foreach ($param as $k => $v) {
         $this->{$k} = $v;
     }
     $this->{$stagevar} = 'doing';
     $this->backuptype = $type;
     $this->metadbaction = 'writeonly';
     $this->dbaction = 'update';
     if ($this->backuptype === 'backup') {
         rl_exec_get(null, null, array("lxbackup", "execbackupphp"), array($this->getParentClass(), $this->getParentName(), $param));
         $this->write();
         throw new lxException("backup_has_been_scheduled", '');
     } else {
         $bpath = "__path_program_home/{$this->getParentO()->get__table()}/{$this->getParentO()->nname}/__backup";
         $fname = $param['backup_from_file_f'];
         $fname = str_replace("/", "", $fname);
         $fname = str_replace(";", "", $fname);
         $fname = str_replace(" ", "", $fname);
         $file = "{$bpath}/{$fname}";
         rl_exec_get(null, null, array("lxbackup", "execrestorephp"), array($this->getParentClass(), $this->getParentName(), $file, $param));
         $url = $ghtml->getFullUrl('a=show');
         $gbl->__this_redirect = "{$url}&frm_smessage=restore_started";
         $this->write();
         return null;
     }
 }