Esempio n. 1
0
 /**
  * Create full copy of www dir and mysql database
  */
 public function make()
 {
     system::getInstance()->createPrivateDirectory(root . '/backup/');
     $file_mainname = system::getInstance()->toDate(time(), 'd') . "_backup";
     $this->zipCreate(root, root . "/backup/" . $file_mainname . "_www.zip");
     $this->mysqlDump("/backup/" . $file_mainname . "_sql.sql.gz");
 }
Esempio n. 2
0
 public function init()
 {
     if (database::getInstance()->isDown() || !property::getInstance()->get('collect_statistic')) {
         return;
     }
     $realip = system::getInstance()->getRealIp();
     $visittime = time();
     $browser = self::user_browser($_SERVER['HTTP_USER_AGENT']);
     $os = self::user_os($_SERVER['HTTP_USER_AGENT']);
     $cookie = $_COOKIE['source'] ?: '';
     $userid = user::getInstance()->get('id');
     if ($userid == null) {
         $userid = 0;
     }
     if ($cookie == null) {
         $settime = $visittime + 365 * 24 * 60 * 60;
         setcookie('source', system::getInstance()->md5random(), $settime, '/');
         $cookie = '';
     }
     $referer = $_SERVER['HTTP_REFERER'] ?: '';
     $path = $_SERVER['REQUEST_URI'] ?: '';
     $query = "INSERT INTO " . property::getInstance()->get('db_prefix') . "_statistic (ip, cookie, browser, os, time, referer, path, reg_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
     $stmt = database::getInstance()->con()->prepare($query);
     $stmt->bindParam(1, $realip, \PDO::PARAM_STR);
     $stmt->bindParam(2, $cookie, \PDO::PARAM_STR, 32);
     $stmt->bindParam(3, $browser, \PDO::PARAM_STR);
     $stmt->bindParam(4, $os, \PDO::PARAM_STR);
     $stmt->bindParam(5, $visittime, \PDO::PARAM_INT);
     $stmt->bindParam(6, $referer, \PDO::PARAM_STR);
     $stmt->bindParam(7, $path, \PDO::PARAM_STR);
     $stmt->bindParam(8, $userid, \PDO::PARAM_INT);
     $stmt->execute();
 }
Esempio n. 3
0
 /**
  * Log message to system information. Types: logger::LEVEL_ERR, logger::LEVEL_WARN, logger::LEVEL_NOTIFY
  * @param string $type
  * @param string $message
  */
 public function log($type, $message)
 {
     system::getInstance()->createPrivateDirectory(root . '/log/');
     $iface = defined('loader') ? loader : 'unknown';
     $compile_message = "=>[" . $iface . ":" . $type . "](" . system::getInstance()->toDate(time(), 's') . "): " . $message . "\n";
     @file_put_contents(root . "/log/" . system::getInstance()->toDate(time(), 'd') . ".log", $compile_message, FILE_APPEND | LOCK_EX);
 }
Esempio n. 4
0
 /**
  * Check if user is permament banned in database and display ban.tpl theme
  */
 public function init()
 {
     $ip = system::getInstance()->getRealIp();
     $time = time();
     $userid = user::getInstance()->get('id');
     if ($userid > 0) {
         $stmt = database::getInstance()->con()->prepare("SELECT COUNT(*) FROM " . property::getInstance()->get('db_prefix') . "_user_block WHERE (user_id = ? or ip = ?) AND (express > ? OR express = 0)");
         $stmt->bindParam(1, $userid, \PDO::PARAM_INT);
         $stmt->bindParam(2, $ip, \PDO::PARAM_STR);
         $stmt->bindParam(3, $time, \PDO::PARAM_INT);
         $stmt->execute();
     } else {
         $stmt = database::getInstance()->con()->prepare("SELECT COUNT(*) FROM " . property::getInstance()->get('db_prefix') . "_user_block WHERE ip = ? AND (express > ? OR express = 0)");
         $stmt->bindParam(1, $ip, \PDO::PARAM_STR);
         $stmt->bindParam(2, $time, \PDO::PARAM_INT);
         $stmt->execute();
     }
     $rowFetch = $stmt->fetch();
     $count = $rowFetch[0];
     if ($count > 0) {
         // block founded in db
         $content = template::getInstance()->twigRender('ban.tpl', array('local' => array('admin_email' => property::getInstance()->get('mail_from'))));
         template::getInstance()->justPrint($content);
     }
 }
Esempio n. 5
0
 /**
  * Get token for csrf prevention. Token is 32...128 chars. Token automatic add in cookie as 'csrf_token' and in template as {{ system.csrf_token }}
  * @return string
  */
 public function buildToken()
 {
     $now = time();
     if (!isset($_SESSION['csrf_token']) || $_SESSION['csrf_token']['time'] == null || $_SESSION['csrf_token']['data'] == null || $now - $_SESSION['csrf_token']['time'] > self::SESSION_TIME) {
         $_SESSION['csrf_token'] = array('time' => $now, 'data' => system::getInstance()->randomSecureString128());
     }
     template::getInstance()->set(template::TYPE_SYSTEM, 'csrf_token', $_SESSION['csrf_token']['data']);
 }
Esempio n. 6
0
 /**
  * Read ini structure data and return as associative array or FALSE if file not founded
  * @param string $file
  * @param bool $sections
  * @return array|bool
  */
 public function read($file, $sections = false)
 {
     if (!system::getInstance()->prefixEquals($file, root)) {
         $file = root . $file;
     }
     if (!file_exists($file)) {
         return false;
     }
     return parse_ini_file($file, $sections);
 }
Esempio n. 7
0
 public function compile()
 {
     template::getInstance()->set(template::TYPE_META, 'description', system::getInstance()->altimplode('. ', $this->metadata['description']));
     template::getInstance()->set(template::TYPE_META, 'keywords', system::getInstance()->altimplode('. ', $this->metadata['keywords']));
     template::getInstance()->set(template::TYPE_META, 'global_title', $this->metadata['global_title']);
     if (property::getInstance()->get('multi_title')) {
         template::getInstance()->set(template::TYPE_META, 'title', system::getInstance()->altimplode(" - ", array_reverse($this->metadata['title'])));
     } else {
         template::getInstance()->set(template::TYPE_META, 'title', array_pop($this->metadata['title']));
     }
     template::getInstance()->set(template::TYPE_META, 'generator', 'FFCMS engine: ffcms.ru. Version: ' . version);
 }
Esempio n. 8
0
 public function make()
 {
     $iface = system::getInstance()->get('iface');
     $object = system::getInstance()->get('object');
     $cron = system::getInstance()->get('cron');
     if ($cron != null) {
         return $this->cronInit();
     }
     $link = $this->call($iface, $object);
     if (method_exists($link, 'make')) {
         $link->make();
     }
     return null;
 }
Esempio n. 9
0
 public function init()
 {
     global $config;
     $this->set('ds', '/');
     // directory separator, but now in all O.S. supported "/" win,nix
     $this->set('slash', '/');
     // web slash, mb someone making amazing ;D
     $this->set('admin_tpl', 'admin');
     $this->set('install_tpl', 'install');
     $this->set('collect_statistic', true);
     $this->set('upload_img_max_size', 500);
     $this->set('tpl_dir', 'templates');
     $this->set('user_friendly_url', true);
     $this->set('use_multi_language', true);
     $this->set('maintenance', false);
     // upd
     $this->set('upload_other_max_size', 3000);
     $this->set('upload_allowed_ext', '.doc;.docx;.rtf;.pdf;.txt;');
     if (is_array($config)) {
         foreach ($config as $key => $value) {
             // allow multi-url support
             if ($key == 'url') {
                 $this->set('source_url', $value);
                 if (system::getInstance()->contains(';', $value)) {
                     // contains ; spliter in urls
                     $adr_array = system::getInstance()->altexplode(';', $value);
                     $user_address = system::getInstance()->getProtocol() . '://';
                     $user_address .= $_SERVER['HTTP_HOST'];
                     foreach ($adr_array as $address) {
                         if (system::getInstance()->prefixEquals($address, $user_address)) {
                             $this->set('url', $address);
                             break;
                         }
                     }
                     if ($this->get('url') == null) {
                         // if url still null - set first of know
                         $this->set('url', $adr_array[0]);
                     }
                 } else {
                     $this->set($key, $value);
                 }
             } else {
                 $this->set($key, $value);
             }
         }
     }
     $this->set('yandex_translate_key', 'trnsl.1.1.20140923T120415Z.11ea02784e7b7447.158c20fac47143a5ccda5fc8a8ca81182669c80f');
 }
Esempio n. 10
0
 public function init()
 {
     if (!file_exists(root . '/language/')) {
         return;
     }
     $scan = scandir(root . '/language/');
     $found_language = array();
     // get all available
     foreach ($scan as $file) {
         if (!system::getInstance()->prefixEquals($file, '.') && system::getInstance()->suffixEquals($file, '.ini')) {
             $found_language = system::getInstance()->arrayAdd(strstr($file, '.', true), $found_language);
         }
     }
     // check if exists
     foreach ($found_language as $check_language) {
         if (file_exists(root . '/language/' . $check_language . '.ini')) {
             $this->available[] = $check_language;
         }
     }
 }
Esempio n. 11
0
 /**
  * Get configuration value of extension by config name, extension name and extension type.
  * @param string $name
  * @param string $ext_dir
  * @param string $object
  * @param string $var_type
  * @return bool|int|string
  */
 public function getConfig($name, $ext_dir, $object, $var_type = null)
 {
     $configs = unserialize($this->extconfigs[$object][$ext_dir]['configs']);
     if (in_array($var_type, array('bool', 'boolean', 'bol'))) {
         return $configs[$name] == "0" ? false : true;
     } elseif (in_array($var_type, array('int', 'integer'))) {
         return system::getInstance()->toInt($configs[$name]);
     } elseif (in_array($var_type, array('float', 'double'))) {
         return (double) $configs[$name];
     }
     return $configs[$name];
 }
Esempio n. 12
0
 /**
  * Return array of all available permissions in datatable user_access_level. Ex: array['global/read', 'global/write', 'global/owner' ... , 'etc']
  * @return array
  */
 public function getAllPermissions()
 {
     $this->loadAllData();
     // get data from db
     foreach ($this->full_access_data as $row) {
         // even row
         $permission_array = system::getInstance()->altexplode(';', $row['permissions']);
         // row permissions
         foreach ($permission_array as $permission) {
             // single permission
             if (!in_array($permission, $this->all_permissions) && !system::getInstance()->prefixEquals($permission, 'admin/')) {
                 $this->all_permissions[] = $permission;
                 // add
             }
         }
     }
     return $this->all_permissions;
 }
Esempio n. 13
0
    private function viewInstall()
    {
        $params = array();
        if (file_exists(root . '/install/.lock')) {
            $params['notify']['prepare']['lock'] = true;
        }
        if (file_exists(root . '/config.php') && !is_writable(root . '/config.php')) {
            $params['notify']['prepare']['cfg_write'] = true;
        }
        if (!is_writable(root . '/install/')) {
            $params['notify']['prepare']['inst_write'] = true;
        }
        if (!file_exists(root . '/install/sql/install.sql')) {
            $params['notify']['prepare']['sql_notfound'] = true;
        }
        $timezone_array = timezone::getInstance()->getZoneUTC();
        template::getInstance()->set(template::TYPE_SYSTEM, 'timezones', $timezone_array);
        if (sizeof($params['notify']) == 0) {
            if (system::getInstance()->post('submit')) {
                $testCon = null;
                try {
                    $testCon = @new \PDO("mysql:host=" . system::getInstance()->post('config:db_host') . ";dbname=" . system::getInstance()->post('config:db_name') . "", system::getInstance()->post('config:db_user'), system::getInstance()->post('config:db_pass'));
                } catch (\PDOException $exception) {
                    $params['notify']['process']['db_conn_miss'] = true;
                }
                if ($testCon != null) {
                    $reg_login = system::getInstance()->post('admin:login');
                    $reg_email = system::getInstance()->post('admin:email');
                    $reg_pass = system::getInstance()->post('admin:pass');
                    $reg_repass = system::getInstance()->post('admin:repass');
                    if (!filter_var($reg_email, FILTER_VALIDATE_EMAIL)) {
                        $params['notify']['process']['reg_email_wrong'] = true;
                    }
                    if (!system::getInstance()->validPasswordLength($reg_pass)) {
                        $params['notify']['process']['reg_pass_wrong'] = true;
                    }
                    if (system::getInstance()->length($reg_login) < 3 || system::getInstance()->length($reg_login) > 64) {
                        $params['notify']['process']['reg_login_wrong'] = true;
                    }
                    if ($reg_pass != $reg_repass) {
                        $params['notify']['process']['reg_repass_nomatch'] = true;
                    }
                    if (sizeof($params['notify']) == 0) {
                        $configs_data = '<?php' . "\n";
                        foreach (system::getInstance()->post(null) as $var_name => $var_value) {
                            if (system::getInstance()->prefixEquals($var_name, 'config:')) {
                                $var_name = substr($var_name, strlen('config:'));
                                $var_name = system::getInstance()->nohtml($var_name);
                                if ($var_name === 'seo_title') {
                                    foreach (language::getInstance()->getAvailable() as $clang) {
                                        $configs_data .= '$config[\'' . $var_name . '\'][\'' . $clang . '\'] = "' . system::getInstance()->nohtml($var_value[$clang]) . '";' . "\n";
                                    }
                                } else {
                                    $configs_data .= '$config[\'' . $var_name . '\'] = "' . system::getInstance()->nohtml($var_value) . '"' . ";\n";
                                }
                            }
                        }
                        $random_password_salt = system::getInstance()->randomString(rand(12, 16));
                        $configs_data .= '$config[\'tpl_dir\'] = "templates";
$config[\'tpl_name\'] = "default";
$config[\'debug\'] = true;
$config[\'multi_title\'] = false;
$config[\'cache_interval\'] = "120";
$config[\'token_time\'] = "86400";
$config[\'user_friendly_url\'] = false;
$config[\'mail_from\'] = "*****@*****.**";
$config[\'mail_ownername\'] = "Site Admin";
$config[\'mail_smtp_use\'] = false;
$config[\'mail_smtp_host\'] = "smtp.yandex.ru";
$config[\'mail_smtp_port\'] = "25";
$config[\'mail_smtp_auth\'] = true;
$config[\'mail_smtp_login\'] = "*****@*****.**";
$config[\'mail_smtp_password\'] = "madness";
$config[\'password_salt\'] = "' . $random_password_salt . '";
';
                        $configs_data .= '?>';
                        file_put_contents(root . '/install/.lock', 'Install success');
                        file_put_contents(root . '/config.php', $configs_data);
                        $prefix = system::getInstance()->post('config:db_prefix');
                        if (!system::getInstance()->isLatinOrNumeric($prefix)) {
                            $prefix = "ffcms";
                        }
                        $query_dump = str_replace('{$db_prefix}', $prefix, file_get_contents(root . '/install/sql/install.sql'));
                        $testCon->exec($query_dump);
                        $md5_doublehash = system::getInstance()->doublemd5($reg_pass, $random_password_salt);
                        $stmt = $testCon->prepare("INSERT INTO " . $prefix . "_user (`login`, `email`, `nick`, `pass`, `access_level`) VALUES(?, ?, 'admin', ?, '3')");
                        $stmt->bindParam(1, $reg_login, \PDO::PARAM_STR);
                        $stmt->bindParam(2, $reg_email, \PDO::PARAM_STR);
                        $stmt->bindParam(3, $md5_doublehash, \PDO::PARAM_STR, 32);
                        $stmt->execute();
                        $user_id = $testCon->lastInsertId();
                        $stmt = null;
                        $stmt = $testCon->prepare("INSERT INTO " . $prefix . "_user_custom(`id`) VALUES (?)");
                        $stmt->bindParam(1, $user_id, \PDO::PARAM_INT);
                        $stmt->execute();
                        $stmt = null;
                        $testCon = null;
                        $params['notify']['success'] = true;
                    }
                }
                foreach (system::getInstance()->post(null) as $var_name => $var_value) {
                    if (system::getInstance()->prefixEquals($var_name, 'config:')) {
                        $var_name = substr($var_name, strlen('config:'));
                        template::getInstance()->set('cfg', $var_name, $var_value);
                    }
                }
            }
        }
        return template::getInstance()->twigRender('install.tpl', $params);
    }
Esempio n. 14
0
 /**
  * Save data in cache file storage
  * @param string $name
  * @param string $data
  */
 public function store($name, $data)
 {
     $name = md5($name);
     system::getInstance()->putFile($data, root . self::CACHE_DIR . $name . '.cache');
 }
Esempio n. 15
0
 /**
  * Add to rendering variable with value. If add is true value not be replaced, added.
  * @param $type ['content', 'language', 'system']
  * @param string $variable
  * @param string|array $value
  * @param bool $add
  */
 public function set($type, $variable, $value, $add = false)
 {
     if (system::getInstance()->length($variable) < 1 || !is_array($value) && system::getInstance()->length($value) < 1 || is_array($value) && $add) {
         return;
     }
     $this->variables[$type][$variable] = $add ? $this->variables[$type][$variable] . $value : $value;
 }
Esempio n. 16
0
 /**
  * Load user data in memory from list $idlist (array or string list like 1,5,7,8)
  * @param string|array $idlist
  */
 public function listload($idlist)
 {
     $list_array = system::getInstance()->removeNullFrontIntList($idlist);
     // array
     if (sizeof($list_array) < 2) {
         return;
     }
     $idlist = system::getInstance()->altimplode(',', $list_array);
     // string
     $query = "SELECT * FROM\r\n            " . property::getInstance()->get('db_prefix') . "_user a,\r\n            " . property::getInstance()->get('db_prefix') . "_user_access_level b,\r\n            " . property::getInstance()->get('db_prefix') . "_user_custom c\r\n            WHERE a.id in ({$idlist}) AND a.aprove = 0 AND a.access_level = b.group_id AND a.id = c.id";
     $stmt = database::getInstance()->con()->prepare($query);
     $stmt->execute();
     $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt = null;
     foreach ($result as $item) {
         foreach ($item as $param => $data) {
             $this->userdata[$item['id']][$param] = $data;
         }
     }
 }
Esempio n. 17
0
// HTTP/1.0
header("Pragma: no-cache");
//error_reporting(-1);
//ini_set('display_errors', 1);
//path properties
define('MAIN_PATH', $mainPath);
define('ROOT_PATH', $rootPath);
define('MAIN_DIR', $mainDir);
//DB config
define('DB_HOST', "10.10.10.120");
define('DB_NAME', "tree_editor");
define('DB_USER', "root");
define('DB_PASS', "`12345';';");
//DB config ENSEMBL
define('DB_HOST_ENSEMBL', "gramenedb.gramene.org");
define('DB_NAME_ENSEMBL', "ensembl_compara_plants_40_74");
define('DB_USER_ENSEMBL', "anonymous");
define('DB_PASS_ENSEMBL', "gramene");
//includes
require_once $libDir . 'smarty/SmartyBC.class.php';
require_once $libDir . 'smarty/SmartyInstance.class.php';
// create object
$smarty = SmartyInstance::getInstance()->smarty;
require_once $libDir . "adodb/adodb.inc.php";
require_once $libDir . "adodb/DBConn.class.php";
require_once $libDir . "classes/all_classes.inc.php";
require_once $rootPath . "php/all_controllers.inc.php";
//database connect
$dbconn = DBConn::getInstance()->conn;
$system = system::getInstance($dbconn);
$smarty->assign('mainDir', $mainDir);
Esempio n. 18
0
 function __construct()
 {
     $this->dbconn = DBConn::getInstance()->conn;
     $this->smarty = SmartyInstance::getInstance()->smarty;
     $this->system = system::getInstance($this->dbconn);
 }
Esempio n. 19
0
 private function loadVersionMd5List()
 {
     $ff_repo_url = self::REMOTE_CHECKSUM . '?version=' . version;
     $save_cache_name = 'antivirus_checksum_' . version;
     if (cache::getInstance()->get($save_cache_name, self::REMOTE_CACHETIME)) {
         $this->version_md5 = @unserialize(cache::getInstance()->get($save_cache_name, self::REMOTE_CACHETIME));
         return null;
     }
     $response = system::getInstance()->url_get_contents($ff_repo_url);
     if (!is_null($response) && $response != 'error') {
         $this->version_md5 = @unserialize($response);
     } else {
         $md5file = root . "/resource/antivirus/.md5sum";
         if (file_exists($md5file)) {
             $this->version_md5 = unserialize(@file_get_contents($md5file));
             logger::getInstance()->log(logger::LEVEL_NOTIFY, 'Using local antivirus signature. Remote repository with hashsum antivirus is not available: ' . $ff_repo_url);
         } else {
             logger::getInstance()->log(logger::LEVEL_WARN, 'Local antivirus hashsum signature not founded:' . $md5file);
         }
     }
     cache::getInstance()->save($save_cache_name, serialize($this->version_md5));
 }
Esempio n. 20
0
 /**
  * Create fast hash from current URI without 1st element usage.
  * Can also create from $additional array way without usage current path
  * @param null $additional
  * @return null|string
  */
 public function hashUri($additional = null)
 {
     $array_object = array();
     if ($additional != null) {
         // nil element
         $array_object[] = $this->patharray[0];
         // next way from add
         foreach ($additional as $values) {
             $array_object[] = $values;
         }
     } else {
         $array_object = $this->patharray;
     }
     $string = null;
     for ($i = 1; $i <= sizeof($array_object); $i++) {
         if (system::getInstance()->suffixEquals($array_object[$i], '.html')) {
             $string .= $array_object[$i];
             continue;
         } elseif ($array_object[$i] != null) {
             $string .= $array_object[$i] . "/";
         }
     }
     return $string != null ? md5($string) : null;
 }