Exemple #1
0
include_once dirname(__FILE__) . "/framework/frame.class.inc";
$users = new usersMenus();
if (!$users->kas_installed) {
    die;
}
if ($argv[1] == '--rebuild-tables') {
    rebuildtables();
    die;
}
if ($argv[1] == '--dograph') {
    dograph();
    die;
}
BuildRobots();
filter_conf();
removes();
ListOU();
BuildDefault();
shell_exec("/bin/chown mailflt3:mailflt3 /usr/local/ap-mailfilter3/conf/def/group/*");
shell_exec("/usr/local/ap-mailfilter3/bin/mkprofiles");
shell_exec("/usr/local/ap-mailfilter3/bin/kas-restart -f -p -m");
function dograph()
{
    exec("/usr/local/ap-mailfilter3/control/bin/stat -c /usr/local/ap-mailfilter3/control/stat/stat.conf >/dev/null 2>&1");
    exec("/usr/local/ap-mailfilter3/control/bin/statvisual -c /usr/local/ap-mailfilter3/control/stat/stat.conf");
}
function removes()
{
    @unlink("/usr/local/ap-mailfilter3/conf/def/common/common-allow.xml");
    shell_exec('/bin/touch /usr/local/ap-mailfilter3/conf/def/common/common-allow.xml');
    @unlink("/usr/local/ap-mailfilter3/conf/def/common/common-deny.xml");
Exemple #2
0
 /**
  * @protected
  *
  * Load task contents, remove task scripts.
  */
 function afterLoad()
 {
     // unpack uuid
     $this->uuid = util::unpackUuid($this->uuid);
     $this->nextTask = util::unpackUuid($this->nextTask);
     // note: Only users with access to nextTask has view permission.
     if (!$this->__isSuperUser) {
         // 1. Group:User
         $res = (array) @$this->__request->user->groups;
         // 2. Task:Group
         $res = Relation::getAncestors($res, Task::GROUP_RELATION);
         // 3. Task
         $res = Relation::getDescendants($res, 'Task');
         // 4. UUID comparison
         if (!in_array($this->nextTask, $res)) {
             return $this->data(array());
         }
     }
     // load task details, do not expose internal scripts
     $taskInstance = new TaskInstance();
     $this->tasks = array_map(removes('order'), $taskInstance->find(array('uuid' => $this->children($taskInstance::WORK_RELATION), '@sorter' => ['order'])));
     unset($taskInstance);
     $res = parent::afterLoad();
     // lock the item after load
     $this->_immutable = true;
     return $res;
 }
Exemple #3
0
 /**
  * Gets fields with specified key type.
  */
 public static function getFields($tables, $key = null, $nameOnly = true)
 {
     $tables = Utility::wrapAssoc($tables);
     $cache =& self::$schemaCache;
     // Clear the cache on expire
     if (@$cache['timestamp'] < strtotime('-30min')) {
         unset($cache['collections']);
         $cache['timestamp'] = microtime(1);
     }
     array_walk($tables, function ($tableName) use(&$cache) {
         if (!Database::hasTable($tableName)) {
             throw new \PDOException("Table {$tableName} doesn't exists!");
         }
         if (@$cache['collections'][$tableName]) {
             return;
         }
         $res = Database::fetchArray('SHOW COLUMNS FROM ' . static::escapeField($tableName));
         $res = array_combine(array_map(prop('Field'), $res), array_map(removes('Field'), $res));
         $res = array_map(function ($info) {
             $info['Key'] = preg_split('/\\s*,\\s*/', $info['Key']);
             foreach ($info as &$value) {
                 switch ($value) {
                     case 'YES':
                         $value = true;
                         break;
                     case 'NO':
                         $value = false;
                         break;
                 }
             }
             return $info;
         }, $res);
         $cache['collections'][$tableName] = $res;
     });
     $tables = array_map(function ($tableName) use($cache, $key, $nameOnly) {
         $cache = $cache['collections'][$tableName];
         if ($key !== null) {
             $key = Utility::wrapAssoc($key);
             $cache = array_filter($cache, propHas('Key', $key));
         }
         return $cache;
     }, $tables);
     $tables = array_reduce($tables, function ($result, $fields) {
         return array_merge($result, (array) $fields);
     }, array());
     if ($nameOnly) {
         $tables = array_unique(array_keys($tables));
     }
     return $tables;
 }
Exemple #4
0
 /**
  * Inspired by os.networkInterfaces() from node.js.
  *
  * @return {array} Returns a brief info of available network interfaces.
  */
 public static function networkInterfaces()
 {
     switch (strtoupper(PHP_OS)) {
         case 'DARWIN':
             // MAC OS X
             $res = preg_split('/\\n/', @`ifconfig`);
             $res = array_filter(array_map('trim', $res));
             $result = array();
             foreach ($res as $row) {
                 if (preg_match('/^(\\w+\\d+)\\:\\s+(.+)/', $row, $matches)) {
                     $result['__currentInterface'] = $matches[1];
                     $result[$result['__currentInterface']]['__internal'] = false !== strpos($matches[2], 'LOOPBACK');
                 } else {
                     if (preg_match('/^inet(6)?\\s+([^\\/\\s]+)(?:%.+)?/', $row, $matches)) {
                         $iface =& $result[$result['__currentInterface']];
                         @($iface[] = array('address' => $matches[2], 'family' => $matches[1] ? 'IPv6' : 'IPv4', 'internal' => $iface['__internal']));
                         unset($iface);
                     }
                 }
                 unset($matches);
             }
             unset($row, $res);
             unset($result['__currentInterface']);
             return array_filter(array_map(compose('array_filter', removes('__internal')), $result));
         case 'LINUX':
             // $ifaces = `ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\)$/d'`;
             // $ifaces = preg_split('/\s+/', $ifaces);
             $res = preg_split('/\\n/', @`ip addr`);
             $res = array_filter(array_map('trim', $res));
             $result = array();
             foreach ($res as $row) {
                 if (preg_match('/^\\d+\\:\\s+(\\w+)/', $row, $matches)) {
                     $result['__currentInterface'] = $matches[1];
                 } else {
                     if (preg_match('/^link\\/(\\w+)/', $row, $matches)) {
                         $result[$result['__currentInterface']]['__internal'] = strtolower($matches[1]) == 'loopback';
                     } else {
                         if (preg_match('/^inet(6)?\\s+([^\\/]+)(?:\\/\\d+)?.+\\s([\\w\\d]+)(?:\\:\\d+)?$/', $row, $matches)) {
                             @($result[$matches[3]][] = array('address' => $matches[2], 'family' => $matches[1] ? 'IPv6' : 'IPv4', 'internal' => Utility::cascade(@$result[$matches[3]]['__internal'], false)));
                         }
                     }
                 }
                 unset($matches);
             }
             unset($row, $res);
             unset($result['__currentInterface']);
             return array_filter(array_map(compose('array_filter', removes('__internal')), $result));
         case 'WINNT':
             // Currently not supported.
         // Currently not supported.
         default:
             return false;
     }
 }