PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/core/Cockpit/Controller/Settings.php

https://github.com/scogle/cockpit
PHP | 114 lines | 72 code | 42 blank | 0 comment | 7 complexity | ac814422ce4b28cf45f034545488adca MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. namespace Cockpit\Controller;
  3. class Settings extends \Cockpit\Controller {
  4. public function general() {
  5. $registry = json_encode((object)$this->app->memory->get("cockpit.api.registry", []));
  6. $token = $this->app->memory->get("cockpit.api.token", '');
  7. return $this->render('cockpit:views/settings/general.php', compact('token', 'registry'));
  8. }
  9. public function info() {
  10. $info = [];
  11. $info["app"] = json_decode($this->app->helper("fs")->read("#root:package.json"), true);
  12. $info['system'] = php_uname();
  13. $info['phpversion'] = phpversion();
  14. $info['sapi_name'] = php_sapi_name();
  15. $info['extensions'] = get_loaded_extensions();
  16. $info["mailer"] = $this->app->retrieve("app.config/mailer", false);
  17. $info["sizeCache"] = $this->app->helper("utils")->formatSize($this->app->helper("fs")->getDirSize("cache:"));
  18. $info["sizeData"] = $this->app->helper("utils")->formatSize($this->app->helper("fs")->getDirSize("data:"));
  19. $info['folders'] = [];
  20. foreach (['cache:', 'cache:assets', 'cache:thumbs', 'data:'] as $dir) {
  21. $info['folders'][$dir] = is_writable($this->app->path($dir));
  22. }
  23. return $this->render('cockpit:views/settings/info.php', compact('info'));
  24. }
  25. public function test($case) {
  26. switch ($case) {
  27. case 'email':
  28. $email = $this->param("email", false);
  29. if($email) {
  30. $ret = $this->app->mailer->mail($email, "Test Email", "It seems your Server can send Emails with the current mailer settings.");
  31. } else {
  32. $ret = false;
  33. }
  34. return json_encode(["status"=>$ret]);
  35. break;
  36. }
  37. return false;
  38. }
  39. public function clearcache() {
  40. $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->app->path("cache:")), \RecursiveIteratorIterator::SELF_FIRST);
  41. foreach ($files as $file) {
  42. if(!$file->isFile()) continue;
  43. if(preg_match('/(.gitkeep|index\.html)$/', $file)) continue;
  44. @unlink($file->getRealPath());
  45. }
  46. return json_encode(["size"=>$this->app->helper("utils")->formatSize($this->app->helper("fs")->getDirSize("cache:"))]);
  47. }
  48. public function vacuumdata() {
  49. $this->helper("history")->clear();
  50. foreach ($this->app->helper("fs")->ls('*.sqlite', 'data:') as $file) {
  51. $db = new \PDO("sqlite:".$file->getRealPath());
  52. @$db->query("VACUUM");
  53. @$db->exec("VACUUM");
  54. }
  55. return json_encode(["size"=>$this->app->helper("utils")->formatSize($this->app->helper("fs")->getDirSize("data:"))]);
  56. }
  57. public function saveToken() {
  58. if ($token = $this->param("token", false)) {
  59. $this->app->memory->set("cockpit.api.token", $token);
  60. return ["success"=>true];
  61. }
  62. return false;
  63. }
  64. public function saveRegistry() {
  65. $registry = $this->param("registry", false);
  66. if ($registry !== false) {
  67. $this->app->memory->set("cockpit.api.registry", (object)$registry);
  68. return ["success"=>true];
  69. }
  70. return false;
  71. }
  72. }