/** * 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(); }
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; }
/** * 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; }
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; }
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; }
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); } } }
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; }
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); }
/** * 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()); } }
/** * 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; }
/** * 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; }
/** * 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); }
/** * 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; }
/** * 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; }
/** * * @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; }
/** * 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); }
/** * 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 . '"!'); } }
/** * 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'))); }
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; }
/** * 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; }
/** * 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); }
/** * 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; }
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; }
/** * 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(); } }
/** * 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'))); }
public function getTitle() { $rez = 'Facet'; $coreLanguage = \CB\Config::get('language'); $userLanguage = \CB\Config::get('user_language'); if (!empty($this->config['title'])) { $t =& $this->config['title']; if (is_scalar($t)) { $rez = $t; if ($t[0] == '[') { $rez = L\get(substr($t, 1, strlen($t) - 2)); if (empty($rez)) { $rez = $t; } } } elseif (!empty($t[$userLanguage])) { $rez = $t[$userLanguage]; } elseif (!empty($t[$coreLanguage])) { $rez = $t[$coreLanguage]; } } return $rez; }
/** * Test controller. * * Execute climbuddy tests :) * * @access public * @return void */ public function __construct() { // disable tests in production if (\CB\Config::get('cb.environment') === 'production') { header('location: ' . \CB\Config::get('folder.root') . '/api/info'); } // buffer output ob_start(); // start tests $Start = new \CB\Test\Start(); $Start->run(new \CB\Test\UnitTestReporter()); // run other test suites $testDir = \CB\Config::get('path.root') . '/CB/Test/'; $excludeFiles = array('.', '..', 'AbstractTest.php', 'Start.php', 'Stop.php'); foreach (scandir($testDir) as $file) { // run single test with $_GET['suite'] $class = str_replace('.php', '', $file); $Class = '\\CB\\Test\\' . $class; // test suite? if (isset($_GET['suite']) && $class !== $_GET['suite']) { continue; } // skip some files and all folders if (in_array($file, $excludeFiles) || is_dir($testDir . '/' . $file)) { continue; } $Test = new $Class(); $Test->run(new \CB\Test\UnitTestReporter()); } // stop tests $Stop = new \CB\Test\Stop(); $Stop->run(new \CB\Test\UnitTestReporter()); // output results ob_end_flush(); exit; die; }
/** * Get file directory. * * @access private * @return string */ private function _getFileDir() { return \CB\Config::get('path.uploads') . '/' . $this->_created->format('Y/m/d') . '/' . $this->_slug; }
/** * function to check if any objects name from sourceIds exists in targetId * @param int | array $objectIds * @param int $targetId * @return boolean | int false if not exists or id of existent target */ private function overwriteCheck($sourceIds, $targetId) { $rez = false; if (\CB\Config::get('allow_duplicates', false)) { return $rez; } $sourceIds = Util\toNumericArray($sourceIds); $res = DB\dbQuery('SELECT t2.id FROM tree t1 JOIN tree t2 ON t2.pid = $1 AND t1.name = t2.name AND t2.dstatus = 0 WHERE t1.id in (' . implode(',', $sourceIds) . ') AND t1.dstatus = 0', $targetId); if ($r = $res->fetch_assoc()) { $rez = $r['id']; } $res->close(); return $rez; }
/** * update tree nodes into solr * * @param string[] $p { * @type boolean $all if true then all nodes will be updated into solr, * otherwise - only the nodes marked as updated will be reindexed in solr * @type int[] $id id or array of object ids to update * * @type varchar $cron_id when this function is called by a cron then cron_id should be passed * * @type boolean $nolimit if true then no limit will be applied to maximum indexed nodes * (default 2000) * } */ public function updateTree($p = array()) { /* connect to solr service */ $this->connect(); $eventParams = array('class' => &$this, 'params' => &$p); $this->folderTemplates = \CB\Config::get('folder_templates'); \CB\fireEvent('onBeforeSolrUpdate', $eventParams); /** @type int the last processed document id */ $lastId = 0; $indexedDocsCount = 0; $all = !empty($p['all']); $nolimit = !empty($p['nolimit']); /* prepeare where condition for sql depending on incomming params */ $where = '(t.updated > 0) AND (t.draft = 0) AND (t.id > $1)'; if ($all) { $this->deleteByQuery('*:*'); $where = '(t.id > $1) AND (t.draft = 0) '; \CB\Templates\SingletonCollection::getInstance()->loadAll(); } elseif (!empty($p['id'])) { $ids = \CB\Util\toNumericArray($p['id']); $where = '(t.id in (0' . implode(',', $ids) . ') ) and (t.id > $1)'; } $sql = 'SELECT t.id ,t.pid ,ti.pids ,ti.case_id ,ti.acl_count ,ti.security_set_id ,t.name ,t.system ,t.template_id ,t.target_id ,t.size ,DATE_FORMAT(t.`date`, \'%Y-%m-%dT%H:%i:%sZ\') `date` ,DATE_FORMAT(t.`date_end`, \'%Y-%m-%dT%H:%i:%sZ\') `date_end` ,t.oid ,t.cid ,DATE_FORMAT(t.cdate, \'%Y-%m-%dT%H:%i:%sZ\') `cdate` ,t.uid ,DATE_FORMAT(t.udate, \'%Y-%m-%dT%H:%i:%sZ\') `udate` ,t.did ,DATE_FORMAT(t.ddate, \'%Y-%m-%dT%H:%i:%sZ\') `ddate` ,t.dstatus ,t.updated ,o.sys_data FROM tree t LEFT JOIN tree_info ti ON t.id = ti.id LEFT JOIN objects o ON o.id = t.id where ' . $where . ' ORDER BY t.id LIMIT 500'; $docs = true; while (!empty($docs) && ($nolimit || $indexedDocsCount < 2000)) { $docs = array(); $res = DB\dbQuery($sql, $lastId) or die(DB\dbQueryError()); while ($r = $res->fetch_assoc()) { $lastId = $r['id']; /* process full object update only if: - updated = 1 - specific ids are specified - if $all parameter is true */ if ($all || !empty($p['id']) || $r['updated'] & 1) { $r['sys_data'] = Util\toJsonArray($r['sys_data']); $this->prepareDBRecord($r); $docs[$r['id']] = $r; } $this->updateCronLastActionTime(@$p['cron_id']); } $res->close(); if (!empty($docs)) { //append file contents for files to content field $this->appendFileContents($docs); $this->addDocuments($docs); /* reset updated flag into database for processed documents */ DB\dbQuery('UPDATE tree ,tree_info SET tree.updated = 0 ,tree_info.updated = 0 WHERE tree.id in (' . implode(',', array_keys($docs)) . ') AND tree_info.id = tree.id') or die(DB\dbQueryError()); $this->updateCronLastActionTime(@$p['cron_id']); $this->commit(); $indexedDocsCount += sizeof($docs); } } $this->updateTreeInfo($p); \CB\fireEvent('onSolrUpdate', $eventParams); }