|
| 1 | +<?php |
| 2 | +$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; |
| 3 | + |
| 4 | +// check if memcache isn't available but enabled in config -> error |
| 5 | +if (!class_exists('Memcached') && $config['memcache']['enabled']) { |
| 6 | + $newerror = array(); |
| 7 | + $newerror['name'] = "Memcache Config"; |
| 8 | + $newerror['level'] = 3; |
| 9 | + $newerror['extdesc'] = "Memcache is a service that you run that lets us cache commonly used data and access it quickly. It's highly recommended you <a href='https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide#requirements-1'>install the service and php packages</a> for your distro."; |
| 10 | + $newerror['description'] = "You have memcached enabled in your config and it's not available as a PHP module. Install the package on your system."; |
| 11 | + $newerror['configvalue'] = "memcache.enabled"; |
| 12 | + $newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-memcache"; |
| 13 | + $error[] = $newerror; |
| 14 | + $newerror = null; |
| 15 | +} |
| 16 | + |
| 17 | +// if it's not enabled, test it if it exists, if it works -> error tell them to enable, -> otherwise notice it's disabled |
| 18 | +if (!$config['memcache']['enabled']) { |
| 19 | + if (PHP_OS == 'WINNT') { |
| 20 | + require_once(CLASS_DIR . 'memcached.class.php'); |
| 21 | + } |
| 22 | + if (class_exists('Memcached')) { |
| 23 | + $memcache_test = @new Memcached(); |
| 24 | + if ($config['memcache']['sasl'] === true) { |
| 25 | + $memcache_test->setOption(Memcached::OPT_BINARY_PROTOCOL, true); |
| 26 | + $memcache_test->setSaslAuthData($config['memcache']['sasl']['username'], $config['memcache']['sasl']['password']); |
| 27 | + } |
| 28 | + $memcache_test_add = @$memcache_test->addServer($config['memcache']['host'], $config['memcache']['port']); |
| 29 | + $randmctv = rand(5,10); |
| 30 | + $memcache_test_set = @$memcache_test->set('test_mpos_setval', $randmctv); |
| 31 | + $memcache_test_get = @$memcache_test->get('test_mpos_setval'); |
| 32 | + } |
| 33 | + if (class_exists('Memcached') && $memcache_test_get == $randmctv) { |
| 34 | + $newerror = array(); |
| 35 | + $newerror['name'] = "Memcache Config"; |
| 36 | + $newerror['level'] = 2; |
| 37 | + $newerror['extdesc'] = "Memcache is a service that you run that lets us cache commonly used data and access it quickly. It's highly recommended you <a href='https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide#requirements-1'>install the service and php packages</a> for your distro."; |
| 38 | + $newerror['description'] = "You have memcache disabled in the config but it's available and works! Enable it for best performance."; |
| 39 | + $newerror['configvalue'] = "memcache.enabled"; |
| 40 | + $newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-memcache"; |
| 41 | + $error[] = $newerror; |
| 42 | + $newerror = null; |
| 43 | + } else { |
| 44 | + $newerror = array(); |
| 45 | + $newerror['name'] = "Memcache Config"; |
| 46 | + $newerror['level'] = 2; |
| 47 | + $newerror['extdesc'] = "Memcache is a service that you run that lets us cache commonly used data and access it quickly. It's highly recommended you <a href='https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide#requirements-1'>install the service and php packages</a> for your distro."; |
| 48 | + $newerror['description'] = "Memcache is disabled; Almost every linux distro has packages for it, you should be using it if you can."; |
| 49 | + $newerror['configvalue'] = "memcache.enabled"; |
| 50 | + $newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-memcache"; |
| 51 | + $error[] = $newerror; |
| 52 | + $newerror = null; |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// check anti DOS protection, we need memcache for that |
| 57 | +if ($config['mc_antidos'] && !$config['memcache']['enabled']) { |
| 58 | + $newerror = array(); |
| 59 | + $newerror['name'] = "Memcache Config"; |
| 60 | + $newerror['level'] = 3; |
| 61 | + $newerror['extdesc'] = "Memcache is a service that you run that lets us cache commonly used data and access it quickly. It's highly recommended you <a href='https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide#requirements-1'>install the service and php packages</a> for your distro."; |
| 62 | + $newerror['description'] = "mc_antidos is enabled and memcache is not, <u>memcache is required</u> to use this."; |
| 63 | + $newerror['configvalue'] = "memcache.enabled"; |
| 64 | + $newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#memcache-rate-limiting"; |
| 65 | + $error[] = $newerror; |
| 66 | + $newerror = null; |
| 67 | +} |
0 commit comments