Exemplo n.º 1
0
 /**
  * Remote procedure call.
  *
  * Execute api function.
  *
  * @param  \stdObject $cdata
  * @return array
  * @throws \CB\Controller\Exception
  */
 private function _doRpc($cdata)
 {
     $api = \CB\Config::getApiFunctions();
     if (!isset($api[$cdata['action']])) {
         throw new \CB\Controller\Exception('Call to undefined action: ' . $cdata['action']);
     }
     $action = $cdata['action'];
     $a = $api[$action];
     $this->_doAroundCalls($a['before'], $cdata);
     $method = $cdata['method'];
     $mdef = $a['methods'][$method];
     if (!$mdef) {
         throw new \CB\Controller\Exception('Call to undefined method: ' . $method . ' on action $action');
     }
     $this->_doAroundCalls($mdef['before'], $cdata);
     $r = array('type' => 'rpc', 'tid' => $cdata['tid'], 'action' => $action, 'method' => $method);
     // load api controller
     $Class = '\\CB\\Api\\' . $action;
     $Controller = $Class::getInstance();
     // build function params
     if (isset($mdef['len'])) {
         $params = isset($cdata['data']) && is_array($cdata['data']) ? $cdata['data'] : array();
     } else {
         $params = array($cdata['data']);
     }
     // prepare fields and values
     array_walk($params, function ($param) {
         (array) $param;
     });
     // call api controller function
     $r['result'] = call_user_func_array(array($Controller, $method), $params);
     $this->_doAroundCalls($mdef['after'], $cdata, $r);
     $this->_doAroundCalls($a['after'], $cdata, $r);
     return $r;
 }
Exemplo n.º 2
0
 public function getData($id = false)
 {
     $rez = array('success' => true, 'data' => array());
     parent::getData($id);
     $o = $this->getObjectClass();
     if (empty($o)) {
         return $rez;
     }
     $data = $o->getData();
     //dont display thumb for images less then 1MB
     $maxDisplaySize = Util\coalesce(Config::get('images_display_size'), 1024 * 1024);
     if (substr($data['content_type'], 0, 5) == 'image' && $data['size'] < $maxDisplaySize) {
         $preview = Files::generatePreview($data['id']);
         if (!empty($preview['filename'])) {
             $fn = Config::get('files_preview_dir') . $preview['filename'];
             $rez['data']['html'] = $fn;
             if (file_exists($fn)) {
                 $rez['data']['html'] = str_replace('fit-img', 'click fit-img', file_get_contents($fn));
             }
         }
     } else {
         $rez['data']['cls'] = 'pr-th-' . \CB\Files::getExtension($data['name']);
     }
     return $rez;
 }
Exemplo n.º 3
0
 public function getContentItems()
 {
     $p =& $this->requestParams;
     $folderTemplates = \CB\Config::get('folder_templates');
     $p['fl'] = 'id,system,path,name,case,date,date_end,size,cid,oid,cdate,uid,udate,template_id,acl_count,cls,status,task_status,dstatus';
     if (@$p['from'] == 'tree') {
         $p['templates'] = $folderTemplates;
     }
     if (is_numeric($this->lastNode->id)) {
         $p['pid'] = $pid;
     }
     $p['dstatus'] = 1;
     $p['fq'] = $this->fq;
     $s = new \CB\Search();
     $rez = $s->query($p);
     if (!empty($rez['data'])) {
         for ($i = 0; $i < sizeof($rez['data']); $i++) {
             $d =& $rez['data'][$i];
             $r = DM\Tree::read($d['id']);
             if (!empty($r)) {
                 $d['cfg'] = $r['cfg'];
                 $r = DM\Tree::getChildCount($d['id'], @$p['from'] == 'tree' ? $folderTemplates : false);
                 $d['has_childs'] = !empty($r[$d['id']]);
             }
         }
     }
     return $rez;
 }
Exemplo n.º 4
0
 /**
  * constructor
  *
  * @param string[] $p {
  *     @type boolean $host    custom Solr host or default will be used from config
  *     @type string  $port    Solr port
  *     @type string  $core    Solr core
  * }
  */
 public function __construct($p = array())
 {
     if (empty($p)) {
         // get params from core config
         $this->host = \CB\Config::get('solr_host', '127.0.0.1');
         $this->port = \CB\Config::get('solr_port', 8983);
         $this->core = \CB\Config::get('solr_core');
     } else {
         //get params from specified arguments
         $this->host = empty($p['host']) ? '127.0.0.1' : $p['host'];
         $this->port = empty($p['port']) ? 8983 : $p['port'];
         $this->core = @$p['core'];
         if (isset($p['SOLR_CLIENT'])) {
             $this->client = $p['SOLR_CLIENT'];
         }
         if (isset($p['fireEvents'])) {
             $this->fireEvents = $p['fireEvents'];
         }
     }
     if (empty($this->client)) {
         $this->client = \CB\Config::get('SOLR_CLIENT');
     }
     if (substr($this->core, 0, 6) != '/solr/') {
         $this->core = '/solr/' . $this->core;
     }
     $this->connect();
 }
Exemplo n.º 5
0
 public function getContentItems()
 {
     $p =& $this->requestParams;
     $folderTemplates = \CB\Config::get('folder_templates');
     $p['fl'] = 'id,system,path,name,case,date,date_end,size,cid,oid,cdate,uid,udate,template_id,acl_count,cls,status,task_status,dstatus';
     if (@$p['from'] == 'tree') {
         $p['templates'] = $folderTemplates;
     }
     if (is_numeric($this->lastNode->id)) {
         $p['pid'] = $pid;
     }
     $p['dstatus'] = 1;
     $p['fq'] = $this->fq;
     $s = new \CB\Search();
     $rez = $s->query($p);
     if (!empty($rez['data'])) {
         for ($i = 0; $i < sizeof($rez['data']); $i++) {
             $d =& $rez['data'][$i];
             $res = DB\dbQuery('SELECT cfg
                   , (SELECT 1
                      FROM tree
                      WHERE pid = $1' . (@$p['from'] == 'tree' ? ' AND `template_id` IN (0' . implode(',', $folderTemplates) . ')' : '') . ' LIMIT 1) has_childs
                 FROM tree
                 WHERE id = $1', $d['id']) or die(DB\dbQueryError());
             if ($r = $res->fetch_assoc()) {
                 $d['cfg'] = Util\toJSONArray($r['cfg']);
                 $d['has_childs'] = !empty($r['has_childs']);
             }
             $res->close();
         }
     }
     return $rez;
 }
Exemplo n.º 6
0
 /**
  * Get SQL log file.
  *
  * @access private
  * @return string
  */
 private function _getFile()
 {
     if (!$this->_file) {
         $this->_file = \CB\Config::get('path.root') . '/logs/doctrine_sql_' . date('Y-m-d') . '.log';
     }
     return $this->_file;
 }
Exemplo n.º 7
0
function sendUserMails($u)
{
    $uid = $u['id'];
    if (empty($u['email'])) {
        return;
    }
    $sendType = User::canSendNotifications($uid);
    if ($sendType == false) {
        return;
    }
    $coreName = Config::get('core_name');
    // $coreUrl = Config::get('core_url');
    $languages = Config::get('languages');
    $lang = $languages[$u['language_id'] - 1];
    if (filter_var($u['email'], FILTER_VALIDATE_EMAIL)) {
        //group mails into digest and separate ones (where user is mentioned)
        $mails = array('digest' => array(), 'separate' => array());
        foreach ($u['mails'] as $notificationId => $notification) {
            //[$core #$nodeId] $action_type $template_name: $object_title
            $templateId = Objects::getTemplateId($notification['object_id']);
            $templateName = Objects::getName($templateId);
            $subject = '[' . $coreName . ' #' . $notification['object_id'] . '] ' . Notifications::getActionDeclination($notification['action_type'], $lang) . ' ' . $templateName . ' "' . htmlspecialchars_decode($notification['data']['name']) . '"';
            $sender = Notifications::getSender($notification['from_user_id']);
            //divide notification into separate number of actions it consist of
            $actions = getNotificationActions($notification);
            for ($i = 0; $i < sizeof($actions); $i++) {
                $a = $actions[$i];
                $message = Notifications::getMailBodyForAction($a, $u);
                $isMentioned = !empty($a['data']['mentioned']) && in_array($uid, $a['data']['mentioned']);
                $mails[$isMentioned ? 'separate' : 'digest'][] = array('subject' => $subject, 'body' => $message, 'sender' => $sender, 'nId' => $notificationId);
            }
        }
        //merge digest emails group into one email and put it into separate group
        if (sizeof($mails['digest']) == 1) {
            $mails['separate'][] = $mails['digest'][0];
        } elseif (!empty($mails['digest'])) {
            $mail = array();
            $ids = array();
            $sender = '';
            foreach ($mails['digest'] as $m) {
                $mail[] = $m['body'];
                $sender = $m['sender'];
                $ids[] = $m['nId'];
            }
            $mails['separate'][] = array('subject' => '[' . $coreName . '] Notifications digest', 'body' => implode('<hr />', $mail), 'sender' => $sender, 'nId' => $ids);
        }
        foreach ($mails['separate'] as $mail) {
            echo $u['email'] . ': ' . $mail['subject'] . "\n";
            if (!mail($u['email'], $mail['subject'], $mail['body'], "Content-type: text/html; charset=utf-8\r\nFrom: " . $mail['sender'] . "\r\n")) {
                System::notifyAdmin('CaseBox cron notification: Cant send notification (' . $mail['nId'] . ') mail to "' . $u['email'] . '"', $mail['body']);
            } else {
                DM\Notifications::markAsSeen($mail['nId'], $uid);
            }
        }
        if (!empty($mails['digest'])) {
            User::setUserConfigParam('lastNotifyTime', Util\dateISOToMysql('now'), $uid);
        }
    }
}
Exemplo n.º 8
0
 public function getChildren(&$pathArray, $requestParams)
 {
     $pid = null;
     /* should start with path check and see if child request is for a real db node*/
     if (empty($pathArray)) {
         if (empty($requestParams['query'])) {
             return;
         }
     } else {
         $lastNode = @$pathArray[sizeof($pathArray) - 1];
         if ($lastNode instanceof Dbnode || get_class($lastNode) == 'CB\\TreeNode\\Base') {
             $pid = $lastNode->id;
         } else {
             //we are under another node type
             $cfg = $lastNode->getConfig();
             if (!empty($cfg['realNodeId']) && $lastNode instanceof RealSubnode) {
                 $pid = $cfg['realNodeId'];
             } else {
                 return array();
             }
         }
     }
     if (empty($pid)) {
         return array();
     }
     /* end of check */
     $p =& $requestParams;
     $folderTemplates = \CB\Config::get('folder_templates');
     $p['fl'] = 'id,pid,system,path,name,case_id,date,date_end,size,cid,' . 'oid,cdate,uid,udate,template_id,acl_count,cls,status,task_status,versions,' . 'comment_user_id,comment_date';
     if (empty($p['showFoldersContent'])) {
         $p['templates'] = $folderTemplates;
     }
     if (empty($p['descendants'])) {
         $p['pid'] = $pid;
     } else {
         $p['pids'] = $pid;
     }
     $s = new \CB\Search();
     $rez = $s->query($p);
     if (!empty($rez['data'])) {
         for ($i = 0; $i < sizeof($rez['data']); $i++) {
             $d =& $rez['data'][$i];
             $r = DM\Tree::read($d['id']);
             if (!empty($r['cfg']) && $p['from'] == 'tree') {
                 if (isset($r['cfg']['loaded'])) {
                     $d['loaded'] = $r['cfg']['loaded'];
                 }
                 if (isset($r['cfg']['expanded'])) {
                     $d['expanded'] = $r['cfg']['expanded'];
                 }
                 if (isset($r['cfg']['leaf'])) {
                     $d['leaf'] = $r['cfg']['leaf'];
                 }
             }
         }
         \CB\Tasks::setTasksActionFlags($rez['data']);
     }
     return $rez;
 }
Exemplo n.º 9
0
 public function testCreateSolrConfigsetsSymlinks()
 {
     $cfg = \CB\Config::loadConfigFile(\CB_DOC_ROOT . 'config.ini');
     $result = \CB\Install\createSolrConfigsetsSymlinks($cfg);
     $this->assertTrue($result['success'], ' creates symplink return errors');
     $this->assertTrue(file_exists($result['links']['log']), 'solr logs configset symlink not created : ' . $result['links']['log']);
     $this->assertTrue(file_exists($result['links']['default']), 'solr default configset symlink not created : ' . $result['links']['default']);
 }
Exemplo n.º 10
0
 /**
  * Get app configuration.
  *
  * Send configuration to the client.
  *
  * @access public
  * @return array
  */
 public function read()
 {
     try {
         $config = ['cb.version' => \CB\Config::get('cb.version'), 'cb.build' => \CB\Config::get('cb.build'), 'cb.environment' => \CB\Config::get('cb.environment'), 'url.root' => \CB\Config::get('url.root'), 'url.uploads' => \CB\Config::get('url.uploads'), 'url.resources' => \CB\Config::get('url.resources'), 'folder.root' => \CB\Config::get('folder.root'), 'folder.uploads' => \CB\Config::get('folder.uploads'), 'folder.resources' => \CB\Config::get('folder.resources')];
         return $this->success('Read configuration successful.', $config);
     } catch (\CB\Exception $e) {
         return $this->error($e->getMessage());
     }
 }
Exemplo n.º 11
0
 /**
  * load all templates from database
  * @param  boolean $reload reload even if already all loaded
  * @return void
  */
 public function loadAll($reload = false)
 {
     //skip loading if already loaded and reload not true
     if ($this->loadedAll && !$reload) {
         return;
     }
     $this->reset();
     /* collecting template_fields */
     $template_fields = array();
     $res = DB\dbQuery('SELECT
             ts.id
             ,ts.pid
             ,ts.template_id
             ,ts.name
             ,ts.l' . \CB\Config::get('user_language_index') . ' `title`
             ,ts.`type`
             ,ts.cfg
             ,ts.order
             ,ts.solr_column_name
         FROM templates_structure ts
         JOIN tree t on ts.id = t.id AND t.dstatus = 0') or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         $template_id = $r['template_id'];
         unset($r['template_id']);
         $r['cfg'] = Util\toJSONArray($r['cfg']);
         $template_fields[$template_id][$r['id']] = $r;
     }
     $res->close();
     /* loading templates */
     $res = DB\dbQuery('SELECT t.id
             ,t.pid
             ,t.is_folder
             ,t.`type`
             ,t.name
             ,t.`order`
             ,t.`visible`
             ,t.iconCls
             ,t.default_field
             ,t.cfg
             ,t.title_template
             ,t.info_template
             ,o.data
         FROM templates t
         LEFT JOIN objects o
             ON t.id = o.id
         WHERE t.is_folder = 0') or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         $r['cfg'] = Util\toJSONArray($r['cfg']);
         $r['data'] = Util\toJSONArray($r['data']);
         $r['fields'] = empty($template_fields[$r['id']]) ? array() : $template_fields[$r['id']];
         /* store template in collection */
         $this->templates[$r['id']] = new \CB\Objects\Template($r['id'], false);
         $this->templates[$r['id']]->setData($r);
     }
     $res->close();
     $this->loadedAll = true;
 }
Exemplo n.º 12
0
 public function setUp()
 {
     $config['solr_port'] = \CB\Config::get('solr_port');
     $config['solr_host'] = \CB\Config::get('solr_host');
     $config['solr_core'] = \CB\Config::get('prefix') . '_' . \CB\Config::get('core_name');
     // print_r($config);
     $layer = new \Apache_Solr_Compatibility_Solr4CompatibilityLayer();
     $this->solr = $solr = new \Apache_Solr_Service($this->config['solr_host'], $this->config['solr_port'], "/solr/" . $this->config['solr_core'] . "/", false, $layer);
 }
Exemplo n.º 13
0
 /**
  * update file
  * @param  array   $p optional properties. If not specified then $this-data is used
  * @return boolean
  */
 public function update($p = false)
 {
     //disable default log from parent Object class
     \CB\Config::setFlag('disableActivityLog', true);
     $rez = parent::update($p);
     \CB\Config::setFlag('disableActivityLog', false);
     $p =& $this->data;
     $this->logAction('file_update', array('file' => array('id' => $p['id'], 'name' => $p['name'])));
     return $rez;
 }
Exemplo n.º 14
0
 /**
  * save state for grid view of the browser
  * @return Ext.Direct responce
  */
 public function saveGridViewState($p)
 {
     $rez = array('success' => true);
     $guid = false;
     /* incomming params example
        p: {params:{id:251, view:grid, path:1/114/101/251, query:null, start:0},…}
            params: {id:251, view:grid, path:1/114/101/251, query:null, start:0}
                id: 251
                path: "1/114/101/251"
                query: null
                start: 0
                view: "grid"
            state: {columns:{nid:{id:0, width:80, hidden:true, sortable:true}, name:{id:1, width:160, sortable:true},…}}
                columns: {nid:{id:0, width:80, hidden:true, sortable:true}, name:{id:1, width:160, sortable:true},…}
                case: {id:3, width:150, sortable:true}
                cdate: {id:8, width:120, hidden:true, sortable:true}
                cid: {id:6, width:200, hidden:true, sortable:true}
                date: {id:4, width:120, sortable:true}
                name: {id:1, width:160, sortable:true}
                nid: {id:0, width:80, hidden:true, sortable:true}
                oid: {id:7, width:200, sortable:true}
                path: {id:2, width:150, hidden:true, sortable:true}
                size: {id:5, width:80, sortable:true}
                udate: {id:9, width:120, hidden:true, sortable:true}
         */
     if (!empty($p['params']['search']['template_id'])) {
         $guid = 'template_' . $p['params']['search']['template_id'];
     } elseif (!empty($p['params']['query'])) {
         $guid = 'search';
     } else {
         $path = empty($p['params']['path']) ? $p['params']['id'] : $p['params']['path'];
         if (!empty($path)) {
             $treeNodeConfigs = Config::get('treeNodes', array('Dbnode' => array()));
             $treeNodeClasses = Path::getNodeClasses($treeNodeConfigs);
             $treeNodeGUIDConfigs = array();
             foreach ($treeNodeClasses as $nodeClass) {
                 $cfg = $nodeClass->getConfig();
                 $treeNodeGUIDConfigs[$cfg['guid']] = $cfg;
             }
             $nodesPath = Path::createNodesPath($path, $treeNodeGUIDConfigs);
             if (!empty($nodesPath)) {
                 $lastNode = array_pop($nodesPath);
                 $DCConfig = $lastNode->getDC();
                 $guid = empty($DCConfig['from']) ? 'default' : $DCConfig['from'];
             }
         }
     }
     if ($guid) {
         DB\dbQuery('INSERT INTO tree_user_config
             (guid, user_id, cfg)
             VALUES($1, $2, $3)
             ON DUPLICATE KEY UPDATE cfg = $3', array($guid, User::getId(), Util\jsonEncode($p['state'])));
     }
     return $rez;
 }
Exemplo n.º 15
0
Arquivo: Api.php Projeto: nexcra/cb5
 /**
  * Api info controller
  *
  * @access public
  * @return void
  */
 public function __construct()
 {
     // convert API functions to Ext.Direct specs
     $actions = array();
     $api = \CB\Config::getApiFunctions();
     foreach ($api as $aname => &$a) {
         $methods = array();
         foreach ($a['methods'] as $mname => &$m) {
             if (isset($m['len'])) {
                 $md = array('name' => $mname, 'len' => $m['len']);
             } else {
                 $md = array('name' => $mname, 'params' => $m['params']);
             }
             if (isset($m['formHandler']) && $m['formHandler']) {
                 $md['formHandler'] = true;
             }
             $methods[] = $md;
         }
         $actions[$aname] = $methods;
     }
     // API specs
     $api = array('url' => \CB\Config::get('folder.root') . '/api/router/', 'namespace' => 'CB.api', 'type' => 'remoting', 'actions' => $actions);
     // send javascript headers
     header('Content-Type: text/javascript');
     // init api
     $response = 'var CB = {}; CB.init = {};';
     $response .= 'CB.init.API=' . json_encode($api) . ';';
     // init config
     $config = $this->getApiController('Config')->read();
     if ($config['success']) {
         $response .= 'CB.init.Config=' . json_encode($config['data']) . ';';
     }
     // init session user
     $user = $this->getApiController('User')->readSession();
     if ($user['success']) {
         $response .= 'CB.init.User='******'data']) . ';';
     }
     /*
     $countries = $this->getApiController('Country')->read()['data'];
     $response .= 'CB.init.Countries=' . json_encode($countries) . ';';
     
     $locations = $this->getApiController('Location')->read()['data'];
     $response .= 'CB.init.Locations=' . json_encode($locations) . ';';
     
     $locationTypes = $this->getApiController('LocationType')->read()['data'];
     $response .= 'CB.init.LocationTypes=' . json_encode($locationTypes) . ';';
     
     $gradeTypes = $this->getApiController('GradeTypes')->read()['data'];
     $response .= 'CB.init.GradeTypes=' . json_encode($gradeTypes) . ';';
     */
     echo $response;
     exit;
     die;
 }
Exemplo n.º 16
0
 /**
  * update object
  * @param  array   $p optional properties. If not specified then $this-data is used
  * @return boolean
  */
 public function update($p = false)
 {
     if ($p === false) {
         $p = $this->data;
     }
     $this->data = $p;
     if (empty($p['template_id'])) {
         $p['template_id'] = \CB\Config::get('default_shortcut_template');
     }
     return parent::update($p);
 }
Exemplo n.º 17
0
 /**
  * delete core record form __casebox.cores table
  * and drop database
  * @param  varchar $idOrName
  * @return boolean
  */
 public static function delete($idOrName)
 {
     $id = static::toId($idOrName);
     $data = static::read($id);
     $rez = parent::delete($id);
     if ($rez) {
         $dbName = Config::get('prefix') . '_' . $data['name'];
         DB\dbQuery("DROP DATABASE `{$dbName}`") or die(DB\dbQueryError());
     }
     return $rez;
 }
Exemplo n.º 18
0
 /**
  * update comment
  * @param  array   $p optional properties. If not specified then $this-data is used
  * @return boolean
  */
 public function update($p = false)
 {
     //disable default log from parent Object class
     //we'll set comments add as comment action for parent
     Config::setFlag('disableActivityLog', true);
     $rez = parent::update($p);
     Config::setFlag('disableActivityLog', false);
     $p =& $this->data;
     $this->logAction('comment_update', array('new' => Objects::getCachedObject($p['pid']), 'comment' => $p['data']['_title']));
     return $rez;
 }
Exemplo n.º 19
0
 /**
  *
  * @param  type   $provider
  * @return string url to login
  */
 public static function getLoginUrl($provider = null)
 {
     $authUrl = null;
     if (isset($provider)) {
         $generator = $provider->getRandomFactory()->getMediumStrengthGenerator();
         // $random_state = $generator->generateString(32);
         $state = ['core' => Config::get('core_name'), 'state' => session_id()];
         $authUrl = $provider->getAuthorizationUrl(['state' => strtr(base64_encode(json_encode($state)), '+/=', '-_,')]);
         $_SESSION['oauth2state'] = $provider->getState();
     }
     return $authUrl;
 }
Exemplo n.º 20
0
 /**
  * Prevent direct object creation
  */
 private final function __construct()
 {
     require_once Config::get('HTML_PURIFIER');
     require_once 'HTMLPurifier.func.php';
     //create default config
     $config = \HTMLPurifier_Config::createDefault();
     $config->set('AutoFormat.AutoParagraph', false);
     $config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
     $config->set('HTML.ForbiddenElements', array('head'));
     $config->set('HTML.SafeIframe', true);
     $config->set('HTML.TargetBlank', true);
     $config->set('URI.DefaultScheme', 'https');
     $config->set('Attr.EnableID', true);
     static::$purifier = new \HTMLPurifier($config);
 }
Exemplo n.º 21
0
 public function testcliLoadConfig()
 {
     $configFile = \UnitTest\Helpers::getConfigFilenameTPL();
     $cfg = \CB\Install\cliLoadConfig(['config' => $configFile]);
     $realConf = \CB\Config::loadConfigFile($configFile);
     // test if loaded solr_port is equal with real solr_port
     $this->assertEquals($cfg['solr_port'], $realConf['solr_port']);
     $cfg = \CB\Install\cliLoadConfig(['config' => $configFile, 'solr_port' => 8180]);
     $this->assertEquals($cfg['solr_port'], 8180);
     $cfg = \CB\Install\cliLoadConfig(['config' => $configFile, 'su_db_pass' => '1234567', 'core_root_pass' => '1234567']);
     $this->assertEquals($cfg['su_db_pass'], '1234567');
     $this->assertEquals($cfg['core_root_pass'], '1234567');
     $cfg = \CB\Install\cliLoadConfig(['su_db_pass' => '1234567', 'core_root_pass' => '1234567']);
     $this->assertEquals($cfg['su_db_pass'], '1234567');
     $this->assertEquals($cfg['core_root_pass'], '1234567');
 }
Exemplo n.º 22
0
 /**
  * executing preimporting changes to target core
  * @return void
  */
 protected function prepare()
 {
     $ids = DM\Templates::getIdsByType('config');
     if (!empty($ids)) {
         //set flag that config is already in tree
         //and we'll
         $this->skipTreeCration = true;
         return;
     }
     //update template types
     DB\dbQuery("ALTER TABLE `templates`\n              CHANGE `type` `type` ENUM('case','object','file','task','user','email','template','field','search','comment','shortcut','menu','config')\n              CHARSET utf8 COLLATE utf8_general_ci NULL");
     // set templates template id in config
     $ids = DM\Templates::getIdsByType('template');
     $id = array_shift($ids);
     BBM::$cfg['templatesTemplateId'] = $id;
     // $this->cfg['templates']['Menu rule']['fields']['template_ids']['cfg']['templates'] = $id;
     // $this->cfg['templates']['Menu rule']['fields']['menu']['cfg']['templates'] = $id;
     // detect fields template id
     $ids = DM\Templates::getIdsByType('field');
     $id = array_shift($ids);
     BBM::$cfg['fieldTemplateId'] = $id;
     //detect folderTemplateId
     $ids = Config::get('folder_templates');
     if (!empty($ids)) {
         BBM::$cfg['folderTemplateId'] = array_shift($ids);
     }
     //create "Config" folder under templates to store our config templates there
     //and update BBM::$cfg['templatesFolderId'] to our folder id
     $o = new \CB\Objects\Object();
     $rootId = Browser::getRootFolderId();
     $this->systemFolderId = Objects::getChildId($rootId, 'System');
     $pid = Objects::getChildId($rootId, 'Templates');
     if (empty($pid)) {
         if (!empty($this->systemFolderId)) {
             $pid = Objects::getChildId($this->systemFolderId, 'Templates');
         }
     }
     $id = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'Config', 'data' => array('_title' => 'Config')));
     BBM::$cfg['templatesFolderId'] = $id;
     //create System/Config folder for transferring config options
     $pid = Objects::getChildId($rootId, 'System');
     if (empty($pid)) {
         $pid = $o->create(array('id' => null, 'pid' => $rootId, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'System', 'data' => array('_title' => 'System')));
     }
     $this->cfg['configFolderId'] = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'Config', 'data' => array('_title' => 'Config')));
 }
Exemplo n.º 23
0
 /**
  * Remove cookie.
  *
  * @access public
  * @param  string  $key
  * @param  string  $path
  * @param  string  $domain
  * @param  boolean $secure
  * @param  boolean $httpOnly
  * @return boolean
  */
 public static function remove($key, $path = null, $domain = null, $secure = null, $httpOnly = null)
 {
     if (is_null($path)) {
         $path = \CB\Config::get('cookie.path');
     }
     if (is_null($domain)) {
         $domain = \CB\Config::get('cookie.domain');
     }
     if (is_null($secure)) {
         $secure = \CB\Config::get('cookie.secure');
     }
     if (setcookie($key, '', time() - 3600, $path, $domain, $secure, $httpOnly)) {
         unset($_COOKIE[$key]);
     } else {
         throw new Exception('Unable to remove cookie "' . $key . '"!');
     }
 }
Exemplo n.º 24
0
 /**
  * Get Doctrine entity manager instance.
  *
  * @access public
  * @return \Doctrine\ORM\EntityManager
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         // model paths
         $paths = array(\CB\Config::get('path.root') . '/CB/Entity');
         // development mode?
         $development = \CB\Config::get('cb.environment') === 'development';
         // create entity manager
         $config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($paths, $development);
         // the connection configuration
         $dbParams = array('driver' => \CB\Config::get('doctrine.driver'), 'host' => \CB\Config::get('doctrine.host'), 'user' => \CB\Config::get('doctrine.user'), 'password' => \CB\Config::get('doctrine.password'), 'dbname' => \CB\Config::get('doctrine.dbname'), 'charset' => \CB\Config::get('doctrine.charset'));
         // create doctrine entity manager
         self::$_instance = \Doctrine\ORM\EntityManager::create($dbParams, $config);
         // enable sql logger
         if ($development) {
             self::$_instance->getConfiguration()->setSQLLogger(new \CB\Doctrine\FileSQLLogger());
         }
     }
     return self::$_instance;
 }
Exemplo n.º 25
0
 public function getData($id = false)
 {
     $rez = array('success' => true);
     if (empty(parent::getData($id))) {
         return $rez;
     }
     $params = array('pid' => $this->id, 'fq' => array('(template_type:object) OR (target_type:object)'), 'fl' => 'id,pid,name,template_id,cdate,cid', 'sort' => 'cdate', 'dir' => 'desc');
     $folderTemplates = \CB\Config::get('folder_templates');
     if (!empty($folderTemplates)) {
         $params['fq'][] = '!template_id:(' . implode(' OR ', Util\toNumericArray($folderTemplates)) . ')';
     }
     $s = new \CB\Search();
     $sr = $s->query($params);
     foreach ($sr['data'] as $d) {
         $d['ago_text'] = Util\formatAgoTime($d['cdate']);
         $d['user'] = @User::getDisplayName($d['cid']);
         $rez['data'][] = $d;
     }
     return $rez;
 }
Exemplo n.º 26
0
/**
 * function to set translations in Cache
 */
function initTranslations()
{
    $translations = \CB\Cache::get('translations', []);
    // if already defined translations then exit
    if (!empty($translations)) {
        return;
    }
    $languages = \CB\Config::get('languages');
    // or : \CB\USER_LANGUAGE;
    /* reading main translations table from casebox database*/
    $res = DB\dbQuery('SELECT name, ' . implode(',', $languages) . '
        FROM ' . \CB\PREFIX . '_casebox.translations
        WHERE `type` < 2');
    // if ($rez = $res->fetch_all(MYSQLI_ASSOC)) {
    // foreach ($rez as &$r) {
    while ($r = $res->fetch_assoc()) {
        reset($r);
        $name = current($r);
        while ($v = next($r)) {
            $translations[key($r)][$name] = $v;
        }
        // }
    }
    $res->close();
    /* reading specific translations of core */
    $res = DB\dbQuery('SELECT *
        FROM translations
        WHERE `type` < 2');
    // if ($rez = $res->fetch_all(MYSQLI_ASSOC)) {
    //     foreach ($rez as &$r) {
    while ($r = $res->fetch_assoc()) {
        foreach ($languages as $l) {
            if (!empty($r[$l])) {
                $translations[$l][$r['name']] = $r[$l];
            }
        }
        //  }
    }
    $res->close();
    \CB\Cache::set('translations', $translations);
}
Exemplo n.º 27
0
 /**
  * create secret data
  * $params {
  *     email
  *     code
  * }
  * @return varchar | array secret data
  */
 public function createSecretData($params = null)
 {
     if (!empty($params['clientId']) && !empty($params['sk'])) {
         return $params;
     }
     if (empty($params['email'])) {
         throw new \Exception('Yubico error: Email not specified for secret data creation.', 1);
     }
     if (empty($params['code'])) {
         throw new \Exception('Yubico error: OTP not specified for secret data creation.', 1);
     }
     $data = array('email' => $params['email'], 'otp' => $params['code']);
     $data = http_build_query($data, '', '&');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->secretDataCreationURL);
     // curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type:text/html; Content-Length:".strlen($data)));
     curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
     curl_setopt($ch, CURLOPT_FAILONERROR, 1);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     // curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
     curl_setopt($ch, CURLOPT_VERBOSE, 1);
     $rez = curl_exec($ch);
     file_put_contents(\CB\Config::get('debug_log') . '_yubikey', $rez);
     if (curl_errno($ch)) {
         throw new \Exception("curl_error:" . curl_error($ch), 1);
     }
     $rez = strip_tags($rez);
     preg_match_all('/client id:[\\s]*([\\d]+)\\s+secret key:[\\s]*([^\\s]+)/i', $rez, $matches);
     if (empty($matches[1][0]) || empty($matches[2][0])) {
         throw new \Exception('Cannot find Client ID and Secret key on Yubiko response for getting api key.', 1);
     }
     $params['clientId'] = $matches[1][0];
     $params['sk'] = $matches[2][0];
     return $params;
 }
Exemplo n.º 28
0
 /**
  * executing preimporting changes to target core
  * @return void
  */
 protected function prepare()
 {
     //update template types
     DB\dbQuery("ALTER TABLE `templates`\n            CHANGE `type` `type` enum('case','object','file','task','user','email','template','field','search','comment','shortcut','menu')\n            COLLATE utf8_general_ci NULL after `is_folder`") or die(DB\dbQueryError());
     // set templates template id in config
     $ids = DM\Templates::getIdsByType('template');
     $id = array_shift($ids);
     BBM::$cfg['templatesTemplateId'] = $id;
     $this->cfg['templates']['Menu rule']['fields']['template_ids']['cfg']['templates'] = $id;
     $this->cfg['templates']['Menu rule']['fields']['menu']['cfg']['templates'] = $id;
     // detect fields template id
     $ids = DM\Templates::getIdsByType('field');
     $id = array_shift($ids);
     BBM::$cfg['fieldTemplateId'] = $id;
     //detect folderTemplateId
     $ids = Config::get('folder_templates');
     if (!empty($ids)) {
         BBM::$cfg['folderTemplateId'] = array_shift($ids);
     }
     //create "Menu" folder under templates to store our menu templates there
     //and update BBM::$cfg['templatesFolderId'] to our folder id
     $o = new \CB\Objects\Object();
     $rootId = Browser::getRootFolderId();
     $pid = Objects::getChildId($rootId, 'Templates');
     if (empty($pid)) {
         $pid = Objects::getChildId($rootId, 'System');
         if (!empty($pid)) {
             $pid = Objects::getChildId($pid, 'Templates');
         }
     }
     $id = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'Menu', 'data' => array('_title' => 'Menu')));
     BBM::$cfg['templatesFolderId'] = $id;
     //create System/Menus folder for transferring menu rules to it
     $pid = Objects::getChildId($rootId, 'System');
     if (empty($pid)) {
         $pid = $o->create(array('id' => null, 'pid' => $rootId, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'System', 'data' => array('_title' => 'System')));
     }
     $this->cfg['menusFolderId'] = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'Menus', 'data' => array('_title' => 'Menus')));
 }
Exemplo n.º 29
0
function doRpc($cdata)
{
    $API = \CB\Cache::get('ExtDirectAPI');
    if (!\CB\User::isLoged() && ($cdata['action'] != 'User' || $cdata['method'] != 'login') && !(php_sapi_name() == "cli")) {
        return array(array('type' => 'exception', 'name' => 'login', 'tid' => $cdata['tid'], 'action' => $cdata['action'], 'method' => $cdata['method'], 'result' => array('success' => false)));
    }
    try {
        if (!isset($API[$cdata['action']])) {
            throw new \Exception('Call to undefined action: ' . $cdata['action']);
        }
        $action = $cdata['action'];
        $a = $API[$action];
        doAroundCalls($a['before'], $cdata);
        $method = $cdata['method'];
        $mdef = $a['methods'][$method];
        if (!$mdef) {
            throw new \Exception("Call to undefined method: {$method} on action {$action}");
        }
        doAroundCalls($mdef['before'], $cdata);
        $r = array('type' => 'rpc', 'tid' => $cdata['tid'], 'action' => $action, 'method' => $method);
        $action = str_replace('_', '\\', $action);
        $o = new $action();
        $params = isset($cdata['data']) && is_array($cdata['data']) ? $cdata['data'] : array();
        $r['result'] = call_user_func_array(array($o, $method), $params);
        doAroundCalls($mdef['after'], $cdata, $r);
        doAroundCalls($a['after'], $cdata, $r);
    } catch (\Exception $e) {
        $r['type'] = 'exception';
        $r['result'] = array('success' => false, 'msg' => $e->getMessage());
        if (\CB\IS_DEBUG_HOST) {
            $r['where'] = $e->getTraceAsString();
        }
        //notify admin
        if (!(php_sapi_name() == "cli")) {
            @mail(Config::get('ADMIN_EMAIL'), 'Remote router exception on ' . Config::get('core_url'), var_export($r, true), 'From: ' . Config::get('SENDER_EMAIL') . "\r\n");
        }
    }
    return $r;
}
Exemplo n.º 30
0
 /**
  * catch server side errors and return json encoded exception
  * @return void
  */
 function extDirectShutdownFunction()
 {
     $data = \CB\Cache::get('ExtDirectData');
     $error = error_get_last();
     if (in_array($error['type'], array(1, 4))) {
         $data['type'] = 'exception';
         $data['result'] = array('success' => false);
         $data['msg'] = 'Internal server error.';
         if (\CB\IS_DEBUG_HOST) {
             $data['msg'] = $error['message'];
             $data['where'] = print_r(debug_backtrace(false), true);
         }
         //notify admin
         if (!(php_sapi_name() == "cli")) {
             @mail(Config::get('ADMIN_EMAIL'), 'Remote router error on ' . Config::get('core_url'), var_export($data, true), 'From: ' . Config::get('SENDER_EMAIL') . "\r\n");
         }
         echo Util\jsonEncode($data);
     }
     if (\CB\User::isLoged()) {
         \CB\User::updateLastActionTime();
     }
 }