/**
  * Parses Module registry from local file or from remote peer
  *
  * @param string $host the host from which the registry has to be loaded (if null regitry is loaded locally)
  * @param string $port the port on the remote host (if null regitry is loaded locally)
  * @since 5.1
  * @return void
  */
 public function parseRegistry($host = null, $port = null)
 {
     $context = \Innomatic\Module\Server\ModuleServerContext::instance('\\Innomatic\\Module\\Server\\ModuleServerContext');
     $mode = $context->getConfig()->getKey('load_services_register');
     if ($host == null || $port == null) {
         //loading registry for the first time
         if ($mode == 'local') {
             print 'Module: services-extension loading netregistry locally' . "\n";
             $this->loadLocalRegistry('modules-netregistry.xml');
         } elseif ($mode == 'remote') {
             $r_address = $context->getConfig()->getKey('remote_address');
             $r_port = $context->getConfig()->getKey('remote_port');
             print "Module: services-extension loading netregistry from {$r_address}:{$r_port}" . "\n";
             $this->downloadRemoteRegistry($r_address, $r_port);
             $this->loadLocalRegistry('modules-netregistry-remote.xml');
         } else {
             Carthag::instance()->halt("error: check .ini file");
         }
     } else {
         //refreshing registry after a modification of the peers (es. ping timeout)
         print "Module: services-extension refreshing net-registry from {$host}:{$port}" . "\n";
         $this->downloadRemoteRegistry($host, $port);
         $this->loadLocalRegistry('modules-netregistry-remote.xml');
     }
 }
Ejemplo n.º 2
0
 public function AmpConfig($configFile)
 {
     // Checks to see if the file is there
     if (file_exists($configFile)) {
         $fp = @fopen($configFile, 'r');
         if ($fp) {
             $this->mConfigFile = $configFile;
             $this->mOpened = true;
             while ($fl = @fgets($fp)) {
                 $trimmed_line = trim($fl);
                 if (substr($trimmed_line, 0, 1) != '#' and substr($trimmed_line, 0, 1) != ';' and strpos($trimmed_line, '=')) {
                     $key = substr($trimmed_line, 0, strpos($trimmed_line, '='));
                     $value = substr($trimmed_line, strpos($trimmed_line, '=') + 1);
                     $this->mConfigValues[trim($key)] = trim($value);
                 }
             }
             @fclose($fp);
         } else {
             $carthag = Carthag::instance();
             $carthag->halt('Could not open ' . $configFile);
         }
     } else {
         $carthag = Carthag::instance();
         $carthag->halt('Configuration file ' . $configFile . " doesn't exists");
     }
 }
Ejemplo n.º 3
0
 public function huiXml($elemName, $elemArgs = '', $elemTheme = '', $dispEvents = '')
 {
     $this->HuiWidgetElement($elemName, $elemArgs, $elemTheme, $dispEvents);
     if (isset($this->mArgs['definitionfile']) and file_exists($this->mArgs['definitionfile'])) {
         $this->mDefinitionFile = $this->mArgs['definitionfile'];
         if (file_exists($this->mDefinitionFile)) {
             $this->mDefinition = file_get_contents($this->mDefinitionFile);
         }
     } else {
         if (isset($this->mArgs['definition'])) {
             $this->mDefinition =& $this->mArgs['definition'];
         }
     }
     $this->carthag = Carthag::instance();
     $this->cl = $this->carthag->getClassLoader();
 }
Ejemplo n.º 4
0
 public function onReceiveData($clientId = null, $data = null)
 {
     //print('dati ricevuti');
     $response = new \Innomatic\Modules\Server\ModuleServerResponse();
     $raw_request = explode("\n", $data);
     $headers = array();
     $body = '';
     $body_start = false;
     $command_line = '';
     foreach ($raw_request as $line) {
         $line = trim($line);
         if (!$body_start and $line == '') {
             $body_start = true;
             continue;
         }
         if ($body_start) {
             $body .= $line . "\n";
         } else {
             if (strlen($command_line)) {
                 $headers[substr($line, 0, strpos($line, ':'))] = trim(substr($line, strpos($line, ':') + 1));
             } else {
                 $command_line = $line;
             }
         }
     }
     if (!isset($headers['User'])) {
         $headers['User'] = '';
     }
     if (!isset($headers['Password'])) {
         $headers['Password'] = '';
     }
     if ($this->authenticator->authenticate($headers['User'], $headers['Password'])) {
         $command = explode(' ', $command_line);
         switch ($command[0]) {
             case 'PING':
                 if ($this->authenticator->authorizeAction($headers['User'], 'ping')) {
                     $response->setBuffer("pong. (from " . $this->bindAddress . ":" . $this->port . ")\n");
                 } else {
                     $response->sendWarning(\Innomatic\Modules\Server\ModuleServerResponse::SC_FORBIDDEN, 'Action not authorized');
                 }
                 print "I've been pinged" . "\n";
                 break;
             case 'SHUTDOWN':
                 if ($this->authenticator->authorizeAction($headers['User'], 'shutdown')) {
                     $this->serversocket->sendData($clientId, "pinger server: shuting down.\n", true);
                     print "pinger server: shuting down" . "\n";
                     Carthag::instance()->halt("pinger server: terminated.");
                 } else {
                     $response->sendWarning(\Innomatic\Modules\Server\ModuleServerResponse::SC_FORBIDDEN, 'Action not authorized');
                 }
                 break;
             default:
                 $response->sendWarning(\Innomatic\Modules\Server\ModuleServerResponse::SC_BAD_REQUEST, 'Cannot hunderstand command');
         }
     } else {
         $response->sendWarning(\Innomatic\Modules\Server\ModuleServerResponse::SC_UNAUTHORIZED, 'Authentication needed');
     }
     $this->serversocket->sendData($clientId, $response->getResponse(), true);
     $this->serversocket->closeConnection();
 }
Ejemplo n.º 5
0
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
// $Id: ampoliros.php,v 1.2 2004-07-08 15:04:25 alex Exp $
if (!defined('AMPOLIROS')) {
    define('AMPOLIROS', true);
    // Carthag
    require 'carthag.php';
    $carthag = Carthag::instance();
    $carthag->startup();
    Carthag::package('com.solarix.ampoliros');
    class main extends Object
    {
        function main($args)
        {
            include 'ampconfigpath.php';
            import('com.solarix.ampoliros.core.Ampoliros');
            $amp = Ampoliros::instance('Ampoliros');
            $amp->bootstrap(AMP_CONFIG);
        }
    }
    $carthag->runAsEmbedded();
}
Ejemplo n.º 6
0
    public function abort($text, $forceInterface)
    {
        global $gEnv;
        OpenLibrary('hui.library');
        if (strlen($forceInterface)) {
            $interface = $forceInterface;
        } else {
            $interface = $this->interface;
        }
        if ($interface == Ampoliros::INTERFACE_EXTERNAL) {
            if (isset($gEnv['runtime']['external_interface_error_handler']) and function_exists($gEnv['runtime']['external_interface_error_handler'])) {
                $func = $gEnv['runtime']['external_interface_error_handler'];
                $func($text);
            } else {
                $interface = Ampoliros::INTERFACE_WEB;
                $this->interface = Ampoliros::INTERFACE_WEB;
            }
        }
        switch ($interface) {
            case Ampoliros::INTERFACE_GUI:
            case Ampoliros::INTERFACE_UNKNOWN:
            case Ampoliros::INTERFACE_REMOTE:
            case Ampoliros::INTERFACE_EXTERNAL:
                break;
            case Ampoliros::INTERFACE_CONSOLE:
                echo "\n" . $text . "\n";
                break;
            case Ampoliros::INTERFACE_WEB:
                $reg = Registry::instance();
                $tmp_hui = new Hui($reg->getEntry('amp.root.db'));
                $tmp_hui->LoadWidget('empty');
                //$tmp_elem = new HuiEmpty('empty');
                if (is_object($gEnv['hui']['theme']['handler'])) {
                    $die_image = $gEnv['hui']['theme']['handler']->mStyle['bigdot'];
                } else {
                    $die_image = '';
                }
                ?>
 
                                                <html>
                                                <head>
                                                <basefont face="Verdana">
                                                <title>Ampoliros</title>
                                                <link rel="stylesheet" type="text/css" href="<?php 
                echo $gEnv['hui']['theme']['handler']->mStyle['css'];
                ?>
">
                                                </head>
                                                
                                                <body bgcolor="white">
                                                
                                                <table border="0" cellspacing="0" cellpadding="0" align="center" width="200">
                                                <tr>
                                                    <td align="center"><a href="<?php 
                echo AMP_URL;
                ?>
"><img src="<?php 
                echo $die_image;
                ?>
" alt="Ampoliros" border="0"></a></td>
                                                </tr>
                                                <tr>
                                                <td>&nbsp; </td>
                                                </tr>
                                                <tr>
                                                <td align="center"><?php 
                echo $text;
                ?>
</td>
                                                </tr>
                                                </table>
                                                
                                                </body>
                                                </html>
                                                <?php 
                break;
        }
        $carthag = Carthag::instance();
        $carthag->halt();
    }
Ejemplo n.º 7
0
 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();
 }
Ejemplo n.º 8
0
function main_phpinfo($eventData)
{
    phpinfo();
    $carthag = Carthag::instance();
    $carthag->halt();
}
Ejemplo n.º 9
0
 public function render()
 {
     if (!$this->mBuilt) {
         $this->Build();
     }
     if ($this->mBuilt) {
         @header('P3P: CP="CUR ADM OUR NOR STA NID"');
         $carthag = Carthag::instance();
         $carthag->out->println($this->mLayout);
         return true;
     } else {
         import('com.solarix.ampoliros.io.log.Logger');
         $log = new Logger(AMP_LOG);
         $log->LogEvent('ampoliros.hui_library.hui_class.render', 'Unable to render hui', LOGGER_ERROR);
         $this->mLastError = Hui::RENDER_UNABLE_TO_RENDER;
     }
     return false;
 }