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; }
define('AMPREMOTE_PHP', true); require 'ampoliros.php'; $amp = Ampoliros::instance('Ampoliros'); $amp->setMode(Ampoliros::MODE_ROOT); $amp->setInterface(Ampoliros::INTERFACE_REMOTE); OpenLibrary('xmlrpc.library'); OpenLibrary('misc.library'); $env['db'] = $GLOBALS['gEnv']['root']['db']; $GLOBALS['gEnv']['remote']['methods'] = array(); $xuser = new XmlRpcUser($GLOBALS['gEnv']['root']['db']); if ($xuser->SetByAccount($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) { $GLOBALS['gEnv']['remote']['user'] = $_SERVER['PHP_AUTH_USER']; $GLOBALS['gEnv']['remote']['profile'] = $xuser->mProfileId; if ($xuser->mSiteId) { $site_query = $GLOBALS['gEnv']['root']['db']->Execute('SELECT siteid FROM sites WHERE id=' . $xuser->mSiteId); if ($site_query->NumRows()) { $amp = Ampoliros::instance('Ampoliros'); $amp->startSite($site_query->Fields('siteid')); } } $xprofile = new XmlRpcProfile($GLOBALS['gEnv']['root']['db'], $GLOBALS['gEnv']['remote']['profile']); $GLOBALS['gEnv']['remote']['methods'] = $xprofile->AvailableMethods(); } else { if ($GLOBALS['gEnv']['core']['config']->Value('ALERT_ON_WRONG_REMOTE_LOGIN') == '1') { import('com.solarix.ampoliros.security.SecurityLayer'); $amp_security = new SecurityLayer(); $amp_security->SendAlert('Wrong remote login for user ' . $_SERVER['PHP_AUTH_USER'] . ' from remote address ' . $_SERVER['REMOTE_ADDR']); unset($amp_security); } } }
function DoAuth($wrong = false, $reason = '') { global $gEnv; $amp_locale = new Locale('amp_misc_auth', AMP_LANG); $amp = Ampoliros::instance('Ampoliros'); $amp->startRoot(); $hui = new Hui($gEnv['root']['db']); $hui->LoadWidget('button'); $hui->LoadWidget('formarg'); $hui->LoadWidget('form'); $hui->LoadWidget('grid'); $hui->LoadWidget('horizbar'); $hui->LoadWidget('horizframe'); $hui->LoadWidget('horizgroup'); $hui->LoadWidget('image'); $hui->LoadWidget('label'); $hui->LoadWidget('link'); $hui->LoadWidget('page'); $hui->LoadWidget('sessionkey'); $hui->LoadWidget('statusbar'); $hui->LoadWidget('string'); $hui->LoadWidget('submit'); $hui->LoadWidget('titlebar'); $hui->LoadWidget('vertframe'); $hui->LoadWidget('vertgroup'); $hui_page = new HuiPage('loginpage', array('title' => $amp_locale->GetStr('amplogin'), 'border' => 'false')); $hui_topgroup = new HuiVertGroup('topgroup', array('align' => 'center', 'groupalign' => 'center', 'groupvalign' => 'middle', 'height' => '100%')); $hui_maingroup = new HuiVertGroup('maingroup', array('align' => 'center')); $hui_titlebar = new HuiTitleBar('titlebar', array('title' => $amp_locale->GetStr('amplogin'), 'closewidget' => 'false', 'newwindowwidget' => 'false')); $hui_mainbframe = new HuiVertFrame('vframe', array('align' => 'center')); $hui_mainframe = new HuiHorizGroup('horizframe'); $hui_mainstatus = new HuiStatusBar('mainstatusbar'); // Main frame // $hui_grid = new HuiGrid('grid', array('rows' => '2', 'cols' => '2')); $hui_grid->AddChild(new HuiLabel('usernamelabel', array('label' => $amp_locale->GetStr('username'))), 0, 0); $hui_grid->AddChild(new HuiString('username', array('disp' => 'login')), 0, 1); $hui_grid->AddChild(new HuiLabel('passwordlabel', array('label' => $amp_locale->GetStr('password'))), 1, 0); $hui_grid->AddChild(new HuiString('password', array('disp' => 'login', 'password' => 'true')), 1, 1); $hui_vgroup = new HuiVertGroup('vertgroup', array('align' => 'center')); //$hui_vgroup->AddChild( new HuiLabel( 'titlelabel', array( 'label' => $amp_locale->GetStr( 'amprootlogin' ) ) ) ); $hui_vgroup->AddChild($hui_grid); $hui_vgroup->AddChild(new HuiSubmit('submit', array('caption' => $amp_locale->GetStr('enter')))); $form_events_call = new HuiEventsCall(); $form_events_call->AddEvent(new HuiEvent('login', 'login', '')); $form_events_call->AddEvent(new HuiEvent('main', 'default', '')); $hui_form = new HuiForm('form', array('action' => $form_events_call->GetEventsCallString())); $hui_hgroup = new HuiHorizGroup('horizgroup', array('align' => 'middle')); // $hui_hgroup -> AddChild(new HuiButton('amplogo', array('image' => $hui_page -> mThemeHandler -> mStyle['middot'], 'action' => AMP_URL, 'highlight' => false))); $hui_hgroup->AddChild(new HuiButton('password', array('themeimage' => 'password', 'themeimagetype' => 'big', 'action' => AMP_URL, 'highlight' => false))); $hui_hgroup->AddChild($hui_vgroup); $hui_form->AddChild($hui_hgroup); $hui_mainframe->AddChild($hui_form); // Wrong account check // if ($wrong) { if ($gEnv['core']['config']->Value('ALERT_ON_WRONG_LOCAL_USER_LOGIN') == '1') { Carthag::import('com.solarix.ampoliros.security.SecurityLayer'); global $login_disp; $event_data = $login_disp->GetEventData(); $amp_security = new SecurityLayer(); $amp_security->SendAlert('Wrong user local login for user ' . $event_data['username'] . ' from remote address ' . $_SERVER['REMOTE_ADDR']); $amp_security->LogFailedAccess($event_data['username'], false, $_SERVER['REMOTE_ADDR']); unset($amp_security); } $sleep_time = $gEnv['core']['config']->Value('WRONG_LOGIN_DELAY'); if (!strlen($sleep_time)) { $sleep_time = 1; } $max_attempts = $gEnv['core']['config']->Value('MAX_WRONG_LOGINS'); if (!strlen($max_attempts)) { $max_attempts = 3; } sleep($sleep_time); if (isset($_SESSION['site_login_attempts'])) { $_SESSION['site_login_attempts']++; if ($_SESSION['site_login_attempts'] >= $max_attempts) { AmpDie($amp_locale->GetStr('wrongpwd')); } } else { $_SESSION['site_login_attempts'] = 1; } if ($reason) { $hui_mainstatus->mArgs['status'] = $amp_locale->GetStr($reason); } else { $hui_mainstatus->mArgs['status'] = $amp_locale->GetStr('wrongpwd'); } } else { $_SESSION['site_login_attempts'] = 0; } // Page render // $hui_maingroup->AddChild($hui_titlebar); //$hui_maingroup->AddChild( new HuiButton( 'amplogo', array( 'image' => CGI_URL.'ampbigdot.gif', 'action' => AMP_URL ) ) ); $hui_mainbframe->AddChild($hui_mainframe); $hui_mainbframe->AddChild(new HuiHorizBar('hb')); $hui_mainbframe->AddChild(new HuiLink('copyright', array('label' => $amp_locale->GetStr('auth_copyright.label'), 'link' => 'http://www.solarix.it/', 'target' => '_blank'))); $hui_maingroup->AddChild($hui_mainbframe); $hui_maingroup->AddChild($hui_mainstatus); $hui_topgroup->AddChild($hui_maingroup); $hui_page->AddChild($hui_topgroup); $hui->AddChild($hui_page); $hui->Render(); $carthag = Carthag::instance(); $carthag->halt(); }
public function remove() { $result = false; $hook = new Hook($this->ampdb, 'ampoliros', 'site.remove'); if ($hook->CallHooks('calltime', $this, '') == HOOK_RESULT_OK) { $query = $this->ampdb->Execute('SELECT * ' . 'FROM sites ' . 'WHERE id=' . (int) $this->siteserial); $data = $query->Fields(); // Disables all modules // $this->DisableAllModules($this->siteserial); $args['dbname'] = $data['sitedbname']; $args['dbhost'] = $data['sitedbhost']; $args['dbport'] = $data['sitedbport']; $args['dbuser'] = $data['sitedbuser']; $args['dbpass'] = $data['sitedbpass']; $args['dbtype'] = $data['sitedbtype']; $args['dblog'] = $data['sitedblog']; $this->sitedb->Close(); $this->sitedb->DropDB($args); // Remove cached items // Carthag::import('com.solarix.ampoliros.datatransfer.cache.CacheGarbageCollector'); $cache_gc = new CacheGarbageCollector(); $cache_gc->RemoveSiteItems((int) $data['id']); // Removes site users // $this->RemoveAllUsers(); // Removes site from amp database // $this->ampdb->Execute('DELETE FROM sites ' . 'WHERE id=' . (int) $data['id']); $this->ampdb->Execute('DELETE FROM disabledsubmodules ' . 'WHERE siteid=' . $this->siteserial); import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent($data['siteid'], 'Removed site ' . $data['siteid'], LOGGER_NOTICE); if (!empty($data['siteid'])) { RecRemoveDir(SITESTUFF_PATH . $data['siteid']); } if ($hook->CallHooks('siteremoved', $this, '') == HOOK_RESULT_OK) { $result = true; } global $gEnv; if ($gEnv['core']['config']->Value('ALERT_ON_SITE_OPERATION') == '1') { Carthag::import('com.solarix.ampoliros.security.SecurityLayer'); $amp_security = new SecurityLayer(); $amp_security->SendAlert('Site ' . $data['siteid'] . ' has been removed'); unset($amp_security); } } return $result; }