public function shutdown() { global $gEnv; if ($this->state != Ampoliros::STATE_SETUP) { import('com.solarix.ampoliros.util.Hook'); $reg = Registry::instance(); $hook = new Hook($reg->getEntry('amp.root.db'), 'ampoliros', 'instance'); switch ($hook->CallHooks('shutdown', $null, '')) { case Hook::RESULT_ABORT: $this->abort('Shutdown aborted'); break; } } switch ($this->state) { case Ampoliros::STATE_DEBUG: if (is_object($gEnv['runtime']['debug']['loadtime'])) { $gEnv['runtime']['debug']['loadtime']->Mark('end'); if (function_exists('memory_get_usage')) { $gEnv['runtime']['debug']['memoryusage'] = memory_get_usage(); } import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger($gEnv['root']['log']); $log->LogEvent('ampoliros', 'Profiler total time: ' . $gEnv['runtime']['debug']['loadtime']->GetTotalTime(), LOGGER_DEBUG); if ($fh = @fopen(TMP_PATH . 'pids/' . $this->pid, 'w')) { $defined_functions = get_defined_functions(); @fwrite($fh, serialize(array('gEnv' => $gEnv, 'classes' => get_declared_classes(), 'functions' => $defined_functions['user'], 'extensions' => get_loaded_extensions(), 'includedfiles' => get_included_files()))); @fclose($fh); } } break; } if ($this->state != Ampoliros::STATE_DEBUG and file_exists(TMP_PATH . 'pids/' . $this->pid)) { @unlink(TMP_PATH . 'pids/' . $this->pid); } $carthag = Carthag::instance(); $carthag->halt(); }
public function removeGroup($deleteuserstoo) { $result = false; import('com.solarix.ampoliros.util.Hook'); $hook = new Hook($this->mrAmpDb, 'ampoliros', 'site.group.remove'); if ($hook->CallHooks('calltime', $this, array('siteserial' => $this->siteserial, 'groupid' => $this->groupid)) == HOOK_RESULT_OK) { if ($this->groupid != 0) { if ($this->mrSiteDb->Execute('DELETE FROM groups ' . 'WHERE id=' . (int) $this->groupid)) { // Check if we must delete users in this group if ($deleteuserstoo == true) { $usersquery =& $this->mrAmpDb->Execute('SELECT id ' . 'FROM users ' . 'WHERE siteid=' . (int) $this->siteserial . ' AND groupid=' . (int) $this->groupid); $numusers = $usersquery->NumRows(); if ($numusers > 0) { // Remove users in this group while (!$usersquery->eof) { $usdata = $usersquery->Fields(); Carthag::import('com.solarix.ampoliros.site.user.User'); $tmpuser = new user($this->mrAmpDb, $this->siteserial, $usdata['id']); $tmpuser->removeuser(); $usersquery->MoveNext(); //delete $tmpuser; } } } else { $this->mrAmpDb->Execute("UPDATE users SET groupid = '0' WHERE groupid=" . (int) $this->groupid . ' AND siteid =' . $this->siteserial); } if ($hook->CallHooks('groupremoved', $this, array('siteserial' => $this->siteserial, 'groupid' => $this->groupid)) != HOOK_RESULT_OK) { $result = false; } $this->groupid = 0; } } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.users_library.group_class.removegroup', "Attempted to call a member of an object that doesn't refer to any group", LOGGER_ERROR); } } return $result; }
public function removeUser() { import('com.solarix.ampoliros.util.Hook'); $hook = new Hook($this->mrAmpDb, 'ampoliros', 'site.user.remove'); if ($hook->CallHooks('calltime', $this, array('siteserial' => $this->siteserial, 'userid' => $this->userid)) == HOOK_RESULT_OK) { if ($this->userid != 0) { $result = $this->mrAmpDb->Execute('DELETE FROM users ' . 'WHERE siteid=' . (int) $this->siteserial . ' ' . 'AND id=' . (int) $this->userid); // Remove user dir $site_query =& $GLOBALS['gEnv']['root']['db']->Execute('SELECT siteid ' . 'FROM sites ' . 'WHERE id=' . (int) $this->siteserial); OpenLibrary('misc.library'); if (SITESTUFF_PATH . $site_query->Fields('siteid') . '/users/' . $this->username != SITESTUFF_PATH . $site_query->Fields('siteid') . '/users/') { RecRemoveDir(SITESTUFF_PATH . $site_query->Fields('siteid') . '/users/' . $this->username, 0755); } // Remove cached items Carthag::import('com.solarix.ampoliros.datatransfer.cache.CacheGarbageCollector'); $cache_gc = new CacheGarbageCollector(); $cache_gc->RemoveUserItems((int) $this->userid); //$this->htp->remuser( $this->username ); if ($hook->CallHooks('userremoved', $this, array('siteserial' => $this->siteserial, 'userid' => $this->userid)) != HOOK_RESULT_OK) { $result = false; } $this->userid = 0; } } return $result; }
function Disable($siteid) { $result = FALSE; import('com.solarix.ampoliros.util.Hook'); $hook = new Hook($this->ampdb, 'ampoliros', 'module.disable'); if ($hook->CallHooks('calltime', $this, array('siteserial' => $siteid, 'modserial' => $this->serial)) == HOOK_RESULT_OK) { if ($this->serial) { // Checks if the module exists in modules table // $modquery =& $this->ampdb->Execute('SELECT * FROM modules WHERE id=' . (int) $this->serial); if ($modquery->NumRows() == 1) { $moddata = $modquery->Fields(); if ($moddata['onlyextension'] != $this->ampdb->fmttrue) { // Checks if the structure file still exists // if (file_exists(MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE)) { $this->modname = $moddata['modid']; $sitequery = $this->ampdb->Execute('SELECT * FROM sites WHERE id=' . $this->ampdb->Format_Text((int) $siteid)); $sitedata = $sitequery->Fields(); $args['dbtype'] = $sitedata['sitedbtype']; $args['dbname'] = $sitedata['sitedbname']; $args['dbhost'] = $sitedata['sitedbhost']; $args['dbport'] = $sitedata['sitedbport']; $args['dbuser'] = $sitedata['sitedbuser']; $args['dbpass'] = $sitedata['sitedbpassword']; $args['dblog'] = $sitedata['sitedblog']; import('com.solarix.ampoliros.db.DBLayerFactory'); $db_fact = new DBLayerFactory(); $this->sitedb = $db_fact->NewDBLayer($args); $this->sitedb->Connect($args); // Dependencies check // $this->unmetdeps = array(); $this->unmetsuggs = array(); $moddeps = new ModuleDep($this->ampdb); $pendingdeps = $moddeps->CheckSiteDependingModules($this->modname, $sitedata['siteid'], FALSE); $modenabled = $moddeps->IsEnabled($this->modname, $sitedata['siteid']); // If dependencies are ok, go on // if ($pendingdeps == FALSE and $modenabled == TRUE) { $result = $this->HandleStructure(MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE, Module::INSTALL_MODE_DISABLE, MODULE_PATH . $moddata['modid'] . '/', $siteid); $modquery = $this->ampdb->Execute('SELECT id FROM modules WHERE modid=' . $this->ampdb->Format_Text($this->modname)); $this->ampdb->Execute('DELETE FROM activemodules WHERE moduleid=' . (int) $this->serial . ' AND siteid=' . $this->ampdb->Format_Text($siteid)); $this->ampdb->Execute('DELETE FROM disabledsubmodules WHERE moduleid=' . (int) $this->serial . ' AND siteid=' . (int) $siteid); if ($GLOBALS['gEnv']['core']['config']->Value('ALERT_ON_MODULE_SITE_OPERATION') == '1') { Carthag::import('com.solarix.ampoliros.security.SecurityLayer'); $amp_security = new SecurityLayer(); $amp_security->SendAlert('Module ' . $moddata['modid'] . ' has been disabled from site ' . $sitedata['siteid']); unset($amp_security); } if ($hook->CallHooks('moduledisabled', $this, array('siteserial' => $siteid, 'modserial' => $this->serial)) != HOOK_RESULT_OK) { $result = false; } } else { if ($modenabled == FALSE) { } else { $this->unmetdeps = $pendingdeps; } } //if ( $result == TRUE ) $this->mLog->LogEvent( 'Ampoliros', 'Uninstalled module '.$this->modname, LOGGER_NOTICE ); $sitequery->Free(); } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Structure file ' . MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE . ' for module ' . $moddata['modid'] . ' was not found', LOGGER_ERROR); } } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Tried to disable module ' . $moddata['modid'] . ', but it is an extension only module', LOGGER_ERROR); } } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'A module with serial ' . $this->serial . ' was not found in modules table', LOGGER_ERROR); } $modquery->Free(); } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Empty module serial', LOGGER_ERROR); } } return $result; }
function Rename($profileName) { $result = false; $hook = new Hook($this->mAmpDb, 'ampoliros', 'xmlrpcprofile.rename'); if ($hook->CallHooks('calltime', $this, array('name' => $profileName)) == HOOK_RESULT_OK) { if ($this->mAmpDb) { if ($this->mProfileId) { if (strlen($profileName)) { // Removes the profile // $result = $this->mAmpDb->Execute('UPDATE xmlrpcprofiles ' . 'SET profilename=' . $this->mAmpDb->Format_Text($profileName) . ' ' . 'WHERE id=' . (int) $this->mProfileId); $hook->CallHooks('profilerenamed', $this, array('name' => $profileName)); } else { $this->mLog->LogEvent('ampoliros.xmlrpc_library.xmlrpcprofile_class.rename', 'Empty new profile name', LOGGER_ERROR); } } else { $this->mLog->LogEvent('ampoliros.xmlrpc_library.xmlrpcprofile_class.rename', 'Object not assigned to a profile', LOGGER_ERROR); } } else { $this->mLog->LogEvent('ampoliros.xmlrpc_library.xmlrpcprofile_class.rename', 'Invalid Ampoliros database handler', LOGGER_ERROR); } } return $result; }
function Update($name, $host = 'localhost', $port = '80', $cgi = '', $username = '', $password = '', $proxy = '', $proxyPort = '') { $result = false; $hook = new Hook($this->mrAmpDb, 'ampoliros', 'xmlrpcaccount.update'); if ($hook->CallHooks('calltime', $this, array('name' => $name, 'host' => $host, 'port' => $port, 'cgi' => $cgi, 'username' => $username, 'password' => $password)) == HOOK_RESULT_OK) { if ($this->mId) { if (strlen($name)) { $result =& $this->mrAmpDb->Execute('UPDATE xmlrpcaccounts ' . 'SET ' . 'name=' . $this->mrAmpDb->Format_Text($name) . ',' . 'host=' . $this->mrAmpDb->Format_Text($host) . ',' . 'cgi=' . $this->mrAmpDb->Format_Text($cgi) . ',' . 'port=' . $this->mrAmpDb->Format_Text($port) . ',' . 'username='******',' . 'password='******',' . 'proxy=' . $this->mrAmpDb->Format_Text($proxy) . ',' . 'proxyport=' . $this->mrAmpDb->Format_Text($proxyPort) . ' ' . 'WHERE id=' . (int) $this->mId); if ($result) { if ($hook->CallHooks('accountudpated', $this, array('name' => $name, 'host' => $host, 'port' => $port, 'cgi' => $cgi, 'username' => $username, 'password' => $password, 'id' => $this->mId)) != HOOK_RESULT_OK) { $result = false; } } else { $result = AMPOLIROS_XMLRPCACCOUNT_UPDATE_UNABLE_TO_UPDATE_ACCOUNT; } } else { $result = AMPOLIROS_XMLRPCACCOUNT_UPDATE_EMPTY_ACCOUNT_NAME; } } else { $result = AMPOLIROS_XMLRPCACCOUNT_REMOVE_EMPTY_ACCOUNT_ID; } } return $result; }
public function disableModule($modid) { $result = false; $hook = new Hook($this->ampdb, 'ampoliros', 'site.module.disable'); if ($hook->CallHooks('calltime', $this, array('siteserial' => $this->siteserial, 'modid' => $modid)) == HOOK_RESULT_OK) { if (!empty($this->sitedb) and !empty($modid) and $this->IsModuleEnabled($modid)) { OpenLibrary('modulesbase.library'); $modquery =& $this->ampdb->Execute('SELECT modid ' . 'FROM modules ' . 'WHERE id=' . (int) $modid); $tmpmod = new Module($this->ampdb, $modid); if ($tmpmod->Disable($this->siteserial)) { if ($hook->CallHooks('moduledisabled', $this, array('siteserial' => $this->siteserial, 'modid' => $modid)) == HOOK_RESULT_OK) { $result = true; } import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent($this->siteid, 'Disabled module ' . $modquery->Fields('modid'), LOGGER_NOTICE); $this->sitelog->LogEvent($this->siteid, 'Disabled module ' . $modquery->Fields('modid'), LOGGER_NOTICE); } $this->unmetdeps = $tmpmod->GetLastActionUnmetDeps(); } } return $result; }