コード例 #1
0
 /**
  * Method for enabling an apache2 site
  * The script does the following:
  * - create access.log and error.log in ./logs
  * - create virtual configuration and put it in sites-available
  * - enable new site
  * - create new /etc/hosts file
  *
  * @param array $options $options[sitename] 
  */
 public static function enableSite($options)
 {
     $hostname = trim($options['hostname']);
     self::createLogs();
     common::needRoot();
     // create apache2 conf and enable site
     $apache2_conf = self::getA2Conf($hostname);
     $tmp_file = conf::pathBase() . "/tmp/{$hostname}";
     file_put_contents($tmp_file, $apache2_conf);
     $apache2_conf_file = "/etc/apache2/sites-available/{$hostname}";
     // some changes in apache 2.4.x from apache 2.2.x
     // se http://httpd.apache.org/docs/current/upgrading.html
     $version = self::getVersion();
     $version = version::getSemanticAry($version);
     if ($version['minor'] >= 4) {
         $apache2_conf_file .= ".conf";
     }
     common::execCommand("cp -f tmp/{$hostname} {$apache2_conf_file}");
     common::execCommand("a2ensite {$hostname}");
     // create new hosts file and reload server
     // not very exact match
     $hosts_file_str = file_get_contents("/etc/hosts");
     $host_str = "127.0.0.1\t{$hostname}\n";
     if (!strstr($hosts_file_str, $host_str)) {
         $new_hosts_file_str = $host_str . $hosts_file_str;
         file_put_contents("tmp/hosts", $new_hosts_file_str);
         common::execCommand("cp -f tmp/hosts /etc/hosts");
     }
     common::execCommand("/etc/init.d/apache2 reload");
 }
コード例 #2
0
 /**
  * 
  * @param   array $options
  */
 public function setInstallInfo($options)
 {
     $this->installInfo = array();
     // Base info
     $module_name = $options['module'];
     $module_dir = conf::pathModules() . "/{$module_name}";
     // ini file info
     $ini_file = $module_dir . "/{$module_name}.ini";
     $ini_file_dist = $module_dir . "/{$module_name}.ini-dist";
     // If profile is set. Then use profile's module ini dist settings
     if (isset($options['profile'])) {
         $ini_file_dist = conf::pathBase() . "/profiles/{$options['profile']}/{$module_name}.ini-dist";
     }
     // If module_dir already exists, then try to load ini settings of the module
     if (file_exists($module_dir)) {
         // Generate an ini file
         $this->generateInifile($ini_file, $ini_file_dist);
         // Merge in locale.ini settings if found
         $this->loadLocaleIniSettings($module_dir);
         // load install.inc if found
         $install_file = "{$module_dir}/install.inc";
         $this->loadInstallFile($module_name, $install_file);
     } else {
         $status = "No module dir: {$module_dir}";
         common::echoStatus('NOTICE', 'y', $status);
         return false;
     }
 }
コード例 #3
0
ファイル: micro.php プロジェクト: gpawlik/suited-php-classes
 /**
  * Sets a controller and a action
  */
 private function setControllerAction()
 {
     // Parse url. 2 cases:
     // a) Default controller
     // b) Module controller
     // Get all modules
     $mod_path = conf::pathBase() . "/" . $this->modules;
     $mods = file::getDirsGlob($mod_path, array('basename' => true));
     $base = direct::fragment(0);
     if (!in_array($base, $mods)) {
         // Could not find a controller / module
         $this->controller = $this->default;
         $action = direct::fragment(0);
         if ($action) {
             $this->action = $action;
         }
     } else {
         // Found a controller / module
         $this->controller = $base;
         $action = direct::fragment(1);
         if ($action) {
             $this->action = $action;
         }
     }
 }
コード例 #4
0
ファイル: log.php プロジェクト: gpawlik/suited-php-classes
 /**
  * set log file. 
  * Can be used for CLI
  * @param string $file
  */
 public static function setErrorLog($file = null)
 {
     if (!$file) {
         self::$cliLog = conf::pathBase() . '/logs/coscms.log';
     } else {
         self::$cliLog = $file;
     }
 }
コード例 #5
0
ファイル: clear.php プロジェクト: gpawlik/suited-php-classes
 public static function assets($options = null)
 {
     $path = conf::pathBase() . "/htdocs/files/default/cached_assets";
     if (file_exists($path)) {
         file::rrmdir($path);
     }
     return 1;
 }
コード例 #6
0
 public function modulesAutoLoader($classname)
 {
     $class = str_replace('\\', '/', $classname) . "";
     $class = conf::pathBase() . "/" . ($class .= ".php");
     if (file_exists($class)) {
         require $class;
     }
 }
コード例 #7
0
ファイル: cron.php プロジェクト: diversen/simple-php-classes
function cron_install()
{
    $mes = "Add the following line to your crontab";
    common::echoMessage($mes);
    $command = conf::pathBase() . "/coscli.sh cron --run";
    $log = conf::pathBase() . "/logs/cron.log";
    $command = "* * * * * {$command} >> {$log} 2>&1";
    common::echoMessage($command);
    return 0;
}
コード例 #8
0
function multi_shared_exec_command($options = null)
{
    $path = conf::pathBase() . "/config/multi/*";
    if (!isset($options['command'])) {
        common::abort('Specify a command');
        return 1;
    }
    $command = $options['command'];
    $dirs = file::getDirsGlob($path, array('basename' => 1));
    foreach ($dirs as $domain) {
        $exec_command = "./coscli.sh --domain={$domain} {$command}";
        common::echoMessage("Executing command: {$exec_command}");
        passthru($exec_command, $return_var);
    }
}
コード例 #9
0
/**
 * function for purgeing a template
 *
 * @param   array  options
 */
function purge_template($options)
{
    //uninstall_module($options);
    if (strlen($options['template']) == 0) {
        common::echoMessage("No such template: {$options['template']}");
        common::abort();
    }
    $template_path = conf::pathBase() . '/htdocs/templates/' . $options['template'];
    if (!file_exists($template_path)) {
        common::echoMessage("Template already purged: No such template path: {$template_path}");
        common::abort();
    }
    $command = "rm -rf {$template_path}";
    common::execCommand($command);
}
コード例 #10
0
ファイル: doc.php プロジェクト: gpawlik/suited-php-classes
/**
 * wrapper function for creating documention with phpdoc
 * hi! I'am created with this function :)
 *
 * @return int  value from cos_system command
 */
function create_docs()
{
    // check if command exists
    $command = "whereis phpdoc";
    $ret = common::execCommand($command);
    if ($ret) {
        common::echoMessage("Could not find command phpdoc on your system");
        common::echoMessage("If the command phpdoc is not on your system we will not be able to create documentation.");
        common::echoMessage("One way to do this is to: pear install PhpDocumentor");
        exit(127);
    }
    $command = "phpdoc run ";
    $command .= "-d coslib ";
    $command .= "--template abstract -t " . conf::pathBase() . "/htdocs/phpdocs ";
    common::systemCommand($command);
}
コード例 #11
0
ファイル: main.php プロジェクト: gpawlik/suited-php-classes
 /**
  * Do this after the commandline options has been parsed. 
  * Examine the --domain flag and the --verbose flag
  * @param type $result
  */
 public static function afterParse($result)
 {
     $verbose = $result->options['verbose'];
     conf::setMainIni('verbose', $verbose);
     // Check if other domain than default is being used
     $domain = $result->options['domain'];
     conf::setMainIni('domain', $domain);
     if ($domain != 'default' || empty($domain)) {
         $domain_ini = conf::pathBase() . "/config/multi/{$domain}/config.ini";
         if (!file_exists($domain_ini)) {
             common::abort("No such domain - no configuration found: '{$domain_ini}'");
         } else {
             // If domain is used - Load domain specific configuration
             conf::loadMainCli();
         }
     }
 }
コード例 #12
0
/**
 * will update all translation files in specified language
 * @param array $options
 */
function translate_path($options)
{
    if (!isset($options['path'])) {
        common::abort('Add a path');
    }
    $path = conf::pathBase() . "/{$options['path']}";
    if (!file_exists($path) or !is_dir($path)) {
        common::abort('Specify a dir as path');
    }
    $e = new extractor();
    if (!empty($options['language'])) {
        $e->defaultLanguage = $options['language'];
    }
    $e->setSingleDir($options['path']);
    $e->updateLang();
    common::echoStatus('OK', 'g', 'Extraction done');
}
コード例 #13
0
ファイル: multi.php プロジェクト: gpawlik/suited-php-classes
/**
 * executes a shell command on all coscms systems install in parent dir (../) from
 * current dir
 * @param string $command
 * @return int $ret
 */
function multi_exec_shell_command($options = array())
{
    $path = conf::pathBase() . "/../";
    if (!isset($options['command'])) {
        common::abort('Specify a command');
        return 1;
    }
    $command = $options['command'];
    $dirs = file::getDirsGlob($path, array('basename' => 1));
    foreach ($dirs as $domain) {
        if (!file_exists("../{$domain}/config/config.ini")) {
            continue;
        }
        $exec_command = "cd ../{$domain} && {$command}";
        multi_passthru($exec_command);
    }
}
コード例 #14
0
ファイル: sqlite.php プロジェクト: gpawlik/suited-php-classes
function db_to_sqlite($options = array())
{
    $check = "which sequel";
    if (common::execCommand($check)) {
        common::echoMessage('You need sequel. Install it like this, e.g.:');
        common::echoMessage('sudo aptitude install ruby-sequel libsqlite3-ruby libmysql-ruby');
        common::abort();
    } else {
        common::echoStatus('OK', 'g', 'Sequel is installed');
    }
    $ok = false;
    $info = admin::getDbInfo();
    if (!$info) {
        return db_no_url();
    }
    if ($info['scheme'] == 'mysql') {
        $ok = true;
    }
    if ($info['scheme'] == 'mysqli') {
        $ok = true;
    }
    if (!$ok) {
        common::echoStatus('ERROR', 'r', 'Driver needs to be mysql or mysqli');
    }
    $fs = new Filesystem();
    $fs->remove('sqlite/database.sql');
    $username = conf::getMainIni('username');
    $password = conf::getMainIni('password');
    $command = "sequel ";
    $command .= "{$info['scheme']}://{$username}:{$password}@{$info['host']}/{$info['dbname']} ";
    $command .= "-C ";
    $command .= "sqlite://sqlite/database.sql";
    $ret = common::systemCommand($command);
    $base = conf::pathBase();
    if (!$ret) {
        $fs->chmod('sqlite/database.sql', 0777, 00, true);
        common::echoMessage('Sqlite database created. Edit config.ini and add:');
        common::echoMessage("sqlite:/{$base}/sqlite/database.sql");
    }
}
コード例 #15
0
/**
 * function for loading a database file into db specified in config.ini
 *
 * @param   array   options. You can specifiy a file to load in options.
 *                  e.g. <code>$options = array('File' => 'backup/sql/latest.sql')</code>
 * @return  int     the executed commands shell status 0 on success.
 */
function cos_db_load_table($options)
{
    if (!isset($options['table'])) {
        common::abort('Specify a table to load with a backup');
    }
    $dump_dir = "backup/sql/{$options['table']}";
    if (!file_exists($dump_dir)) {
        common::abort('Yet no backups');
    }
    $search = conf::pathBase() . "/backup/sql/{$options['table']}";
    $latest = get_latest_db_dump($search);
    if ($latest == 0) {
        common::abort('Yet no database dumps');
    }
    $latest = "backup/sql/{$options['table']}/" . $latest . ".sql";
    $db = admin::getDbInfo();
    if (!$db) {
        return db_no_url();
    }
    $command = "mysql --default-character-set=utf8  -u" . conf::$vars['coscms_main']['username'] . " -p" . conf::$vars['coscms_main']['password'] . " {$db['dbname']} < {$latest}";
    return $ret = common::execCommand($command);
}
コード例 #16
0
ファイル: heroku.php プロジェクト: gpawlik/suited-php-classes
/**
 * set csendgrid config in config.ini
 */
function heroku_set_sendgrid_conf()
{
    $user = heroku_get_setting('SENDGRID_USERNAME');
    $pass = heroku_get_setting('SENDGRID_PASSWORD');
    if ($user && $pass) {
        $config_file = heroku_get_config_filename();
        conf::$vars['coscms_main'] = conf::getIniFileArray($config_file, true);
        $from_text = common::readSingleline('Enter which from text should be seen in his inbx, e.g. CosCMS (not the email)');
        $reply = common::readSingleline('Enter which email users should reply to (an email):');
        conf::$vars['coscms_main']['site_email'] = "{$from_text} <{$user}>";
        conf::$vars['coscms_main']['site_email_reply'] = "{$from_text} <{$reply}>";
        conf::$vars['coscms_main']['smtp_params_host'] = "smtp.sendgrid.net";
        conf::$vars['coscms_main']['smtp_params_sender'] = $user;
        conf::$vars['coscms_main']['smtp_params_username'] = $user;
        conf::$vars['coscms_main']['smtp_params_password'] = $pass;
        conf::$vars['coscms_main']['smtp_params_auth'] = "true";
        conf::$vars['coscms_main']['smtp_params_port'] = 587;
        $content = conf::arrayToIniFile(conf::$vars['coscms_main'], false);
        $path = conf::pathBase() . "/config/config.ini";
        file_put_contents($path, $content);
    }
}
コード例 #17
0
 /**
  * reads install info from modules/module_name/install.inc
  * @param   array $options
  */
 public function setInstallInfo($options)
 {
     // In profile all templates are also modules
     if (isset($options['module_name'])) {
         $template_name = $options['module_name'];
     } else {
         $template_name = $options['template'];
     }
     // Set dir and ini files
     $template_dir = conf::pathHtdocs() . "/templates/{$template_name}";
     $ini_file = $template_dir . "/{$template_name}.ini";
     $ini_file_dist = $template_dir . "/{$template_name}.ini-dist";
     // Profile
     if (isset($options['profile'])) {
         $ini_file_dist = conf::pathBase() . "/profiles/{$options['profile']}/{$template_name}.ini-dist";
     }
     // Generate ini file
     $this->generateInifile($ini_file, $ini_file_dist);
     if (file_exists($template_dir)) {
         $install_file = "{$template_dir}/install.inc";
         if (!file_exists($install_file)) {
             common::echoMessage("Notice: No install file '{$install_file}' found in: '{$template_dir}'\n");
         }
         $this->installInfo['NAME'] = $template_name;
         // if no version we check if this is a git repo
         if (!isset($this->installInfo['VERSION'])) {
             $this->setInstallInfoFromGit();
         }
         if (file_exists($install_file)) {
             include $install_file;
             $this->installInfo = $_INSTALL;
             $this->installInfo['NAME'] = $template_name;
             $this->installInfo['RUN_LEVEL'] = 0;
         }
     } else {
         common::echoMessage("Notice: No template dir: {$template_dir}\n");
     }
 }
コード例 #18
0
/**
 * function for updating a modules .ini file with new settings
 * from updated ini-dist file.
 *  
 * @param array     $options 
 */
function upgrade_config_ini_file($options)
{
    $ini_file_path = conf::pathBase() . "/config/config.ini";
    $ini_dist_path = conf::pathBase() . "/profiles/{$options['profile']}/config.ini-dist";
    $ini_file = conf::getIniFileArray($ini_file_path, true);
    $ini_dist = conf::getIniFileArray($ini_dist_path, true);
    $ary = array_merge($ini_dist, $ini_file);
    $ary_diff = array_diff($ary, $ini_file);
    $content = conf::arrayToIniFile($ary);
    file_put_contents($ini_file_path, $content);
    if (empty($ary_diff)) {
        common::echoMessage("No new ini file settings for config.ini");
    } else {
        $new_settings_str = conf::arrayToIniFile($ary_diff);
        common::echoMessage("New ini file written to: {$ini_file_path}");
        common::echoMessage("These are the new ini settings for config.ini");
        common::echoMessage(trim($new_settings_str));
    }
}
コード例 #19
0
/**
 * function for doing a prompt install from shell mode
 * is a wrapper around other shell functions.
 */
function prompt_install()
{
    common::echoMessage('Pick a version to install:', 'y');
    $tags = git::getTagsInstallLatest() . PHP_EOL;
    $tags .= "master";
    common::echoMessage($tags);
    $tag = common::readSingleline("Enter tag (version) to use:");
    common::execCommand("git checkout {$tag}");
    // Which profile to install
    $profiles = file::getFileList('profiles', array('dir_only' => true));
    if (count($profiles) == 1) {
        $profile = array_pop($profiles);
    } else {
        common::echoMessage("List of profiles: ");
        foreach ($profiles as $val) {
            common::echoMessage("\t" . $val);
        }
        // select profile and load it
        $profile = common::readSingleline('Enter profile, and hit return: ');
    }
    common::echoMessage("Loading the profile '{$profile}'", 'y');
    load_profile(array('profile' => $profile, 'config_only' => true));
    common::echoMessage("Main configuration (placed in config/config.ini) for '{$profile}' is loaded", 'y');
    // Keep base path. Ortherwise we will lose it when loading profile
    $base_path = conf::pathBase();
    // Load the default config.ini settings as a skeleton
    conf::$vars['coscms_main'] = conf::getIniFileArray($base_path . '/config/config.ini', true);
    // Reset base path
    conf::setMainIni('base_path', $base_path);
    conf::defineCommon();
    common::echoMessage("Enter MySQL credentials", 'y');
    // Get configuration info
    $host = common::readSingleline('Enter your MySQL host: ');
    $database = common::readSingleline('Enter database name: ');
    $username = common::readSingleline('Enter database user: '******'Enter database users password: '******'Enter server host name: ');
    common::echoMessage("Writing database connection info to main configuration");
    // Assemble configuration info
    conf::$vars['coscms_main']['url'] = "mysql:dbname={$database};host={$host};charset=utf8";
    conf::$vars['coscms_main']['username'] = $username;
    conf::$vars['coscms_main']['password'] = $password;
    conf::$vars['coscms_main']['server_name'] = $server_name;
    // Write it to ini file
    $content = conf::arrayToIniFile(conf::$vars['coscms_main'], false);
    $path = conf::pathBase() . "/config/config.ini";
    file_put_contents($path, $content);
    common::echoMessage("Your can also always change the config/config.ini file manually");
    $options = array();
    $options['profile'] = $profile;
    if ($tag == 'master') {
        $options['master'] = true;
    }
    common::echoMessage("Will now clone and install all modules", 'y');
    cos_install($options);
    common::echoMessage("Create a super user", 'y');
    useradd_add();
    $login = "******";
    common::echoMessage("If there was no errors you will be able to login at {$login}");
    common::echoMessage("Remember to change file permissions. This will require super user");
    common::echoMessage("E.g. like this:");
    common::echoMessage("sudo ./coscli.sh file --chmod-files");
}
コード例 #20
0
ファイル: boot.php プロジェクト: gpawlik/suited-php-classes
 public function run()
 {
     // Register an autoloader for loading modules from mopdules dir
     $m = new modules();
     $m->autoloadRegister();
     // define HTML constants
     common::defineConstants();
     // define global constants - based on base path
     conf::defineCommon();
     // set include paths
     conf::setIncludePath();
     // load config file
     conf::load();
     // set log level - based on config.ini
     log::setLogLevel();
     // utf-8
     ini_set('default_charset', 'UTF-8');
     // load config/config.ini
     // check if there exists a shared ini file
     // shared ini is used if we want to enable settings between hosts
     // which share same code base.
     // e.g. when updating all sites, it is a good idea to set the following flag
     // site_update = 1
     // this flag will send correct 503 headers, when we are updating our site.
     // if site is being updaing we send temporarily headers
     // and display an error message
     if (conf::getMainIni('site_update')) {
         http::temporarilyUnavailable();
     }
     // set a unified server_name if not set in config file.
     $server_name = conf::getMainIni('server_name');
     if (!$server_name) {
         conf::setMainIni('server_name', $_SERVER['SERVER_NAME']);
     }
     // redirect to uniform server name is set in config.ini
     // e.g. www.testsite.com => testsite.com
     $server_redirect = conf::getMainIni('server_redirect');
     if (isset($server_redirect)) {
         http::redirectHeaders($server_redirect);
     }
     // redirect to https is set in config.ini
     // force anything into ssl mode
     $server_force_ssl = conf::getMainIni('server_force_ssl');
     if (isset($server_force_ssl)) {
         http::sslHeaders();
     }
     // catch all output
     ob_start();
     // Create a db connection
     $db = new db();
     // init module loader.
     $ml = new moduleloader();
     // initiate uri
     uri::getInstance();
     // runlevel 1: merge db config
     $ml->runLevel(1);
     // select all db settings and merge them with ini file settings
     $db_settings = $db->selectOne('settings', 'id', 1);
     // merge db settings with config/config.ini settings
     // db settings override ini file settings
     conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings);
     // run level 2: set locales
     $ml->runLevel(2);
     // set locales
     intl::setLocale();
     // set default timezone
     intl::setTimezone();
     // runlevel 3 - init session
     $ml->runLevel(3);
     // start session
     session::initSession();
     $res = session::checkAccount();
     if (!$res) {
         // To prevent
         http::locationHeader('/');
     }
     // set account timezone if enabled - can only be done after session
     // as user needs to be logged in
     intl::setAccountTimezone();
     // run level 4 - load language
     $ml->runLevel(4);
     // load all language files
     $l = new lang();
     $base = conf::pathBase();
     $htdocs = conf::pathHtdocs();
     $l->setDirsInsideDir("{$base}/modules/");
     $l->setDirsInsideDir("{$htdocs}/templates/");
     $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
     $l->setSingleDir("{$base}/vendor/diversen/simple-pager");
     $l->loadLanguage(conf::getMainIni('language'));
     // runlevel 5
     $ml->runLevel(5);
     // load routes if any
     dispatch::setDbRoutes();
     // runlevel 6
     $ml->runLevel(6);
     // check db routes or load by defaults
     $db_route = dispatch::getMatchRoutes();
     if (!$db_route) {
         $ml->setModuleInfo();
         $ml->initModule();
     }
     // Init layout. Sets template name
     // load correct CSS. St menus if any. Etc.
     $layout = new layout();
     // we first load menus here so we can se what happened when we
     // init our module. In case of a 404 not found error we don't want
     // to load module menus
     $layout->loadMenus();
     // init blocks
     $layout->initBlocks();
     // if any matching route was found we check for a method or function
     if ($db_route) {
         $str = dispatch::call($db_route['method']);
     } else {
         // or we use default module parsing
         $str = $ml->getParsedModule();
     }
     // set view vars
     $vars['content'] = $str;
     // run level 7
     $ml->runLevel(7);
     // echo module content
     echo $str = \mainTemplate::view($vars);
     conf::$vars['final_output'] = ob_get_contents();
     ob_end_clean();
     // Last divine intervention
     // e.g. Dom or Tidy
     $ml->runLevel(8);
     echo conf::$vars['final_output'];
 }
コード例 #21
0
/**
 * CLI command: function for getting latest timestamp from /backup/full dir
 *
 * @return int   backup with most recent timestamp
 */
function backup_get_latest_backup($type = null)
{
    if ($type == 'files') {
        $dir = conf::pathBase() . "/backup/files";
    } else {
        $dir = conf::pathBase() . "/backup/full";
    }
    $list = file::getFileList($dir);
    $time_stamp = 0;
    foreach ($list as $key => $val) {
        $file = explode('.', $val);
        if (is_numeric($file[0])) {
            if ($file[0] > $time_stamp) {
                $time_stamp = $file[0];
            }
        }
    }
    return $time_stamp;
}
コード例 #22
0
ファイル: db.php プロジェクト: diversen/simple-php-classes
/**
 * function for getting latest timestamp for dumps
 * 
 * default to backup/sql but you can specify a dir. 
 *
 * @param   string  $dir
 * @return  int     $timestamp
 */
function get_latest_db_dump($dir = null, $num_files = null)
{
    if (!$dir) {
        $dir = conf::pathBase() . "/backup/sql";
    }
    $list = file::getFileList($dir);
    $time_stamp = 0;
    foreach ($list as $val) {
        $file = explode('.', $val);
        if (is_numeric($file[0])) {
            if ($file[0] > $time_stamp) {
                $time_stamp = $file[0];
            }
        }
    }
    return $time_stamp;
}
コード例 #23
0
ファイル: common.php プロジェクト: gpawlik/suited-php-classes
 function readSql()
 {
     $file = conf::pathBase() . '/scripts/default.sql';
     $this->sql = file_get_contents($file);
     return $this->sql;
 }
コード例 #24
0
ファイル: files.php プロジェクト: gpawlik/suited-php-classes
/**
 * function for removing all files in htdocs/files/*, htdocs/logo/*
 * when doing an install
 *
 * @return int  value from exec command
 */
function cos_create_files()
{
    $files_path = conf::pathBase() . '/logs/coscms.log';
    if (!file_exists($files_path)) {
        $command = "touch {$files_path}";
        common::execCommand($command);
    }
    $files_path = conf::pathBase() . '/htdocs/files';
    if (!file_exists($files_path)) {
        $command = "mkdir {$files_path}";
        common::execCommand($command);
    }
    $domain = conf::getDomain();
    $files_path = conf::pathBase() . "/htdocs/files/{$domain}";
    if (!file_exists($files_path)) {
        $command = "mkdir {$files_path}";
        common::execCommand($command);
    }
}
コード例 #25
0
ファイル: files.php プロジェクト: diversen/simple-php-classes
/**
 * function for removing all files in htdocs/files/*, htdocs/logo/*
 * when doing an install
 *
 * @return int  value from exec command
 */
function cos_create_files()
{
    $files_path = conf::pathBase() . '/logs/coscms.log';
    if (!file_exists($files_path)) {
        $command = "touch {$files_path}";
        common::execCommand($command);
    }
    $files_path = conf::pathBase() . '/logs/cron.log';
    if (!file_exists($files_path)) {
        $command = "touch {$files_path}";
        common::execCommand($command);
    }
    $files_path = conf::pathFiles();
    if (!file_exists($files_path)) {
        $command = "mkdir -p {$files_path}";
        common::execCommand($command);
    }
}
コード例 #26
0
 /**
  * Method for loading main configuration file for a profile
  * @param string $profile the name of profile
  */
 public function loadConfigIni($profile)
 {
     $profile_dir = conf::pathBase() . "/profiles/{$profile}";
     $dest = conf::pathBase() . "/config/config.ini";
     $source = $profile_dir . "/config.ini-dist";
     if (copy($source, $dest)) {
         $this->confirm[] = "Copy {$source} to {$dest}";
     } else {
         $this->error[] = "Could not Copy {$source} to {$dest}";
     }
 }
コード例 #27
0
ファイル: git.php プロジェクト: gpawlik/suited-php-classes
/**
 * function used for cloning a repo
 * @param array $options
 * @param string $type
 */
function cos_git_clone($options, $type)
{
    // get latest repo tag
    $latest = git::getTagsRemoteLatest($options['repo']);
    // if version is set we will use this version.
    // or we will use latest tag.
    if (isset($options['version'])) {
        $checkout = $options['version'];
    } else {
        $checkout = $latest;
    }
    // we abort if there is no tags.
    if (!$latest) {
        $checkout = 'master';
    }
    // check if profile use master or if master is set
    if (isset(conf::$vars['git_use_master']) || isset($options['master'])) {
        $checkout = 'master';
    }
    // set dir according to module type. Template, profile or module.
    if ($type == 'template') {
        $clone_path = conf::pathHtdocs() . "/templates";
    } else {
        if ($type == 'profile') {
            $clone_path = conf::pathBase() . "/profiles";
        } else {
            $clone_path = conf::pathModules();
        }
    }
    // create path if it does not exists
    if (!file_exists($clone_path)) {
        mkdir($clone_path);
    }
    // get module name
    $module_name = git::getModulenameFromRepo($options['repo']);
    $module_path = "{$clone_path}/{$module_name}";
    // if dir exists we check if it is a git repo
    // or just a directory
    $ret = null;
    if (file_exists($module_path)) {
        $repo_dir = $clone_path . "/{$module_name}";
        // check if path is a git repo
        $git_folder = $repo_dir . "/.git";
        if (file_exists($git_folder)) {
            // repo exists. We pull changes and set version
            $git_command = "cd {$repo_dir} && git checkout master && git pull && git checkout {$checkout}";
        } else {
            // no git repo - empty dir we presume.
            $git_command = "cd {$clone_path} && git clone {$options['repo']} && cd {$module_name} && git checkout {$checkout}";
        }
        $ret = common::execCommand($git_command);
    } else {
        $git_command = "cd {$clone_path} && git clone {$options['repo']} && cd {$module_name} && git checkout {$checkout}";
        $ret = common::execCommand($git_command);
    }
    // evaluate actions
    if ($ret) {
        common::abort("{$git_command} failed");
    }
}
コード例 #28
0
 /**
  * Method for moving uploaded file
  * @param  string $filename name of file in the html forms file field
  *                 e.g. 'file'
  * @param array  $options
  * @return boolean $res true on success or false on failure
  */
 public static function moveFile($file = null, $options = null)
 {
     if (isset($options)) {
         self::$options = $options;
     }
     // We can give both just the /htdocs/files ... path
     // then we add conf::pathBase()
     if (!strstr(self::$options['upload_dir'], conf::pathBase())) {
         self::$options['upload_dir'] = conf::pathBase() . self::$options['upload_dir'];
     }
     // check if dir exists
     if (!file_exists(self::$options['upload_dir'])) {
         $res = @mkdir(self::$options['upload_dir'], self::$mode, true);
         if (!$res) {
             echo "Could not make dir: " . self::$options['upload_dir'] . "\n";
         }
     }
     // check if an upload were performed
     if (isset($file)) {
         // check native
         $res = self::checkUploadNative($file);
         if (!$res) {
             return false;
         }
         // check mime
         if (isset(self::$options['allow_mime'])) {
             $res = self::checkAllowedMime($file);
             if (!$res) {
                 return false;
             }
         }
         // check maxsize. Note: Will overrule php ini settings
         if (isset(self::$options['maxsize'])) {
             $res = self::checkMaxSize($file);
             if (!$res) {
                 return false;
             }
         }
         // sets a new filename to save the file as or use the
         // name of the uploaded file.
         if (isset(self::$options['save_basename'])) {
             $save_basename = self::$options['save_basename'];
         } else {
             $save_basename = basename($file['name']);
         }
         self::$confirm['save_basename'] = $save_basename;
         $savefile = self::$options['upload_dir'] . '/' . $save_basename;
         // check if file exists.
         if (file_exists($savefile)) {
             if (isset(self::$options['only_unique'])) {
                 self::$errors[] = lang::translate('File already exists') . MENU_SUB_SEPARATOR_SEC . $savefile;
                 return false;
             } else {
                 // this call will also set self::$info['save_filename']
                 $savefile = self::newFileName($savefile);
             }
         } else {
             self::$saveBasename = $save_basename;
         }
         $ret = move_uploaded_file($file['tmp_name'], $savefile);
         if (!$ret) {
             self::$errors[] = lang::translate('Could not move file.');
             return false;
         }
         $savefile = str_replace(conf::pathHtdocs(), '', $savefile);
         return $savefile;
     }
     log::error('No file to move in ' . __FILE__ . ' ' . __LINE__, false);
     return false;
 }
コード例 #29
0
ファイル: boot.php プロジェクト: diversen/simple-php-classes
 /**
  * Run the system 
  */
 public function run()
 {
     // Register an autoloader for loading modules from mopdules dir
     $m = new modules();
     $m->autoloadRegister();
     // define HTML constants
     common::defineConstants();
     // define global constants - based on base path
     conf::defineCommon();
     // set include paths
     conf::setIncludePath();
     // load config file
     conf::load();
     if (conf::getMainIni('debug')) {
         log::enableDebug();
     }
     // set public file folder in file class
     file::$basePath = conf::getFullFilesPath();
     // utf-8
     ini_set('default_charset', 'UTF-8');
     // load config/config.ini
     // check if there exists a shared ini file
     // shared ini is used if we want to enable settings between hosts
     // which share same code base.
     // e.g. when updating all sites, it is a good idea to set the following flag
     // site_update = 1
     // this flag will send correct 503 headers, when we are updating our site.
     // if site is being updaing we send temporarily headers
     // and display an error message
     if (conf::getMainIni('site_update')) {
         http::temporarilyUnavailable();
     }
     // set a unified server_name if not set in config file.
     $server_name = conf::getMainIni('server_name');
     if (!$server_name) {
         conf::setMainIni('server_name', $_SERVER['SERVER_NAME']);
     }
     // redirect to uniform server name is set in config.ini
     // e.g. www.testsite.com => testsite.com
     $server_redirect = conf::getMainIni('server_redirect');
     if (isset($server_redirect)) {
         http::redirectHeaders($server_redirect);
     }
     // redirect to https is set in config.ini
     // force anything into ssl mode
     $server_force_ssl = conf::getMainIni('server_force_ssl');
     if (isset($server_force_ssl)) {
         http::sslHeaders();
     }
     // catch all output
     ob_start();
     // Create a db connection
     $db_conn = array('url' => conf::getMainIni('url'), 'username' => conf::getMainIni('username'), 'password' => conf::getMainIni('password'), 'db_init' => conf::getMainIni('db_init'));
     // Other options
     // db_dont_persist = 0
     // dont_die = 0 // Set to one and the connection don't die because of
     // e.g. no database etc. This will return NO_DB_CONN as string
     //$url = conf::getMainIni('url');
     connect::connect($db_conn);
     // init module loader.
     $ml = new moduleloader();
     // initiate uri
     uri::getInstance();
     // runlevel 1: merge db config
     $ml->runLevel(1);
     // select all db settings and merge them with ini file settings
     $db_Settings = [];
     if (moduleloader::moduleExists('settings')) {
         $db_settings = q::select('settings')->filter('id =', 1)->fetchSingle();
     }
     // merge db settings with config/config.ini settings
     // db settings override ini file settings
     conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings);
     // run level 2: set locales
     $ml->runLevel(2);
     // set locales
     intl::setLocale();
     // set default timezone
     intl::setTimezone();
     // runlevel 3 - init session
     $ml->runLevel(3);
     // start session
     session::initSession();
     // Se if user is logged in with SESSION
     if (!session::isUser()) {
         // If not logged in check system cookie
         // This will start the session, if an appropiate cookie exists
         session::checkSystemCookie();
     }
     // Check account
     $res = session::checkAccount();
     if (!$res) {
         // Redirect to main page if user is not allowed
         // With current SESSION or COOKIE
         http::locationHeader('/');
     }
     // set account timezone if enabled - can only be done after session
     // as user needs to be logged in
     intl::setAccountTimezone();
     // run level 4 - load language
     $ml->runLevel(4);
     // load all language files
     $l = new lang();
     $base = conf::pathBase();
     $htdocs = conf::pathHtdocs();
     $l->setDirsInsideDir("{$base}/modules/");
     $l->setDirsInsideDir("{$htdocs}/templates/");
     $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes");
     $l->setSingleDir("{$base}/vendor/diversen/simple-pager");
     $l->loadLanguage(conf::getMainIni('lang'));
     // runlevel 5
     $ml->runLevel(5);
     // load routes if any
     dispatch::setDbRoutes();
     // check db routes or load defaults
     $db_route = dispatch::getMatchRoutes();
     if (!$db_route) {
         $ml->setModuleInfo();
         $ml->initModule();
     } else {
         dispatch::includeModule($db_route['method']);
     }
     // After module has been loaded.
     // You can e.g. override module ini settings
     $ml->runLevel(6);
     // Init layout. Sets template name
     // load correct CSS. St menus if any. Etc.
     $layout = new layout();
     // we first load menus here so we can se what happened when we
     // init our module. In case of a 404 not found error we don't want
     // to load module menus
     $layout->loadMenus();
     // init blocks
     $layout->initBlocks();
     // if any matching route was found we check for a method or function
     if ($db_route) {
         $str = dispatch::call($db_route['method']);
     } else {
         // or we use default module parsing
         $str = $ml->getParsedModule();
     }
     // set view vars
     $vars['content'] = $str;
     // run level 7
     $ml->runLevel(7);
     // echo module content
     echo $str = \mainTemplate::view($vars);
     conf::$vars['final_output'] = ob_get_contents();
     ob_end_clean();
     // Last divine intervention
     // e.g. Dom or Tidy
     $ml->runLevel(8);
     echo conf::$vars['final_output'];
 }