From 9a835eccd13769c71f7fefc6d58567435390e54d Mon Sep 17 00:00:00 2001 From: "lukas.weberruss" Date: Wed, 23 Jul 2025 08:40:04 +0000 Subject: [PATCH] Add config.php.tpl --- config.php.tpl | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 config.php.tpl diff --git a/config.php.tpl b/config.php.tpl new file mode 100644 index 0000000..af20f9b --- /dev/null +++ b/config.php.tpl @@ -0,0 +1,82 @@ +wwwroot = "${wwwroot}"; +$CFG->dirroot = __DIR__; +$CFG->dataroot = '/tmp/moodledata'; +$CFG->admin = 'admin'; +$CFG->directorypermissions = 0777; + +$CFG->sslproxy = 1; +$CFG->slasharguments = false; +%{ if use_cdn ~} +$CFG->reverseproxy = 1; +$CFG->trustedproxies = '127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, ${cdn_proxy_ip}'; +%{ endif ~} + +if (!file_exists($CFG->dataroot)) { + @mkdir($CFG->dataroot, $CFG->directorypermissions, true); +} + +$CFG->dbtype = 'mariadb'; +$CFG->dblibrary = 'native'; +$CFG->prefix = 'mdl_'; +$CFG->dboptions = array ('dbpersist' => 0, 'dbcollation' => 'utf8mb4_unicode_ci'); + +$vcap_services_json = getenv('VCAP_SERVICES'); +if ($vcap_services_json) { + $vcap_services = json_decode($vcap_services_json, true); + + if (isset($vcap_services["${db_service_name}"])) { + $db_creds = $vcap_services["${db_service_name}"][0]['credentials']; + $CFG->dbhost = $db_creds['host']; + $CFG->dbname = $db_creds['name']; + $CFG->dbuser = $db_creds['username']; + $CFG->dbpass = $db_creds['password']; + $CFG->dboptions['dbport'] = $db_creds['port']; + if (isset($db_creds['cacrt'])) { + $ca_cert_path = '/tmp/db-ca.crt'; + file_put_contents($ca_cert_path, $db_creds['cacrt']); + $CFG->dboptions['ssl_ca'] = $ca_cert_path; + $CFG->dboptions['ssl_verify_server_cert'] = true; + } + } + + if (isset($vcap_services["${redis_service_name}"])) { + $redis_creds = $vcap_services["${redis_service_name}"][0]['credentials']; + $CFG->session_handler_class = '\cachestore_redis\session_handler'; + $CFG->session_redis_host = $redis_creds['host']; + $CFG->session_redis_port = $redis_creds['port']; + $CFG->session_redis_password = $redis_creds['password']; + $CFG->session_redis_prefix = 'moodlesess_'; + $CFG->lock_factory = '\cachestore_redis\lock_factory'; + } + + if (isset($vcap_services['user-provided'])) { + foreach ($vcap_services['user-provided'] as $service) { + if ($service['name'] === '${s3_cups_name}') { + $s3_creds = $service['credentials']; + $CFG->objectfs_s3_key = $s3_creds['access_key']; + $CFG->objectfs_s3_secret = $s3_creds['secret_key']; + $CFG->objectfs_s3_bucket = $s3_creds['bucket']; + $CFG->objectfs_s3_endpoint = $s3_creds['endpoint']; + break; + } + } + } +} +if (empty($CFG->session_handler_class)) { + $CFG->session_handler_class = '\core\session\database'; +} + +%{ if use_cdn ~} +$CFG->cookiepath = '/'; +$CFG->cookiedomain = "${moodle_domain}"; +$CFG->cookiesecure = 1; +$CFG->cookiehttponly = 1; +%{ endif ~} + +require_once(__DIR__ . '/lib/setup.php'); \ No newline at end of file