From 55fff19de450c8e0d201b3f2a1777447be71fb82 Mon Sep 17 00:00:00 2001 From: Francis G Date: Wed, 17 Aug 2016 22:49:38 -0400 Subject: [PATCH 01/76] Initial commit --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0ae9f1c..d0cab3f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ -# api -Webcampak API, used by the web frontend +Webcampak 3.0 API +============================================================================== + +[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) + From 79073373942d8b12599b5f9fe7c2ea1f5d658b7e Mon Sep 17 00:00:00 2001 From: Francis G Date: Wed, 17 Aug 2016 22:53:53 -0400 Subject: [PATCH 02/76] Added Symfony framework --- Symfony/3.0/.gitignore | 16 + Symfony/3.0/README.md | 4 + Symfony/3.0/app/.htaccess | 7 + Symfony/3.0/app/AppCache.php | 7 + Symfony/3.0/app/AppKernel.php | 51 + .../3.0/app/Resources/views/base.html.twig | 13 + .../Resources/views/default/index.html.twig | 76 + Symfony/3.0/app/autoload.php | 13 + Symfony/3.0/app/config/config.yml | 69 + Symfony/3.0/app/config/config_dev.yml | 35 + Symfony/3.0/app/config/config_prod.yml | 27 + Symfony/3.0/app/config/config_test.yml | 16 + Symfony/3.0/app/config/parameters.yml.dist | 19 + Symfony/3.0/app/config/routing.yml | 77 + Symfony/3.0/app/config/routing_dev.yml | 14 + Symfony/3.0/app/config/security.yml | 24 + Symfony/3.0/app/config/services.yml | 9 + Symfony/3.0/bin/console | 29 + Symfony/3.0/bin/symfony_requirements | 143 + Symfony/3.0/composer.json | 73 + Symfony/3.0/composer.lock | 2478 +++++++++++++++++ Symfony/3.0/phpunit.xml.dist | 34 + Symfony/3.0/src/.htaccess | 7 + Symfony/3.0/src/AppBundle/AppBundle.php | 9 + .../src/AppBundle/Classes/BufferedOutput.php | 19 + .../src/AppBundle/Command/AlertsCommand.php | 298 ++ .../AppBundle/Command/DailyReportCommand.php | 352 +++ .../src/AppBundle/Command/DbInitCommand.php | 408 +++ .../src/AppBundle/Command/GphotoCommand.php | 74 + .../AppBundle/Command/ParseConfigCommand.php | 67 + .../Command/RunSyncReportsCommand.php | 346 +++ .../AppBundle/Command/SendEmailsCommand.php | 280 ++ .../AppBundle/Command/SourceCreateCommand.php | 330 +++ .../AppBundle/Command/SourceCronCommand.php | 71 + .../AppBundle/Command/SourceDeleteCommand.php | 125 + .../AppBundle/Command/SourceFTPCommand.php | 71 + .../AppBundle/Command/SourceMoveCommand.php | 171 ++ .../ApiMethods/DesktopController.php | 74 + .../ChangepasswordController.php | 49 + ...DesktopStatefulConfigurationController.php | 80 + .../Authentication/LoginController.php | 107 + .../ReAuthenticateController.php | 118 + .../ResetpasswordController.php | 107 + .../Authentication/UserSettingsController.php | 44 + .../Controller/DefaultController.php | 32 + .../Accesscontrol/ACCustomersController.php | 125 + .../Accesscontrol/ACGroupsController.php | 294 ++ .../Accesscontrol/ACSourcesController.php | 249 ++ .../Accesscontrol/ACUsersController.php | 245 ++ .../Desktop/AdministrativeController.php | 111 + .../Desktop/ApplicationsController.php | 82 + .../Desktop/DesktopEmailsController.php | 60 + .../Desktop/DesktopIconsController.php | 182 ++ .../Desktop/Devices/DevicesController.php | 32 + .../Desktop/Logs/LogsController.php | 74 + .../Desktop/Pictures/PicturesController.php | 68 + .../Controller/Desktop/SourcesController.php | 39 + .../SCCaptureController.php | 78 + .../SCFTPServersController.php | 101 + .../Sourcesconfiguration/SCMiscController.php | 101 + .../SCVideoController.php | 77 + .../SCVideoCustomController.php | 79 + .../SCVideoPostController.php | 79 + .../SCWindowController.php | 63 + .../Desktop/Stats/StatsController.php | 61 + .../SyncReports/SyncReportsController.php | 63 + .../SystemConfigurationController.php | 59 + .../Desktop/Videos/VideosController.php | 44 + .../XferReports/XferReportsController.php | 35 + .../Controller/ExtDirectRouterController.php | 154 + .../Controller/Misc/DownloadController.php | 57 + .../Misc/OnlineStatusController.php | 48 + .../Controller/Misc/PhpinfoController.php | 30 + .../Controller/Misc/StatusController.php | 63 + .../Controller/Misc/SystemController.php | 48 + .../Controller/Root/DashboardController.php | 43 + .../Controller/Root/DesktopController.php | 43 + .../Controller/SecurityController.php | 34 + .../Entities/Configuration/Configuration.php | 92 + .../Entities/Configuration/Parameter.php | 133 + .../Entities/Configuration/Section.php | 85 + .../Entities/Configuration/Value.php | 105 + .../Entities/Database/Applications.php | 142 + .../Database/ApplicationsRepository.php | 30 + .../Entities/Database/Configuration.php | 79 + .../Database/ConfigurationRepository.php | 30 + .../AppBundle/Entities/Database/Customers.php | 79 + .../Entities/Database/CustomersRepository.php | 30 + .../AppBundle/Entities/Database/Groups.php | 113 + .../Entities/Database/GroupsApplications.php | 145 + .../Database/GroupsApplicationsRepository.php | 30 + .../Entities/Database/GroupsPermissions.php | 158 ++ .../Database/GroupsPermissionsRepository.php | 30 + .../Entities/Database/GroupsRepository.php | 30 + .../Entities/Database/LoginHistory.php | 169 ++ .../Database/LoginHistoryRepository.php | 30 + .../Entities/Database/Permissions.php | 110 + .../Database/PermissionsRepository.php | 30 + .../AppBundle/Entities/Database/Pictures.php | 139 + .../Entities/Database/PicturesRepository.php | 30 + .../AppBundle/Entities/Database/Sources.php | 288 ++ .../Entities/Database/SourcesGroups.php | 139 + .../Database/SourcesGroupsRepository.php | 30 + .../Entities/Database/SourcesRepository.php | 31 + .../src/AppBundle/Entities/Database/Users.php | 530 ++++ .../Entities/Database/UsersIcons.php | 190 ++ .../Database/UsersIconsRepository.php | 30 + .../Entities/Database/UsersPreferences.php | 172 ++ .../Database/UsersPreferencesRepository.php | 30 + .../Entities/Database/UsersRepository.php | 30 + .../Entities/Database/UsersSources.php | 130 + .../Database/UsersSourcesRepository.php | 30 + .../EventListener/ExceptionListener.php | 47 + .../AppBundle/EventListener/LoginListener.php | 114 + .../views/Dashboard/dashboard.html.php | 101 + .../Desktoproot/desktoproot-ext5.1.html.php | 56 + .../views/Desktoproot/desktoproot.html.php | 140 + .../Resources/views/Download/index.html.php | 36 + .../views/Emails/resetpassword.html.twig | 14 + .../Resources/views/Phpinfo/index.html.php | 6 + .../Resources/views/Security/login.html.php | 54 + .../src/AppBundle/Services/AlertsService.php | 81 + .../Services/ConfigurationService.php | 325 +++ .../src/AppBundle/Services/DevicesService.php | 123 + .../AppBundle/Services/DownloadService.php | 97 + .../src/AppBundle/Services/EmailsService.php | 140 + .../src/AppBundle/Services/FilesService.php | 24 + .../3.0/src/AppBundle/Services/FtpService.php | 133 + .../src/AppBundle/Services/GroupsService.php | 111 + .../3.0/src/AppBundle/Services/LogService.php | 41 + .../AppBundle/Services/PhidgetsService.php | 39 + .../Services/PicturesDirectoryService.php | 310 +++ .../AppBundle/Services/PicturesService.php | 195 ++ .../AppBundle/Services/ResponseService.php | 37 + .../src/AppBundle/Services/RouterService.php | 123 + .../AppBundle/Services/ScheduleService.php | 136 + .../src/AppBundle/Services/SourcesService.php | 254 ++ .../src/AppBundle/Services/StatsService.php | 262 ++ .../src/AppBundle/Services/StatusService.php | 156 ++ .../AppBundle/Services/SyncReportsService.php | 281 ++ .../AppBundle/Services/SystemLogsService.php | 94 + .../src/AppBundle/Services/UserService.php | 242 ++ .../src/AppBundle/Services/VideosService.php | 120 + .../AppBundle/Services/XferReportsService.php | 127 + .../src/AppBundle/SessionRequestProcessor.php | 41 + .../Controller/DefaultControllerTest.php | 18 + .../Controller/DefaultControllerTest.php | 18 + Symfony/3.0/var/SymfonyRequirements.php | 764 +++++ Symfony/3.0/var/cache/.gitkeep | 0 Symfony/3.0/var/logs/.gitkeep | 0 Symfony/3.0/var/sessions/.gitkeep | 0 Symfony/3.0/web/.htaccess | 68 + Symfony/3.0/web/app.php | 30 + Symfony/3.0/web/app_dev.php | 33 + Symfony/3.0/web/app_test.php | 33 + Symfony/3.0/web/apple-touch-icon.png | Bin 0 -> 10784 bytes Symfony/3.0/web/config.php | 205 ++ Symfony/3.0/web/dashboard.php | 30 + Symfony/3.0/web/dashboard_dev.php | 32 + Symfony/3.0/web/dashboard_test.php | 32 + Symfony/3.0/web/favicon.ico | Bin 0 -> 6518 bytes Symfony/3.0/web/index.html | 18 + Symfony/3.0/web/robots.txt | 4 + 163 files changed, 18188 insertions(+) create mode 100644 Symfony/3.0/.gitignore create mode 100644 Symfony/3.0/README.md create mode 100644 Symfony/3.0/app/.htaccess create mode 100644 Symfony/3.0/app/AppCache.php create mode 100644 Symfony/3.0/app/AppKernel.php create mode 100644 Symfony/3.0/app/Resources/views/base.html.twig create mode 100644 Symfony/3.0/app/Resources/views/default/index.html.twig create mode 100644 Symfony/3.0/app/autoload.php create mode 100644 Symfony/3.0/app/config/config.yml create mode 100644 Symfony/3.0/app/config/config_dev.yml create mode 100644 Symfony/3.0/app/config/config_prod.yml create mode 100644 Symfony/3.0/app/config/config_test.yml create mode 100644 Symfony/3.0/app/config/parameters.yml.dist create mode 100644 Symfony/3.0/app/config/routing.yml create mode 100644 Symfony/3.0/app/config/routing_dev.yml create mode 100644 Symfony/3.0/app/config/security.yml create mode 100644 Symfony/3.0/app/config/services.yml create mode 100755 Symfony/3.0/bin/console create mode 100755 Symfony/3.0/bin/symfony_requirements create mode 100644 Symfony/3.0/composer.json create mode 100644 Symfony/3.0/composer.lock create mode 100644 Symfony/3.0/phpunit.xml.dist create mode 100644 Symfony/3.0/src/.htaccess create mode 100644 Symfony/3.0/src/AppBundle/AppBundle.php create mode 100644 Symfony/3.0/src/AppBundle/Classes/BufferedOutput.php create mode 100644 Symfony/3.0/src/AppBundle/Command/AlertsCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/DailyReportCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/DbInitCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/GphotoCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/ParseConfigCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/RunSyncReportsCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/SendEmailsCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/SourceCreateCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/SourceCronCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/SourceDeleteCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/SourceFTPCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Command/SourceMoveCommand.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/ApiMethods/DesktopController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Authentication/ChangepasswordController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Authentication/DesktopStatefulConfigurationController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Authentication/LoginController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Authentication/ReAuthenticateController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Authentication/ResetpasswordController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Authentication/UserSettingsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/DefaultController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACCustomersController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACGroupsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACSourcesController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACUsersController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/AdministrativeController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/ApplicationsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/DesktopEmailsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/DesktopIconsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Devices/DevicesController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Logs/LogsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Pictures/PicturesController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/SourcesController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCCaptureController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCFTPServersController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCMiscController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoCustomController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoPostController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCWindowController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Stats/StatsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/SyncReports/SyncReportsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Systemconfiguration/SystemConfigurationController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/Videos/VideosController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Desktop/XferReports/XferReportsController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/ExtDirectRouterController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Misc/DownloadController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Misc/OnlineStatusController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Misc/PhpinfoController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Misc/StatusController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Misc/SystemController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Root/DashboardController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/Root/DesktopController.php create mode 100644 Symfony/3.0/src/AppBundle/Controller/SecurityController.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Configuration/Configuration.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Configuration/Parameter.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Configuration/Section.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Configuration/Value.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/Applications.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/ApplicationsRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/Configuration.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/ConfigurationRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/Customers.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/CustomersRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/Groups.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/GroupsApplications.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/GroupsApplicationsRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/GroupsPermissions.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/GroupsPermissionsRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/GroupsRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/LoginHistory.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/LoginHistoryRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/Permissions.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/PermissionsRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/Pictures.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/PicturesRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/Sources.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/SourcesGroups.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/SourcesGroupsRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/SourcesRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/Users.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/UsersIcons.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/UsersIconsRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/UsersPreferences.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/UsersPreferencesRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/UsersRepository.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/UsersSources.php create mode 100644 Symfony/3.0/src/AppBundle/Entities/Database/UsersSourcesRepository.php create mode 100644 Symfony/3.0/src/AppBundle/EventListener/ExceptionListener.php create mode 100644 Symfony/3.0/src/AppBundle/EventListener/LoginListener.php create mode 100644 Symfony/3.0/src/AppBundle/Resources/views/Dashboard/dashboard.html.php create mode 100644 Symfony/3.0/src/AppBundle/Resources/views/Desktoproot/desktoproot-ext5.1.html.php create mode 100644 Symfony/3.0/src/AppBundle/Resources/views/Desktoproot/desktoproot.html.php create mode 100644 Symfony/3.0/src/AppBundle/Resources/views/Download/index.html.php create mode 100644 Symfony/3.0/src/AppBundle/Resources/views/Emails/resetpassword.html.twig create mode 100644 Symfony/3.0/src/AppBundle/Resources/views/Phpinfo/index.html.php create mode 100644 Symfony/3.0/src/AppBundle/Resources/views/Security/login.html.php create mode 100644 Symfony/3.0/src/AppBundle/Services/AlertsService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/ConfigurationService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/DevicesService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/DownloadService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/EmailsService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/FilesService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/FtpService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/GroupsService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/LogService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/PhidgetsService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/PicturesDirectoryService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/PicturesService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/ResponseService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/RouterService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/ScheduleService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/SourcesService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/StatsService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/StatusService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/SyncReportsService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/SystemLogsService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/UserService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/VideosService.php create mode 100644 Symfony/3.0/src/AppBundle/Services/XferReportsService.php create mode 100644 Symfony/3.0/src/AppBundle/SessionRequestProcessor.php create mode 100644 Symfony/3.0/src/AppBundle/Tests/Controller/DefaultControllerTest.php create mode 100644 Symfony/3.0/tests/AppBundle/Controller/DefaultControllerTest.php create mode 100644 Symfony/3.0/var/SymfonyRequirements.php create mode 100644 Symfony/3.0/var/cache/.gitkeep create mode 100644 Symfony/3.0/var/logs/.gitkeep create mode 100644 Symfony/3.0/var/sessions/.gitkeep create mode 100644 Symfony/3.0/web/.htaccess create mode 100644 Symfony/3.0/web/app.php create mode 100644 Symfony/3.0/web/app_dev.php create mode 100644 Symfony/3.0/web/app_test.php create mode 100644 Symfony/3.0/web/apple-touch-icon.png create mode 100644 Symfony/3.0/web/config.php create mode 100644 Symfony/3.0/web/dashboard.php create mode 100644 Symfony/3.0/web/dashboard_dev.php create mode 100644 Symfony/3.0/web/dashboard_test.php create mode 100644 Symfony/3.0/web/favicon.ico create mode 100644 Symfony/3.0/web/index.html create mode 100644 Symfony/3.0/web/robots.txt diff --git a/Symfony/3.0/.gitignore b/Symfony/3.0/.gitignore new file mode 100644 index 0000000..93821ad --- /dev/null +++ b/Symfony/3.0/.gitignore @@ -0,0 +1,16 @@ +/app/config/parameters.yml +/build/ +/phpunit.xml +/var/* +!/var/cache +/var/cache/* +!var/cache/.gitkeep +!/var/logs +/var/logs/* +!var/logs/.gitkeep +!/var/sessions +/var/sessions/* +!var/sessions/.gitkeep +!var/SymfonyRequirements.php +/vendor/ +/web/bundles/ diff --git a/Symfony/3.0/README.md b/Symfony/3.0/README.md new file mode 100644 index 0000000..e63c96c --- /dev/null +++ b/Symfony/3.0/README.md @@ -0,0 +1,4 @@ +3.0 +=== + +A Symfony project created on February 25, 2016, 10:42 pm. diff --git a/Symfony/3.0/app/.htaccess b/Symfony/3.0/app/.htaccess new file mode 100644 index 0000000..fb1de45 --- /dev/null +++ b/Symfony/3.0/app/.htaccess @@ -0,0 +1,7 @@ + + Require all denied + + + Order deny,allow + Deny from all + diff --git a/Symfony/3.0/app/AppCache.php b/Symfony/3.0/app/AppCache.php new file mode 100644 index 0000000..639ec2c --- /dev/null +++ b/Symfony/3.0/app/AppCache.php @@ -0,0 +1,7 @@ +getEnvironment(), ['dev', 'test'], true)) { + $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); + $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); + $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); + $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); + } + + return $bundles; + } + + public function getRootDir() + { + return __DIR__; + } + + public function getCacheDir() + { + return '/home/webcampak/webcampak/resources/cache/symfony/'.$this->environment.'/cache'; + } + + public function getLogDir() + { + return dirname(__DIR__).'/var/logs'; + } + + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load('/home/webcampak/webcampak/etc/symfony/config_'.$this->getEnvironment().'.yml'); + } +} diff --git a/Symfony/3.0/app/Resources/views/base.html.twig b/Symfony/3.0/app/Resources/views/base.html.twig new file mode 100644 index 0000000..bafd28d --- /dev/null +++ b/Symfony/3.0/app/Resources/views/base.html.twig @@ -0,0 +1,13 @@ + + + + + {% block title %}Welcome!{% endblock %} + {% block stylesheets %}{% endblock %} + + + + {% block body %}{% endblock %} + {% block javascripts %}{% endblock %} + + diff --git a/Symfony/3.0/app/Resources/views/default/index.html.twig b/Symfony/3.0/app/Resources/views/default/index.html.twig new file mode 100644 index 0000000..7319df7 --- /dev/null +++ b/Symfony/3.0/app/Resources/views/default/index.html.twig @@ -0,0 +1,76 @@ +{% extends 'base.html.twig' %} + +{% block body %} +
+
+
+

Welcome to Symfony {{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}

+
+ +
+

+ + + Your application is now ready. You can start working on it at: + {{ base_dir }}/ +

+
+ + + +
+
+{% endblock %} + +{% block stylesheets %} + +{% endblock %} diff --git a/Symfony/3.0/app/autoload.php b/Symfony/3.0/app/autoload.php new file mode 100644 index 0000000..fa582ec --- /dev/null +++ b/Symfony/3.0/app/autoload.php @@ -0,0 +1,13 @@ +getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev'); +$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; + +if ($debug) { + Debug::enable(); +} + +$kernel = new AppKernel($env, $debug); +$application = new Application($kernel); +$application->run($input); diff --git a/Symfony/3.0/bin/symfony_requirements b/Symfony/3.0/bin/symfony_requirements new file mode 100755 index 0000000..1eca671 --- /dev/null +++ b/Symfony/3.0/bin/symfony_requirements @@ -0,0 +1,143 @@ +#!/usr/bin/env php +getPhpIniConfigPath(); + +echo_title('Symfony2 Requirements Checker'); + +echo '> PHP is using the following php.ini file:'.PHP_EOL; +if ($iniPath) { + echo_style('green', ' '.$iniPath); +} else { + echo_style('warning', ' WARNING: No configuration file (php.ini) used by PHP!'); +} + +echo PHP_EOL.PHP_EOL; + +echo '> Checking Symfony requirements:'.PHP_EOL.' '; + +$messages = array(); +foreach ($symfonyRequirements->getRequirements() as $req) { + /** @var $req Requirement */ + if ($helpText = get_error_message($req, $lineSize)) { + echo_style('red', 'E'); + $messages['error'][] = $helpText; + } else { + echo_style('green', '.'); + } +} + +$checkPassed = empty($messages['error']); + +foreach ($symfonyRequirements->getRecommendations() as $req) { + if ($helpText = get_error_message($req, $lineSize)) { + echo_style('yellow', 'W'); + $messages['warning'][] = $helpText; + } else { + echo_style('green', '.'); + } +} + +if ($checkPassed) { + echo_block('success', 'OK', 'Your system is ready to run Symfony2 projects'); +} else { + echo_block('error', 'ERROR', 'Your system is not ready to run Symfony2 projects'); + + echo_title('Fix the following mandatory requirements', 'red'); + + foreach ($messages['error'] as $helpText) { + echo ' * '.$helpText.PHP_EOL; + } +} + +if (!empty($messages['warning'])) { + echo_title('Optional recommendations to improve your setup', 'yellow'); + + foreach ($messages['warning'] as $helpText) { + echo ' * '.$helpText.PHP_EOL; + } +} + +echo PHP_EOL; +echo_style('title', 'Note'); +echo ' The command console could use a different php.ini file'.PHP_EOL; +echo_style('title', '~~~~'); +echo ' than the one used with your web server. To be on the'.PHP_EOL; +echo ' safe side, please check the requirements from your web'.PHP_EOL; +echo ' server using the '; +echo_style('yellow', 'web/config.php'); +echo ' script.'.PHP_EOL; +echo PHP_EOL; + +exit($checkPassed ? 0 : 1); + +function get_error_message(Requirement $requirement, $lineSize) +{ + if ($requirement->isFulfilled()) { + return; + } + + $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL; + $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL; + + return $errorMessage; +} + +function echo_title($title, $style = null) +{ + $style = $style ?: 'title'; + + echo PHP_EOL; + echo_style($style, $title.PHP_EOL); + echo_style($style, str_repeat('~', strlen($title)).PHP_EOL); + echo PHP_EOL; +} + +function echo_style($style, $message) +{ + // ANSI color codes + $styles = array( + 'reset' => "\033[0m", + 'red' => "\033[31m", + 'green' => "\033[32m", + 'yellow' => "\033[33m", + 'error' => "\033[37;41m", + 'success' => "\033[37;42m", + 'title' => "\033[34m", + ); + $supports = has_color_support(); + + echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : ''); +} + +function echo_block($style, $title, $message) +{ + $message = ' '.trim($message).' '; + $width = strlen($message); + + echo PHP_EOL.PHP_EOL; + + echo_style($style, str_repeat(' ', $width).PHP_EOL); + echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL); + echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL); + echo_style($style, str_repeat(' ', $width).PHP_EOL); +} + +function has_color_support() +{ + static $support; + + if (null === $support) { + if (DIRECTORY_SEPARATOR == '\\') { + $support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI'); + } else { + $support = function_exists('posix_isatty') && @posix_isatty(STDOUT); + } + } + + return $support; +} diff --git a/Symfony/3.0/composer.json b/Symfony/3.0/composer.json new file mode 100644 index 0000000..5c7d3fd --- /dev/null +++ b/Symfony/3.0/composer.json @@ -0,0 +1,73 @@ +{ + "name": "webcampak/3.0", + "license": "proprietary", + "type": "project", + "autoload": { + "psr-4": { + "": "src/" + }, + "classmap": [ + "app/AppKernel.php", + "app/AppCache.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "require": { + "php": ">=5.5.9", + "symfony/symfony": "3.0.*", + "doctrine/orm": "^2.5", + "doctrine/doctrine-bundle": "^1.6", + "doctrine/doctrine-cache-bundle": "^1.2", + "symfony/swiftmailer-bundle": "^2.3", + "symfony/monolog-bundle": "^2.8", + "sensio/distribution-bundle": "^5.0", + "sensio/framework-extra-bundle": "^3.0.2", + "incenteev/composer-parameter-handler": "^2.0", + "doctrine/dbal": "^2.5", + "twig/extensions": "^1.3", + "symfony/assetic-bundle": "^2.7", + "jms/serializer-bundle": "^1.1" + }, + "require-dev": { + "sensio/generator-bundle": "^3.0", + "symfony/phpunit-bridge": "^2.7" + }, + "scripts": { + "post-install-cmd": [ + "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" + ], + "post-update-cmd": [ + "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", + "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" + ] + }, + "config": { + "platform": { + "php": "5.5.9" + } + }, + "extra": { + "symfony-app-dir": "app", + "symfony-bin-dir": "bin", + "symfony-var-dir": "var", + "symfony-web-dir": "web", + "symfony-tests-dir": "tests", + "symfony-assets-install": "relative", + "incenteev-parameters": { + "file": "app/config/parameters.yml" + } + } +} diff --git a/Symfony/3.0/composer.lock b/Symfony/3.0/composer.lock new file mode 100644 index 0000000..944044e --- /dev/null +++ b/Symfony/3.0/composer.lock @@ -0,0 +1,2478 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "b6e2a641466df10257abfe466f764be6", + "content-hash": "eba15cf5e12066c60df7abadbee2dbb5", + "packages": [ + { + "name": "doctrine/annotations", + "version": "v1.2.7", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "f25c8aab83e0c3e976fd7d19875f198ccf2f7535" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/f25c8aab83e0c3e976fd7d19875f198ccf2f7535", + "reference": "f25c8aab83e0c3e976fd7d19875f198ccf2f7535", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Annotations\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2015-08-31 12:32:49" + }, + { + "name": "doctrine/cache", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/f8af318d14bdb0eff0336795b428b547bd39ccb6", + "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6", + "shasum": "" + }, + "require": { + "php": "~5.5|~7.0" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "phpunit/phpunit": "~4.8|~5.0", + "predis/predis": "~1.0", + "satooshi/php-coveralls": "~0.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2015-12-31 16:37:02" + }, + { + "name": "doctrine/collections", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/collections.git", + "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/collections/zipball/6c1e4eef75f310ea1b3e30945e9f06e652128b8a", + "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Collections\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Collections Abstraction library", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "array", + "collections", + "iterator" + ], + "time": "2015-04-14 22:21:58" + }, + { + "name": "doctrine/common", + "version": "v2.6.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/common.git", + "reference": "a579557bc689580c19fee4e27487a67fe60defc0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/common/zipball/a579557bc689580c19fee4e27487a67fe60defc0", + "reference": "a579557bc689580c19fee4e27487a67fe60defc0", + "shasum": "" + }, + "require": { + "doctrine/annotations": "1.*", + "doctrine/cache": "1.*", + "doctrine/collections": "1.*", + "doctrine/inflector": "1.*", + "doctrine/lexer": "1.*", + "php": "~5.5|~7.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8|~5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common Library for Doctrine projects", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "collections", + "eventmanager", + "persistence", + "spl" + ], + "time": "2015-12-25 13:18:31" + }, + { + "name": "doctrine/dbal", + "version": "v2.5.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/dbal.git", + "reference": "abbdfd1cff43a7b99d027af3be709bc8fc7d4769" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/abbdfd1cff43a7b99d027af3be709bc8fc7d4769", + "reference": "abbdfd1cff43a7b99d027af3be709bc8fc7d4769", + "shasum": "" + }, + "require": { + "doctrine/common": ">=2.4,<2.7-dev", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*", + "symfony/console": "2.*" + }, + "suggest": { + "symfony/console": "For helpful console commands such as SQL execution and import of files." + }, + "bin": [ + "bin/doctrine-dbal" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\DBAL\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Database Abstraction Layer", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "dbal", + "persistence", + "queryobject" + ], + "time": "2016-01-05 22:11:12" + }, + { + "name": "doctrine/doctrine-bundle", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineBundle.git", + "reference": "c4ffef2b2296e9d0179eb0b5248e5ae25c9bba3b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineBundle/zipball/c4ffef2b2296e9d0179eb0b5248e5ae25c9bba3b", + "reference": "c4ffef2b2296e9d0179eb0b5248e5ae25c9bba3b", + "shasum": "" + }, + "require": { + "doctrine/dbal": "~2.3", + "doctrine/doctrine-cache-bundle": "~1.0", + "jdorn/sql-formatter": "~1.1", + "php": ">=5.3.2", + "symfony/console": "~2.3|~3.0", + "symfony/doctrine-bridge": "~2.2|~3.0", + "symfony/framework-bundle": "~2.3|~3.0" + }, + "require-dev": { + "doctrine/orm": "~2.3", + "phpunit/phpunit": "~4", + "satooshi/php-coveralls": "~0.6.1", + "symfony/validator": "~2.2|~3.0", + "symfony/yaml": "~2.2|~3.0", + "twig/twig": "~1.10" + }, + "suggest": { + "doctrine/orm": "The Doctrine ORM integration is optional in the bundle.", + "symfony/web-profiler-bundle": "to use the data collector" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Bundle\\DoctrineBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org/" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony DoctrineBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "dbal", + "orm", + "persistence" + ], + "time": "2015-11-16 17:11:46" + }, + { + "name": "doctrine/doctrine-cache-bundle", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineCacheBundle.git", + "reference": "18c600a9b82f6454d2e81ca4957cdd56a1cf3504" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineCacheBundle/zipball/18c600a9b82f6454d2e81ca4957cdd56a1cf3504", + "reference": "18c600a9b82f6454d2e81ca4957cdd56a1cf3504", + "shasum": "" + }, + "require": { + "doctrine/cache": "^1.4.2", + "doctrine/inflector": "~1.0", + "php": ">=5.3.2", + "symfony/doctrine-bridge": "~2.2|~3.0" + }, + "require-dev": { + "instaclick/coding-standard": "~1.1", + "instaclick/object-calisthenics-sniffs": "dev-master", + "instaclick/symfony2-coding-standard": "dev-remaster", + "phpunit/phpunit": "~4", + "predis/predis": "~0.8", + "satooshi/php-coveralls": "~0.6.1", + "squizlabs/php_codesniffer": "~1.5", + "symfony/console": "~2.2|~3.0", + "symfony/finder": "~2.2|~3.0", + "symfony/framework-bundle": "~2.2|~3.0", + "symfony/phpunit-bridge": "~2.7|~3.0", + "symfony/security-acl": "~2.3|~3.0", + "symfony/validator": "~2.2|~3.0", + "symfony/yaml": "~2.2|~3.0" + }, + "suggest": { + "symfony/security-acl": "For using this bundle to cache ACLs" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Bundle\\DoctrineCacheBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Fabio B. Silva", + "email": "fabio.bat.silva@gmail.com" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@hotmail.com" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org/" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Bundle for Doctrine Cache", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2016-01-26 17:28:51" + }, + { + "name": "doctrine/inflector", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "90b2128806bfde671b6952ab8bea493942c1fdae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/90b2128806bfde671b6952ab8bea493942c1fdae", + "reference": "90b2128806bfde671b6952ab8bea493942c1fdae", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Inflector\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2015-11-06 14:35:42" + }, + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14 21:17:01" + }, + { + "name": "doctrine/lexer", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09 13:34:57" + }, + { + "name": "doctrine/orm", + "version": "v2.5.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/doctrine2.git", + "reference": "bc4ddbfb0114cb33438cc811c9a740d8aa304aab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/bc4ddbfb0114cb33438cc811c9a740d8aa304aab", + "reference": "bc4ddbfb0114cb33438cc811c9a740d8aa304aab", + "shasum": "" + }, + "require": { + "doctrine/cache": "~1.4", + "doctrine/collections": "~1.2", + "doctrine/common": ">=2.5-dev,<2.7-dev", + "doctrine/dbal": ">=2.5-dev,<2.6-dev", + "doctrine/instantiator": "~1.0.1", + "ext-pdo": "*", + "php": ">=5.4", + "symfony/console": "~2.5|~3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "symfony/yaml": "~2.3|~3.0" + }, + "suggest": { + "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" + }, + "bin": [ + "bin/doctrine", + "bin/doctrine.php" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\ORM\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Object-Relational-Mapper for PHP", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "orm" + ], + "time": "2016-01-05 21:34:58" + }, + { + "name": "incenteev/composer-parameter-handler", + "version": "v2.1.2", + "source": { + "type": "git", + "url": "https://github.com/Incenteev/ParameterHandler.git", + "reference": "d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Incenteev/ParameterHandler/zipball/d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc", + "reference": "d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/yaml": "~2.3|~3.0" + }, + "require-dev": { + "composer/composer": "1.0.*@dev", + "phpspec/prophecy-phpunit": "~1.0", + "symfony/filesystem": "~2.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Incenteev\\ParameterHandler\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christophe Coevoet", + "email": "stof@notk.org" + } + ], + "description": "Composer script handling your ignored parameter file", + "homepage": "https://github.com/Incenteev/ParameterHandler", + "keywords": [ + "parameters management" + ], + "time": "2015-11-10 17:04:01" + }, + { + "name": "jdorn/sql-formatter", + "version": "v1.2.17", + "source": { + "type": "git", + "url": "https://github.com/jdorn/sql-formatter.git", + "reference": "64990d96e0959dff8e059dfcdc1af130728d92bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jdorn/sql-formatter/zipball/64990d96e0959dff8e059dfcdc1af130728d92bc", + "reference": "64990d96e0959dff8e059dfcdc1af130728d92bc", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "lib" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeremy Dorn", + "email": "jeremy@jeremydorn.com", + "homepage": "http://jeremydorn.com/" + } + ], + "description": "a PHP SQL highlighting library", + "homepage": "https://github.com/jdorn/sql-formatter/", + "keywords": [ + "highlight", + "sql" + ], + "time": "2014-01-12 16:20:24" + }, + { + "name": "jms/metadata", + "version": "1.5.1", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/metadata.git", + "reference": "22b72455559a25777cfd28c4ffda81ff7639f353" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/metadata/zipball/22b72455559a25777cfd28c4ffda81ff7639f353", + "reference": "22b72455559a25777cfd28c4ffda81ff7639f353", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "doctrine/cache": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5.x-dev" + } + }, + "autoload": { + "psr-0": { + "Metadata\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache" + ], + "authors": [ + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com", + "homepage": "https://github.com/schmittjoh", + "role": "Developer of wrapped JMSSerializerBundle" + } + ], + "description": "Class/method/property metadata management in PHP", + "keywords": [ + "annotations", + "metadata", + "xml", + "yaml" + ], + "time": "2014-07-12 07:13:19" + }, + { + "name": "jms/parser-lib", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/parser-lib.git", + "reference": "c509473bc1b4866415627af0e1c6cc8ac97fa51d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/parser-lib/zipball/c509473bc1b4866415627af0e1c6cc8ac97fa51d", + "reference": "c509473bc1b4866415627af0e1c6cc8ac97fa51d", + "shasum": "" + }, + "require": { + "phpoption/phpoption": ">=0.9,<2.0-dev" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-0": { + "JMS\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "description": "A library for easily creating recursive-descent parsers.", + "time": "2012-11-18 18:08:43" + }, + { + "name": "jms/serializer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/serializer.git", + "reference": "fe13a1f993ea3456e195b7820692f2eb2b6bbb48" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/fe13a1f993ea3456e195b7820692f2eb2b6bbb48", + "reference": "fe13a1f993ea3456e195b7820692f2eb2b6bbb48", + "shasum": "" + }, + "require": { + "doctrine/annotations": "1.*", + "doctrine/instantiator": "~1.0.3", + "jms/metadata": "~1.1", + "jms/parser-lib": "1.*", + "php": ">=5.4.0", + "phpcollection/phpcollection": "~0.1" + }, + "conflict": { + "twig/twig": "<1.12" + }, + "require-dev": { + "doctrine/orm": "~2.1", + "doctrine/phpcr-odm": "~1.0.1", + "jackalope/jackalope-doctrine-dbal": "1.0.*", + "phpunit/phpunit": "~4.0", + "propel/propel1": "~1.7", + "symfony/filesystem": "2.*", + "symfony/form": "~2.1", + "symfony/translation": "~2.0", + "symfony/validator": "~2.0", + "symfony/yaml": "2.*", + "twig/twig": "~1.12|~2.0" + }, + "suggest": { + "symfony/yaml": "Required if you'd like to serialize data to YAML format." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-0": { + "JMS\\Serializer": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.", + "homepage": "http://jmsyst.com/libs/serializer", + "keywords": [ + "deserialization", + "jaxb", + "json", + "serialization", + "xml" + ], + "time": "2015-10-27 09:24:41" + }, + { + "name": "jms/serializer-bundle", + "version": "1.1.0", + "target-dir": "JMS/SerializerBundle", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/JMSSerializerBundle.git", + "reference": "3e396c980545350c2efb65a50041d2a9f9d6562e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/JMSSerializerBundle/zipball/3e396c980545350c2efb65a50041d2a9f9d6562e", + "reference": "3e396c980545350c2efb65a50041d2a9f9d6562e", + "shasum": "" + }, + "require": { + "jms/serializer": "^1.0.0", + "php": ">=5.4.0", + "phpoption/phpoption": "^1.1.0", + "symfony/framework-bundle": "~2.3|~3.0" + }, + "require-dev": { + "doctrine/doctrine-bundle": "*", + "doctrine/orm": "*", + "symfony/browser-kit": "*", + "symfony/class-loader": "*", + "symfony/css-selector": "*", + "symfony/finder": "*", + "symfony/form": "*", + "symfony/process": "*", + "symfony/stopwatch": "*", + "symfony/twig-bundle": "*", + "symfony/validator": "*", + "symfony/yaml": "*" + }, + "suggest": { + "jms/di-extra-bundle": "Required to get lazy loading (de)serialization visitors, ~1.3" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-0": { + "JMS\\SerializerBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Allows you to easily serialize, and deserialize data of any complexity", + "homepage": "http://jmsyst.com/bundles/JMSSerializerBundle", + "keywords": [ + "deserialization", + "jaxb", + "json", + "serialization", + "xml" + ], + "time": "2015-11-10 12:26:42" + }, + { + "name": "kriswallsmith/assetic", + "version": "v1.3.2", + "source": { + "type": "git", + "url": "https://github.com/kriswallsmith/assetic.git", + "reference": "9928f7c4ad98b234e3559d1049abd13387f86db5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kriswallsmith/assetic/zipball/9928f7c4ad98b234e3559d1049abd13387f86db5", + "reference": "9928f7c4ad98b234e3559d1049abd13387f86db5", + "shasum": "" + }, + "require": { + "php": ">=5.3.1", + "symfony/process": "~2.1|~3.0" + }, + "conflict": { + "twig/twig": "<1.23" + }, + "require-dev": { + "cssmin/cssmin": "3.0.1", + "joliclic/javascript-packer": "1.1", + "kamicane/packager": "1.0", + "leafo/lessphp": "^0.3.7", + "leafo/scssphp": "~0.1", + "mrclay/minify": "~2.2", + "patchwork/jsqueeze": "~1.0|~2.0", + "phpunit/phpunit": "~4.8", + "psr/log": "~1.0", + "ptachoire/cssembed": "~1.0", + "symfony/phpunit-bridge": "~2.7|~3.0", + "twig/twig": "~1.8|~2.0" + }, + "suggest": { + "leafo/lessphp": "Assetic provides the integration with the lessphp LESS compiler", + "leafo/scssphp": "Assetic provides the integration with the scssphp SCSS compiler", + "leafo/scssphp-compass": "Assetic provides the integration with the SCSS compass plugin", + "patchwork/jsqueeze": "Assetic provides the integration with the JSqueeze JavaScript compressor", + "ptachoire/cssembed": "Assetic provides the integration with phpcssembed to embed data uris", + "twig/twig": "Assetic provides the integration with the Twig templating engine" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-0": { + "Assetic": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kris Wallsmith", + "email": "kris.wallsmith@gmail.com", + "homepage": "http://kriswallsmith.net/" + } + ], + "description": "Asset Management for PHP", + "homepage": "https://github.com/kriswallsmith/assetic", + "keywords": [ + "assets", + "compression", + "minification" + ], + "time": "2015-11-12 13:51:40" + }, + { + "name": "monolog/monolog", + "version": "1.17.2", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "bee7f0dc9c3e0b69a6039697533dca1e845c8c24" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bee7f0dc9c3e0b69a6039697533dca1e845c8c24", + "reference": "bee7f0dc9c3e0b69a6039697533dca1e845c8c24", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "psr/log": "~1.0" + }, + "provide": { + "psr/log-implementation": "1.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "^2.4.9", + "doctrine/couchdb": "~1.0@dev", + "graylog2/gelf-php": "~1.0", + "jakub-onderka/php-parallel-lint": "0.9", + "php-console/php-console": "^3.1.3", + "phpunit/phpunit": "~4.5", + "phpunit/phpunit-mock-objects": "2.3.0", + "raven/raven": "^0.13", + "ruflin/elastica": ">=0.90 <3.0", + "swiftmailer/swiftmailer": "~5.3", + "videlalvaro/php-amqplib": "~2.4" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-mongo": "Allow sending log messages to a MongoDB server", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "php-console/php-console": "Allow sending log messages to Google Chrome", + "raven/raven": "Allow sending log messages to a Sentry server", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server", + "videlalvaro/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.16.x-dev" + } + }, + "autoload": { + "psr-4": { + "Monolog\\": "src/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "http://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "time": "2015-10-14 12:51:02" + }, + { + "name": "paragonie/random_compat", + "version": "1.1.6", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "e6f80ab77885151908d0ec743689ca700886e8b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/e6f80ab77885151908d0ec743689ca700886e8b0", + "reference": "e6f80ab77885151908d0ec743689ca700886e8b0", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "pseudorandom", + "random" + ], + "time": "2016-01-29 16:19:52" + }, + { + "name": "phpcollection/phpcollection", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-collection.git", + "reference": "b8bf55a0a929ca43b01232b36719f176f86c7e83" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-collection/zipball/b8bf55a0a929ca43b01232b36719f176f86c7e83", + "reference": "b8bf55a0a929ca43b01232b36719f176f86c7e83", + "shasum": "" + }, + "require": { + "phpoption/phpoption": "1.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.3-dev" + } + }, + "autoload": { + "psr-0": { + "PhpCollection": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com", + "homepage": "https://github.com/schmittjoh", + "role": "Developer of wrapped JMSSerializerBundle" + } + ], + "description": "General-Purpose Collection Library for PHP", + "keywords": [ + "collection", + "list", + "map", + "sequence", + "set" + ], + "time": "2014-03-11 13:46:42" + }, + { + "name": "phpoption/phpoption", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-option.git", + "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/94e644f7d2051a5f0fcf77d81605f152eecff0ed", + "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "4.7.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-0": { + "PhpOption\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Option Type for PHP", + "keywords": [ + "language", + "option", + "php", + "type" + ], + "time": "2015-07-25 16:39:46" + }, + { + "name": "psr/log", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-0": { + "Psr\\Log\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2012-12-21 11:40:51" + }, + { + "name": "sensio/distribution-bundle", + "version": "v5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/SensioDistributionBundle.git", + "reference": "419c1824af940e2be0f833aca2327e1181a6b503" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/SensioDistributionBundle/zipball/419c1824af940e2be0f833aca2327e1181a6b503", + "reference": "419c1824af940e2be0f833aca2327e1181a6b503", + "shasum": "" + }, + "require": { + "php": ">=5.3.9", + "sensiolabs/security-checker": "~3.0", + "symfony/class-loader": "~2.3|~3.0", + "symfony/config": "~2.3|~3.0", + "symfony/dependency-injection": "~2.3|~3.0", + "symfony/filesystem": "~2.3|~3.0", + "symfony/http-kernel": "~2.3|~3.0", + "symfony/process": "~2.3|~3.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Sensio\\Bundle\\DistributionBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Base bundle for Symfony Distributions", + "keywords": [ + "configuration", + "distribution" + ], + "time": "2015-12-18 17:44:11" + }, + { + "name": "sensio/framework-extra-bundle", + "version": "v3.0.12", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git", + "reference": "3e8936fe13aa4086644977d334d8fcd275f50357" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/3e8936fe13aa4086644977d334d8fcd275f50357", + "reference": "3e8936fe13aa4086644977d334d8fcd275f50357", + "shasum": "" + }, + "require": { + "doctrine/common": "~2.2", + "symfony/framework-bundle": "~2.3|~3.0" + }, + "require-dev": { + "symfony/expression-language": "~2.4|~3.0", + "symfony/security-bundle": "~2.4|~3.0" + }, + "suggest": { + "symfony/expression-language": "", + "symfony/psr-http-message-bridge": "To use the PSR-7 converters", + "symfony/security-bundle": "" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Sensio\\Bundle\\FrameworkExtraBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "This bundle provides a way to configure your controllers with annotations", + "keywords": [ + "annotations", + "controllers" + ], + "time": "2015-12-18 17:39:27" + }, + { + "name": "sensiolabs/security-checker", + "version": "v3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/security-checker.git", + "reference": "21696b0daa731064c23cfb694c60a2584a7b6e93" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/21696b0daa731064c23cfb694c60a2584a7b6e93", + "reference": "21696b0daa731064c23cfb694c60a2584a7b6e93", + "shasum": "" + }, + "require": { + "symfony/console": "~2.0|~3.0" + }, + "bin": [ + "security-checker" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-0": { + "SensioLabs\\Security": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien.potencier@gmail.com" + } + ], + "description": "A security checker for your composer.lock", + "time": "2015-11-07 08:07:40" + }, + { + "name": "swiftmailer/swiftmailer", + "version": "v5.4.1", + "source": { + "type": "git", + "url": "https://github.com/swiftmailer/swiftmailer.git", + "reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/0697e6aa65c83edf97bb0f23d8763f94e3f11421", + "reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "mockery/mockery": "~0.9.1,<0.9.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.4-dev" + } + }, + "autoload": { + "files": [ + "lib/swift_required.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Corbyn" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Swiftmailer, free feature-rich PHP mailer", + "homepage": "http://swiftmailer.org", + "keywords": [ + "email", + "mail", + "mailer" + ], + "time": "2015-06-06 14:19:39" + }, + { + "name": "symfony/assetic-bundle", + "version": "v2.7.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/assetic-bundle.git", + "reference": "d885ec8451d5a7b077bda81bb19ac9fbff9cdc76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/assetic-bundle/zipball/d885ec8451d5a7b077bda81bb19ac9fbff9cdc76", + "reference": "d885ec8451d5a7b077bda81bb19ac9fbff9cdc76", + "shasum": "" + }, + "require": { + "kriswallsmith/assetic": "~1.3", + "php": ">=5.3.0", + "symfony/console": "~2.3|~3.0", + "symfony/dependency-injection": "~2.3|~3.0", + "symfony/framework-bundle": "~2.3|~3.0", + "symfony/yaml": "~2.3|~3.0" + }, + "conflict": { + "kriswallsmith/spork": "<=0.2", + "twig/twig": "<1.20" + }, + "require-dev": { + "kriswallsmith/spork": "~0.3", + "patchwork/jsqueeze": "~1.0", + "symfony/class-loader": "~2.3|~3.0", + "symfony/css-selector": "~2.3|~3.0", + "symfony/dom-crawler": "~2.3|~3.0", + "symfony/phpunit-bridge": "~2.7|~3.0", + "symfony/twig-bundle": "~2.3|~3.0" + }, + "suggest": { + "kriswallsmith/spork": "to be able to dump assets in parallel", + "symfony/twig-bundle": "to use the Twig integration" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\AsseticBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kris Wallsmith", + "email": "kris.wallsmith@gmail.com", + "homepage": "http://kriswallsmith.net/" + } + ], + "description": "Integrates Assetic into Symfony2", + "homepage": "https://github.com/symfony/AsseticBundle", + "keywords": [ + "assets", + "compression", + "minification" + ], + "time": "2015-11-17 09:45:47" + }, + { + "name": "symfony/monolog-bundle", + "version": "v2.8.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/monolog-bundle.git", + "reference": "84785c4d44801c4dd82829fa2e1820cacfe2c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/monolog-bundle/zipball/84785c4d44801c4dd82829fa2e1820cacfe2c46f", + "reference": "84785c4d44801c4dd82829fa2e1820cacfe2c46f", + "shasum": "" + }, + "require": { + "monolog/monolog": "~1.8", + "php": ">=5.3.2", + "symfony/config": "~2.3|~3.0", + "symfony/dependency-injection": "~2.3|~3.0", + "symfony/http-kernel": "~2.3|~3.0", + "symfony/monolog-bridge": "~2.3|~3.0" + }, + "require-dev": { + "symfony/console": "~2.3|~3.0", + "symfony/yaml": "~2.3|~3.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\MonologBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony MonologBundle", + "homepage": "http://symfony.com", + "keywords": [ + "log", + "logging" + ], + "time": "2015-11-17 10:02:29" + }, + { + "name": "symfony/polyfill-intl-icu", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-icu.git", + "reference": "66b0bb4abda229bc073eff6bbc8f2685bdaac165" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/66b0bb4abda229bc073eff6bbc8f2685bdaac165", + "reference": "66b0bb4abda229bc073eff6bbc8f2685bdaac165", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/intl": "~2.3|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's ICU-related data and classes", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "icu", + "intl", + "polyfill", + "portable", + "shim" + ], + "time": "2016-01-20 09:13:37" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "1289d16209491b584839022f29257ad859b8532d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/1289d16209491b584839022f29257ad859b8532d", + "reference": "1289d16209491b584839022f29257ad859b8532d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2016-01-20 09:13:37" + }, + { + "name": "symfony/polyfill-php56", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php56.git", + "reference": "4d891fff050101a53a4caabb03277284942d1ad9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/4d891fff050101a53a4caabb03277284942d1ad9", + "reference": "4d891fff050101a53a4caabb03277284942d1ad9", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/polyfill-util": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php56\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2016-01-20 09:13:37" + }, + { + "name": "symfony/polyfill-php70", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php70.git", + "reference": "8428ceddbbaf102f2906769a8ef2438220c5cb95" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/8428ceddbbaf102f2906769a8ef2438220c5cb95", + "reference": "8428ceddbbaf102f2906769a8ef2438220c5cb95", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "~1.0", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php70\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2016-01-25 08:44:42" + }, + { + "name": "symfony/polyfill-util", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-util.git", + "reference": "8de62801aa12bc4dfcf85eef5d21981ae7bb3cc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/8de62801aa12bc4dfcf85eef5d21981ae7bb3cc4", + "reference": "8de62801aa12bc4dfcf85eef5d21981ae7bb3cc4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Util\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony utilities for portability of PHP codes", + "homepage": "https://symfony.com", + "keywords": [ + "compat", + "compatibility", + "polyfill", + "shim" + ], + "time": "2016-01-20 09:13:37" + }, + { + "name": "symfony/swiftmailer-bundle", + "version": "v2.3.11", + "source": { + "type": "git", + "url": "https://github.com/symfony/swiftmailer-bundle.git", + "reference": "5e1a90f28213231ceee19c953bbebc5b5b95c690" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/swiftmailer-bundle/zipball/5e1a90f28213231ceee19c953bbebc5b5b95c690", + "reference": "5e1a90f28213231ceee19c953bbebc5b5b95c690", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "swiftmailer/swiftmailer": ">=4.2.0,~5.0", + "symfony/config": "~2.3|~3.0", + "symfony/dependency-injection": "~2.3|~3.0", + "symfony/http-kernel": "~2.3|~3.0", + "symfony/yaml": "~2.3|~3.0" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7|~3.0" + }, + "suggest": { + "psr/log": "Allows logging" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\SwiftmailerBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony SwiftmailerBundle", + "homepage": "http://symfony.com", + "time": "2016-01-15 16:41:20" + }, + { + "name": "symfony/symfony", + "version": "v3.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/symfony.git", + "reference": "4e17cb2ecb3fd637097ebeb871fc0e2cbdd5e7ff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/symfony/zipball/4e17cb2ecb3fd637097ebeb871fc0e2cbdd5e7ff", + "reference": "4e17cb2ecb3fd637097ebeb871fc0e2cbdd5e7ff", + "shasum": "" + }, + "require": { + "doctrine/common": "~2.4", + "php": ">=5.5.9", + "psr/log": "~1.0", + "symfony/polyfill-intl-icu": "~1.0", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php56": "~1.0", + "symfony/polyfill-php70": "~1.0", + "symfony/polyfill-util": "~1.0", + "twig/twig": "~1.23|~2.0" + }, + "conflict": { + "phpdocumentor/reflection": "<1.0.7" + }, + "replace": { + "symfony/asset": "self.version", + "symfony/browser-kit": "self.version", + "symfony/class-loader": "self.version", + "symfony/config": "self.version", + "symfony/console": "self.version", + "symfony/css-selector": "self.version", + "symfony/debug": "self.version", + "symfony/debug-bundle": "self.version", + "symfony/dependency-injection": "self.version", + "symfony/doctrine-bridge": "self.version", + "symfony/dom-crawler": "self.version", + "symfony/event-dispatcher": "self.version", + "symfony/expression-language": "self.version", + "symfony/filesystem": "self.version", + "symfony/finder": "self.version", + "symfony/form": "self.version", + "symfony/framework-bundle": "self.version", + "symfony/http-foundation": "self.version", + "symfony/http-kernel": "self.version", + "symfony/intl": "self.version", + "symfony/ldap": "self.version", + "symfony/monolog-bridge": "self.version", + "symfony/options-resolver": "self.version", + "symfony/process": "self.version", + "symfony/property-access": "self.version", + "symfony/property-info": "self.version", + "symfony/proxy-manager-bridge": "self.version", + "symfony/routing": "self.version", + "symfony/security": "self.version", + "symfony/security-bundle": "self.version", + "symfony/security-core": "self.version", + "symfony/security-csrf": "self.version", + "symfony/security-guard": "self.version", + "symfony/security-http": "self.version", + "symfony/serializer": "self.version", + "symfony/stopwatch": "self.version", + "symfony/templating": "self.version", + "symfony/translation": "self.version", + "symfony/twig-bridge": "self.version", + "symfony/twig-bundle": "self.version", + "symfony/validator": "self.version", + "symfony/var-dumper": "self.version", + "symfony/web-profiler-bundle": "self.version", + "symfony/yaml": "self.version" + }, + "require-dev": { + "doctrine/data-fixtures": "1.0.*", + "doctrine/dbal": "~2.4", + "doctrine/doctrine-bundle": "~1.4", + "doctrine/orm": "~2.4,>=2.4.5", + "egulias/email-validator": "~1.2", + "monolog/monolog": "~1.11", + "ocramius/proxy-manager": "~0.4|~1.0|~2.0", + "phpdocumentor/reflection": "^1.0.7", + "symfony/polyfill-apcu": "~1.1", + "symfony/security-acl": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bridge\\": "src/Symfony/Bridge/", + "Symfony\\Bundle\\": "src/Symfony/Bundle/", + "Symfony\\Component\\": "src/Symfony/Component/" + }, + "classmap": [ + "src/Symfony/Component/Intl/Resources/stubs" + ], + "exclude-from-classmap": [ + "**/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "The Symfony PHP framework", + "homepage": "https://symfony.com", + "keywords": [ + "framework" + ], + "time": "2016-03-30 10:41:14" + }, + { + "name": "twig/extensions", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig-extensions.git", + "reference": "449e3c8a9ffad7c2479c7864557275a32b037499" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig-extensions/zipball/449e3c8a9ffad7c2479c7864557275a32b037499", + "reference": "449e3c8a9ffad7c2479c7864557275a32b037499", + "shasum": "" + }, + "require": { + "twig/twig": "~1.20|~2.0" + }, + "require-dev": { + "symfony/translation": "~2.3" + }, + "suggest": { + "symfony/translation": "Allow the time_diff output to be translated" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_Extensions_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Common additional features for Twig that do not directly belong in core", + "homepage": "http://twig.sensiolabs.org/doc/extensions/index.html", + "keywords": [ + "i18n", + "text" + ], + "time": "2015-08-22 16:38:35" + }, + { + "name": "twig/twig", + "version": "v1.24.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8", + "reference": "3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8", + "shasum": "" + }, + "require": { + "php": ">=5.2.7" + }, + "require-dev": { + "symfony/debug": "~2.7", + "symfony/phpunit-bridge": "~2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.24-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + }, + { + "name": "Twig Team", + "homepage": "http://twig.sensiolabs.org/contributors", + "role": "Contributors" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ], + "time": "2016-01-25 21:22:18" + } + ], + "packages-dev": [ + { + "name": "sensio/generator-bundle", + "version": "v3.0.5", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/SensioGeneratorBundle.git", + "reference": "5274eafa251359087230bade2ff35dd6cec2e530" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/zipball/5274eafa251359087230bade2ff35dd6cec2e530", + "reference": "5274eafa251359087230bade2ff35dd6cec2e530", + "shasum": "" + }, + "require": { + "symfony/console": "~2.7|~3.0", + "symfony/framework-bundle": "~2.7|~3.0", + "symfony/process": "~2.7|~3.0", + "symfony/yaml": "~2.7|~3.0" + }, + "require-dev": { + "doctrine/orm": "~2.4", + "symfony/doctrine-bridge": "~2.7|~3.0", + "twig/twig": "~1.18" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Sensio\\Bundle\\GeneratorBundle\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "This bundle generates code for you", + "time": "2016-01-05 16:30:36" + }, + { + "name": "symfony/phpunit-bridge", + "version": "v2.8.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/phpunit-bridge.git", + "reference": "855dc0e829fad123966347612b4183e307338c11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/9562f8291b98bcd4abd4959ab74f35191d7b34b5", + "reference": "855dc0e829fad123966347612b4183e307338c11", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" + }, + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Bridge\\PhpUnit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony PHPUnit Bridge", + "homepage": "https://symfony.com", + "time": "2016-01-06 09:59:23" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.5.9" + }, + "platform-dev": [], + "platform-overrides": { + "php": "5.5.9" + } +} diff --git a/Symfony/3.0/phpunit.xml.dist b/Symfony/3.0/phpunit.xml.dist new file mode 100644 index 0000000..a2a0910 --- /dev/null +++ b/Symfony/3.0/phpunit.xml.dist @@ -0,0 +1,34 @@ + + + + + + + + + + + tests + + + + + + + + + + src + + src/*Bundle/Resources + src/*/*Bundle/Resources + src/*/Bundle/*Bundle/Resources + + + + diff --git a/Symfony/3.0/src/.htaccess b/Symfony/3.0/src/.htaccess new file mode 100644 index 0000000..fb1de45 --- /dev/null +++ b/Symfony/3.0/src/.htaccess @@ -0,0 +1,7 @@ + + Require all denied + + + Order deny,allow + Deny from all + diff --git a/Symfony/3.0/src/AppBundle/AppBundle.php b/Symfony/3.0/src/AppBundle/AppBundle.php new file mode 100644 index 0000000..74f125e --- /dev/null +++ b/Symfony/3.0/src/AppBundle/AppBundle.php @@ -0,0 +1,9 @@ +buffer .= $message. ($newline? PHP_EOL: ''); + } + + public function getBuffer() + { + return $this->buffer; + } +} diff --git a/Symfony/3.0/src/AppBundle/Command/AlertsCommand.php b/Symfony/3.0/src/AppBundle/Command/AlertsCommand.php new file mode 100644 index 0000000..5931896 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/AlertsCommand.php @@ -0,0 +1,298 @@ +setName('wpak:alerts') + ->setDescription('Monitor source for potential schedule alerts') + ; + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| MONITOR SOURCES FOR POSSIBLE SCHEDULE ALERTS |'); + self::log($output, 'info', '--------------------------------------------------------'); + + //Fake the authentication mechanism and act as root + $searchRootUserEntity = $this->getContainer()->get('doctrine')->getRepository('AppBundle:Users')->findOneByUsername('root'); + $token = new UsernamePasswordToken($searchRootUserEntity, null, "secured_area", $searchRootUserEntity->getRoles()); + $this->getContainer()->get("security.token_storage")->setToken($token); + + // Array to be used when sending emails to users + $sourceAlerts = array(); + + // Get list of sources + $availableSources = $this->getContainer() + ->get('doctrine') + ->getRepository('AppBundle:Sources')->findAll(); + + // First part is dealing with data collection + foreach ($availableSources as $sourceEntity) { + self::log($output, 'info', 'AlertsCommand.php\execute() ---------------------------------------------------------------------------------'); + self::log($output, 'info', 'AlertsCommand.php\execute() - Processing Source: ' . $sourceEntity->getSourceId()); + $sourceHasSchedule = $this->getContainer()->get('app.svc.sources')->checkSourceScheduleExists($sourceEntity->getSourceId()); + $sourceIsActive = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $sourceEntity->getSourceId() . '.cfg', 'cfgsourceactive'); + $latestPictureFile = $this->getContainer()->get('app.svc.pictures.directory')->getLatestPictureForSource($sourceEntity->getSourceId()); + if ($sourceHasSchedule !== false && $sourceIsActive == 'yes' && $latestPictureFile != '') { + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Source has a schedule, is active and has previously captured pictures'); + + $sourceTimezone = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $sourceEntity->getSourceId() . '.cfg', 'cfgcapturetimezone'); + $sourceAlertEmail = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $sourceEntity->getSourceId() . '.cfg', 'cfgemailalertfailure'); + $sourceAlertEmailReminder = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $sourceEntity->getSourceId() . '.cfg', 'cfgemailalertreminder'); + + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Source Timezone is: ' . $sourceTimezone); + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Source Alert user if delay greated than: ' . $sourceAlertEmail . ' Minutes'); + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Source Send a reminder every: ' . $sourceAlertEmailReminder . ' Minutes'); + + $currentDate = new \DateTime('now', new \DateTimeZone($sourceTimezone)); + $lastPictureDate = \DateTime::createFromFormat('YmdHis', substr($latestPictureFile, 0,14), new \DateTimeZone($sourceTimezone)); + $nextCaptureFromPictureDate = $this->getContainer()->get('app.svc.schedule')->getNextCaptureSlot($sourceHasSchedule, $lastPictureDate, $output->isDebug()); + + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Current date is _______________________: ' . $currentDate->format('Y-m-d H:i:s')); + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Latest picture was captured at ________: ' . $lastPictureDate->format('Y-m-d H:i:s')); + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Following capture is/was scheduled for : ' . $nextCaptureFromPictureDate->format('Y-m-d H:i:s')); + + // Difference in minutes between current date and last time a picture was expected to be captured + $diffInMinutes = round(($currentDate->getTimestamp() - $nextCaptureFromPictureDate->getTimestamp())/60); + + $incidentFile = null; + if ($nextCaptureFromPictureDate >= $currentDate) { + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - All good, the following capture should happen in the future'); + $alertStatus = 'good'; + } else { + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Picture acquisition is late by ' . $diffInMinutes . ' minutes'); + if ($diffInMinutes >= intval($sourceAlertEmail)) { + self::log($output, 'info', 'AlertsCommand.php\execute() - ' . $sourceEntity->getSourceId() . ' - Source has been late by more than ' . $sourceAlertEmail . ' minutes'); + $alertStatus = 'error'; + $incidentFile = substr($latestPictureFile, 0,14) . '.jsonl'; + } else { + $alertStatus = 'late'; + } + } + + $alertsFile = $this->getContainer()->getParameter('dir_sources') . 'source' . $sourceEntity->getSourceId() . '/resources/alerts/' . substr($latestPictureFile, 0,8) . '.jsonl'; + + $alertArray = array( + 'sourceid' => $sourceEntity->getSourceId() + , 'status' => $alertStatus + , 'previousStatus' => self::checkPreviousStatus($output, $alertsFile) + , 'currentDate' => $currentDate->format('c') + , 'lastPictureFile' => $latestPictureFile + , 'lastPictureDate' => $lastPictureDate->format('c') + , 'lastScheduledDate' => $nextCaptureFromPictureDate->format('c') + , 'captureLateBy' => $diffInMinutes + , 'sendAlertAfter' => $sourceAlertEmail + , 'sendReminderAfter' => $sourceAlertEmailReminder + , 'incidentFile' => $incidentFile + ); + + file_put_contents($alertsFile, json_encode($alertArray) . "\n", FILE_APPEND); + + $sourceAlerts[$sourceEntity->getSourceId()] = $alertArray; + } + } + + // Second part is dealing with sending users an alert + self::processUSerAlerts($output, $sourceAlerts); + + } + + function processUSerAlerts(OutputInterface $output, $sourceAlerts) { + self::log($output, 'info', 'AlertsCommand.php\processUSerAlerts()'); + $users = $this->getContainer()->get('app.svc.alerts')->getUsersSourcesWithAlertsFlag(); + foreach($users as $currentUserSource) { + self::log($output, 'info', 'AlertsCommand.php\processUSerAlerts() - Processing User: ' . $currentUserSource['EMAIL']); + $currentSourceId = $currentUserSource['SOURCEID']; + if (isset($sourceAlerts[$currentSourceId])) { + $incidentsFile = $this->getContainer()->getParameter('dir_sources') . 'source' . $currentUserSource['SOURCEID'] . '/resources/alerts/incidents/' . $sourceAlerts[$currentSourceId]['incidentFile']; + self::log($output, 'info', 'AlertsCommand.php\processUSerAlerts() - Incidents File (if needed): ' . $incidentsFile); + if ($sourceAlerts[$currentSourceId]['status'] == 'error' && intval($sourceAlerts[$currentSourceId]['sendAlertAfter']) > 0) { + self::log($output, 'info', 'AlertsCommand.php\processUSerAlerts() - ' . $currentUserSource['EMAIL'] . ' - Processing source: ID: ' . $currentUserSource['SOURCEID'] . ' - Name: ' . $currentUserSource['SOURCENAME']); + if (!is_file($incidentsFile)) { + self::sendIncidentEmail($output, $sourceAlerts[$currentSourceId], $currentUserSource['EMAIL'], $currentUserSource['SOURCENAME'], $incidentsFile); + } else { + $incidentEmailLog = file($incidentsFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $logArray = array(); + foreach($incidentEmailLog as $logLine) { + $logLine = json_decode($logLine, true); + if ($logLine['emailTo'] == $currentUserSource['EMAIL']) { + array_push($logArray, $logLine); + } + } + $logArray = array_reverse($logArray); + if (count($logArray) == 0) { + self::sendIncidentEmail($output, $sourceAlerts[$currentSourceId], $currentUserSource['EMAIL'], $currentUserSource['SOURCENAME'], $incidentsFile); + } else { + $lastEmailDate = \DateTime::createFromFormat(\DateTime::ISO8601,$logArray[0]['currentDate']); + $sourceTimezone = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $currentUserSource['SOURCEID'] . '.cfg', 'cfgcapturetimezone'); + $currentDate = new \DateTime('now', new \DateTimeZone($sourceTimezone)); + + // Difference in minutes between current date and last time a picture was expected to be captured + $diffInMinutes = round(($currentDate->getTimestamp() - $lastEmailDate->getTimestamp())/60); + self::log($output, 'info', 'AlertsCommand.php\processUSerAlerts() - ' . $currentUserSource['EMAIL'] . ' - Processing source: ID: ' . $currentUserSource['SOURCEID'] . ' Time since last reminder: ' . $diffInMinutes . 'mn'); + if ($diffInMinutes >= $sourceAlerts[$currentSourceId]['sendReminderAfter'] && intval($sourceAlerts[$currentSourceId]['sendReminderAfter']) > 0) { + self::sendIncidentEmail($output, $sourceAlerts[$currentSourceId], $currentUserSource['EMAIL'], $currentUserSource['SOURCENAME'], $incidentsFile); + } else { + self::log($output, 'info', 'AlertsCommand.php\processUSerAlerts() - ' . $currentUserSource['EMAIL'] . ' - Processing source: ID: ' . $currentUserSource['SOURCEID'] . ' Not enough time since last capture, not sending reminder'); + } + } + } + } else if ($sourceAlerts[$currentSourceId]['status'] == 'good' && $sourceAlerts[$currentSourceId]['previousStatus'] == 'error') { + self::log($output, 'info', 'AlertsCommand.php\processUSerAlerts() - ' . $currentUserSource['EMAIL'] . ' - Source is recovering after an error, source ID: ' . $currentUserSource['SOURCEID'] . ' - Name: ' . $currentUserSource['SOURCENAME']); + self::sendRecoveryEmail($output, $sourceAlerts[$currentSourceId], $currentUserSource['EMAIL'], $currentUserSource['SOURCENAME'], $incidentsFile); + } else { + self::log($output, 'info', 'AlertsCommand.php\processUSerAlerts() - ' . $currentUserSource['EMAIL'] . ' - No Error on source ID: ' . $currentUserSource['SOURCEID'] . ' - Name: ' . $currentUserSource['SOURCENAME'] . ' or email alerts disabled'); + } + } + } + } + + function checkPreviousStatus(OutputInterface $output, $alertsFile) { + self::log($output, 'info', 'AlertsCommand.php\checkPreviousStatus()'); + if (!is_file($alertsFile)) { + return null; + } else { + $alertsLog = file($alertsFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $logArray = array(); + foreach($alertsLog as $logLine) { + $logLine = json_decode($logLine, true); + array_push($logArray, $logLine); + } + $logArray = array_reverse($logArray); + if (isset($logArray[0]['status'])) { + return $logArray[0]['status']; + } else { + return null; + } + } + } + + function sendIncidentEmail(OutputInterface $output, $incidentArray, $userEmail, $sourceName, $incidentsFile) { + self::log($output, 'info', 'AlertsCommand.php\sendIncidentEmail()'); + + $sourceLocale = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $incidentArray['sourceid'] . '.cfg', 'cfgsourcelanguage'); + $lastCaptureDate = \DateTime::createFromFormat(\DateTime::ISO8601,$incidentArray['lastPictureDate']); + $currentDate = \DateTime::createFromFormat(\DateTime::ISO8601,$incidentArray['currentDate']); + + $templateSubjectFile = $this->getContainer()->getParameter('dir_locale') . $sourceLocale . '/emails/captureAlertSubject.txt'; + if (!file_exists($templateSubjectFile)) {$templateSubjectFile = $this->getContainer()->getParameter('dir_locale') . 'en_US.utf8/emails/captureAlertSubject.txt';} + $templateContentFile = $this->getContainer()->getParameter('dir_locale') . $sourceLocale . '/emails/captureAlertContent.txt'; + if (!file_exists($templateContentFile)) {$templateContentFile = $this->getContainer()->getParameter('dir_locale') . 'en_US.utf8/emails/captureAlertContent.txt';} + + $emailSubject = file_get_contents($templateSubjectFile); + $emailSubject = str_replace("#CURRENTHOSTNAME#", gethostname(), $emailSubject); + $emailSubject = str_replace("#CURRENTSOURCENAME#", $sourceName, $emailSubject); + $emailSubject = str_replace("#CURRENTSOURCEID#", $incidentArray['sourceid'], $emailSubject); + + $emailBody = file_get_contents($templateContentFile); + $emailBody = str_replace("#TIMESINCELASTCAPTURE#", $incidentArray['captureLateBy'], $emailBody); + $emailBody = str_replace("#SENDALERTAFTER#", $incidentArray['sendAlertAfter'], $emailBody); + $emailBody = str_replace("#SENDREMINDERAFTER#", $incidentArray['sendReminderAfter'], $emailBody); + $emailBody = str_replace("#SOURCENAME#", $sourceName, $emailBody); + $emailBody = str_replace("#SOURCEID#", $incidentArray['sourceid'], $emailBody); + $emailBody = str_replace("#LASTSUCCESSFULCAPTUREDATE#", $lastCaptureDate->format('Y-m-d H:i:s'), $emailBody); + $emailBody = str_replace("#CURRENTSERVERTIME#", $currentDate->format('Y-m-d H:i:s'), $emailBody); + + $emailsParams = array( + 'EMAIL_FROM' => $this->getContainer()->getParameter('mailer_from') + , 'EMAIL_TO' => $userEmail + , 'EMAIL_CC' => '' + , 'SUBJECT' => $emailSubject + , 'BODY' => $emailBody + , 'ATTACHMENT_PATH' => '' + , 'ATTACHMENT_NAME' => '' + , 'ATTACHMENT_SOURCEID' => '' + ); + + $this->getContainer()->get('app.svc.emails')->prepareEmailForQueue($emailsParams); + + $incidentEmailLog = array( + 'sourceid' => $incidentArray['sourceid'] + , 'currentDate' => $currentDate->format('c') + , 'emailTo' => $userEmail + ); + self::log($output, 'info', 'AlertsCommand.php\sendIncidentEmail() - IncidentEmailLog: ' . $incidentsFile); + file_put_contents($incidentsFile, json_encode($incidentEmailLog) . "\n", FILE_APPEND); + } + + function sendRecoveryEmail(OutputInterface $output, $incidentArray, $userEmail, $sourceName, $incidentsFile) { + self::log($output, 'info', 'AlertsCommand.php\sendRecoveryEmail()'); + + $sourceLocale = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $incidentArray['sourceid'] . '.cfg', 'cfgsourcelanguage'); + $lastCaptureDate = \DateTime::createFromFormat(\DateTime::ISO8601,$incidentArray['lastPictureDate']); + $currentDate = \DateTime::createFromFormat(\DateTime::ISO8601,$incidentArray['currentDate']); + + $templateSubjectFile = $this->getContainer()->getParameter('dir_locale') . $sourceLocale . '/emails/captureRecoveredSubject.txt'; + if (!file_exists($templateSubjectFile)) {$templateSubjectFile = $this->getContainer()->getParameter('dir_locale') . 'en_US.utf8/emails/captureRecoveredSubject.txt';} + $templateContentFile = $this->getContainer()->getParameter('dir_locale') . $sourceLocale . '/emails/captureRecoveredContent.txt'; + if (!file_exists($templateContentFile)) {$templateContentFile = $this->getContainer()->getParameter('dir_locale') . 'en_US.utf8/emails/captureRecoveredContent.txt';} + + $emailSubject = file_get_contents($templateSubjectFile); + $emailSubject = str_replace("#CURRENTHOSTNAME#", gethostname(), $emailSubject); + $emailSubject = str_replace("#CURRENTSOURCENAME#", $sourceName, $emailSubject); + $emailSubject = str_replace("#CURRENTSOURCEID#", $incidentArray['sourceid'], $emailSubject); + + $emailBody = file_get_contents($templateContentFile); + $emailBody = str_replace("#SOURCENAME#", $sourceName, $emailBody); + $emailBody = str_replace("#SOURCEID#", $incidentArray['sourceid'], $emailBody); + $emailBody = str_replace("#LASTSUCCESSFULCAPTUREDATE#", $lastCaptureDate->format('Y-m-d H:i:s'), $emailBody); + $emailBody = str_replace("#CURRENTSERVERTIME#", $currentDate->format('Y-m-d H:i:s'), $emailBody); + + $emailsParams = array( + 'EMAIL_FROM' => $this->getContainer()->getParameter('mailer_from') + , 'EMAIL_TO' => $userEmail + , 'EMAIL_CC' => '' + , 'SUBJECT' => $emailSubject + , 'BODY' => $emailBody + , 'ATTACHMENT_PATH' => '' + , 'ATTACHMENT_NAME' => '' + , 'ATTACHMENT_SOURCEID' => '' + ); + + $this->getContainer()->get('app.svc.emails')->prepareEmailForQueue($emailsParams); + } + + function countNumberSourcesErrors(OutputInterface $output, $userSources, $sourceAlerts) { + self::log($output, 'info', 'AlertsCommand.php\countNumberSourcesErrors()'); + $errorCount = 0; + foreach ($sourceAlerts as $alert) { + if ($alert['status'] == 'error') { + foreach ($userSources as $source) { + if ($source['SOURCEID'] == $alert['sourceid']) { + $errorCount++; + } + } + } + } + return $errorCount; + } + +} + diff --git a/Symfony/3.0/src/AppBundle/Command/DailyReportCommand.php b/Symfony/3.0/src/AppBundle/Command/DailyReportCommand.php new file mode 100644 index 0000000..c1f7dbd --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/DailyReportCommand.php @@ -0,0 +1,352 @@ +setName('wpak:dailyreport') + ->setDescription('Generate a capture report for the previous day or for a specific day') + ->addArgument('day', InputArgument::OPTIONAL, 'Process report for a specific day (YYYYMMDD), ALL to generate for all') + ; + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| GENERATE A DAILY CAPTURE REPORT AND SEND IT BY EMAIL |'); + self::log($output, 'info', '--------------------------------------------------------'); + + //Fake the authentication mechanism and act as root + $searchRootUserEntity = $this->getContainer()->get('doctrine')->getRepository('AppBundle:Users')->findOneByUsername('root'); + $token = new UsernamePasswordToken($searchRootUserEntity, null, "secured_area", $searchRootUserEntity->getRoles()); + $this->getContainer()->get("security.token_storage")->setToken($token); + + $reportDay = $input->getArgument('day'); + + if ($reportDay != 'ALL') { + $sourceDailyReport = self::generateReports($output, $reportDay); + + // Second part is dealing with going through those reports and sending users an alert, only for a single day though. + self::parseReports($output, $sourceDailyReport); + } else { + $serverTimezone = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-general.cfg', 'cfgservertimezone'); + + $firstPictureDay = $this->getContainer()->get('app.svc.pictures.directory')->getFirstPictureDayAmongstAllSources(); + self::log($output, 'info', 'execute() - First picture day: ' . $firstPictureDay); + $currentDay = new \DateTime('now', new \DateTimeZone($serverTimezone)); + $reportDateYmd = $currentDay->format('Ymd'); + while ($reportDateYmd >= $firstPictureDay) { + self::log($output, 'info', 'execute() - Current Date: ' . $reportDateYmd); + $sourceDailyReport = self::generateReports($output, $reportDateYmd); + $currentDay->sub(new \DateInterval('P1D')); + $reportDateYmd = $currentDay->format('Ymd'); + } + } + } + + function generateReports(OutputInterface $output, $reportDay) { + self::log($output, 'info', 'DailyReportCommand.php\generateReports()'); + + // Array to be used when sending emails to users + $sourceDailyReport = array(); + + // Get list of sources + $availableSources = $this->getContainer() + ->get('doctrine') + ->getRepository('AppBundle:Sources')->findAll(); + + // First part is dealing with data collection + foreach ($availableSources as $sourceEntity) { + self::log($output, 'info', 'DailyReportCommand.php\generateReports() ---------------------------------------------------------------------------------'); + self::log($output, 'info', 'DailyReportCommand.php\generateReports() - Processing Source: ' . $sourceEntity->getSourceId()); + $scheduleArray = $this->getContainer()->get('app.svc.sources')->checkSourceScheduleExists($sourceEntity->getSourceId()); + $sourceIsActive = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $sourceEntity->getSourceId() . '.cfg', 'cfgsourceactive'); + $latestPictureFile = $this->getContainer()->get('app.svc.pictures.directory')->getLatestPictureForSource($sourceEntity->getSourceId()); + if (/*$scheduleArray !== false && $sourceIsActive == 'yes' && */$latestPictureFile != '') { + self::log($output, 'info', 'DailyReportCommand.php\generateReports() - ' . $sourceEntity->getSourceId() . ' - Source has a schedule, is active and has previously captured pictures'); + + $sourceTimezone = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $sourceEntity->getSourceId() . '.cfg', 'cfgcapturetimezone'); + //Identify Report Day + if (!is_int($reportDay) || intval($reportDay) == 0) { + //Identify day to process + $reportDay = new \DateTime('now', new \DateTimeZone($sourceTimezone)); + $reportDay->sub(new \DateInterval('P1D')); + $reportDateYmd = $reportDay->format('Ymd'); + } else { + self::log($output, 'info', 'DailyReportCommand.php\generateReports() - ' . $sourceEntity->getSourceId() . ' - Report Day: ' . $reportDay); + $reportDay = \DateTime::createFromFormat('Ymd', $reportDay, new \DateTimeZone($sourceTimezone)); + $reportDateYmd = $reportDay->format('Ymd'); + } + if (intval($reportDateYmd) > 0) { + self::log($output, 'info', 'DailyReportCommand.php\generateReports() - ' . $sourceEntity->getSourceId() . ' - Will run a report on day: ' . $reportDateYmd); + + // Get array of captured pictures + $jpgDirectory = $this->getContainer()->getParameter('dir_sources') . 'source' . $sourceEntity->getSourceId() . '/pictures/' . $reportDateYmd . '/'; + $capturedJpgs = array(); + if (is_dir($jpgDirectory)) { + $capturedJpgs = $this->getContainer()->get('app.svc.pictures.directory')->listPicturesInDirectory($jpgDirectory, 'jpg', 'size'); + } + $rawDirectory = $this->getContainer()->getParameter('dir_sources') . 'source' . $sourceEntity->getSourceId() . '/pictures/raw/' . $reportDateYmd . '/'; + $capturedRaws = array(); + if (is_dir($rawDirectory)) { + $capturedRaws = $this->getContainer()->get('app.svc.pictures.directory')->listPicturesInDirectory($rawDirectory, 'jpg', 'size'); + } + self::log($output, 'info', 'DailyReportCommand.php\generateReports() - ' . $sourceEntity->getSourceId() . ' - Output: ' . serialize($capturedJpgs)); + + $sourceProcessRaw = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $sourceEntity->getSourceId() . '.cfg', 'cfgprocessraw'); + + $reportComparison = self::compareCapturedReportWithCaptureSchedule($output, $capturedJpgs, $capturedRaws, $scheduleArray, $reportDay, $sourceProcessRaw); + + $sourceReport = array_merge(array( + 'sourceId' => $sourceEntity->getSourceId() + , 'sourceName' => $sourceEntity->getName() + , 'reportDay' => $reportDay->format('Y-m-d') + , 'active' => $sourceIsActive + ), $reportComparison); + + self::log($output, 'info', 'DailyReportCommand.php\generateReports() - ' . $sourceEntity->getSourceId() . ' - Report Comparison: Serialize: ' . serialize($sourceReport)); + + $sourceReportFile = $this->getContainer()->getParameter('dir_sources') . 'source' . $sourceEntity->getSourceId() . '/resources/reports/' . $reportDateYmd . '.json'; + file_put_contents($sourceReportFile, json_encode($sourceReport, JSON_FORCE_OBJECT)); + + $sourceDailyReport[$sourceEntity->getSourceId()] = $sourceReport; + } else { + self::log($output, 'info', 'DailyReportCommand.php\generateReports() - ' . $sourceEntity->getSourceId() . ' - There was no picutres captured yesterday, cancelling ... '); + } + } + } + return $sourceDailyReport; + } + + function parseReports(OutputInterface $output, $sourceDailyReport) { + self::log($output, 'info', 'DailyReportCommand.php\parseReports()'); + $users = $this->getContainer()->get('app.svc.alerts')->getSingleUsersSourcesWithAlertsFlag(); + foreach($users as $currentUser) { + self::log($output, 'info', 'DailyReportCommand.php\parseReports() - Processing: ' . $currentUser['EMAIL']); + $emailReportArray = array(); + //Get the list of sources of a specific user + $sources = $this->getContainer()->get('app.svc.alerts')->getUserSourcesWithAlertsFlag($currentUser['USE_ID']); + foreach($sources as $currentSource) { + $currentSourceId = $currentSource['SOURCEID']; + if (isset($sourceDailyReport[$currentSourceId])) { + self::log($output, 'info', 'DailyReportCommand.php\parseReports() - Adding source: ' . $currentSourceId . ' to the email report'); + array_push($emailReportArray, $sourceDailyReport[$currentSourceId]); + } else { + self::log($output, 'info', 'DailyReportCommand.php\parseReports() - Not adding source: ' . $currentSourceId . ' to the email report'); + } + } + if (count($emailReportArray) > 0) { + self::sendReportEmail($output, $emailReportArray, $currentUser); + } else { + self::log($output, 'info', 'DailyReportCommand.php\parseReports() - Report empty, skipping email...'); + } + } + } + + function getOverallReportScore(OutputInterface $output, $emailReportArray) { + self::log($output, 'info', 'AlertsCommand.php\getOverallReportScore()'); + $scoreArray = array(); + foreach($emailReportArray as $report) { + if (isset($report['schedule']) && isset($report['schedule']['overall']) && isset($report['schedule']['overall']['score']) && $report['schedule']['overall']['score'] != '-') { + array_push($scoreArray, $report['schedule']['overall']['score']); + } + } + if (count($scoreArray) > 0) { + return array_sum($scoreArray) / count($scoreArray); + } else { + return '-'; + } + } + + + function sendReportEmail(OutputInterface $output, $emailReportArray, $currentUser) { + self::log($output, 'info', 'AlertsCommand.php\sendReportEmail()'); + + self::log($output, 'info', 'AlertsCommand.php\sendReportEmail() - serialize: ' . serialize($emailReportArray)); + + $sourceLocale = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-source' . $emailReportArray[0]['sourceId'] . '.cfg', 'cfgsourcelanguage'); + + $templateSubjectFile = $this->getContainer()->getParameter('dir_locale') . $sourceLocale . '/emails/dailyReportSubject.txt'; + if (!file_exists($templateSubjectFile)) {$templateSubjectFile = $this->getContainer()->getParameter('dir_locale') . 'en_US.utf8/emails/dailyReportSubject.txt';} + $templateContentFile = $this->getContainer()->getParameter('dir_locale') . $sourceLocale . '/emails/dailyReportContentTxt.twig'; + if (!file_exists($templateContentFile)) {$templateContentFile = $this->getContainer()->getParameter('dir_locale') . 'en_US.utf8/emails/dailyReportContentTxt.twig';} + $templateContentHtmlFile = $this->getContainer()->getParameter('dir_locale') . $sourceLocale . '/emails/dailyReportContentHtml.twig'; + if (!file_exists($templateContentHtmlFile)) {$templateContentHtmlFile = $this->getContainer()->getParameter('dir_locale') . 'en_US.utf8/emails/dailyReportContentHtml.twig';} + + $emailSubject = file_get_contents($templateSubjectFile); + $emailSubject = str_replace("#CURRENTHOSTNAME#", gethostname(), $emailSubject); + $emailSubject = str_replace("#REPORTSCORE#", self::getOverallReportScore($output, $emailReportArray), $emailSubject); + $emailSubject = str_replace("#REPORTDAY#", $emailReportArray[0]['reportDay'], $emailSubject); + + $emailBodyHtml = $this->getContainer()->get('templating')->render($templateContentHtmlFile,array('emailReportArray' => $emailReportArray)); + $emailBodyTxt = $this->getContainer()->get('templating')->render($templateContentFile,array('emailReportArray' => $emailReportArray)); + + $emailsParams = array( + 'EMAIL_FROM' => $this->getContainer()->getParameter('mailer_from') + , 'EMAIL_TO' => $currentUser['EMAIL'] + , 'EMAIL_CC' => '' + , 'SUBJECT' => $emailSubject + , 'BODY' => $emailBodyTxt + , 'BODYHTML' => $emailBodyHtml + , 'ATTACHMENT_PATH' => '' + , 'ATTACHMENT_NAME' => '' + , 'ATTACHMENT_SOURCEID' => '' + ); + + $this->getContainer()->get('app.svc.emails')->prepareEmailForQueue($emailsParams); + } + + function processSchedule(OutputInterface $output, $currentDayOfWeek, $currentDateYmd, $capturedJpgs, $capturedRaws, $scheduleArray, $sourceProcessRaw) { + self::log($output, 'info', 'DailyReportCommand.php\processSchedule()'); + $totalPlannedCapturedInSchedule = 0; + $jpgCaptureMissingAtScheduleCount = 0; + $jpgCaptureInScheduleCount = 0; + $rawCaptureMissingAtScheduleCount = 0; + $rawCaptureInScheduleCount = 0; + $overallSchedule = array(); + $overallScore = 0; + for ($h=0;$h<24;$h++) { + for ($m=0;$m<60;$m++) { + if ($h < 10) {$fullHour = '0' . $h;} else {$fullHour = $h;} + if ($m < 10) {$fullMinute = '0' . $m;} else {$fullMinute = $m;} + $pictureDatehourMinute = $currentDateYmd . $fullHour . $fullMinute; + if (isset($scheduleArray[$currentDayOfWeek][$h][$m])) { // Means capture was expected at this slot, and we are going to record something into the array + $overallSchedule[$currentDayOfWeek][$h][$m]['schedule'] = true; + if (isset($capturedJpgs[$pictureDatehourMinute])) { + $overallSchedule[$currentDayOfWeek][$h][$m]['jpg'] = $capturedJpgs[$pictureDatehourMinute]['filename']; + $jpgCaptureInScheduleCount++; + } else { + $jpgCaptureMissingAtScheduleCount++; + } + if (isset($capturedRaws[$pictureDatehourMinute])) { + $overallSchedule[$currentDayOfWeek][$h][$m]['raw'] = $capturedJpgs[$pictureDatehourMinute]['filename']; + $rawCaptureInScheduleCount++; + } else { + $rawCaptureMissingAtScheduleCount++; + } + if (!isset($capturedJpgs[$pictureDatehourMinute]) && !isset($capturedRaws[$pictureDatehourMinute])) { + $overallSchedule[$currentDayOfWeek][$h][$m]['success'] = false; + } + $totalPlannedCapturedInSchedule++; + } elseif (isset($capturedJpgs[$pictureDatehourMinute]) || isset($capturedRaws[$pictureDatehourMinute])) { // Means a JPG picture was captured at this slot but we are outside the planned schedule + $overallSchedule[$currentDayOfWeek][$h][$m]['schedule'] = false; + if (isset($capturedJpgs[$pictureDatehourMinute])) { + $overallSchedule[$currentDayOfWeek][$h][$m]['jpg'] = $capturedJpgs[$pictureDatehourMinute]['filename']; + } + if (isset($capturedRaws[$pictureDatehourMinute])) { // Means a JPG picture was captured at this slot but we are outside the planned schedule + $overallSchedule[$currentDayOfWeek][$h][$m]['raw'] = $capturedRaws[$pictureDatehourMinute]['filename']; + } + } + } + } + if ($totalPlannedCapturedInSchedule > 0) { + $jpgSuccessRate = round($jpgCaptureInScheduleCount * 100 / $totalPlannedCapturedInSchedule) . '%'; + $rawSuccessRate = round($rawCaptureInScheduleCount * 100 / $totalPlannedCapturedInSchedule) . '%'; + if ($sourceProcessRaw == 'no') { + $overallScore = round($jpgCaptureInScheduleCount * 100 / $totalPlannedCapturedInSchedule); + } else { + $overallScore = round(($jpgCaptureInScheduleCount + $rawCaptureInScheduleCount) * 100 / ($totalPlannedCapturedInSchedule*2)); + } + } else { + $jpgSuccessRate = '-'; + $rawSuccessRate = '-'; + $overallScore = '-'; + } + if ($sourceProcessRaw == 'no') { + $rawSuccessRate = '-'; + } + + return array( + 'overall' => array( + 'plannedSlots' => $totalPlannedCapturedInSchedule + , 'schedule' => $overallSchedule + , 'score' => $overallScore + ) + , 'jpg' => array( + 'missing' => array( + 'count' => $jpgCaptureMissingAtScheduleCount + ) + , 'successCount' => $jpgCaptureInScheduleCount + , 'successRate' => $jpgSuccessRate + ) + , 'raw' => array( + 'missing' => array( + 'count' => $rawCaptureMissingAtScheduleCount + ) + , 'successCount' => $rawCaptureInScheduleCount + , 'successRate' => $rawSuccessRate + )); + + } + + function compareCapturedReportWithCaptureSchedule(OutputInterface $output, $capturedJpgs, $capturedRaws, $scheduleArray, \DateTime $reportDay, $sourceProcessRaw) { + self::log($output, 'info', 'DailyReportCommand.php\compareCapturedReportWithCaptureSchedule()'); + $currentDayOfWeek = $reportDay->format('N'); + $currentDateYmd = $reportDay->format('Ymd'); + self::log($output, 'info', 'DailyReportCommand.php\compareCapturedReportWithCaptureSchedule() - Processing Day of Week: ' . $currentDayOfWeek); + + $scheduleReport = self::processSchedule($output, $currentDayOfWeek, $currentDateYmd, $capturedJpgs, $capturedRaws, $scheduleArray, $sourceProcessRaw); + + $jpgReport = self::getPictureCount($output, $scheduleArray, $currentDayOfWeek, $capturedJpgs); + $rawReport = self::getPictureCount($output, $scheduleArray, $currentDayOfWeek, $capturedRaws); + $report = array( + 'schedule' => $scheduleReport + , 'jpg' => $jpgReport + , 'raw' => $rawReport + , 'total' => array( + 'count' => $jpgReport['count'] + $rawReport['count'] + , 'size' => $jpgReport['size'] + $rawReport['size'] + ) + ); + return $report; + } + + function getPictureCount(OutputInterface $output, $scheduleArray, $currentDayOfWeek, $capturedPictures) { + $picturesOutsideScheduleCount = 0; + $picturesCount = 0; + $picturesSize = 0; + foreach ($capturedPictures as $idx => $currentPicture) { + $capturedHour = substr($idx, 8,2); + $capturedMinute = substr($idx, 10,2); + if (!isset($scheduleArray[$currentDayOfWeek][$capturedHour][$capturedMinute])) { + $picturesOutsideScheduleCount++; + } + $picturesSize = $picturesSize + $currentPicture['size']; + $picturesCount++; + } + return array( + 'outsideScheduleCount' => $picturesOutsideScheduleCount + , 'count' => $picturesCount + , 'size' => $picturesSize + ); + + } + +} + diff --git a/Symfony/3.0/src/AppBundle/Command/DbInitCommand.php b/Symfony/3.0/src/AppBundle/Command/DbInitCommand.php new file mode 100644 index 0000000..21aad75 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/DbInitCommand.php @@ -0,0 +1,408 @@ +setName('wpak:dbinit') + ->setDescription('Initialise Database') + ->addOption('preconfigure', null, InputOption::VALUE_NONE, 'If set, the system will pre-configure 3 sources'); + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| INITIALIZE DATABASE |'); + self::log($output, 'info', '--------------------------------------------------------'); + + self::createApplications($output); + self::createPermissions($output); + self::createGroups($output); + self::createRootUser($output); + + if ($input->getOption('preconfigure')) { + + //Fake the authentication mechanism to update configuration as root + $searchRootUserEntity = $this->getContainer()->get('doctrine')->getRepository('AppBundle:Users')->findOneByUsername('root'); + $token = new UsernamePasswordToken($searchRootUserEntity, null, "secured_area", $searchRootUserEntity->getRoles()); + $this->getContainer()->get("security.token_storage")->setToken($token); + + //SOURCE 1 + self::createSources($output, 1, 'S1: Mon-Fri 09:00-18:00'); + $sourceCapture = array ( + array ('NAME' => 'cfgsourceactive','VALUE' => 'yes','SOURCEID' => 1) + , array ('NAME' => 'cfgsourcetype','VALUE' => 'testpicture','SOURCEID' => 1) + , array ('NAME' => 'cfgminimumcapturevalue','VALUE' => '30','SOURCEID' => 1) + , array ('NAME' => 'cfgminimumcaptureinterval','VALUE' => 'seconds','SOURCEID' => 1) + , array ('NAME' => 'cfgcroncapturevalue','VALUE' => '5','SOURCEID' => 1) + , array ('NAME' => 'cfgcroncaptureinterval','VALUE' => 'minutes','SOURCEID' => 1) + , array ('NAME' => 'cfgcroncalendar','VALUE' => 'yes','SOURCEID' => 1) + , array ('NAME' => 'cfgcronday1','VALUE' => 'yes,09,00,18,00','SOURCEID' => 1) + , array ('NAME' => 'cfgcronday2','VALUE' => 'yes,09,00,18,00','SOURCEID' => 1) + , array ('NAME' => 'cfgcronday3','VALUE' => 'yes,09,00,18,00','SOURCEID' => 1) + , array ('NAME' => 'cfgcronday4','VALUE' => 'yes,09,00,18,00','SOURCEID' => 1) + , array ('NAME' => 'cfgcronday5','VALUE' => 'yes,09,00,18,00','SOURCEID' => 1) + , array ('NAME' => 'cfgcronday6','VALUE' => 'no,00,00,00,00','SOURCEID' => 1) + , array ('NAME' => 'cfgcronday7','VALUE' => 'no,00,00,00,00','SOURCEID' => 1) + , array ('NAME' => 'cfgemailalertreminder','VALUE' => '50','SOURCEID' => 1) + , array ('NAME' => 'cfgphidgeterroractivate','VALUE' => 'true','SOURCEID' => 1) + , array ('NAME' => 'cfgphidgetcameraport','VALUE' => '0','SOURCEID' => 1) + , array ('NAME' => 'cfgcopymainenable','VALUE' => 'yes','SOURCEID' => 1) + , array ('NAME' => 'cfgcopymainsourceid','VALUE' => '10','SOURCEID' => 1) + , array ('NAME' => 'cfghotlinksize2','VALUE' => '','SOURCEID' => 1) + , array ('NAME' => 'cfghotlinksize3','VALUE' => '','SOURCEID' => 1) + , array ('NAME' => 'cfgpicwatermarkactivate','VALUE' => 'no','SOURCEID' => 1) + ); + + $confFile = $this->getContainer()->getParameter('dir_etc') . "config-source1.cfg"; + $confSettingsFile = $this->getContainer()->getParameter('sys_config') . "config-source.json"; + foreach($sourceCapture as $param) { + $result = $this->getContainer()->get('app.svc.configuration')->updateSourceConfiguration('127.0.0.1', $param['SOURCEID'], $param['NAME'], $param['VALUE'], $confFile, $confSettingsFile, $this->getContainer()); + self::log($output, 'info', 'Source Configuration: ' . $result['message']); + } + + $sourceVideo = array ( + array ('NAME' => 'cfgvideocodecH2641080pcreate','VALUE' => 'no','SOURCEID' => 1) + ); + $confFile = $this->getContainer()->getParameter('dir_etc') . "config-source1-video.cfg"; + $confSettingsFile = $this->getContainer()->getParameter('sys_config') . "config-source-video.json"; + foreach($sourceVideo as $param) { + $result = $this->getContainer()->get('app.svc.configuration')->updateSourceConfiguration('127.0.0.1', $param['SOURCEID'], $param['NAME'], $param['VALUE'], $confFile, $confSettingsFile, $this->getContainer()); + self::log($output, 'info', 'Source Configuration: ' . $result['message']); + } + + //SOURCE 2 + self::createSources($output, 2, 'S2: Mon-Fri 18:00-09:00 and Weekend'); + $sourceCapture = array ( + array ('NAME' => 'cfgsourceactive','VALUE' => 'yes','SOURCEID' => 2) + , array ('NAME' => 'cfgsourcetype','VALUE' => 'testpicture','SOURCEID' => 2) + , array ('NAME' => 'cfgminimumcapturevalue','VALUE' => '30','SOURCEID' => 2) + , array ('NAME' => 'cfgminimumcaptureinterval','VALUE' => 'seconds','SOURCEID' => 2) + , array ('NAME' => 'cfgcroncapturevalue','VALUE' => '30','SOURCEID' => 2) + , array ('NAME' => 'cfgcroncaptureinterval','VALUE' => 'minutes','SOURCEID' => 2) + , array ('NAME' => 'cfgcroncalendar','VALUE' => 'yes','SOURCEID' => 2) + , array ('NAME' => 'cfgcronday1','VALUE' => 'yes,18,00,09,00','SOURCEID' => 2) + , array ('NAME' => 'cfgcronday2','VALUE' => 'yes,18,00,09,00','SOURCEID' => 2) + , array ('NAME' => 'cfgcronday3','VALUE' => 'yes,18,00,09,00','SOURCEID' => 2) + , array ('NAME' => 'cfgcronday4','VALUE' => 'yes,18,00,09,00','SOURCEID' => 2) + , array ('NAME' => 'cfgcronday5','VALUE' => 'yes,18,00,09,00','SOURCEID' => 2) + , array ('NAME' => 'cfgcronday6','VALUE' => 'yes,00,00,00,00','SOURCEID' => 2) + , array ('NAME' => 'cfgcronday7','VALUE' => 'yes,00,00,00,00','SOURCEID' => 2) + , array ('NAME' => 'cfgemailalertreminder','VALUE' => '50','SOURCEID' => 2) + , array ('NAME' => 'cfgphidgeterroractivate','VALUE' => 'true','SOURCEID' => 2) + , array ('NAME' => 'cfgphidgetcameraport','VALUE' => '0','SOURCEID' => 2) + , array ('NAME' => 'cfgcopymainenable','VALUE' => 'yes','SOURCEID' => 2) + , array ('NAME' => 'cfgcopymainsourceid','VALUE' => '10','SOURCEID' => 2) + , array ('NAME' => 'cfghotlinksize2','VALUE' => '','SOURCEID' => 2) + , array ('NAME' => 'cfghotlinksize3','VALUE' => '','SOURCEID' => 2) + , array ('NAME' => 'cfgpicwatermarkactivate','VALUE' => 'no','SOURCEID' => 2) + ); + + $confFile = $this->getContainer()->getParameter('dir_etc') . "config-source2.cfg"; + $confSettingsFile = $this->getContainer()->getParameter('sys_config') . "config-source.json"; + foreach($sourceCapture as $param) { + $result = $this->getContainer()->get('app.svc.configuration')->updateSourceConfiguration('127.0.0.1', $param['SOURCEID'], $param['NAME'], $param['VALUE'], $confFile, $confSettingsFile, $this->getContainer()); + self::log($output, 'info', 'Source Configuration: ' . $result['message']); + } + + $sourceVideo = array ( + array ('NAME' => 'cfgvideocodecH2641080pcreate','VALUE' => 'no','SOURCEID' => 2) + ); + $confFile = $this->getContainer()->getParameter('dir_etc') . "config-source2-video.cfg"; + $confSettingsFile = $this->getContainer()->getParameter('sys_config') . "config-source-video.json"; + foreach($sourceVideo as $param) { + $result = $this->getContainer()->get('app.svc.configuration')->updateSourceConfiguration('127.0.0.1', $param['SOURCEID'], $param['NAME'], $param['VALUE'], $confFile, $confSettingsFile, $this->getContainer()); + self::log($output, 'info', 'Source Configuration: ' . $result['message']); + } + + self::createSources($output, 10, 'S10: Centralization'); + $sourceCapture = array ( + array ('NAME' => 'cfgsourceactive','VALUE' => 'yes','SOURCEID' => 10) + , array ('NAME' => 'cfgsourcetype','VALUE' => 'wpak','SOURCEID' => 10) + , array ('NAME' => 'cfgcapturedelay','VALUE' => '40','SOURCEID' => 10) + , array ('NAME' => 'cfgcapturedelayinterval','VALUE' => 'seconds','SOURCEID' => 10) + , array ('NAME' => 'cfgcroncapturevalue','VALUE' => '10','SOURCEID' => 10) + , array ('NAME' => 'cfgcroncaptureinterval','VALUE' => 'minutes','SOURCEID' => 10) + , array ('NAME' => 'cfgcroncalendar','VALUE' => 'no','SOURCEID' => 10) + , array ('NAME' => 'cfgemailalertreminder','VALUE' => '50','SOURCEID' => 10) + , array ('NAME' => 'cfghotlinksize2','VALUE' => '','SOURCEID' => 10) + , array ('NAME' => 'cfghotlinksize3','VALUE' => '','SOURCEID' => 10) + , array ('NAME' => 'cfgpicwatermarkactivate','VALUE' => 'no','SOURCEID' => 10) + ); + + $confFile = $this->getContainer()->getParameter('dir_etc') . "config-source10.cfg"; + $confSettingsFile = $this->getContainer()->getParameter('sys_config') . "config-source.json"; + foreach($sourceCapture as $param) { + $result = $this->getContainer()->get('app.svc.configuration')->updateSourceConfiguration('127.0.0.1', $param['SOURCEID'], $param['NAME'], $param['VALUE'], $confFile, $confSettingsFile, $this->getContainer()); + self::log($output, 'info', 'Source Configuration: ' . $result['message']); + } + + } + + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + + function createApplications(OutputInterface $output) { + self::log($output, 'comment', '*********'); + self::log($output, 'info', 'DbInitCommand.php\createApplications() - Adding Applications to Database'); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->getConnection()->getConfiguration()->setSQLLogger(null); + + $allApplications = $this->getContainer()->getParameter('applications'); + foreach($allApplications as $currentApplication) { + $appCode = key($currentApplication); + self::log($output, 'info', 'DbInitCommand.php\processBiDbInitQueue() - Processing: ' . key($currentApplication)); + + $searchApplicationId = $this + ->getContainer() + ->get('doctrine') + ->getRepository('AppBundle:Applications') + ->findOneByName(key($currentApplication)); + if ($searchApplicationId) { + self::log($output, 'comment', 'DbInitCommand.php\processBiDbInitQueue() - Skipping: ' . key($currentApplication) . ' already exists in database'); + } else { + $newApplicationEntity = new Applications(); + $newApplicationEntity->setName($currentApplication[$appCode]['name']); + $newApplicationEntity->setCode($appCode); + $newApplicationEntity->setNotes($currentApplication[$appCode]['description']); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->persist($newApplicationEntity); + } + } + $em->flush(); + } + + function createPermissions(OutputInterface $output) { + self::log($output, 'comment', '*********'); + self::log($output, 'info', 'DbInitCommand.php\createPermissions() - Adding Permissions to Database'); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->getConnection()->getConfiguration()->setSQLLogger(null); + + $allPermissions = $this->getContainer()->getParameter('permissions'); + foreach($allPermissions as $currentPermission) { + self::log($output, 'info', 'DbInitCommand.php\processBiDbInitQueue() - Processing: ' . key($currentPermission)); + + $searchPermissionId = $this + ->getContainer() + ->get('doctrine') + ->getRepository('AppBundle:Permissions') + ->findOneByName(key($currentPermission)); + if ($searchPermissionId) { + self::log($output, 'comment', 'DbInitCommand.php\processBiDbInitQueue() - Skipping: ' . key($currentPermission) . ' already exists in database'); + } else { + $newPermissionEntity = new Permissions(); + $newPermissionEntity->setName(key($currentPermission)); + $newPermissionEntity->setNotes(current($currentPermission)); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->persist($newPermissionEntity); + } + } + $em->flush(); + } + + function createGroups(OutputInterface $output) { + self::log($output, 'comment', '*********'); + self::log($output, 'info', 'DbInitCommand.php\createGroups() - Adding Groups to Database'); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->getConnection()->getConfiguration()->setSQLLogger(null); + + $allGroups = $this->getContainer()->getParameter('groups'); + foreach($allGroups as $currentGroup) { + $groupName = key($currentGroup); + self::log($output, 'info', 'DbInitCommand.php\processBiDbInitQueue() - Processing: ' . $groupName); + self::log($output, 'info', 'DbInitCommand.php\processBiDbInitQueue() - Processing Description: ' . $currentGroup[$groupName]['description']); + + $searchGroupEntity = $this + ->getContainer() + ->get('doctrine') + ->getRepository('AppBundle:Groups') + ->findOneByName(key($currentGroup)); + if (!$searchGroupEntity) { + $newGroupEntity = new Groups(); + $newGroupEntity->setName($groupName); + $newGroupEntity->setNotes($currentGroup[$groupName]['description']); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->persist($newGroupEntity); + } else { + self::log($output, 'comment', 'DbInitCommand.php\processBiDbInitQueue() - Group exists: ' . key($currentGroup) . ' already exists in database'); + $newGroupEntity = $searchGroupEntity; + } + + foreach($currentGroup[$groupName]['applications'] as $currentGroupApplications) { + self::log($output, 'info', 'DbInitCommand.php\processBiDbInitQueue() - Processing Application: ' . $currentGroupApplications); + + $applicationEntity = $this->getContainer()->get('doctrine') + ->getRepository('AppBundle:Applications') + ->findOneByCode($currentGroupApplications); + + $searchGroupApplicationEntity = $this->getContainer()->get('doctrine') + ->getRepository('AppBundle:GroupsApplications') + ->findOneBy(array('app' => $applicationEntity, 'gro' => $newGroupEntity)); + if (!$searchGroupApplicationEntity && $applicationEntity) { + $newGroupsApplicationsEntity = new GroupsApplications(); + $newGroupsApplicationsEntity->setApp($applicationEntity); + $newGroupsApplicationsEntity->setGro($newGroupEntity); + $em->persist($newGroupsApplicationsEntity); + } else { + self::log($output, 'comment', 'DbInitCommand.php\processBiDbInitQueue() - Skipping: ' . $currentGroupApplications . ' application already existing for this group'); + } + + } + + foreach($currentGroup[$groupName]['permissions'] as $currentGroupPermission) { + self::log($output, 'info', 'DbInitCommand.php\processBiDbInitQueue() - Processing Permission: ' . $currentGroupPermission); + + $permissionEntity = $this->getContainer()->get('doctrine') + ->getRepository('AppBundle:Permissions') + ->findOneByName($currentGroupPermission); + + $searchGroupPermissionEntity = $this->getContainer()->get('doctrine') + ->getRepository('AppBundle:GroupsPermissions') + ->findOneBy(array('per' => $permissionEntity, 'gro' => $newGroupEntity)); + if (!$searchGroupPermissionEntity) { + $newGroupsPermissionsEntity = new GroupsPermissions(); + $newGroupsPermissionsEntity->setPer($permissionEntity); + $newGroupsPermissionsEntity->setGro($newGroupEntity); + $em->persist($newGroupsPermissionsEntity); + } else { + self::log($output, 'comment', 'DbInitCommand.php\processBiDbInitQueue() - Skipping: ' . $currentGroupPermission . ' permission already existing for this group'); + } + } + + } + $em->flush(); + } + + function createRootUser(OutputInterface $output) { + self::log($output, 'comment', '*********'); + self::log($output, 'info', 'DbInitCommand.php\createRootUser() - Create Root User'); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->getConnection()->getConfiguration()->setSQLLogger(null); + + $adminGroupEntity = $this + ->getContainer() + ->get('doctrine') + ->getRepository('AppBundle:Groups') + ->findOneByName('Admin'); + + $searchRootUserEntity = $this + ->getContainer() + ->get('doctrine') + ->getRepository('AppBundle:Users') + ->findOneByUsername('root'); + if ($searchRootUserEntity) { + self::log($output, 'comment', 'DbInitCommand.php\processBiDbInitQueue() - User Root already exists, skipping'); + } else { + $rootDefaultPassword = 'webcampak'; + $rootDefaultEmail = 'support@webcampak.com'; + + $newUserEntity = new Users('root', 'webcampak', 'salt', array()); + $newUserEntity->setSalt(sha1($rootDefaultEmail . microtime())); + + //We generate a new encoded password + $encoder = $this->getContainer()->get('security.encoder_factory')->getEncoder($newUserEntity); + $rootDefaultPasswordEncoded = $encoder->encodePassword($rootDefaultPassword, $newUserEntity->getSalt()); + + self::log($output, 'info', 'DbInitCommand.php\createRootUser() - New encoded password is: ' . $rootDefaultPasswordEncoded); + + $newUserEntity->setPassword($rootDefaultPasswordEncoded); + $newUserEntity->setChangePwdFlag('Y'); + $newUserEntity->setActiveFlag('Y'); + $newUserEntity->setFirstname('Root'); + $newUserEntity->setLastname('Root'); + $newUserEntity->setGro($adminGroupEntity); + + $this->getContainer()->get('doctrine')->getManager()->persist($newUserEntity); + $this->getContainer()->get('doctrine')->getManager()->flush(); + } + } + + function createSources(OutputInterface $output, $sourceId, $sourceName) { + self::log($output, 'comment', '*********'); + self::log($output, 'info', 'DbInitCommand.php\createSources() - Create Source: ' . $sourceId . ' - ' . $sourceName); + + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->getConnection()->getConfiguration()->setSQLLogger(null); + + $searchSourceEntity = $this + ->getContainer() + ->get('doctrine') + ->getRepository('AppBundle:Sources') + ->findOneBySourceId($sourceId); + if ($searchSourceEntity) { + self::log($output, 'comment', 'DbInitCommand.php\createSources() - Source already exists, skipping'); + } else { + $sourceCreateCommand = new SourceCreateCommand(); + $sourceCreateCommand->setContainer($this->getContainer()); + $input = new ArrayInput(array('--sourceid' => $sourceId)); + $output = new BufferedOutput(); + $resultCode = $sourceCreateCommand->run($input, $output); + $commandOutput = explode("\n", $output->getBuffer()); + foreach($commandOutput as $commandOutputLine) { + self::log($output, 'info', 'DbInitCommand.php\createSources() - Console Subprocess: ' . $commandOutputLine); + } + self::log($output, 'info', 'DbInitCommand.php\createSources() - Command Result code: ' . $resultCode); + + $newSourceEntity = new Sources(); + $newSourceEntity->setName($sourceName); + $newSourceEntity->setSourceId($sourceId); + $newSourceEntity->setWeight($sourceId); + + $em->persist($newSourceEntity); + + $searchRootUserEntity = $this->getContainer()->get('doctrine') + ->getRepository('AppBundle:Users') + ->findOneByUsername('root'); + + $newUsersSourceEntity = new UsersSources(); + $newUsersSourceEntity->setSou($newSourceEntity); + $newUsersSourceEntity->setUse($searchRootUserEntity); + $newUsersSourceEntity->setAlertsFlag('Y'); + $em->persist($newUsersSourceEntity); + $em->flush(); + } + } + +} + diff --git a/Symfony/3.0/src/AppBundle/Command/GphotoCommand.php b/Symfony/3.0/src/AppBundle/Command/GphotoCommand.php new file mode 100644 index 0000000..f22f793 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/GphotoCommand.php @@ -0,0 +1,74 @@ +setName('wpak:gphoto') + ->setDescription('Perform various options on gphoto') + ->addOption('port', null, InputOption::VALUE_REQUIRED, 'Port to which the camera is currently connected') + ->addOption('owner', null, InputOption::VALUE_REQUIRED, 'Owner to be assigned to the camera'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| GPHOTO COMMANDS |'); + self::log($output, 'info', '--------------------------------------------------------'); + + $gphotoOwner = $input->getOption('owner'); + $gphotoPort = $input->getOption('port'); + if (isset($gphotoOwner)) { + self::assignOwner($output, $gphotoPort, $gphotoOwner); + } + return 0; + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + function assignOwner(OutputInterface $output, $gphotoPort, $gphotoOwner) { + self::log($output, 'info', 'GphotoCommand.php\assignOwner() - Assign Owner to Gphoto-connected camera'); + self::runSystemProcess($output, 'GphotoCommand.php\assignOwner() - ', "gphoto2 -v --port " . $gphotoPort . " --set-config /main/settings/ownername=" . $gphotoOwner); + } + + function runSystemProcess(OutputInterface $output, $message, $command) { + self::log($output, 'info', $message . 'Running command: ' . $command); + $createConfiguration = new Process($command); + $createConfiguration->run(); + $processOutputLines = explode("\n", $createConfiguration->getOutput()); + foreach($processOutputLines as $processLine) { + self::log($output, 'info', $message . 'Gphoto Subprocess output: ' . $processLine); + return true; + } + if (!$createConfiguration->isSuccessful()) { + self::log($output, 'error', $message . 'Unable to perform action'); + return false; + } + } + +} + diff --git a/Symfony/3.0/src/AppBundle/Command/ParseConfigCommand.php b/Symfony/3.0/src/AppBundle/Command/ParseConfigCommand.php new file mode 100644 index 0000000..7aa9f1a --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/ParseConfigCommand.php @@ -0,0 +1,67 @@ +setName('wpak:parseconf') + ->setDescription('Parse Configuration') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| INITIALIZE DATABASE |'); + self::log($output, 'info', '--------------------------------------------------------'); + + self::parseConfig($output); + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + + function parseConfig(OutputInterface $output) { + self::log($output, 'comment', '*********'); + self::log($output, 'info', 'ParseConfigCommand.php\parseConfig() - Starting to parse config'); + + $linesArray = file("/home/francois/NetBeansProjects/v3.0/src/init/etc/config-source-videopost.cfg", FILE_IGNORE_NEW_LINES); + + $sourceConfigurationRaw = parse_ini_file("/home/francois/NetBeansProjects/v3.0/src/init/etc/config-source-videopost.cfg", FALSE, INI_SCANNER_RAW); + foreach($sourceConfigurationRaw as $key=>$value) { + $value = trim(str_replace("\"", "", $value)); + $currentDescription = ""; + foreach($linesArray as $currentLine) { + if (isset($currentLine[0]) && $currentLine[0] == "#" && strpos($currentLine,$key) !== false) { + $currentDescription = trim(str_replace("#", "", $currentLine)); + $currentDescription = trim(str_replace($key, "", $currentDescription)); + $currentDescription = trim(str_replace(":", "", $currentDescription)); + } + } + echo ', "' . $key . '":{"default": "' . $value . '", "type": "alphanum", "description": "' . $currentDescription . '"}'; + echo "\n"; + } + } +} + diff --git a/Symfony/3.0/src/AppBundle/Command/RunSyncReportsCommand.php b/Symfony/3.0/src/AppBundle/Command/RunSyncReportsCommand.php new file mode 100644 index 0000000..70d3241 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/RunSyncReportsCommand.php @@ -0,0 +1,346 @@ +setName('wpak:runsyncreports') + ->setDescription('Process the email queue and send emails') + ->addArgument('sleep', InputArgument::OPTIONAL, 'Sleep before starting to process the queue (seconds)') + ; + } + + function log($level, $message) { + $this->output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $this->output = $output; + self::log('info', '--------------------------------------------------------'); + self::log('info', '| PROCESS THE SYNC REPORT QUEUE |'); + self::log('info', '--------------------------------------------------------'); + + //Fake the authentication mechanism and act as root + $searchRootUserEntity = $this->getContainer()->get('doctrine')->getRepository('AppBundle:Users')->findOneByUsername('root'); + $token = new UsernamePasswordToken($searchRootUserEntity, null, "secured_area", $searchRootUserEntity->getRoles()); + $this->getContainer()->get("security.token_storage")->setToken($token); + + $sleepTime = $input->getArgument('sleep'); + if ($sleepTime) { + self::log('info', 'Program will sleep for ' . $sleepTime . ' seconds'); + sleep($sleepTime); + } + + $this->serverTimezone = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-general.cfg', 'cfgservertimezone'); + + $fs = new Filesystem(); + $reportDir = $this->getContainer()->getParameter('dir_sync-reports'); + $reportFiles = $this->getContainer()->get('app.svc.syncreports')->getReports($reportDir . 'queued/'); + foreach ($reportFiles as $currentReportFile) { + self::log('info', 'RunSyncReportsCommand.php\execute() - Looking at file: ' . $currentReportFile); + $reportFilePathInfo = pathinfo($currentReportFile); + $currentFileDir = $reportDir . 'process/'; + $currentFileName = $reportFilePathInfo['basename']; + + $this->reportContent = $this->getContainer()->get('app.svc.syncreports')->readReportFile($currentReportFile); + $this->reportContent['job']['status'] = 'process'; + + //1- Move the file to the process directory, any file remaining here for too long can be considered failed + $fs->dumpFile($currentFileDir . $currentFileName, json_encode($this->reportContent)); + $fs->remove($currentReportFile); + + $currentDate = new \DateTime('now', new \DateTimeZone($this->serverTimezone)); + $this->reportContent['job']['date_start'] = $currentDate->format('c'); + + self::processLog($currentFileDir . $currentFileName, 'Report file moved to processing directory'); + self::processReport($currentFileDir, $currentFileName); + + $currentDate = new \DateTime('now', new \DateTimeZone($this->serverTimezone)); + $this->reportContent['job']['status'] = 'completed'; + $this->reportContent['job']['date_completed'] = $currentDate->format('c'); + + //2- Check if some files need to be transferred + if ($this->reportContent['job']['xfer'] === true) { + self::processLog($currentFileDir . $currentFileName, 'Preparing xfer queue'); + self::queueXferFiles($currentFileDir, $currentFileName); + } + + //3- Once done, move the file to the completed directory + $fs->dumpFile($this->getContainer()->getParameter('dir_sources') . 'source' . $this->reportContent['job']['source']['sourceid'] . '/resources/sync-reports/' . $currentFileName, json_encode($this->reportContent, JSON_PRETTY_PRINT)); + $fs->remove($currentFileDir . $currentFileName); + self::log('info', 'RunSyncReportsCommand.php\execute() - Processing completed for: ' . $currentReportFile); + } + self::log('info', 'RunSyncReportsCommand.php\execute() - Finished processing queue'); + + } + + function processLog($file, $logMessage) { + self::log('info', 'AlertsCommand.php\processLog() - ' . $logMessage); + + $fs = new Filesystem(); + $currentDate = new \DateTime('now', new \DateTimeZone($this->serverTimezone)); + + if (!isset($this->reportContent['job']['logs']) || count($this->reportContent['job']['logs']) == 0) {$this->reportContent['job']['logs'] = array();} + array_push($this->reportContent['job']['logs'], array( + 'date' => $currentDate->format('c') + , 'message' => $logMessage + )); + + $fs->dumpFile($file, json_encode($this->reportContent, JSON_PRETTY_PRINT)); + } + + function queueXferFiles($currentFileDir, $currentFileName) { + self::log('info', 'AlertsCommand.php\queueXferFiles()'); + if (isset($this->reportContent['result']['destination']['missing']['list']) && count($this->reportContent['result']['destination']['missing']['list']) > 0) { + self::log('info', 'AlertsCommand.php\queueXferFiles(): Number of files to queue for transfer: ' . count($this->reportContent['result']['destination']['missing']['list'])); + foreach($this->reportContent['result']['destination']['missing']['list'] as $currentMissingFile) { + //1- Identify filename for the queued file + //Filename is built as follow: + // 2016040112-S2-MD5.json (YYYYMMDDHH-Source ID-MD5 + $missingPictureFilename = pathinfo($currentMissingFile['path']); + $missingPictureFilename = $missingPictureFilename['basename']; + + $filenameMd5 = md5('S' + . $this->reportContent['job']['source']['sourceid'] . '-' + . $this->reportContent['job']['source']['type'] . '-' + . $this->reportContent['job']['source']['ftpserverid'] . '-' + . $this->reportContent['job']['destination']['sourceid'] . '-' + . $this->reportContent['job']['destination']['type'] . '-' + . $this->reportContent['job']['destination']['ftpserverid'] . '-' + . $currentMissingFile['path'] + ); + $currentMissingFilename = substr($missingPictureFilename, 0,12) . '-' . $this->reportContent['job']['source']['sourceid'] . '-' . $filenameMd5 . '.json'; + self::log('info', 'AlertsCommand.php\queueXferFiles(): Currrent Filename: ' . $currentMissingFilename); + + //2- Check if file exists in queue + if (!is_file($this->getContainer()->getParameter('dir_xfer') . 'queued/' . substr($currentMissingFilename, 0,8) . '/' . $currentMissingFilename)) { + #If transfer type is ftp, calculate the server md5, composed of remote host and username + if ($this->reportContent['job']['source']['type'] === 'ftp') { + $ftpConfigFile = $this->getContainer()->getParameter('dir_etc') . 'config-source' . $this->reportContent['job']['source']['sourceid'] . '-ftpservers.cfg'; + $ftpServersFromConfigFile = $this->getContainer()->get('app.svc.ftp')->getServersFromConfigFile($ftpConfigFile); + $this->reportContent['job']['source']['ftpserverhash'] = $this->getContainer()->get('app.svc.ftp')->calculateFTPServerHash($ftpServersFromConfigFile, $this->reportContent['job']['source']['ftpserverid']); + } else { + $this->reportContent['job']['source']['ftpserverhash'] = null; + } + if ($this->reportContent['job']['destination']['type'] === 'ftp') { + $ftpConfigFile = $this->getContainer()->getParameter('dir_etc') . 'config-source' . $this->reportContent['job']['destination']['sourceid'] . '-ftpservers.cfg'; + $ftpServersFromConfigFile = $this->getContainer()->get('app.svc.ftp')->getServersFromConfigFile($ftpConfigFile); + $this->reportContent['job']['destination']['ftpserverhash'] = $this->getContainer()->get('app.svc.ftp')->calculateFTPServerHash($ftpServersFromConfigFile, $this->reportContent['job']['destination']['ftpserverid']); + } else { + $this->reportContent['job']['destination']['ftpserverhash'] = null; + } + $xferContent = array(); + $xferContent['job'] = array(); + $xferContent['job']['status'] = 'queued'; + #$xferContent['job']['path'] = $currentMissingFile['path']; + $xferContent['job']['source'] = $this->reportContent['job']['source']; + $xferContent['job']['source']['filepath'] = $currentMissingFile['path']; + $xferContent['job']['destination'] = $this->reportContent['job']['destination']; + $xferContent['job']['destination']['filepath'] = $currentMissingFile['path']; + $xferContent['job']['hash'] = $filenameMd5; + $xferContent['job']['sync-report']['filename'] = $currentFileName; + $xferContent['job']['sync-report']['hash'] = $this->reportContent['job']['hash']; + $currentDate = new \DateTime('now', new \DateTimeZone($this->serverTimezone)); + $xferContent['job']['date_queued'] = $currentDate->format('c'); + $xferContent['job']['date_start'] = ''; + $xferContent['job']['date_completed'] = ''; + $xferContent['logs'] = array(); + $fs = new Filesystem(); + $fs->dumpFile($this->getContainer()->getParameter('dir_xfer') . 'queued/' . substr($currentMissingFilename, 0,8) . '/' . $currentMissingFilename, json_encode($xferContent, JSON_FORCE_OBJECT)); + self::log('info', 'AlertsCommand.php\queueXferFiles(): Added file to XFER queue'); + } else { + self::log('info', 'AlertsCommand.php\queueXferFiles(): File already exists, skipping...'); + } + } + } else { + self::log('info', 'AlertsCommand.php\queueXferFiles(): No files to queue for transfer'); + + } + + } + + function processReport($currentFileDir, $currentFileName) { + self::log('info', 'AlertsCommand.php\processReport()'); + //$fs = new Filesystem(); + + //1- Add source files + if ($this->reportContent['job']['source']['type'] === 'filesystem') { + $parsedDu = self::runFilesystemDu($this->reportContent['job']['source']['sourceid'], 'pictures/'); + } else if ($this->reportContent['job']['source']['type'] === 'ftp') { + $parsedDu = self::runFtpDu($this->reportContent['job']['source']['sourceid'], $this->reportContent['job']['source']['ftpserverid'], 'pictures/'); + } + if ($parsedDu !== false) { + $this->reportContent['result']['source']['files'] = $parsedDu; + self::processLog($currentFileDir . $currentFileName, 'Scanned source directory for pictures'); + } + + //2- Add destination files + if ($this->reportContent['job']['destination']['type'] === 'filesystem') { + $parsedDu = self::runFilesystemDu($this->reportContent['job']['destination']['sourceid'], 'pictures/'); + } else if ($this->reportContent['job']['destination']['type'] === 'ftp') { + $parsedDu = self::runFtpDu($this->reportContent['job']['destination']['sourceid'], $this->reportContent['job']['destination']['ftpserverid'], 'pictures/'); + } +// $parsedDu = self::runFilesystemDu($this->reportContent['job']['destination']['path']); + if ($parsedDu !== false) { + $this->reportContent['result']['destination']['files'] = $parsedDu; + self::processLog($currentFileDir . $currentFileName, 'Scanned destination directory for pictures'); + } + + //3- Calculate diff + $this->reportContent['result']['destination']['missing']['list'] = array_diff_key($this->reportContent['result']['source']['files']['list'], $this->reportContent['result']['destination']['files']['list']); + $dstSummary = self::summarizeFileList($this->reportContent['result']['destination']['missing']['list']); + $this->reportContent['result']['destination']['missing']['count'] = $dstSummary['count']; + $this->reportContent['result']['destination']['missing']['size'] = $dstSummary['size']; + self::processLog($currentFileDir . $currentFileName, 'Calculated diff between source and destination (missing pictures at source)'); + + $this->reportContent['result']['source']['missing']['list'] = array_diff_key($this->reportContent['result']['destination']['files']['list'], $this->reportContent['result']['source']['files']['list']); + $srcSummary = self::summarizeFileList($this->reportContent['result']['source']['missing']['list']); + $this->reportContent['result']['source']['missing']['count'] = $srcSummary['count']; + $this->reportContent['result']['source']['missing']['size'] = $srcSummary['size']; + self::processLog($currentFileDir . $currentFileName, 'Calculated diff between destination and source (missing pictures at destination'); + + $this->reportContent['result']['intersect']['list'] = array_intersect_key($this->reportContent['result']['source']['files']['list'], $this->reportContent['result']['destination']['files']['list']); + $itrSummary = self::summarizeFileList($this->reportContent['result']['intersect']['list']); + $this->reportContent['result']['intersect']['count'] = $itrSummary['count']; + $this->reportContent['result']['intersect']['size'] = $itrSummary['size']; + self::processLog($currentFileDir . $currentFileName, 'Calculated intersection between destination and source'); + + } + + function summarizeFileList($fileList) { + self::log('info', 'summarizeFileList'); + $summary = array('count' => array('jpg' => 0, 'raw' => 0, 'total' => 0), 'size' => array('jpg' => 0, 'raw' => 0, 'total' => 0)); + foreach($fileList as $currentFile) { + $summary['count']['total'] = $summary['count']['total'] + 1; + if ($currentFile['type'] === 'jpg') {$summary['count']['jpg'] = $summary['count']['jpg']+1;} + else {$summary['count']['raw'] = $summary['count']['raw']+1;} + + $summary['size']['total'] = $summary['size']['total'] + $currentFile['size']; + if ($currentFile['type'] === 'jpg') {$summary['size']['jpg'] = $summary['size']['jpg']+$currentFile['size'];} + else {$summary['size']['raw'] = $summary['size']['raw']+$currentFile['size'];} + + } + return $summary; + } + + function runFtpDu($sourceId, $serverId, $duDirectory) { + self::log('info', 'runFtpDu(): Running du -a -b via lftp'); + $ftpConfigFile = $this->getContainer()->getParameter('dir_etc') . 'config-source' . $sourceId . '-ftpservers.cfg'; + $ftpServersFromConfigFile = $this->getContainer()->get('app.svc.ftp')->getServersFromConfigFile($ftpConfigFile); + $ftpServer = $this->getContainer()->get('app.svc.ftp')->getFtpServerbyId($ftpServersFromConfigFile, $serverId); + $this->ftpServer = $ftpServer; + $this->ftpDuDirectory = $duDirectory; + self::log('info', 'runFtpDu(): FTP Server: ' . $ftpServer['NAME']); + $this->duParsedOutput = array('list' => array(), 'count' => array('jpg' => 0, 'raw' => 0, 'total' => 0), 'size' => array('jpg' => 0, 'raw' => 0, 'total' => 0)); + $runSystemProcess = new Process('lftp -u ' . $ftpServer['USERNAME'] . ':' . $ftpServer['PASSWORD'] . ' ' . $ftpServer['HOST'] . ':' . $ftpServer['DIRECTORY'] . $duDirectory . ' -e "du -b -a;exit"'); + $runSystemProcess->setTimeout(120000); + $runSystemProcess->run(function ($type, $buffer) { + if (Process::ERR === $type) { + self::log('info', 'runFtpDu(): Error: ' . $buffer); + } else { + $processOutputLines = explode("\n", $buffer); + foreach($processOutputLines as $processLine) { + $duParsedLine = self::parseDuLine($processLine, './'); + if ($duParsedLine !== false && intval($duParsedLine['size']) > 0 && ($duParsedLine['type'] === 'jpg' || $duParsedLine['type'] === 'raw')) { + $duParsedLine['path'] = substr($duParsedLine['path'], 1); #Hack: When running ftp du, remove first characted of the path, which is typically a / + $duParsedLine['path'] = $this->ftpDuDirectory . $duParsedLine['path']; + //self::log('info', 'runFtpDu(): Filepath: ' . $duParsedLine['path']); + $currentMd5 = md5($duParsedLine['size'] . $duParsedLine['type'] . $duParsedLine['path']); + $this->duParsedOutput['list'][$currentMd5] = $duParsedLine; + $this->duParsedOutput['count']['total'] = $this->duParsedOutput['count']['total']+1; + if ($duParsedLine['type'] === 'jpg') {$this->duParsedOutput['count']['jpg'] = $this->duParsedOutput['count']['jpg']+1;} + else {$this->duParsedOutput['count']['raw'] = $this->duParsedOutput['count']['raw']+1;} + $this->duParsedOutput['size']['total'] = $this->duParsedOutput['size']['total'] + $duParsedLine['size']; + if ($duParsedLine['type'] === 'jpg') {$this->duParsedOutput['size']['jpg'] = $this->duParsedOutput['size']['jpg']+$duParsedLine['size'];} + else {$this->duParsedOutput['size']['raw'] = $this->duParsedOutput['size']['raw']+$duParsedLine['size'];} + } + } + } + }); + if (!$runSystemProcess->isSuccessful()) { + self::log('error', 'Unable to perform action'); + return false; + } + return $this->duParsedOutput; + } + + function runFilesystemDu($sourceId, $duDirectory) { + $fullDuDirectoryPath = $this->getContainer()->getParameter('dir_sources') . 'source' . intval($sourceId) . '/' . $duDirectory; + $sourcePath = $this->getContainer()->getParameter('dir_sources') . 'source' . intval($sourceId) . '/'; + self::log('info', 'Running command: du -b -a ' . $fullDuDirectoryPath); + $duParsedOutput = array('list' => array(), 'count' => array('jpg' => 0, 'raw' => 0, 'total' => 0), 'size' => array('jpg' => 0, 'raw' => 0, 'total' => 0)); + $runSystemProcess = new Process('du -b -a ' . $fullDuDirectoryPath); + $runSystemProcess->run(); + $processOutputLines = explode("\n", $runSystemProcess->getOutput()); + foreach($processOutputLines as $processLine) { + //$duParsedLine = self::parseDuLine($processLine, $fullDuDirectoryPath); + $duParsedLine = self::parseDuLine($processLine, $sourcePath); + if ($duParsedLine !== false && intval($duParsedLine['size']) > 0 && ($duParsedLine['type'] === 'jpg' || $duParsedLine['type'] === 'raw')) { + $currentMd5 = md5($duParsedLine['size'] . $duParsedLine['type'] . $duParsedLine['path']); + $duParsedOutput['list'][$currentMd5] = $duParsedLine; + $duParsedOutput['count']['total'] = $duParsedOutput['count']['total']+1; + if ($duParsedLine['type'] === 'jpg') {$duParsedOutput['count']['jpg'] = $duParsedOutput['count']['jpg']+1;} + else {$duParsedOutput['count']['raw'] = $duParsedOutput['count']['raw']+1;} + $duParsedOutput['size']['total'] = $duParsedOutput['size']['total'] + $duParsedLine['size']; + if ($duParsedLine['type'] === 'jpg') {$duParsedOutput['size']['jpg'] = $duParsedOutput['size']['jpg']+$duParsedLine['size'];} + else {$duParsedOutput['size']['raw'] = $duParsedOutput['size']['raw']+$duParsedLine['size'];} + } + } + if (!$runSystemProcess->isSuccessful()) { + self::log('error', 'Unable to perform action'); + return false; + } + return $duParsedOutput; + } + + function parseDuLine($duLine, $duDirectory) { + self::log('info', 'Du line: ' . $duLine); + $reFileSize='(\\d+)'; # Integer Number 1 + $reSpace='.*?'; # Non-greedy match on filler + $rePath='((?:\\/[\\w\\.\\-]+)+)'; # Unix Path 1 + $parsedLine = array(); + if (preg_match_all ("/".$reFileSize.$reSpace.$rePath."/is", $duLine, $matches)) { + $parsedLine['size'] = $matches[1][0]; + $parsedLine['path'] = str_replace($duDirectory, "", $matches[2][0]); + $parsedLine['type'] = pathinfo($parsedLine['path'], PATHINFO_EXTENSION); + return $parsedLine; + } else { + return false; + } + + } +} + diff --git a/Symfony/3.0/src/AppBundle/Command/SendEmailsCommand.php b/Symfony/3.0/src/AppBundle/Command/SendEmailsCommand.php new file mode 100644 index 0000000..887d70a --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/SendEmailsCommand.php @@ -0,0 +1,280 @@ +setName('wpak:sendemails') + ->setDescription('Process the email queue and send emails') + ->addArgument('sleep', InputArgument::OPTIONAL, 'Sleep before starting to process the queue (seconds)') + ; + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| PROCESS THE EMAIL QUEUE AND SEND EMAILS |'); + self::log($output, 'info', '--------------------------------------------------------'); + + //Fake the authentication mechanism and act as root + $searchRootUserEntity = $this->getContainer()->get('doctrine')->getRepository('AppBundle:Users')->findOneByUsername('root'); + $token = new UsernamePasswordToken($searchRootUserEntity, null, "secured_area", $searchRootUserEntity->getRoles()); + $this->getContainer()->get("security.token_storage")->setToken($token); + + $sleepTime = $input->getArgument('sleep'); + if ($sleepTime) { + self::log($output, 'info', 'Program will sleep for ' . $sleepTime . ' seconds'); + sleep($sleepTime); + } + + $serverTimezone = $this->getContainer()->get('app.svc.configuration')->getSourceConfigurationParameterValue($this->getContainer()->getParameter('dir_etc') . 'config-general.cfg', 'cfgservertimezone'); + + $fs = new Filesystem(); + + $emailDir = $this->getContainer()->getParameter('dir_emails'); + $currentFileDir = $emailDir . 'queued/'; + $finder = new Finder(); + $finder->files(); + $finder->sortByName(); + $finder->files()->name('*.json'); + $finder->in($emailDir . 'queued/'); + $emailHashTable = array();// Used to store emails to be sent in batch + foreach ($finder as $file) { + self::log($output, 'info', 'SendEmailsCommand.php\execute() - Looking at file: ' . $file->getFilename()); + $currentFileDir = $emailDir . 'failed/'; + $currentFileName = $file->getFilename(); + + $emailContent = json_decode($file->getContents(), true); + + //Check if same email has been sent too many times + $currentHash = $emailContent['hash']; + if (!isset($emailHashTable[$currentHash]['count'])) {$emailHashTable[$currentHash]['count'] = 0;} + + self::log($output, 'info', 'SendEmailsCommand.php\execute() - Email Hash is: ' . $currentHash); + + $emailContent['status'] = 'process'; + + //1- Move the file to the failed directory, any file remaining here for too long can be considered failed + $fs->dumpFile($currentFileDir . $currentFileName, json_encode($emailContent)); + $fs->remove($file); + + $currentDate = new \DateTime('now', new \DateTimeZone($serverTimezone)); + $emailContent['process'] = $currentDate->format('c'); + + if ($emailHashTable[$currentHash]['count'] <= 4 ) { + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Email file moved to processing directory'); + self::processEmail($output, $emailContent, $currentFileDir, $currentFileName, $serverTimezone); + } else { + if (!isset($emailHashTable[$currentHash]['email'])) { + $emailHashTable[$currentHash]['email'] = $emailContent; + $emailHashTable[$currentHash]['currentFileDir'] = $currentFileDir; + $emailHashTable[$currentHash]['currentFileName'] = $currentFileName; + } else { + $emailHashTable[$currentHash]['email']['content']['BODY'] = $emailHashTable[$currentHash]['email']['content']['BODY'] . '---------- EMAIL PART OF A BATCH ------------' . $emailContent['content']['BODY']; + } + } + $emailHashTable[$currentHash]['count']++; + } + self::log($output, 'info', 'SendEmailsCommand.php\execute() - Finished processing queue, going through batch'); + + foreach ($emailHashTable as $currentHash=>$currentEmail) { + if ($currentEmail['count'] > 4) { + self::log($output, 'info', 'SendEmailsCommand.php\execute() - Processing Hash: ' . $currentHash); + self::processEmail($output, $currentEmail['email'], $currentEmail['currentFileDir'], $currentEmail['currentFileName'], $serverTimezone); + } + } + } + + function processLog(OutputInterface $output, $emailContent, $file, $tz, $logMessage) { + self::log($output, 'info', 'AlertsCommand.php\processLog() - ' . $logMessage); + + $fs = new Filesystem(); + $currentDate = new \DateTime('now', new \DateTimeZone($tz)); + + if (!isset($emailContent['logs']) || count($emailContent['logs']) == 0) {$emailContent['logs'] = array();} + array_push($emailContent['logs'], array( + 'date' => $currentDate->format('c') + , 'message' => $logMessage + )); + + $fs->dumpFile($file, json_encode($emailContent)); + return $emailContent; + } + + function processEmail(OutputInterface $output, $emailContent, $currentFileDir, $currentFileName, $serverTimezone) { + self::log($output, 'info', 'AlertsCommand.php\sendEmail()'); + $fs = new Filesystem(); + + // We send an email with all details + $newEmail = \Swift_Message::newInstance(); + + // Set Sender + $newEmail->setSender(array($this->getContainer()->getParameter('mailer_from') => $this->getContainer()->getParameter('mailer_from_name'))); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Set Sender'); + + // Set From + if (isset($emailContent['content']['FROM']['name'])) { + $newEmail->setFrom(array($emailContent['content']['FROM']['email'] => $emailContent['content']['FROM']['name'])); + $newEmail->setReplyTo(array($emailContent['content']['FROM']['email'] => $emailContent['content']['FROM']['name'])); + } else { + $newEmail->setFrom(array($emailContent['content']['FROM']['email'])); + $newEmail->setReplyTo(array($emailContent['content']['FROM']['email'])); + } + $newEmail->setReturnPath($emailContent['content']['FROM']['email']); + //$newEmail->setReplyTo(array($emailContent['content']['FROM']['email'] => $emailContent['content']['FROM']['name'])); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Set FROM field'); + + // Set To + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: TO: Beginning setting TO field'); + if (isset($emailContent['content']['TO']) && count($emailContent['content']['TO']) > 0) { + foreach ($emailContent['content']['TO'] as $toEmail) { + if (isset($toEmail['name'])) { + $newEmail->addTo($toEmail['email'], $toEmail['name']); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: TO: Adding ' . $toEmail['email'] . ' (' . $toEmail['name'] . ')'); + } else { + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: TO: Adding ' . $toEmail['email']); + $newEmail->addTo($toEmail['email']); + } + } + } else { + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: TO: No TO field'); + } + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: TO: Setting TO field completed'); + + // Set CC + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: CC: Beginning setting CC field'); + if (isset($emailContent['content']['CC']) && count($emailContent['content']['CC']) > 0) { + foreach ($emailContent['content']['CC'] as $ccEmail) { + if (isset($ccEmail['name'])) { + $newEmail->addCc($ccEmail['email'], $ccEmail['name']); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: CC: Adding ' . $ccEmail['email'] . ' (' . $ccEmail['name'] . ')'); + } else { + $newEmail->addCc($ccEmail['email']); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: CC: Adding ' . $ccEmail['email']); + } + } + } else { + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: CC: No CC field'); + } + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: CC: Setting CC field completed'); + + // Set BCC + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: BCC: Beginning setting BCC field'); + if (isset($emailContent['content']['BCC']) && count($emailContent['content']['BCC']) > 0) { + foreach ($emailContent['content']['BCC'] as $bccEmail) { + if (isset($bccEmail['name'])) { + $newEmail->addBcc($bccEmail['email'], $bccEmail['name']); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: BCC: Adding ' . $bccEmail['email'] . ' (' . $bccEmail['name'] . ')'); + } else { + $newEmail->addBcc($bccEmail['email']); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: BCC: Adding ' . $bccEmail['email']); + } + } + } else { + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: BCC: No BCC field'); + } + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: BCC: Setting BCC field completed'); + + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Setting Email Subject & Body'); + $newEmail->setSubject($emailContent['content']['SUBJECT']); + $newEmail->setBody($emailContent['content']['BODY'], 'text/plain'); + if (isset($emailContent['content']['BODYHTML']) && $emailContent['content']['BODYHTML'] != '') { + $newEmail->addPart($emailContent['content']['BODYHTML'], 'text/html'); + } + $newEmail->setBody('
' . $emailContent['content']['BODY'] . '
', 'text/html'); + + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Attachments: Beginning processing attachments'); + if (isset($emailContent['content']['ATTACHMENTS']) && count($emailContent['content']['ATTACHMENTS']) > 0) { + foreach ($emailContent['content']['ATTACHMENTS'] as $emailAttachmment) { + if (is_file($emailAttachmment['PATH']) && isset($emailAttachmment['WIDTH']) && $emailAttachmment['WIDTH'] != ""){ + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Attachments: Resizing attachment'); + $originalPictureInfo = getimagesize($emailAttachmment['PATH']); + $originalPictureWidth = $originalPictureInfo[0]; + $originalPictureHeight = $originalPictureInfo[1]; + $pictureHeight = intval($emailAttachmment['WIDTH'] * $originalPictureHeight / $originalPictureWidth); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Attachments: Original Size: ' . $originalPictureWidth . 'x' . $originalPictureHeight); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Attachments: Target Size: ' . $emailAttachmment['WIDTH'] . 'x' . $pictureHeight); + + $dstPicture = \imagecreatetruecolor($emailAttachmment['WIDTH'], $pictureHeight); + $srcPicture = \imagecreatefromjpeg($emailAttachmment['PATH']); + \imagecopyresized($dstPicture, $srcPicture, 0, 0, 0, 0, $emailAttachmment['WIDTH'], $pictureHeight, $originalPictureWidth, $originalPictureHeight); + + $tmpPath = tempnam("/tmp", "PIC"); + \imagejpeg($dstPicture, $tmpPath); + + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $contentType = finfo_file($finfo, $emailAttachmment['PATH']); + finfo_close($finfo); + + $attachment = \Swift_Attachment::newInstance(file_get_contents($tmpPath), $emailAttachmment['NAME'], $contentType); + $newEmail->attach($attachment); + unlink($tmpPath); + } else if (is_file($emailAttachmment['PATH'])) { + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Attachments: Processing attachment: ' . $emailAttachmment['PATH'] . ' (' . $emailAttachmment['NAME'] . ')'); + $newEmail->attach(\Swift_Attachment::fromPath($emailAttachmment['PATH'])); + } else { + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Attachments: Unable to access file: ' . $emailAttachmment['PATH']); + } + } + } else { + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Attachments: No Attchments in email'); + } + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Swift: Attachments: Setting attachments completed'); + + try{ + $this->getContainer()->get('mailer')->send($newEmail); + $emailContent['status'] = 'sent'; + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Email Sent'); + $currentDate = new \DateTime('now', new \DateTimeZone($serverTimezone)); + $emailContent['sent'] = $currentDate->format('c'); + + $emailDir = $this->getContainer()->getParameter('dir_emails'); + if (!file_exists($emailDir .'sent/' . substr($currentFileName, 0,10) . '/')) { + $fs->mkdir($emailDir .'sent/' . substr($currentFileName, 0,10) . '/', 0700); + } + $fs->dumpFile($emailDir .'sent/' . substr($currentFileName, 0,10) . '/' . $currentFileName, json_encode($emailContent)); + $fs->remove($currentFileDir . $currentFileName); + + } catch(\Swift_TransportException $e){ + $emailContent['status'] = 'error'; + $currentDate = new \DateTime('now', new \DateTimeZone($serverTimezone)); + $emailContent['error'] = $currentDate->format('c'); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Unable to send email'); + $emailContent = self::processLog($output, $emailContent, $currentFileDir . $currentFileName, $serverTimezone, 'Error: ' . $e->getMessage()); + + } + + } + + +} + diff --git a/Symfony/3.0/src/AppBundle/Command/SourceCreateCommand.php b/Symfony/3.0/src/AppBundle/Command/SourceCreateCommand.php new file mode 100644 index 0000000..6a036a4 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/SourceCreateCommand.php @@ -0,0 +1,330 @@ +setName('wpak:sourcecreate') + ->setDescription('Take an ID and create a source with that ID') + ->addOption('sourceid', null, InputOption::VALUE_REQUIRED, 'Source ID to be created on the system'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| CREATE SOURCCE |'); + self::log($output, 'info', '--------------------------------------------------------'); + + + $sourceId = $input->getOption('sourceid'); + self::log($output, 'info', 'Processing source ID: ' . $sourceId); + self::log($output, 'info', 'Processing Current umask: ' . umask()); + + if (self::checkSourceExists($output, $sourceId) === false) { + self::deleteExistingSource($output, $sourceId); + + // Prepare configuration + //self::prepareConfigurationYaml($output, 'config-source.json', 'config-source' . $sourceId . '.yml'); + //self::prepareConfigurationYaml($output, 'config-source-video.json', 'config-source' . $sourceId . '-video.yml'); + //self::prepareConfigurationYaml($output, 'config-source-videocustom.json', 'config-source' . $sourceId . '-videocustom.yml'); + //self::prepareConfigurationYaml($output, 'config-source-videopost.json', 'config-source' . $sourceId . '-videopost.yml'); + //self::prepareConfigurationYaml($output, 'config-source-ftpservers.json', 'config-source' . $sourceId . '-ftpservers.yml'); + self::prepareConfiguration($output, 'config-source.json', 'config-source' . $sourceId . '.cfg'); + self::prepareConfiguration($output, 'config-source-video.json', 'config-source' . $sourceId . '-video.cfg'); + self::prepareConfiguration($output, 'config-source-videocustom.json', 'config-source' . $sourceId . '-videocustom.cfg'); + self::prepareConfiguration($output, 'config-source-videopost.json', 'config-source' . $sourceId . '-videopost.cfg'); + self::prepareConfiguration($output, 'config-source-ftpservers.json', 'config-source' . $sourceId . '-ftpservers.cfg'); + + // Prepare directories + self::createSourceDirectories($output, $sourceId); + + // Configure VSFTPD + self::updateFtpAccounts($output, $sourceId); + + // Update Crontab + self::updateCron($output); + + // Fix any potential permission issues by setting correct permissions + $fs = new Filesystem(); + $fs->chmod($this->getContainer()->getParameter('dir_sources') . "source" . $sourceId, 0700, 0000, true); + + return 0; // Return success + } else { + return 1; // Return failure + } + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + function deleteExistingSource(OutputInterface $output, $sourceId) { + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Delete existing source directory'); + $sourcesDirectory = $this->getContainer()->getParameter('dir_sources'); + $fs = new Filesystem(); + if ($fs->exists($sourcesDirectory . 'source' . $sourceId . '/')) { + $fs->remove($sourcesDirectory . 'source' . $sourceId . '/'); + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Source directory ' . $sourcesDirectory . 'source' . $sourceId . '/' . ' removed'); + } else { + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Source directory does not exist, nothing to delete'); + } + } + + function checkSourceExists(OutputInterface $output, $sourceId) { + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Checking if source already exists'); + + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + $sourcesDirectory = $this->getContainer()->getParameter('dir_sources'); + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Configuration Directory: ' . $wpakConfigDirectory); + + $fs = new Filesystem(); + // Test if source configuration file exists + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '.cfg')) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '-video.cfg')) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '-video.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '-videocustom.cfg')) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '-videocustom.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '-videopost.cfg')) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '-videocustom.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '-ftpservers.cfg')) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '-videocustom.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '.cfg')) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '.cfg' . ' already exists. Exiting ...'); + return true; + } + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - No previous configuration files found'); + + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Source Directory: ' . $sourcesDirectory . 'source' . $sourceId . '/'); + if ($fs->exists($sourcesDirectory . 'source' . $sourceId . '/')) { + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Directory exists'); + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Searching for .jpg'); + + $finder = new Finder(); + $finder->in($sourcesDirectory . 'source' . $sourceId . '/'); + $finder->in($sourcesDirectory . 'source' . $sourceId . '/')->exclude('tmp'); + + $finder->name('*.jpg'); + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Number of jpg files found: ' . iterator_count($finder) / 2); + if (iterator_count($finder) > 0) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - There are jpg files in the sources directory, exiting'); + return true; + } + + $finder->name('*.raw'); + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Number of raw files found: ' . iterator_count($finder) / 2); + if (iterator_count($finder) > 0) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - There are raw files in the sources directory, exiting'); + return true; + } + + $finder->name('*.avi'); + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Number of avi files found: ' . iterator_count($finder) / 2); + if (iterator_count($finder) > 0) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - There are avi files in the sources directory, exiting'); + return true; + } + + $finder->name('*.mp4'); + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - Number of mp4 files found: ' . iterator_count($finder) / 2); + if (iterator_count($finder) > 0) { + self::log($output, 'error', 'SourceCreateCommand.php\checkSourceExists() - There are mp4 files in the sources directory, exiting'); + return true; + } + } + self::log($output, 'info', 'SourceCreateCommand.php\checkSourceExists() - No previous content (jpg, raw, avi, mp4) found'); + return false; + } + + function prepareConfigurationYaml(OutputInterface $output, $configFileSource, $configFileOutput) { + self::log($output, 'info', 'SourceCreateCommand.php\prepareConfiguration() - Prepare webcampak YAML Configuration'); + $sysConfigDirectory = $this->getContainer()->getParameter('sys_config'); + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + + $fs = new Filesystem(); + if ($fs->exists($sysConfigDirectory . $configFileSource)) { + self::log($output, 'info', 'SourceCreateCommand.php\prepareConfiguration() - Processing configuration file ' . $sysConfigDirectory . $configFileSource); + $configArray = array(); + $json = file_get_contents($sysConfigDirectory . $configFileSource); + $configuration = $this->getContainer()->get('jms_serializer')->deserialize($json, 'AppBundle\Entities\Configuration\Configuration', 'json'); + file_put_contents($wpakConfigDirectory . $configFileOutput, '#CREATE: file created on ' . date(DATE_RFC822), FILE_APPEND | LOCK_EX); + file_put_contents($wpakConfigDirectory . $configFileOutput, "\n", FILE_APPEND | LOCK_EX); + foreach($configuration->getSections() as $section) { + self::log($output, 'info', 'SourceCreateCommand.php\prepareConfiguration() - Processing section: ' . $section->getName()); + foreach($section->getParameters() as $parameter) { + if ($parameter->getName() == "cfglocalftppass") { + //Generate default FTP password + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $newPassword = ''; + for ($i = 0; $i < 10; $i++) { + $newPassword .= $characters[rand(0, strlen($characters) - 1)]; + } + $paramValue = $newPassword; + } else { + if ($parameter->getType() == 'list') { + self::log($output, 'info', 'SourceCreateCommand.php\prepareConfiguration() - This parameter is a list: ' . $section->getName()); + $paramValue = array(); + foreach($parameter->getValues() as $valueItem) { + $valueName = $valueItem->getName(); + $paramValue[$valueName] = $valueItem->getDefault(); + } + } else { + $paramValue = $parameter->getDefault(); + } + } + $currentParamName = $parameter->getName(); + $configArray[$currentParamName] = $paramValue; + } + } + file_put_contents($wpakConfigDirectory . $configFileOutput, Yaml::dump($configArray, 1), FILE_APPEND | LOCK_EX); + return true; + } else { + self::log($output, 'error', 'SourceCreateCommand.php\prepareConfiguration() - Unable to find configuration file: ' . $sysConfigDirectory . '_test-config-source.json'); + return false; + } + } + + function prepareConfiguration(OutputInterface $output, $configFileSource, $configFileOutput) { + self::log($output, 'info', 'SourceCreateCommand.php\prepareConfiguration() - Prepare webcampak Configuration'); + $sysConfigDirectory = $this->getContainer()->getParameter('sys_config'); + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + + $fs = new Filesystem(); + if ($fs->exists($sysConfigDirectory . $configFileSource)) { + self::log($output, 'info', 'SourceCreateCommand.php\prepareConfiguration() - Processing configuration file ' . $sysConfigDirectory . $configFileSource); + $json = file_get_contents($sysConfigDirectory . $configFileSource); + $configuration = $this->getContainer()->get('jms_serializer')->deserialize($json, 'AppBundle\Entities\Configuration\Configuration', 'json'); + file_put_contents($wpakConfigDirectory . $configFileOutput, '#EDIT: Created on ' . date(DATE_RFC822), FILE_APPEND | LOCK_EX); + foreach($configuration->getSections() as $section) { + self::log($output, 'info', 'SourceCreateCommand.php\prepareConfiguration() - Processing section: ' . $section->getName()); + file_put_contents($wpakConfigDirectory . $configFileOutput, "\n", FILE_APPEND | LOCK_EX); + file_put_contents($wpakConfigDirectory . $configFileOutput, "# Section: " . $section->getName() ."\n", FILE_APPEND | LOCK_EX); + file_put_contents($wpakConfigDirectory . $configFileOutput, "# -------------------------------------------\n", FILE_APPEND | LOCK_EX); + foreach($section->getParameters() as $parameter) { + file_put_contents($wpakConfigDirectory . $configFileOutput, "# " . $parameter->getName() .": " . $parameter->getDescription() . "\n", FILE_APPEND | LOCK_EX); + } + foreach($section->getParameters() as $parameter) { + self::log($output, 'info', 'SourceCreateCommand.php\prepareConfiguration() - Processing parameter: ' . $parameter->getName()); + + if ($parameter->getName() == "cfglocalftppass") { + //Generate default FTP password + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $newPassword = ''; + for ($i = 0; $i < 10; $i++) { + $newPassword .= $characters[rand(0, strlen($characters) - 1)]; + } + $paramValue = $newPassword; + } else { + if ($parameter->getValues() !== null ) { + $paramValue = ''; + foreach($parameter->getValues() as $value) { + if ($paramValue != '') {$paramValue = $paramValue . ',';} + $paramValue = $paramValue . '"' . $value->getDefault() . '"'; + } + } else { + $paramValue = '"' . $parameter->getDefault() . '"'; + } + } + file_put_contents($wpakConfigDirectory . $configFileOutput, $parameter->getName() . "=" . $paramValue ."\n", FILE_APPEND | LOCK_EX); + } + } + return true; + } else { + self::log($output, 'error', 'SourceCreateCommand.php\prepareConfiguration() - Unable to find configuration file: ' . $sysConfigDirectory . '_test-config-source.json'); + return false; + } + } + + function createSourceDirectories(OutputInterface $output, $sourceId) { + self::log($output, 'info', 'SourceCreateCommand.php\createDirectories() - Create Source Directories'); + $wpakSourcesDirectory = $this->getContainer()->getParameter('dir_sources'); + + $fs = new Filesystem(); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId, 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/pictures", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/tmp", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/live", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/videos", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources/stats", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources/audio", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources/watermark", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources/alerts", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources/alerts/incidents", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources/reports", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources/capture", 0700); + $fs->mkdir($wpakSourcesDirectory . "source" . $sourceId . "/resources/sync-reports", 0700); + + } + + function updateFtpAccounts(OutputInterface $output, $sourceId) { + self::log($output, 'info', 'SourceCreateCommand.php\updateFtpAccounts() - Update FTP accounts'); + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + $wpakBinDirectory = $this->getContainer()->getParameter('dir_bin'); + + self::runSystemProcess($output, 'SourceCreateCommand.php\updateFtpAccounts() - ', "sudo python " . $wpakBinDirectory . "wpak-createlocalftpaccounts.py -g " . $wpakConfigDirectory . "config-general.cfg"); + } + + function updateCron(OutputInterface $output) { + self::log($output, 'info', 'SourceCronCommand.php\updateCron() - Update crontab for all sources'); + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + $wpakBinDirectory = $this->getContainer()->getParameter('dir_bin'); + + self::runSystemProcess($output, 'SourceCreateCommand.php\updateCron() - ', "python " . $wpakBinDirectory . "wpak-cronupdatefile.py -g " . $wpakConfigDirectory . "config-general.cfg"); + } + + function runSystemProcess(OutputInterface $output, $message, $command) { + self::log($output, 'info', $message . 'Running command: ' . $command); + $createConfiguration = new Process($command); + $createConfiguration->run(); + $processOutputLines = explode("\n", $createConfiguration->getOutput()); + foreach($processOutputLines as $processLine) { + self::log($output, 'info', $message . 'Python Subprocess: ' . $processLine); + return true; + } + if (!$createConfiguration->isSuccessful()) { + self::log($output, 'error', $message . 'Unable to perform action'); + return false; + } + } + +} + diff --git a/Symfony/3.0/src/AppBundle/Command/SourceCronCommand.php b/Symfony/3.0/src/AppBundle/Command/SourceCronCommand.php new file mode 100644 index 0000000..a360f8e --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/SourceCronCommand.php @@ -0,0 +1,71 @@ +setName('wpak:sourcecron') + ->setDescription('Update crontab after source modification'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| UPDATE SOURCE CRON |'); + self::log($output, 'info', '--------------------------------------------------------'); + + self::updateCron($output); + + return 0; + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + function updateCron(OutputInterface $output) { + self::log($output, 'info', 'SourceCronCommand.php\updateCron() - Update crontab for all sources'); + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + $wpakBinDirectory = $this->getContainer()->getParameter('dir_bin'); + + self::runSystemProcess($output, 'SourceCronCommand.php\updateCron() - ', "python " . $wpakBinDirectory . "wpak-cronupdatefile.py -g " . $wpakConfigDirectory . "config-general.cfg"); + } + + function runSystemProcess(OutputInterface $output, $message, $command) { + self::log($output, 'info', $message . 'Running command: ' . $command); + $createConfiguration = new Process($command); + $createConfiguration->run(); + $processOutputLines = explode("\n", $createConfiguration->getOutput()); + foreach($processOutputLines as $processLine) { + self::log($output, 'info', $message . 'Python Subprocess: ' . $processLine); + return true; + } + if (!$createConfiguration->isSuccessful()) { + self::log($output, 'error', $message . 'Unable to perform action'); + return false; + } + } + +} + diff --git a/Symfony/3.0/src/AppBundle/Command/SourceDeleteCommand.php b/Symfony/3.0/src/AppBundle/Command/SourceDeleteCommand.php new file mode 100644 index 0000000..108f795 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/SourceDeleteCommand.php @@ -0,0 +1,125 @@ +setName('wpak:sourcedelete') + ->setDescription('Take an ID and delete a source with that ID') + ->addOption('sourceid', null, InputOption::VALUE_REQUIRED, 'Source ID to be delete on the system'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| DELETE SOURCE |'); + self::log($output, 'info', '--------------------------------------------------------'); + + $fs = new Filesystem(); + + $sourceId = $input->getOption('sourceid'); + $resourcesDirectory = $this->getContainer()->getParameter('dir_resources'); + $targetDirectory = $resourcesDirectory . 'deleted/' . date('YmdHis') . '-source' . $sourceId . '/'; + + self::log($output, 'info', 'Processing source ID: ' . $sourceId); + + if (!$fs->exists($resourcesDirectory . 'deleted/')) {$fs->mkdir($resourcesDirectory . 'deleted/', 0700 );} + $fs->mkdir($targetDirectory, 0700 ); + $fs->mkdir($targetDirectory . 'etc', 0700 ); + $fs->mkdir($targetDirectory . 'logs', 0700 ); + + self::moveSourceContent($output, $sourceId, $targetDirectory); + self::moveSourceConfiguration($output, $sourceId, $targetDirectory); + + // Update Crontab + self::updateCron($output); + + return 0; + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + function moveSourceContent(OutputInterface $output, $sourceId, $targetDirectory) { + self::log($output, 'info', 'SourceDeleteCommand.php\moveSourceContent() - Move source directory to backup location'); + $sourcesDirectory = $this->getContainer()->getParameter('dir_sources'); + + self::moveFile($output, $sourcesDirectory . 'source' . $sourceId, $targetDirectory . 'contents'); + } + + function moveSourceConfiguration(OutputInterface $output, $sourceId, $targetDirectory) { + self::log($output, 'info', 'SourceDeleteCommand.php\moveSourceConfiguration() - Move source configuration to backup location'); + $etcDirectory = $this->getContainer()->getParameter('dir_etc'); + + self::moveFile($output, $etcDirectory . 'config-source' . $sourceId . '.cfg', $targetDirectory . 'etc/' . 'config-source' . $sourceId . '.cfg'); + //self::moveFile($output, $etcDirectory . 'config-source' . $sourceId . '.yml', $targetDirectory . 'etc/' . 'config-source' . $sourceId . '.yml'); + self::moveFile($output, $etcDirectory . 'config-source' . $sourceId . '-video.cfg', $targetDirectory . 'etc/' . 'config-source' . $sourceId . '-video.cfg'); + self::moveFile($output, $etcDirectory . 'config-source' . $sourceId . '-videocustom.cfg', $targetDirectory . 'etc/' . 'config-source' . $sourceId . '-videocustom.cfg'); + self::moveFile($output, $etcDirectory . 'config-source' . $sourceId . '-videopost.cfg', $targetDirectory . 'etc/' . 'config-source' . $sourceId . '-videopost.cfg'); + self::moveFile($output, $etcDirectory . 'config-source' . $sourceId . '-ftpservers.cfg', $targetDirectory . 'etc/' . 'config-source' . $sourceId . '-ftpservers.cfg'); + } + + function moveSourceLogs(OutputInterface $output, $sourceId, $targetDirectory) { + self::log($output, 'info', 'SourceDeleteCommand.php\moveSourceConfiguration() - Move source logs to backup location'); + + } + + function moveFile($output, $sourceFile, $destinationFile) { + $fs = new Filesystem(); + if ($fs->exists($sourceFile)) { + $fs->rename($sourceFile, $destinationFile); + self::log($output, 'info', 'SourceDeleteCommand.php\moveSourceConfiguration() - File/Directory moved from ' . $sourceFile . ' to ' . $destinationFile); + } else { + self::log($output, 'info', 'SourceDeleteCommand.php\moveSourceConfiguration() - File/Directory: ' . $sourceFile . ' does not exist, nothing to move'); + } + } + + function updateCron(OutputInterface $output) { + self::log($output, 'info', 'SourceCronCommand.php\updateCron() - Update crontab for all sources'); + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + $wpakBinDirectory = $this->getContainer()->getParameter('dir_bin'); + + self::runSystemProcess($output, 'SourceCreateCommand.php\updateCron() - ', "python " . $wpakBinDirectory . "wpak-cronupdatefile.py -g " . $wpakConfigDirectory . "config-general.cfg"); + } + + function runSystemProcess(OutputInterface $output, $message, $command) { + self::log($output, 'info', $message . 'Running command: ' . $command); + $createConfiguration = new Process($command); + $createConfiguration->run(); + $processOutputLines = explode("\n", $createConfiguration->getOutput()); + foreach($processOutputLines as $processLine) { + self::log($output, 'info', $message . 'Python Subprocess: ' . $processLine); + return true; + } + if (!$createConfiguration->isSuccessful()) { + self::log($output, 'error', $message . 'Unable to perform action'); + return false; + } + } +} + diff --git a/Symfony/3.0/src/AppBundle/Command/SourceFTPCommand.php b/Symfony/3.0/src/AppBundle/Command/SourceFTPCommand.php new file mode 100644 index 0000000..c1fbc68 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/SourceFTPCommand.php @@ -0,0 +1,71 @@ +setName('wpak:sourceftp') + ->setDescription('Update ftp after source modification'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| UPDATE SOURCE FTP |'); + self::log($output, 'info', '--------------------------------------------------------'); + + self::updateFTP($output); + + return 0; + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + function updateFTP(OutputInterface $output) { + self::log($output, 'info', 'SourceFTPCommand.php\updateFTP() - Update ftp for all sources'); + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + $wpakBinDirectory = $this->getContainer()->getParameter('dir_bin'); + + self::runSystemProcess($output, 'SourceFTPCommand.php\updateFTP() - ', "sudo python " . $wpakBinDirectory . "wpak-createlocalftpaccounts.py -g " . $wpakConfigDirectory . "config-general.cfg"); + } + + function runSystemProcess(OutputInterface $output, $message, $command) { + self::log($output, 'info', $message . 'Running command: ' . $command); + $createConfiguration = new Process($command); + $createConfiguration->run(); + $processOutputLines = explode("\n", $createConfiguration->getOutput()); + foreach($processOutputLines as $processLine) { + self::log($output, 'info', $message . 'Python Subprocess: ' . $processLine); + return true; + } + if (!$createConfiguration->isSuccessful()) { + self::log($output, 'error', $message . 'Unable to perform action'); + return false; + } + } + +} + diff --git a/Symfony/3.0/src/AppBundle/Command/SourceMoveCommand.php b/Symfony/3.0/src/AppBundle/Command/SourceMoveCommand.php new file mode 100644 index 0000000..be9d6fd --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Command/SourceMoveCommand.php @@ -0,0 +1,171 @@ +setName('wpak:sourcemove') + ->setDescription('Take an ID and delete a source with that ID') + ->addOption('srcid', null, InputOption::VALUE_REQUIRED, 'Source Source ID to be copied from') + ->addOption('dstid', null, InputOption::VALUE_REQUIRED, 'Destination Source ID to be moved to'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + self::log($output, 'info', '--------------------------------------------------------'); + self::log($output, 'info', '| MOVE SOURCCE |'); + self::log($output, 'info', '--------------------------------------------------------'); + + $srcId = $input->getOption('srcid'); + $dstId = $input->getOption('dstid'); + + self::log($output, 'info', 'Moving content from source ID: ' . $srcId . ' to source ID: ' . $dstId); + if (self::checkSourceExists($output, $dstId) === false) { + self::moveSourceContent($output, $srcId, $dstId); + self::moveSourceConfiguration($output, $srcId, $dstId); + return 0; // Return success + } else { + return 1; // Return failure + } + } + + function log(OutputInterface $output, $level, $message) { + $output->writeln('<' . $level . '>' . date('m/d/Y h:i:s a', time()) . ' | ' . $message . ''); + } + + function moveSourceContent(OutputInterface $output, $srcId, $dstId) { + self::log($output, 'info', 'SourceMoveCommand.php\moveSourceContent() - Move source directory to backup location'); + $sourcesDirectory = $this->getContainer()->getParameter('dir_sources'); + + self::moveFile($output, $sourcesDirectory . 'source' . $srcId, $sourcesDirectory . 'source' . $dstId); + } + + function moveSourceConfiguration(OutputInterface $output, $srcId, $dstId) { + self::log($output, 'info', 'SourceMoveCommand.php\moveSourceConfiguration() - Move source configuration to backup location'); + $etcDirectory = $this->getContainer()->getParameter('dir_etc'); + + self::moveFile($output, $etcDirectory . 'config-source' . $srcId . '.cfg', $etcDirectory . 'config-source' . $dstId . '.cfg'); + self::moveFile($output, $etcDirectory . 'config-source' . $srcId . '-video.cfg', $etcDirectory . 'config-source' . $dstId . '-video.cfg'); + self::moveFile($output, $etcDirectory . 'config-source' . $srcId . '-videocustom.cfg', $etcDirectory . 'config-source' . $dstId . '-videocustom.cfg'); + self::moveFile($output, $etcDirectory . 'config-source' . $srcId . '-videopost.cfg', $etcDirectory . 'config-source' . $dstId . '-videopost.cfg'); + self::moveFile($output, $etcDirectory . 'config-source' . $srcId . '-ftpservers.cfg', $etcDirectory . 'config-source' . $dstId . '-ftpservers.cfg'); + } + + function moveSourceLogs(OutputInterface $output, $sourceId) { + self::log($output, 'info', 'SourceMoveCommand.php\moveSourceConfiguration() - Move source logs to backup location'); + + } + + function moveFile($output, $sourceFile, $destinationFile) { + $fs = new Filesystem(); + if ($fs->exists($sourceFile)) { + $fs->rename($sourceFile, $destinationFile); + self::log($output, 'info', 'SourceMoveCommand.php\moveSourceConfiguration() - File/Directory moved from ' . $sourceFile . ' to ' . $destinationFile); + } else { + self::log($output, 'info', 'SourceMoveCommand.php\moveSourceConfiguration() - File/Directory: ' . $sourceFile . ' does not exist, nothing to move'); + } + } + + function checkSourceExists(OutputInterface $output, $sourceId) { + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Checking if source already exists'); + + $wpakConfigDirectory = $this->getContainer()->getParameter('dir_etc'); + $sourcesDirectory = $this->getContainer()->getParameter('dir_sources'); + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Configuration Directory: ' . $wpakConfigDirectory); + + $fs = new Filesystem(); + // Test if source configuration file exists + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '.cfg')) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '-video.cfg')) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '-video.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '-videocustom.cfg')) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '-videocustom.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '-videopost.cfg')) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '-videocustom.cfg' . ' already exists. Exiting ...'); + return true; + } + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '-ftpservers.cfg')) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '-videocustom.cfg' . ' already exists. Exiting ...'); + return true; + } + + if ($fs->exists($wpakConfigDirectory . 'config-source' . $sourceId . '.cfg')) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - Config file: ' . 'config-source' . $sourceId . '.cfg' . ' already exists. Exiting ...'); + return true; + } + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - No previous configuration files found'); + + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Source Directory: ' . $sourcesDirectory . 'source' . $sourceId . '/'); + if ($fs->exists($sourcesDirectory . 'source' . $sourceId . '/')) { + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Directory exists'); + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Searching for .jpg'); + + $finder = new Finder(); + $finder->in($sourcesDirectory . 'source' . $sourceId . '/'); + $finder->in($sourcesDirectory . 'source' . $sourceId . '/')->exclude('tmp'); + + $finder->name('*.jpg'); + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Number of jpg files found: ' . iterator_count($finder) / 2); + if (iterator_count($finder) > 0) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - There are jpg files in the sources directory, exiting'); + return true; + } + + $finder->name('*.raw'); + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Number of raw files found: ' . iterator_count($finder) / 2); + if (iterator_count($finder) > 0) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - There are raw files in the sources directory, exiting'); + return true; + } + + $finder->name('*.avi'); + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Number of avi files found: ' . iterator_count($finder) / 2); + if (iterator_count($finder) > 0) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - There are avi files in the sources directory, exiting'); + return true; + } + + $finder->name('*.mp4'); + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - Number of mp4 files found: ' . iterator_count($finder) / 2); + if (iterator_count($finder) > 0) { + self::log($output, 'error', 'SourceMoveCommand.php\checkSourceExists() - There are mp4 files in the sources directory, exiting'); + return true; + } + } + self::log($output, 'info', 'SourceMoveCommand.php\checkSourceExists() - No previous content (jpg, raw, avi, mp4) found'); + return false; + } + +} + diff --git a/Symfony/3.0/src/AppBundle/Controller/ApiMethods/DesktopController.php b/Symfony/3.0/src/AppBundle/Controller/ApiMethods/DesktopController.php new file mode 100644 index 0000000..a3a9957 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/ApiMethods/DesktopController.php @@ -0,0 +1,74 @@ +get('logger'); + $logger->info('AppBundle\Controller\ApiMethods\DesktopController.php\indexAction() - Start'); + + $extMethodsConfig = $this->container->getParameter('extMethodsConfig'); + $actions = array(); + foreach ($extMethodsConfig as $aname => &$a) { + $methods = array(); + foreach ($a['methods'] as $mname => &$m) { + if (isset($m['len'])) { + $md = array( + 'name' => $mname, + 'len' => $m['len'] + ); + } else { + $md = array( + 'name' => $mname, + 'params' => $m['params'] + ); + } + if (isset($m['formHandler']) && $m['formHandler']) { + $md['formHandler'] = true; + } + $methods[] = $md; + } + $actions[$aname] = $methods; + } + $logger->info('AppBundle\Controller\ApiMethods\DesktopController.php\indexAction() - Processing Completed, displaying results'); + + //Build Symfony Response + $responseVar = 'console.log("Log: Load: Symfony: Getting a list of all API methods available");'; + $responseVar .= 'var Ext_app_REMOTING_API = '; + $cfg = array( + 'url' => 'router/desktop', + 'type' => 'remoting', + 'actions' => $actions + ); + $responseVar .= json_encode($cfg); + $responseVar .= ';'; + $responseVar .= 'console.log(Ext_app_REMOTING_API);'; + $responseVar .= 'console.log("Log: Load: Symfony: Call to api.php completed");'; + + $response = new Response($responseVar); + $response->headers->set('Content-Type', 'application/javascript'); + + return $response; + } +} + + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Authentication/ChangepasswordController.php b/Symfony/3.0/src/AppBundle/Controller/Authentication/ChangepasswordController.php new file mode 100644 index 0000000..bbf054d --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Authentication/ChangepasswordController.php @@ -0,0 +1,49 @@ +request->get('OLDPASSWORD') != "" && strlen($request->request->get('NEWPASSWORD')) >= 4) { + $userEntity = $this->container->get('security.token_storage')->getToken()->getUser(); + if ($userEntity) { + $encoder = $this->get('security.encoder_factory')->getEncoder($userEntity); + $oldpasswordEncoded = $encoder->encodePassword($request->request->get('OLDPASSWORD'), $userEntity->getSalt()); + + if ($oldpasswordEncoded == $userEntity->getPassword()) { + $newpasswordEncoded = $encoder->encodePassword($request->request->get('NEWPASSWORD'), $userEntity->getSalt()); + + $userEntity->setPassword($newpasswordEncoded); + $userEntity->setChangePwdFlag('N'); + + $em = $this->getDoctrine()->getManager(); + $em->persist($userEntity); + $em->flush(); + return new JsonResponse(array("success" => true, "message" => "Password modified", "status" => "SUCCESS")); + } else { + return new JsonResponse(array("success" => true, "message" => "Error, old password is incorrect. Please try again.", "status" => "FAILED")); + } + } + } + return new JsonResponse(array("success" => true, "message" => "Error, unable to find password. Please try again.", "status" => "FAILED")); + } + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Authentication/DesktopStatefulConfigurationController.php b/Symfony/3.0/src/AppBundle/Controller/Authentication/DesktopStatefulConfigurationController.php new file mode 100644 index 0000000..0e75de9 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Authentication/DesktopStatefulConfigurationController.php @@ -0,0 +1,80 @@ +get('logger'); + $logger->info('AppBundle\Controller\Authentication\DesktopStatefulConfigurationController.php\getStatefulConfiguration() - Start'); + + $userEntity = $this->container->get('security.token_storage')->getToken()->getUser(); + $results = array('results' => array(), 'total' => 0); + if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + $receivedSenchaApp = 'WPAKD'; + if (isset($inputParams['SENCHA_APP'])) {$receivedSenchaApp = $inputParams['SENCHA_APP'];} + $query = " + SELECT USEPRE.USEPRE_ID, USEPRE.WIDGET, USEPRE.STATEFULCONFIG + FROM USERS_PREFERENCES USEPRE + WHERE USEPRE.USE_ID = :useid AND SENCHA_APP = :senchaApp + "; + $dbresults = $this->getDoctrine()->getManager()->getConnection()->fetchAll($query, array(':useid' => $userEntity->getUseId(), 'senchaApp' => $receivedSenchaApp)); + $results = array('results' => $dbresults, 'total' => count($dbresults)); + } + return new JsonResponse($results); + } + + public function addUpdateStatefulConfigurationAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Authentication\DesktopStatefulConfigurationController.php\addStatefulConfiguration() - Start'); + + //Feature disabled, necessary to look at previous version of the file to get some code sample + + $dbresults = array(); + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + } + + public function removeStatefulConfigurationAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Authentication\DesktopStatefulConfigurationController.php\removeStatefulConfiguration() - Start'); + + $receivedUsepreId = $inputParams['USEPRE_ID']; + + if (intval($receivedUsepreId) > 0) { + $usersPreferencesEntity = $this->getDoctrine() + ->getRepository('AppBundle:UsersPreferences') + ->find($receivedUsepreId); + if ($usersPreferencesEntity) { + $em = $this->getDoctrine()->getManager(); + $em->remove($usersPreferencesEntity); + $em->flush(); + } + } + $dbresults = array(); + + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + } + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Authentication/LoginController.php b/Symfony/3.0/src/AppBundle/Controller/Authentication/LoginController.php new file mode 100644 index 0000000..76536cf --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Authentication/LoginController.php @@ -0,0 +1,107 @@ +get('logger'); + $logger->info('AppBundle\Controller\LoginController.php\indexAction() - Start'); + + $receivedUsername = $request->request->get('USERNAME'); + $receivedPassword = $request->request->get('PASSWORD'); + $receivedRememberMe = $request->request->get('REMEMBERME'); + $logger->info('AppBundle\Controller\LoginController.php\indexAction() - USERNAME:' . $receivedUsername); + $logger->info('AppBundle\Controller\LoginController.php\indexAction() - REMEMBERME:' . $receivedRememberMe); + + if ($receivedUsername != '' && $receivedPassword != '') { + //Look for user entity based on username + $user = $this->getDoctrine() + ->getRepository('AppBundle:Users') + ->findOneByUsername($receivedUsername); + if ($user) { + //We generate an encoded password based upon received password + $encoder = $this->get('security.encoder_factory')->getEncoder($user); + $encodedPassword = $encoder->encodePassword($receivedPassword, $user->getSalt()); + $logger->info('AppBundle\Controller\LoginController.php\indexAction() - User Encoded Password: ' . $user->getPassword()); + $logger->info('AppBundle\Controller\LoginController.php\indexAction() - User Received encoded Password: ' . $encodedPassword); + if ($encodedPassword == $user->getPassword()) { + // Create Auth Token + $results = array("success" => true, "message" => "Authentication successful", "authentication" => "SUCCESS", "USERNAME" => $receivedUsername); + $return = new JsonResponse($results); + + // Here, "public" is the name of the firewall in your security.yml + $logger->info('AppBundle\Controller\LoginController.php\indexAction() - Creating security token'); + $token = new UsernamePasswordToken($user, null, "secured_area", $user->getRoles()); + $this->get("security.token_storage")->setToken($token); + + // Fire the login event + // Logging the user in above the way we do it doesn't fire the login event automatically + $logger->info('AppBundle\Controller\LoginController.php\indexAction() - Authenticating user'); + $event = new InteractiveLoginEvent($request, $token); + $this->get("event_dispatcher")->dispatch("security.interactive_login", $event); + + // Remember me + if ($receivedRememberMe == 'Y') { + // write cookie for persistent session storing + $providerKey = 'secured_area'; // defined in security.yml + $securityKey = $this->container->getParameter('secret'); // defined in security.yml + $logger->info('AppBundle\Controller\LoginController.php\indexAction() - Systems secret: ' . $securityKey); + + $userProvider = new EntityUserProvider($this->getDoctrine(), 'AppBundle:Users', $receivedUsername); + + $rememberMeService = new TokenBasedRememberMeServices(array($userProvider), $securityKey, $providerKey, array( + 'path' => '/', + 'name' => 'MyRememberMeCookie', + 'domain' => null, + 'secure' => false, + 'httponly' => true, + 'lifetime' => 1209600, // 14 days + 'always_remember_me' => true, + 'remember_me_parameter' => '_remember_me') + ); + $rememberMeService->loginSuccess($request, $return, $token); + } + } else { + $results = array("success" => true, "message" => "Unable to log-in (username and/or password incorrect)", "authentication" => "FAILED"); + } + } else { + $results = array("success" => true, "message" => "Unable to log-in (username and/or password incorrect)", "authentication" => "FAILED"); + } + } else { + $results = array("success" => true, "message" => "Empty username or empty password provided", "authentication" => "FAILED"); + } + if (!isset($return)) { + $return = new JsonResponse($results); + } + return $return; + } +} + + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Authentication/ReAuthenticateController.php b/Symfony/3.0/src/AppBundle/Controller/Authentication/ReAuthenticateController.php new file mode 100644 index 0000000..ba39796 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Authentication/ReAuthenticateController.php @@ -0,0 +1,118 @@ +get('logger'); + $logger->info('AppBundle\Controller\ReAuthenticateController.php\indexAction() - Start'); + + $receivedAuthToken = $request->request->get('AUTH_TOKEN'); + $receivedUsername = $request->request->get('USERNAME'); + $logger->info('AppBundle\Controller\ReAuthenticateController.php\indexAction() - USERNAME:' . $receivedUsername); + $logger->info('AppBundle\Controller\ReAuthenticateController.php\indexAction() - AUTH_TOKEN:' . $receivedAuthToken); + + if ($receivedUsername != '' && $receivedAuthToken != '') { + // Look for Use_id based on username and auth token + $identifiedUseId = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchColumn("SELECT USE_ID FROM USERS WHERE USERNAME = :username AND AUTH_TOKEN = :authToken AND AUTH_TOKEN_EXPIRY > date('now')" + , array('username' => $receivedUsername, 'authToken' => $receivedAuthToken), 0); + $logger->info('AppBundle\Controller\ReAuthenticateController.php\indexAction() - Identified USE_ID: ' . $identifiedUseId); + if (intval($identifiedUseId) > 0) { + //Look for user entity based on PK (use_id) + $user = $this->getDoctrine() + ->getRepository('AppBundle:Users') + ->find($identifiedUseId); + if ($user) { + // Create Auth Token + $authToken = sha1($receivedUsername . time() . rand(1,999999999)); + $results = array("success" => true, "message" => "Authentication successful", "authentication" => "SUCCESS", "AUTH_TOKEN" => $authToken, "USERNAME" => $receivedUsername); + $return = new JsonResponse($results); + + // Here, "public" is the name of the firewall in your security.yml + $logger->info('AppBundle\Controller\ReAuthenticateController.php\indexAction() - Creating security token'); + $token = new UsernamePasswordToken($user, null, "secured_area", $user->getRoles()); + $this->get("security.token_storage")->setToken($token); + + // Fire the login event + // Logging the user in above the way we do it doesn't fire the login event automatically + $logger->info('AppBundle\Controller\ReAuthenticateController.php\indexAction() - Authenticating user'); + $event = new InteractiveLoginEvent($this->get("request"), $token); + $this->get("event_dispatcher")->dispatch("security.interactive_login", $event); + + // We automatically re-set cookies and write cookie for persistent session storing + $providerKey = 'secured_area'; // defined in security.yml + $securityKey = $this->container->getParameter('secret'); // defined in security.yml + $logger->info('AppBundle\Controller\ReAuthenticateController.php\indexAction() - Systems secret: ' . $securityKey); + + $userProvider = new EntityUserProvider($this->getDoctrine(), 'AppBundle:Users', $receivedUsername); + + $rememberMeService = new TokenBasedRememberMeServices(array($userProvider), $securityKey, $providerKey, array( + 'path' => '/', + 'name' => 'MyRememberMeCookie', + 'domain' => null, + 'secure' => false, + 'httponly' => true, + 'lifetime' => 1209600, // 14 days + 'always_remember_me' => true, + 'remember_me_parameter' => '_remember_me') + ); + $rememberMeService->loginSuccess($request, $return, $token); + + + $logger->info('AppBundle\Controller\ReAuthenticateController.php\indexAction() - Saving Auth Token'); + $userEntity = $this->getDoctrine()->getRepository('AppBundle:Users')->find($user->getUseId()); + $authTokenExpiry = new \DateTime("now"); + $authTokenExpiry->add(new \DateInterval('PT2H')); + $userEntity->setAuthTokenExpiry($authTokenExpiry); + $userEntity->setAuthToken($authToken); + + $em = $this->getDoctrine()->getManager(); + $em->persist($userEntity); + $em->flush(); + } else { + $results = array("success" => true, "message" => "This user does not exist", "authentication" => "FAILED"); + } + } else { + $results = array("success" => true, "message" => "No Credentials provided", "authentication" => "FAILED"); + } + } else { + $results = array("success" => true, "message" => "No Credentials provided", "authentication" => "FAILED"); + } + if (!isset($return)) { + $return = new JsonResponse($results); + } + return $return; + } +} + + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Authentication/ResetpasswordController.php b/Symfony/3.0/src/AppBundle/Controller/Authentication/ResetpasswordController.php new file mode 100644 index 0000000..4656904 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Authentication/ResetpasswordController.php @@ -0,0 +1,107 @@ +get('logger'); + $logger->info('ResetpasswordController - indexAction()'); + + $username = $request->request->get('username', 'ERR-DOESNOTEXIST'); + $email = $request->request->get('email', 'ERR-DOESNOTEXIST'); + + if ($username != 'ERR-DOESNOTEXIST' && $email != 'ERR-DOESNOTEXIST') { + $logger->info('ResetpasswordController - indexAction(): (POST) Username:' . $username . ' - Email: ' . $email); + $user = $this->getDoctrine() + ->getRepository('AppBundle:Users') + ->findOneByUsername($username); + if (!$user) { + $logger->info('ResetpasswordController - indexAction(): ERROR: Could not find a user with the following username: ' . $username); + $results = array("success" => true, "message" => "User doest not exist", "authentication" => "FAILED"); + return new JsonResponse($results); + } else { + $logger->info('ResetpasswordController - indexAction(): User found with username: ' . $username); + $logger->info('ResetpasswordController - indexAction(): Email is: ' . $user->getEmail()); + if ($user->getEmail() != $email) { + $logger->info('ResetpasswordController - indexAction(): ERROR: User email is incorrect' . $username . ' correct email is: ' . $user->getEmail()); + $results = array("success" => true, "message" => "User email is incorrect", "authentication" => "FAILED"); + return new JsonResponse($results); + } else { + //Generate random password + $logger->info('ResetpasswordController - indexAction(): User found in database'); + + //We generate clear-text new password + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $newPassword = ''; + for ($i = 0; $i < 10; $i++) { + $newPassword .= $characters[rand(0, strlen($characters) - 1)]; + } + + //We create a writeable user object + $userEntity = $this->getDoctrine()->getRepository('AppBundle:Users')->find($user->getUseId()); + if (strlen($user->getSalt()) < 10) { + $logger->info('ResetpasswordController - indexAction(): Initial salt: ' . $user->getSalt()); + $userEntity->setSalt(sha1($user->getEmail() . microtime())); + $logger->info('ResetpasswordController - indexAction(): New salt: ' . $userEntity->getSalt()); + } + + //We generate a new encoded password + $encoder = $this->get('security.encoder_factory')->getEncoder($user); + $newPasswordEncoded = $encoder->encodePassword($newPassword, $userEntity->getSalt()); + + $logger->info('ResetpasswordController - indexAction(): New clear-text password has been generated: ' . $newPassword); + $logger->info('ResetpasswordController - indexAction(): Old encoded password was: ' . $user->getPassword()); + $logger->info('ResetpasswordController - indexAction(): New encoded password is: ' . $newPasswordEncoded); + + $userEntity->setPassword($newPasswordEncoded); + $userEntity->setChangePwdFlag('Y'); + $this->getDoctrine()->getManager()->persist($userEntity); + $this->getDoctrine()->getManager()->flush(); + $logger->info('ResetpasswordController - indexAction(): New password updated in database'); + + $logger->info('ResetpasswordController - indexAction(): Password reset request coming from: ' . $request->getClientIp()); + + //We send an email with all details + $message = \Swift_Message::newInstance() + ->setSubject('New password to access your Webcampak') + ->setFrom('support@webcampak.com') + ->setTo($email) + ->setBody( + $this->renderView( + 'AppBundle:Emails:resetpassword.html.twig', array('username' => $username + , 'newPassword' => $newPassword + , 'currentIP' => $request->getClientIp() + ) + ) + , 'text/html') + ; + $this->get('mailer')->send($message); + $logger->info('ResetpasswordController - indexAction(): Email with credentials sent'); + } + } + } + $results = array("success" => true, "message" => "Password reset successful", "authentication" => "SUCCESS"); + return new JsonResponse($results); + } + +} diff --git a/Symfony/3.0/src/AppBundle/Controller/Authentication/UserSettingsController.php b/Symfony/3.0/src/AppBundle/Controller/Authentication/UserSettingsController.php new file mode 100644 index 0000000..0fcc02a --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Authentication/UserSettingsController.php @@ -0,0 +1,44 @@ +get('logger'); + $logger->info('AppBundle\Controller\Authentication\UserSettings.php\getSettingsAction() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $authorizationChecker = $this->container->get('security.authorization_checker'); + + $userEntity = $tokenStorage->getToken()->getUser(); + + $dbresults = array(); + if ($authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) { + $dbresults = $this->get('app.svc.user')->getSettings($userEntity); + } + + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + +} diff --git a/Symfony/3.0/src/AppBundle/Controller/DefaultController.php b/Symfony/3.0/src/AppBundle/Controller/DefaultController.php new file mode 100644 index 0000000..bcf8ed3 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/DefaultController.php @@ -0,0 +1,32 @@ +render('default/index.html.twig'); + } +} diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACCustomersController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACCustomersController.php new file mode 100644 index 0000000..3e672c1 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACCustomersController.php @@ -0,0 +1,125 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACCustomersController.php\getCustomersAction() - Start'); + + $query = " + SELECT + CUS_ID + , NAME + FROM + CUSTOMERS + ORDER BY NAME + "; + + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($query); + + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + } + + public function addCustomerAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACCustomersController.php\addCustomerAction() - Start'); + + $receivedName = $inputParams['NAME']; + + $searchCustomername = $this->getDoctrine() + ->getRepository('AppBundle:Customers') + ->findOneByName($receivedName); + if ($searchCustomername) { + $logger->info('AppBundle\Controller\Desktop\ACCustomersController.php\addCustomerAction() - Error: Customer already exists in database'); + throw new \Exception("Error, Customer already exists in database"); + } else { + $newCustomerEntity = new Customers(); + $newCustomerEntity->setName($receivedName); + + $em = $this->getDoctrine()->getManager(); + $em->persist($newCustomerEntity); + $em->flush(); + + $results = array("success" => true, "message" => "Customer added"); + } + + return new JsonResponse($results); + } + + public function updateCustomerAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACCustomersController.php\updateCustomerAction() - Start'); + + $receivedCusId = $inputParams['CUS_ID']; + $receivedName = $inputParams['NAME']; + + $updateCustomersEntity = $this->getDoctrine() + ->getRepository('AppBundle:Customers') + ->find($receivedCusId); + + if ($updateCustomersEntity) { + $updateCustomersEntity->setName($receivedName); + + $em = $this->getDoctrine()->getManager(); + $em->persist($updateCustomersEntity); + $em->flush(); + + $results = array("success" => true, "message" => "Customer updated"); + + } else { + $logger->info('AppBundle\Controller\Desktop\ACCustomersController.php\updateCustomerAction() - Error: Customer does not exist'); + throw new \Exception("Error, Customer does not exist"); + } + return new JsonResponse($results); + } + + public function removeCustomerAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACCustomersController.php\removeCustomerAction() - Start'); + + + $receivedCusId = $inputParams['CUS_ID']; + if (isset($receivedCusId) && intval($receivedCusId) > 0) { + $customersEntity = $this->getDoctrine() + ->getRepository('AppBundle:Customers') + ->find($receivedCusId); + + $em = $this->getDoctrine()->getManager(); + $em->remove($customersEntity); + $em->flush(); + $results = array("success" => true, "message" => "Customer deleted"); + } else { + throw new \Exception("No customer selected"); + } + return new JsonResponse($results); + } + + } + diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACGroupsController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACGroupsController.php new file mode 100644 index 0000000..d21811c --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACGroupsController.php @@ -0,0 +1,294 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\getGroupsAction() - Start'); + + $query = " + SELECT + GRO_ID + , NAME + , NOTES + FROM + GROUPS + ORDER BY NAME + "; + + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($query); + + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + } + + public function addGroupAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\addGroupAction() - Start'); + + $receivedName = $inputParams['NAME']; + $receivedNotes = $inputParams['NOTES']; + + $searchGroupname = $this->getDoctrine() + ->getRepository('AppBundle:Groups') + ->findOneByName($receivedName); + if ($searchGroupname) { + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\addGroupAction() - Error: Group already exists in database'); + throw new \Exception("Error, Group already exists in database"); + } else { + $newGroupEntity = new Groups(); + $newGroupEntity->setName($receivedName); + $newGroupEntity->setNotes($receivedNotes); + + $em = $this->getDoctrine()->getManager(); + $em->persist($newGroupEntity); + $em->flush(); + + $results = array("success" => true, "message" => "Group added"); + } + return new JsonResponse($results); + } + + public function updateGroupAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\updateGroupAction() - Start'); + + $groupEntity = $this->getDoctrine() + ->getRepository('AppBundle:Groups') + ->find($inputParams['GRO_ID']); + + $searchGroIdEntity = $this->getDoctrine() + ->getRepository('AppBundle:Groups') + ->findOneByName($inputParams['NAME']); + + if ($searchGroIdEntity & $groupEntity != $searchGroIdEntity) { + throw new \Exception("Error, Group already exists in database"); + } else if ($groupEntity) { + $groupEntity->setName($inputParams['NAME']); + $groupEntity->setNotes($inputParams['NOTES']); + + $em = $this->getDoctrine()->getManager(); + $em->persist($groupEntity); + $em->flush(); + return new JsonResponse(array("success" => true, "message" => "Group updated")); + } else { + throw new \Exception("Error, Group does not exist"); + } + } + + public function removeGroupAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\removeGroupAction() - Start'); + + $receivedGroId = $inputParams['GRO_ID']; + if (isset($receivedGroId) && intval($receivedGroId) > 0) { + $groupEntity = $this->getDoctrine() + ->getRepository('AppBundle:Groups') + ->find($receivedGroId); + + $em = $this->getDoctrine()->getManager(); + $em->remove($groupEntity); + $em->flush(); + $results = array("success" => true, "message" => "Group deleted"); + } else { + throw new \Exception("No group selected"); + } + return new JsonResponse($results); + } + + public function getGroupAvailableApplicationsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\getGroupAvailableApplicationsAction() - Start'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\getGroupAvailableApplicationsAction() - GRO_ID:' . $inputParams['GRO_ID']); + $dbresults = array(); + if (isset($inputParams['GRO_ID']) && intval($inputParams['GRO_ID']) > 0) { + $dbresults = $this->get('app.svc.groups')->getAvailableApplicationsByGroId($inputParams['GRO_ID']); + } + + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + public function getGroupCurrentApplicationsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\getGroupCurrentApplicationsAction() - Start'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\getGroupCurrentApplicationsAction() - GRO_ID:' . $inputParams['GRO_ID']); + $dbresults = array(); + if (isset($inputParams['GRO_ID']) && intval($inputParams['GRO_ID']) > 0) { + $dbresults = $this->get('app.svc.groups')->getCurrentApplicationsByGroId($inputParams['GRO_ID']); + } + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + public function removeGroupCurrentApplicationsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\removeGroupCurrentApplicationsAction() - Start'); + + $receivedGroAppId = $inputParams['GROAPP_ID']; + if (isset($receivedGroAppId) && intval($receivedGroAppId) > 0) { + $deleteGroupsApplicationsEntity = $this->getDoctrine() + ->getRepository('AppBundle:GroupsApplications') + ->find($receivedGroAppId); + if ($deleteGroupsApplicationsEntity) { + $em = $this->getDoctrine()->getManager(); + $em->remove($deleteGroupsApplicationsEntity); + $em->flush(); + $results = array("success" => true, "message" => "Application removed"); + + } + } + return new JsonResponse($results); + } + + + public function removeGroupAvailableApplicationsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\removeGroupAvailableApplicationsAction() - Start'); + + $receivedGroId = $inputParams['GRO_ID']; + $receivedAppId = $inputParams['APP_ID']; + + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\removeGroupAvailableApplicationsAction() - GRO_ID:' . $receivedGroId); + + if (isset($receivedGroId) && intval($receivedGroId) > 0) { + //Removal actually corresponds to adding a group to the other store + $newGroupsApplicationsEntity = new GroupsApplications(); + + $groupsEntity = $this->getDoctrine() + ->getRepository('AppBundle:Groups') + ->find($receivedGroId); + + $applicationsEntity = $this->getDoctrine() + ->getRepository('AppBundle:Applications') + ->find($receivedAppId); + + $newGroupsApplicationsEntity->setApp($applicationsEntity); + $newGroupsApplicationsEntity->setGro($groupsEntity); + + $em = $this->getDoctrine()->getManager(); + $em->persist($newGroupsApplicationsEntity); + $em->flush(); + + $results = array("success" => true, "message" => "Modification done"); + } else { + throw new \Exception("Error, Nothing selected"); + } + return new JsonResponse($results); + } + + public function getGroupAvailablePermissionsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\getGroupAvailablePermissionsAction() - GRO_ID:' . $inputParams['GRO_ID']); + $dbresults = array(); + if (isset($inputParams['GRO_ID']) && intval($inputParams['GRO_ID']) > 0) { + $dbresults = $this->get('app.svc.groups')->getAvailablePermissionsByGroId($inputParams['GRO_ID']); + } + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + public function removeGroupAvailablePermissionsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\removeGroupAvailablePermissionsAction() - Start'); + + $receivedGroId = $inputParams['GRO_ID']; + $receivedPerId = $inputParams['PER_ID']; + + if (isset($receivedGroId) && intval($receivedGroId) > 0) { + //Removal actually corresponds to adding a group to the other store + $newGroupsPermissionsEntity = new GroupsPermissions(); + + $groupsEntity = $this->getDoctrine() + ->getRepository('AppBundle:Groups') + ->find($receivedGroId); + + $permissionsEntity = $this->getDoctrine() + ->getRepository('AppBundle:Permissions') + ->find($receivedPerId); + + $newGroupsPermissionsEntity->setPer($permissionsEntity); + $newGroupsPermissionsEntity->setGro($groupsEntity); + + $em = $this->getDoctrine()->getManager(); + $em->persist($newGroupsPermissionsEntity); + $em->flush(); + + $results = array("success" => true, "message" => "Modification done"); + } else { + throw new \Exception("Error, Nothing selected"); + } + return new JsonResponse($results); + } + + public function getGroupCurrentPermissionsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\getGroupCurrentPermissionsAction() - Start'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\getGroupCurrentPermissionsAction() - GRO_ID:' . $inputParams['GRO_ID']); + + $dbresults = array(); + if (isset($inputParams['GRO_ID']) && intval($inputParams['GRO_ID']) > 0) { + $dbresults = $this->get('app.svc.groups')->getCurrentPermissionsByGroId($inputParams['GRO_ID']); + } + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + public function removeGroupCurrentPermissionsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACGroupsController.php\removeGroupCurrentPermissionsAction() - Start'); + + $receivedGroPerId = $inputParams['GROPER_ID']; + if (isset($receivedGroPerId) && intval($receivedGroPerId) > 0) { + $deleteGroupsPermissionsEntity = $this->getDoctrine() + ->getRepository('AppBundle:GroupsPermissions') + ->find($receivedGroPerId); + if ($deleteGroupsPermissionsEntity) { + $em = $this->getDoctrine()->getManager(); + $em->remove($deleteGroupsPermissionsEntity); + $em->flush(); + $results = array("success" => true, "message" => "Permission removed"); + + } + } + return new JsonResponse($results); + } + + } + diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACSourcesController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACSourcesController.php new file mode 100644 index 0000000..641b2fd --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACSourcesController.php @@ -0,0 +1,249 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\getSourcesAction() - Start'); + + $query = " + SELECT + SOU_ID + , NAME + , SOURCEID + , WEIGHT + , QUOTA + , REMOTE_HOST + , REMOTE_USERNAME + , REMOTE_PASSWORD + FROM + SOURCES + ORDER BY WEIGHT + "; + + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($query); + + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + public function addSourceAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\addSourceAction() - Start'); + + $receivedName = $inputParams['NAME']; + $receivedSourceId = $inputParams['SOURCEID']; + $receivedWeight = $inputParams['WEIGHT']; + $receivedQuota = $inputParams['QUOTA']; // We receive in GB, so multiply by 1000000000 + $receivedRemoteHost = $inputParams['REMOTE_HOST']; + $receivedRemoteUsername = $inputParams['REMOTE_USERNAME']; + $receivedRemotePassword = $inputParams['REMOTE_PASSWORD']; + + $searchSourceId = $this->getDoctrine() + ->getRepository('AppBundle:Sources') + ->findOneBySourceId($receivedSourceId); + + if (intval($receivedSourceId) <= 0) { + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\addSourceAction() - Error: Source ID must be positive'); + throw new \Exception("Error, Source ID must be greater than 0"); + } else if ($searchSourceId) { + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\addSourceAction() - Error: Source already exists in database'); + throw new \Exception("Error, Source already exists in database"); + } else { + $sourceCreateCommand = new SourceCreateCommand(); + $sourceCreateCommand->setContainer($this->container); + $input = new ArrayInput(array('--sourceid' => $receivedSourceId)); + $output = new BufferedOutput(); + $resultCode = $sourceCreateCommand->run($input, $output); + $commandOutput = explode("\n", $output->getBuffer()); + foreach($commandOutput as $commandOutputLine) { + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\addSourceAction() - Console Subprocess: ' . $commandOutputLine); + } + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\addSourceAction() - Command Result code: ' . $resultCode); + + + $newSourceEntity = new Sources(); + $newSourceEntity->setName($receivedName); + $newSourceEntity->setSourceId($receivedSourceId); + $newSourceEntity->setWeight($receivedWeight); + $newSourceEntity->setQuota($receivedQuota); + $newSourceEntity->setRemoteHost($receivedRemoteHost); + $newSourceEntity->setRemotePassword($receivedRemoteUsername); + $newSourceEntity->setRemoteUsername($receivedRemotePassword); + + $em = $this->getDoctrine()->getManager(); + $em->persist($newSourceEntity); + + $searchRootUserEntity = $this->getDoctrine() + ->getRepository('AppBundle:Users') + ->findOneByUsername('root'); + + $newUsersSourceEntity = new UsersSources(); + $newUsersSourceEntity->setSou($newSourceEntity); + $newUsersSourceEntity->setUse($searchRootUserEntity); + $newUsersSourceEntity->setAlertsFlag('N'); + + $em = $this->getDoctrine()->getManager(); + $em->persist($newUsersSourceEntity); + + $em->flush(); + + $query = "SELECT SOU_ID , NAME, SOURCEID, WEIGHT, QUOTA, REMOTE_HOST, REMOTE_USERNAME, REMOTE_PASSWORD + FROM SOURCES + WHERE SOU_ID = :souId + ORDER BY WEIGHT"; + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($query, array('souId' => $newSourceEntity->getSouId())); + + $results = array("success" => true, "message" => "Source added", "results" => $dbresults, "total" => count($dbresults)); + } + + return new JsonResponse($results); + } + + public function updateSourceAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\updateSourceAction() - Start'); + + $updateSourcesEntity = $this->getDoctrine() + ->getRepository('AppBundle:Sources') + ->find($inputParams['SOU_ID']); + + $searchSourceId = $this->getDoctrine() + ->getRepository('AppBundle:Sources') + ->findOneBySourceId($inputParams['SOURCEID']); + + if ($searchSourceId && $updateSourcesEntity != $searchSourceId) { + throw new \Exception("Error, Source already exists in database"); + } else if ($updateSourcesEntity) { + if ($updateSourcesEntity->getSourceId() != $inputParams['SOURCEID']) { + $this->get('app.svc.sources')->moveSource($updateSourcesEntity, $inputParams['SOU_ID'], $this->container); + } + $updateSourcesEntity->updateSourceEntity($inputParams); + $em = $this->getDoctrine()->getManager(); + $em->persist($updateSourcesEntity); + $em->flush(); + return new JsonResponse(array("success" => true, "message" => "Source updated")); + } else { + throw new \Exception("Error, Source does not exist"); + } + } + + public function removeSourceAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\removeSourceAction() - Start'); + + if (isset($inputParams['SOU_ID']) && intval($inputParams['SOU_ID']) > 0) { + $sourceEntity = $this->getDoctrine() + ->getRepository('AppBundle:Sources') + ->find($inputParams['SOU_ID']); + if ($sourceEntity) { + $results = $this->get('app.svc.sources')->removeSource($sourceEntity, $this->container); + } else { + throw new \Exception("Error, Unable to find source"); + } + } else { + throw new \Exception("Error, No source selected"); + } + return new JsonResponse($results); + } + + + public function getSourceAvailableUsersAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\getSourceAvailableUsersAction() - SOU_ID:' . $inputParams['SOU_ID']); + $dbresults = array(); + if (isset($inputParams['SOU_ID']) && intval($inputParams['SOU_ID']) > 0) { + $dbresults = $this->get('app.svc.sources')->getAvailableUsersBySouId($inputParams['SOU_ID']); + } + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + public function getSourceCurrentUsersAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\getSourceCurrentUsersAction() - SOU_ID:' . $inputParams['SOU_ID']); + $dbresults = array(); + if (isset($inputParams['SOU_ID']) && intval($inputParams['SOU_ID']) > 0) { + $dbresults = $this->get('app.svc.sources')->getCurrentUsersBySouId($inputParams['SOU_ID']); + } + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + + public function removeSourceAvailableUsersAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\removeSourceAvailableUsersAction() - Start'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\removeSourceAvailableUsersAction() - SOU_ID:' . $inputParams['SOU_ID']); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\removeSourceAvailableUsersAction() - USE_ID:' . $inputParams['USE_ID']); + + //Removal actually corresponds to adding a source to the other store + $results = $this->get('app.svc.sources')->addUserToSource($inputParams['SOU_ID'], $inputParams['USE_ID']); + return new JsonResponse($results); + } + + public function removeSourceCurrentUsersAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ACSourcesController.php\removeSourceCurrentUsersAction() - Start'); + + $receivedUseSouId = $inputParams['USESOU_ID']; + if (isset($receivedUseSouId) && intval($receivedUseSouId) > 0) { + $userSourcesEntity = $this->getDoctrine() + ->getRepository('AppBundle:UsersSources') + ->find($receivedUseSouId); + + if ($userSourcesEntity->getUse()->getUsername() == 'root') { + throw new \Exception("Error, User root cannot be removed from any sources"); + } else if ($userSourcesEntity) { + $em = $this->getDoctrine()->getManager(); + $em->remove($userSourcesEntity); + $em->flush(); + $results = array("success" => true, "message" => "User removed"); + } else { + throw new \Exception("Error, User root cannot be removed from any sources"); + } + } + return new JsonResponse($results); + } + + } + diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACUsersController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACUsersController.php new file mode 100644 index 0000000..b236ed8 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Accesscontrol/ACUsersController.php @@ -0,0 +1,245 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\Accesscontrol\ACUsersController.php\getUsersAction() - Start'); + + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll(" + SELECT + USE_ID + , CUS_ID + , GRO_ID + , USERNAME + , CHANGE_PWD_FLAG + , ACTIVE_FLAG + , FIRSTNAME + , LASTNAME + , EMAIL + , LANG + FROM USERS + ORDER BY USERNAME"); + + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + public function addUserAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\Accesscontrol\ACUsersController.php\addUserAction() - Start'); + + $searchUsername = $this->getDoctrine() + ->getRepository('AppBundle:Users') + ->findOneByUsername($inputParams['USERNAME']); + if ($searchUsername) { + throw new \Exception("Error, Username already exists in database"); + } else { + $connectedUserEntity = $this->container + ->get('security.token_storage') + ->getToken() + ->getUser(); + + $passwordSalt = sha1($inputParams['USERNAME'] . microtime()); + + $newPasswordEncoded = $this->get('security.encoder_factory') + ->getEncoder($connectedUserEntity) + ->encodePassword($inputParams['PASSWORD'], $passwordSalt); + + $inputParams['CUS'] = $this->getDoctrine() + ->getRepository('AppBundle:Customers') + ->find($inputParams['CUS_ID']); + + $inputParams['GRO'] = $this->getDoctrine() + ->getRepository('AppBundle:Groups') + ->find($inputParams['GRO_ID']); + + $newUsersEntity = new Users($inputParams['USERNAME'], $newPasswordEncoded, $passwordSalt, array()); + $newUsersEntity->updateUserEntity($inputParams); + + $em = $this->getDoctrine()->getManager(); + $em->persist($newUsersEntity); + $em->flush(); + + $results = array("success" => true, "message" => "User added"); + } + return new JsonResponse($results); + } + + public function updateUserAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\Accesscontrol\ACUsersController.php\updateUserAction() - Start'); + + $updateUsersEntity = $this->getDoctrine() + ->getRepository('AppBundle:Users') + ->find($inputParams['USE_ID']); + + if ($updateUsersEntity) { + $inputParams['CUS'] = $this->getDoctrine() + ->getRepository('AppBundle:Customers') + ->find($inputParams['CUS_ID']); + + $inputParams['GRO'] = $this->getDoctrine() + ->getRepository('AppBundle:Groups') + ->find($inputParams['GRO_ID']); + + if ($inputParams['PASSWORD'] != '') { + //Only update password if the we receive a non-empty one. + $connectedUserEntity = $this->container + ->get('security.token_storage') + ->getToken() + ->getUser(); + //Generate a new encoded password + $newPasswordEncoded = $this + ->get('security.encoder_factory') + ->getEncoder($connectedUserEntity) + ->encodePassword($inputParams['PASSWORD'], $updateUsersEntity->getSalt()); + $updateUsersEntity->setPassword($newPasswordEncoded); + } + $updateUsersEntity->updateUserEntity($inputParams); + $em = $this->getDoctrine()->getManager(); + $em->persist($updateUsersEntity); + $em->flush(); + $results = array("success" => true, "message" => "User updated"); + } else { + throw new \Exception("Error, User does not exist in database, update not possible"); + } + return new JsonResponse($results); + } + + public function removeUserAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\Accesscontrol\ACUsersController.php\removeUserAction() - Start'); + if (isset($inputParams['USE_ID']) && intval($inputParams['USE_ID']) > 0) { + $userEntity = $this->getDoctrine() + ->getRepository('AppBundle:Users') + ->find($inputParams['USE_ID']); + + if ($userEntity && $userEntity->getUsername() == "root") { + throw new \Exception("Error, User root cannot be deleted"); + } else if ($userEntity) { + $logger->info('AppBundle\Controller\Desktop\AdminUsersCustomersController.php\removeUserAction() - User will be deleted (USE_ID: ' . $userEntity->getUseId() . ' USERNAME:' . $userEntity->getUsername()); + $em = $this->getDoctrine()->getManager(); + $em->remove($userEntity); + $em->flush(); + return new JsonResponse(array("success" => true, "message" => "User deleted")); + } else { + throw new \Exception("Error, Unable to find user"); + } + } else { + throw new \Exception("No user selected"); + } + } + + + public function getUserAvailableSourcesAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\getUserAvailableSourcesAction() - USE_ID:' . $inputParams['USE_ID']); + $dbresults = array(); + if (isset($inputParams['USE_ID']) && intval($inputParams['USE_ID']) > 0) { + $dbresults = $this->get('app.svc.user')->getAvailableSourcesByUseId($inputParams['USE_ID']); + } + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + public function getUserCurrentSourcesAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\getUserCurrentSourcesAction() - USE_ID:' . $inputParams['USE_ID']); + $dbresults = array(); + if (isset($inputParams['USE_ID']) && intval($inputParams['USE_ID']) > 0) { + $dbresults = $this->get('app.svc.user')->getCurrentSourcesByUseId($inputParams['USE_ID']); + } + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => count($dbresults) + )); + } + + + public function removeUserAvailableSourcesAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\removeUserAvailableSourcesAction() - Start'); + + $receivedSouId = $inputParams['SOU_ID']; + $receivedUseId = $inputParams['USE_ID']; + + $logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\removeUserAvailableSourcesAction() - SOU_ID:' . $receivedSouId); + + //Removal actually corresponds to adding a source to the other store + $results = $this->get('app.svc.sources')->addUserToSource($receivedSouId, $receivedUseId); + return new JsonResponse($results); + } + + public function removeUserCurrentSourcesAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\removeUserCurrentSourcesAction() - Start'); + + $receivedUseSouId = $inputParams['USESOU_ID']; + if (isset($receivedUseSouId) && intval($receivedUseSouId) > 0) { + $userSourcesEntity = $this->getDoctrine() + ->getRepository('AppBundle:UsersSources') + ->find($receivedUseSouId); + + if ($userSourcesEntity->getUse()->getUsername() == 'root') { + throw new \Exception("User root cannot be removed any sources"); + } else if ($userSourcesEntity) { + $em = $this->getDoctrine()->getManager(); + $em->remove($userSourcesEntity); + $em->flush(); + $results = array("success" => true, "message" => "User removed"); + } else { + throw new \Exception("User root cannot be removed from sources"); + } + } + return new JsonResponse($results); + } + + public function updateUserCurrentSourcesAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\updateUserCurrentSourcesAction() - Start'); + + $receivedUsesouId = $inputParams['USESOU_ID']; + $receivedAlertsFlag = $inputParams['ALERTS_FLAG']; + $userSourcesEntity = $this->getDoctrine() + ->getRepository('AppBundle:UsersSources') + ->find($receivedUsesouId); + if ($userSourcesEntity) { + $userSourcesEntity->setAlertsFlag($receivedAlertsFlag); + $em = $this->getDoctrine()->getManager(); + $em->flush(); + } + $results = array("success" => true, "message" => "Alerts flag updated"); + return new JsonResponse($results); + } + + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/AdministrativeController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/AdministrativeController.php new file mode 100644 index 0000000..860f957 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/AdministrativeController.php @@ -0,0 +1,111 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\AdministrativeController.php\emptyAnswerAction() - Start'); + + $dbresults = array(); + + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + } + + public function getTimezonesAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AdministrativeController.php\getTimezonesAction() - Start'); + + $timezones = array(); + $zones = timezone_identifiers_list(); + sort($zones); + foreach ($zones as $zone) { + $tmptimezones = array(); + $tmptimezones['NAME'] = $zone; + array_push($timezones, $tmptimezones); + } + + $results = array(); + $results['results'] = $timezones; + $results['total'] = count($timezones); + return new JsonResponse($results); + } + + public function getUsbPortsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AdministrativeController.php\getUsbPortsAction() - Start'); + + $detectedCameras = $this->get('app.svc.devices')->getUsbPorts(); + $results = array(); + $results['results'] = $detectedCameras; + $results['total'] = count($detectedCameras); + return new JsonResponse($results); + } + + public function getCameraModelsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AdministrativeController.php\getCameraModelsAction() - Start'); + + $compactibleCameras = array(); + + $process = new Process('gphoto2 --list-cameras'); + $process->run(); + foreach (explode("\n", $process->getOutput()) as $gphotoOutput) { + if (strpos($gphotoOutput,'"') !== false) { + preg_match("/\".*?\"|\'.*?\'/", $gphotoOutput, $gphotoOutputCameraName); + $gphotoOutput = trim($gphotoOutput); + $gphotoOutput = str_replace('"', "", $gphotoOutput); + $gphotoOutputCameraName = str_replace('"', "", $gphotoOutputCameraName); + array_push($compactibleCameras, array( + 'ID' => trim($gphotoOutputCameraName[0]) + , 'NAME' => $gphotoOutput + )); + } + } + + $results = array(); + $results['results'] = $compactibleCameras; + $results['total'] = count($compactibleCameras); + return new JsonResponse($results); + } + + public function getPhidgetsPortsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\AdministrativeController.php\getPhidgetsPortsAction() - Start'); + + $configFile = $this->container->getParameter('dir_etc') . "config-general.cfg"; + $phidgetsensors = $this->get('app.svc.phidgets')->getPhidgetsPorts($configFile); + + return new JsonResponse(array( + 'results' => $phidgetsensors + , 'total' => count($phidgetsensors) + )); + } + + } + + + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/ApplicationsController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/ApplicationsController.php new file mode 100644 index 0000000..f4231bb --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/ApplicationsController.php @@ -0,0 +1,82 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\ApplicationsController.php\getApplicationsAction() - Start'); + + $sqlQuery = " + SELECT + APP.APP_ID APP_ID + , APP.CODE CODE + , APP.NAME NAME + FROM + APPLICATIONS APP + ORDER BY APP.NAME + "; + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery); + + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + } + + public function getCurrentApplicationsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\ApplicationsController.php\getCurrentApplicationsAction() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $userEntity = $tokenStorage->getToken()->getUser(); + + $dbresults = array(); + if (is_a($userEntity, 'AppBundle\Entities\Database\Users')) { + $sqlQuery = " + SELECT + APP.APP_ID APP_ID + , APP.NAME NAME + , APP.CODE CODE + FROM + GROUPS_APPLICATIONS GROAPP + LEFT JOIN APPLICATIONS APP ON APP.APP_ID = GROAPP.APP_ID + LEFT JOIN USERS USE ON USE.GRO_ID = GROAPP.GRO_ID + WHERE + USE.USE_ID = :useId + ORDER BY APP.NAME + "; + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('useId' => $userEntity->getUseId())); + } + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/DesktopEmailsController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/DesktopEmailsController.php new file mode 100644 index 0000000..ef966f0 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/DesktopEmailsController.php @@ -0,0 +1,60 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\DesktopEmailsController.php\getEmailsAction() - Start'); + + $dbresults = array(); + + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + + return new JsonResponse($results); + } + + public function sendEmailAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\DesktopEmailsController.php\sendEmailAction() - Start'); + + $sendEmail = $this->get('app.svc.emails')->prepareEmailForQueue($inputParams); + + return new JsonResponse($sendEmail); + } + + public function removeEmailAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\DesktopEmailsController.php\removeEmailAction() - Start'); + + //Necessary to implement function + + $results = array("success" => true, "message" => "Modification done"); + + return new JsonResponse($results); + } + + + } + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/DesktopIconsController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/DesktopIconsController.php new file mode 100644 index 0000000..d740e81 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/DesktopIconsController.php @@ -0,0 +1,182 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\DesktopIconsController.php\getDesktopAvailableIconsAction() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $authorizationChecker = $this->container->get('security.authorization_checker'); + $userEntity = $tokenStorage->getToken()->getUser(); + + $dbresults = array(); + if ($authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) { + $sqlQuery = " + SELECT + APP.APP_ID APP_ID + , APP.NAME NAME + , APP.CODE CODE + , APP.NOTES NOTES + FROM + GROUPS_APPLICATIONS GROAPP + LEFT JOIN APPLICATIONS APP ON APP.APP_ID = GROAPP.APP_ID + LEFT JOIN USERS USE ON USE.GRO_ID = GROAPP.GRO_ID + WHERE + USE.USE_ID = :useId + AND APP.APP_ID NOT IN (SELECT APP_ID FROM USERS_ICONS WHERE USE_ID = :useId AND ICON_VISIBLE_FLAG = 'Y') + ORDER BY APP.NAME + "; + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('useId' => $userEntity->getUseId())); + } + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + + } + + public function getDesktopCurrentIconsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\DesktopIconsController.php\getDesktopCurrentIconsAction() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $authorizationChecker = $this->container->get('security.authorization_checker'); + + $userEntity = $tokenStorage->getToken()->getUser(); + + $dbresults = array(); + if ($authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) { + $sqlQuery = " + SELECT + APP.APP_ID APP_ID + , APP.NAME NAME + , APP.CODE CODE + , APP.NOTES NOTES + , USEICO.USEICO_ID + , USEICO.ICON_VISIBLE_FLAG + , USEICO.ICON_X_COORDINATE + , USEICO.ICON_Y_COORDINATE + FROM + USERS_ICONS USEICO + LEFT JOIN APPLICATIONS APP ON USEICO.APP_ID = APP.APP_ID + WHERE + USEICO.ICON_VISIBLE_FLAG = 'Y' + AND USEICO.USE_ID = :useId + ORDER BY APP.NAME + "; + $dbresults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('useId' => $userEntity->getUseId())); + } + $results = array(); + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + } + + public function removeDesktopAvailableIconsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\DesktopIconsController.php\removeDesktopAvailableIconsAction() - Start'); + + $receivedAppId = $inputParams['APP_ID']; + if (isset($receivedAppId) && intval($receivedAppId) > 0) { + //Removal actually corresponds to adding an application to the other store + $userEntity = $this->container->get('security.token_storage')->getToken()->getUser(); + + $newUsersIconsEntity = new UsersIcons(); + $applicationsEntity = $this->getDoctrine() + ->getRepository('AppBundle:Applications') + ->find($receivedAppId); + + $newUsersIconsEntity->setApp($applicationsEntity); + $newUsersIconsEntity->setUse($userEntity); + $newUsersIconsEntity->setIconVisibleFlag('Y'); + + $em = $this->getDoctrine()->getManager(); + $em->persist($newUsersIconsEntity); + $em->flush(); + + $results = array("success" => true, "message" => "Modification done"); + } else { + throw new \Exception("Error, Nothing selected"); + } + return new JsonResponse($results); + } + + + public function removeDesktopCurrentIconsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\DesktopIconsController.php\removeDesktopCurrentIconsAction() - Start'); + + $receivedUseAppId = $inputParams['USEICO_ID']; + $results = array("false" => true, "message" => "Unable to remove application"); + if (isset($receivedUseAppId) && intval($receivedUseAppId) > 0) { + $deleteUsersIconsEntity = $this->getDoctrine() + ->getRepository('AppBundle:UsersIcons') + ->find($receivedUseAppId); + if ($deleteUsersIconsEntity) { + $em = $this->getDoctrine()->getManager(); + $em->remove($deleteUsersIconsEntity); + $em->flush(); + $results = array("success" => true, "message" => "Modification done"); + + } + } + return new JsonResponse($results); + } + + public function updateDesktopCurrentIconsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\DesktopIconsController.php\updateDesktopCurrentIconsAction() - Start'); + + $userEntity = $this->container->get('security.token_storage')->getToken()->getUser(); + + $usersApplicationEntity = $this->getDoctrine() + ->getRepository('AppBundle:UsersIcons') + ->findOneBy(array( + 'use' => $userEntity + , 'useicoId' => $inputParams['USEICO_ID'] + )); + if($usersApplicationEntity) { + $usersApplicationEntity->setIconXCoordinate($inputParams['ICON_X_COORDINATE']); + $usersApplicationEntity->setIconYCoordinate($inputParams['ICON_Y_COORDINATE']); + + $em = $this->getDoctrine()->getManager(); + $em->persist($usersApplicationEntity); + $em->flush(); + return new JsonResponse(array("success" => true, "message" => "Location saved")); + } else { + throw new \Exception("Error, Unable to save icon location"); + } + } + + + } + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Devices/DevicesController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Devices/DevicesController.php new file mode 100644 index 0000000..33838fe --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Devices/DevicesController.php @@ -0,0 +1,32 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\DevicesController.php\getDevices() - Start'); + + $results = $this->get('app.svc.devices')->getDevices(); + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Logs/LogsController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Logs/LogsController.php new file mode 100644 index 0000000..26730fd --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Logs/LogsController.php @@ -0,0 +1,74 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\LogsController.php\getCaptureLogs() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $results = $this->get('app.svc.systemlogs')->getLogFile($receivedSourceid, 'capture'); + return new JsonResponse($results); + } + + public function getConfigurationLogsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\LogsController.php\getConfigurationLogs() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $results = $this->get('app.svc.systemlogs')->getLogFile($receivedSourceid, 'configuration'); + return new JsonResponse($results); + } + + public function getCustomVideosLogsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\LogsController.php\getCustomVideosLogs() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $results = $this->get('app.svc.systemlogs')->getLogFile($receivedSourceid, 'customvideos'); + return new JsonResponse($results); + } + + public function getPostprodLogsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\LogsController.php\getPostprodLogs() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $results = $this->get('app.svc.systemlogs')->getLogFile($receivedSourceid, 'posprod'); + return new JsonResponse($results); + } + + public function getVideosLogsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\LogsController.php\getVideosLogs() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $results = $this->get('app.svc.systemlogs')->getLogFile($receivedSourceid, 'videos'); + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Pictures/PicturesController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Pictures/PicturesController.php new file mode 100644 index 0000000..14e9ad1 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Pictures/PicturesController.php @@ -0,0 +1,68 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\PicturesController.php\getHoursListAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + $receivedSelectedDay = $inputParams['SELECTEDDAY']; + + $results = $this->get('app.svc.pictures.directory')->getHoursFromCaptureDirectory($receivedSourceid, $receivedSelectedDay); + return new JsonResponse($results); + + } + + public function getDaysListAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\PicturesController.php\getDaysListAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $results = $this->get('app.svc.pictures.directory')->getDaysFromCaptureDirectory($receivedSourceid); + return new JsonResponse($results); + } + + public function getPictureAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\PicturesController.php\getPictureAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + $receivedPictureDate = $inputParams['PICTUREDATE']; + + $results = $this->get('app.svc.pictures')->getPicture($receivedSourceid, $receivedPictureDate); + return new JsonResponse($results); + } + + public function getSensorsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\PicturesController.php\getSensorsAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + $receivedPictureDate = $inputParams['PICTUREDATE']; + + $results = $this->get('app.svc.pictures')->getSensors($receivedSourceid, $receivedPictureDate); + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/SourcesController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/SourcesController.php new file mode 100644 index 0000000..9c89204 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/SourcesController.php @@ -0,0 +1,39 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SourcesController.php\getSourcesAction() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $userEntity = $tokenStorage->getToken()->getUser(); + + $dbresults = $this->get('app.svc.user')->getCurrentSourcesByUseId($userEntity->getUseId()); + + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return new JsonResponse($results); + } + + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCCaptureController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCCaptureController.php new file mode 100644 index 0000000..b858de9 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCCaptureController.php @@ -0,0 +1,78 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCCaptureController.php\getCaptureAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $confFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . ".cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source.json"; + + $results = $this->get('app.svc.configuration')->getSourceConfiguration( + $receivedSourceid + , $confFile + , $confSettingsFile); + + return new JsonResponse($results); + } + + public function updateCaptureAction($inputParams, Request $request) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCCaptureController.php\updateCaptureAction() - Start'); + + + $receivedSourceid = $inputParams['SOURCEID']; + $receivedName = $inputParams['NAME']; + $receivedValue = $inputParams['VALUE']; + + $confFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . ".cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source.json"; + + $results = $this->get('app.svc.configuration')->updateSourceConfiguration( + $request->getClientIp() + , $receivedSourceid + , $receivedName + , $receivedValue + , $confFile + , $confSettingsFile + , $this->container + ); + return new JsonResponse($results); + } + + public function getSectionCaptureAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCCaptureController.php\getSectionCaptureAction() - Start'); + + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source.json"; + + $results = $this->get('app.svc.configuration')->getSectionConfiguration( + $confSettingsFile + ); + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCFTPServersController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCFTPServersController.php new file mode 100644 index 0000000..a2c0685 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCFTPServersController.php @@ -0,0 +1,101 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCFTPServersController.php\getFTPServersAction() - Start'); + $logger->info('AppBundle\Controller\Desktop\SCFTPServersController.php\getFTPServersAction() - Serialize: ' . serialize($inputParams)); + + if ($this->get('app.svc.sources')->isUserAllowed($inputParams['SOURCEID'])) { + $configFile = $this->container->getParameter('dir_etc') . "config-source" . $inputParams['SOURCEID'] . "-ftpservers.cfg"; + $sourceconfigurationFTPServers = $this->get('app.svc.ftp')->getServersFromConfigFile($configFile, $inputParams['SOURCEID']); + $results['results'] = $sourceconfigurationFTPServers; + $results['total'] = count($sourceconfigurationFTPServers); + } else { + throw new \Exception("User not allowed to access source"); + } + return new JsonResponse($results); + } + + public function updateFTPServerAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCFTPServersController.php\updateFTPServerAction() - Start'); + + if ($this->get('app.svc.sources')->isUserAllowed($inputParams['SOURCEID'])) { + $configFile = $this->container->getParameter('dir_etc') . "config-source" . $inputParams['SOURCEID'] . "-ftpservers.cfg"; + if (is_file($configFile)) { + $ftpService = $this->get('app.svc.ftp'); + //First we add all existing FTP servers into an array + $sourceconfigurationFTPServers = $ftpService->getServersFromConfigFile($configFile, $inputParams['SOURCEID']); + if (strpos($inputParams['ID'],'FTP_') !== false) { + //This server is the last, we automatically add it to the end of the array + $newFTPServer = array( + 'ID' => $ftpService->getLastServerId($sourceconfigurationFTPServers) + 1 + , 'NAME' => $inputParams['NAME'] + , 'HOST' => $inputParams['HOST'] + , 'USERNAME' => $inputParams['USERNAME'] + , 'PASSWORD' => $inputParams['PASSWORD'] + , 'DIRECTORY' => $inputParams['DIRECTORY'] + , 'ACTIVE' => $inputParams['ACTIVE'] + , 'XFERENABLE' => $inputParams['XFERENABLE'] + , 'XFERTHREADS' => $inputParams['XFERTHREADS'] + , 'SOURCEID' => $inputParams['SOURCEID'] + ); + array_push($sourceconfigurationFTPServers, $newFTPServer); + $results['results'] = $newFTPServer; + } else { + $sourceconfigurationFTPServers = $ftpService->updateFtpServer($sourceconfigurationFTPServers, $inputParams); + $results['results'] = $ftpService->getFtpServerbyId($sourceconfigurationFTPServers, $inputParams['ID']); + } + $ftpService->updateServersConfigFile($configFile, $sourceconfigurationFTPServers, null); + $results['total'] = 1; + } else { + $results = array("success" => false, "title" => "Source Access", "message" => "Unable to access source config file"); + } + } else { + $results = array("success" => false, "title" => "Source Access", "message" => "User not allowed to access source config file"); + } + return new JsonResponse($results); + } + + public function removeFTPServerAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCFTPServersController.php\removeFTPServerAction() - Start'); + + if ($this->get('app.svc.sources')->isUserAllowed($inputParams['SOURCEID'])) { + $configFile = $this->container->getParameter('dir_etc') . "config-source" . $inputParams['SOURCEID'] . "-ftpservers.cfg"; + $sourceconfigurationFTPServers = $this->get('app.svc.ftp')->getServersFromConfigFile($configFile, $inputParams['SOURCEID']); + + $this->get('app.svc.ftp')->updateServersConfigFile($configFile, $sourceconfigurationFTPServers, $inputParams['ID']); + + $sourceconfigurationFTPServers = $this->get('app.svc.ftp')->getServersFromConfigFile($configFile, $inputParams['SOURCEID']); + + $results['results'] = $sourceconfigurationFTPServers; + $results['total'] = count($sourceconfigurationFTPServers); + } else { + $results = array("success" => false, "title" => "Source Access", "message" => "User not allowed to access source config file"); + } + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCMiscController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCMiscController.php new file mode 100644 index 0000000..ddc21e1 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCMiscController.php @@ -0,0 +1,101 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCMiscController.php\getWatermarkFilesAction() - Start'); + + $watermarkfiles = $this->get('app.svc.sources')->getWatermarkFiles($inputParams['SOURCEID']); + + return new JsonResponse(array( + 'results' => $watermarkfiles + , 'total' => count($watermarkfiles) + )); + } + + public function getFontsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCMiscController.php\getFontsAction() - Start'); + + $fonts = array(); + exec('mogrify -list font | grep Font', $fontlist, $ret); + $cptfonts = sizeof($fontlist); + for ($i=0;$i<$cptfonts;$i++) { + $tmpfonts = array(); + $tmpfonts['NAME'] = trim(str_replace("Font:", "", $fontlist[$i])); + array_push($fonts, $tmpfonts); + } + + return new JsonResponse(array( + 'results' => $fonts + , 'total' => count($fonts) + )); + } + + public function getPhidgetSensorsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCMiscController.php\getPhidgetSensorsAction() - Start'); + + $configFile = $this->container->getParameter('dir_etc') . "config-general.cfg"; + $phidgetsensors = $this->get('app.svc.phidgets')->getPhidgetsPorts($configFile); + + return new JsonResponse(array( + 'results' => $phidgetsensors + , 'total' => count($phidgetsensors) + )); + } + + public function getCaptureScheduleAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCMiscController.php\getCaptureScheduleAction() - Start'); + + $userEntity = $this->container->get('security.token_storage')->getToken()->getUser(); + + $availableSources = $this->get('app.svc.user')->getCurrentSourcesByUseId($userEntity->getUseId()); + $dbresults = array(); + foreach ($availableSources as $source) { + $scheduleFile = $this->container->getParameter('dir_etc') . "config-source" . $source['SOURCEID'] . "-schedule.json"; + $jsonContent = ""; + if (is_file($scheduleFile)) {$jsonContent = file_get_contents($scheduleFile);} + array_push($dbresults, array('JSON' => $jsonContent, 'SOURCEID' => $source['SOURCEID'])); + } + return new JsonResponse(array( + 'results' => $dbresults + , 'total' => 1 + )); + } + + public function saveCaptureScheduleAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCMiscController.php\getCaptureScheduleAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + $receivedJson = $inputParams['JSON']; + if ($this->get('app.svc.user')->hasCurrentUserAccessToSourceId($receivedSourceid)) { + $scheduleFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . "-schedule.json"; + file_put_contents($scheduleFile, $receivedJson); + } + return new JsonResponse( array("success" => true, "message" => "User updated")); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoController.php new file mode 100644 index 0000000..9644279 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoController.php @@ -0,0 +1,77 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoController.php\getVideoAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $confFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . "-video.cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-video.json"; + + $results = $this->get('app.svc.configuration')->getSourceConfiguration( + $receivedSourceid + , $confFile + , $confSettingsFile); + + return new JsonResponse($results); + } + + public function updateVideoAction($inputParams, Request $request) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoController.php\updateVideoAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + $receivedName = $inputParams['NAME']; + $receivedValue = $inputParams['VALUE']; + + $confFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . "-video.cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-video.json"; + + $results = $this->get('app.svc.configuration')->updateSourceConfiguration( + $request->getClientIp() + , $receivedSourceid + , $receivedName + , $receivedValue + , $confFile + , $confSettingsFile + , $this->container + ); + return new JsonResponse($results); + } + + public function getSectionVideoAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoController.php\getSectionVideoAction() - Start'); + + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-video.json"; + + $results = $this->get('app.svc.configuration')->getSectionConfiguration( + $confSettingsFile + ); + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoCustomController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoCustomController.php new file mode 100644 index 0000000..29704cc --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoCustomController.php @@ -0,0 +1,79 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoCustomController.php\getVideoCustomAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $confFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . "-videocustom.cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-videocustom.json"; + + $results = $this->get('app.svc.configuration')->getSourceConfiguration( + $receivedSourceid + , $confFile + , $confSettingsFile); + + return new JsonResponse($results); + } + + public function updateVideoCustomAction($inputParams, Request $request) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoCustomController.php\updateVideoCustomAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + $receivedName = $inputParams['NAME']; + $receivedValue = $inputParams['VALUE']; + + $confFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . "-videocustom.cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-videocustom.json"; + + $results = $this->get('app.svc.configuration')->updateSourceConfiguration( + $request->getClientIp() + , $receivedSourceid + , $receivedName + , $receivedValue + , $confFile + , $confSettingsFile + , $this->container + ); + + return new JsonResponse($results); + } + + public function getSectionVideoCustomAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoCustomController.php\getSectionVideoCustomAction() - Start'); + + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-videocustom.json"; + + $results = $this->get('app.svc.configuration')->getSectionConfiguration( + $confSettingsFile + ); + + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoPostController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoPostController.php new file mode 100644 index 0000000..e938f6b --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCVideoPostController.php @@ -0,0 +1,79 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoPostController.php\getVideoPostAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $confFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . "-videopost.cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-videopost.json"; + + $results = $this->get('app.svc.configuration')->getSourceConfiguration( + $receivedSourceid + , $confFile + , $confSettingsFile); + + return new JsonResponse($results); + } + + public function updateVideoPostAction($inputParams, Request $request) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoPostController.php\updateVideoPostAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + $receivedName = $inputParams['NAME']; + $receivedValue = $inputParams['VALUE']; + + $confFile = $this->container->getParameter('dir_etc') . "config-source" . $receivedSourceid . "-videopost.cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-videopost.json"; + + $results = $this->get('app.svc.configuration')->updateSourceConfiguration( + $request->getClientIp() + , $receivedSourceid + , $receivedName + , $receivedValue + , $confFile + , $confSettingsFile + , $this->container + ); + + return new JsonResponse($results); + } + + public function getSectionVideoPostAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCVideoPostController.php\getSectionVideoPostAction() - Start'); + + $confSettingsFile = $this->container->getParameter('sys_config') . "config-source-videopost.json"; + + $results = $this->get('app.svc.configuration')->getSectionConfiguration( + $confSettingsFile + ); + + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCWindowController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCWindowController.php new file mode 100644 index 0000000..3077d33 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Sourcesconfiguration/SCWindowController.php @@ -0,0 +1,63 @@ +get('logger'); + $sqlQuery = "SELECT PER.NAME NAME + FROM GROUPS_PERMISSIONS GROPER + LEFT JOIN PERMISSIONS PER ON PER.PER_ID = GROPER.PER_ID + WHERE GROPER.GRO_ID = :receivedGroId + ORDER BY PER.NAME"; + $userPermissionsDbResults = $this->getDoctrine() + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('receivedGroId' => $userEntity->getGro()->getGroId())); + $userPermissions = array(); + foreach($userPermissionsDbResults as $key=>$value) { + $logger->info('AppBundle\Controller\Desktop\SCWindowController.php\getUserPermissions() - User has permission: ' . $value['NAME']); + array_push($userPermissions, $value['NAME']); + } + return $userPermissions; + } + + public function getConfigurationTabsAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SCWindowController.php\getConfigurationTabsAction() - Start'); + + $userEntity = $this->container + ->get('security.token_storage') + ->getToken() + ->getUser(); + $userPermissions = self::getUserPermissions($userEntity); + $sysConfig = $this->container->getParameter('sys_config'); + + $tabsAllowed = $this->get('app.svc.configuration')->getConfigurationTabs($sysConfig, $userPermissions); + + return new JsonResponse(array( + 'results' => $tabsAllowed + , 'total' => count($tabsAllowed) + )); + } + + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Stats/StatsController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Stats/StatsController.php new file mode 100644 index 0000000..7beabd2 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Stats/StatsController.php @@ -0,0 +1,61 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\StatsController.php\getSystemStatsAction() - Start'); + + $receivedRange = $inputParams['RANGE']; + + $results = $this->get('app.svc.stats')->getSystemStats($receivedRange); + return new JsonResponse($results); + } + + public function getSourcesPicturesCountSizeAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\StatsController.php\getSourcesPicturesCountSizeAction() - Start'); + + $receivedSourceId = $inputParams['SOURCEID']; + + $sourcestats = $this->get('app.svc.stats')->getSourcesPicturesCountSize($receivedSourceId); + $results['results'] = $sourcestats; + $results['total'] = count($sourcestats); + return new JsonResponse($results); + } + + public function getSourcesDiskUsageAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\StatsController.php\getSourcesDiskUsageAction() - Start'); + + $receivedSourceId = $inputParams['SOURCEID']; + + $sourcestats = $this->get('app.svc.stats')->getSourcesDiskUsage($receivedSourceId); + $results['results'] = $sourcestats; + $results['total'] = count($sourcestats); + + return new JsonResponse($results); + } + + + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/SyncReports/SyncReportsController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/SyncReports/SyncReportsController.php new file mode 100644 index 0000000..a316e5e --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/SyncReports/SyncReportsController.php @@ -0,0 +1,63 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SyncReportsController.php\getSyncReports() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $userEntity = $tokenStorage->getToken()->getUser(); + + $results = $this->get('app.svc.syncreports')->getSyncReportsList($userEntity); + return new JsonResponse(array( + 'results' => $results + , 'total' => count($results) + )); + } + + public function createSyncReportAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SyncReportsController.php\createSyncReportAction() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $userEntity = $tokenStorage->getToken()->getUser(); + + $results = $this->get('app.svc.syncreports')->createSyncReport($userEntity, $inputParams); + return new JsonResponse(array( + 'results' => $results + , 'total' => count($results) + )); + } + + public function removeSyncReportAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SyncReportsController.php\removeSyncReportAction() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $userEntity = $tokenStorage->getToken()->getUser(); + + $results = $this->get('app.svc.syncreports')->removeSyncReport($userEntity, $inputParams); + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Systemconfiguration/SystemConfigurationController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Systemconfiguration/SystemConfigurationController.php new file mode 100644 index 0000000..0b0415e --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Systemconfiguration/SystemConfigurationController.php @@ -0,0 +1,59 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\SystemConfigurationController.php\getCaptureAction() - Start'); + + $confFile = $this->container->getParameter('dir_etc') . "config-general.cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-general.json"; + + $results = $this->get('app.svc.configuration')->getSystemConfiguration( + $confFile + , $confSettingsFile); + + return new JsonResponse($results); + } + + public function updateConfigurationAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\SystemConfigurationController.php\updateCaptureAction() - Start'); + + $receivedName = $inputParams['NAME']; + $receivedValue = $inputParams['VALUE']; + + $confFile = $this->container->getParameter('dir_etc') . "config-general.cfg"; + $confSettingsFile = $this->container->getParameter('sys_config') . "config-general.json"; + + $results = $this->get('app.svc.configuration')->updateSystemConfiguration( + $this->container->get('request')->getClientIp() + , $receivedName + , $receivedValue + , $confFile + , $confSettingsFile + , $this->container + ); + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/Videos/VideosController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/Videos/VideosController.php new file mode 100644 index 0000000..2dc4d48 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/Videos/VideosController.php @@ -0,0 +1,44 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\VideosController.php\getDaysListAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $results = $this->get('app.svc.videos')->getDaysFromVideoDirectory($receivedSourceid); + return new JsonResponse($results); + } + + public function getVideosListAction($inputParams) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Controller\Desktop\VideosController.php\getVideoAction() - Start'); + + $receivedSourceid = $inputParams['SOURCEID']; + + $results = $this->get('app.svc.videos')->getVideos($receivedSourceid); + return new JsonResponse($results); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/Desktop/XferReports/XferReportsController.php b/Symfony/3.0/src/AppBundle/Controller/Desktop/XferReports/XferReportsController.php new file mode 100644 index 0000000..697e4a8 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Desktop/XferReports/XferReportsController.php @@ -0,0 +1,35 @@ +get('logger'); + $logger->info('AppBundle\Controller\Desktop\XferReportsController.php\getXferReports() - Start'); + + $results = $this->get('app.svc.xferreports')->getXferReportsList(); + return new JsonResponse(array( + 'results' => $results + , 'total' => count($results) + )); + } + + } diff --git a/Symfony/3.0/src/AppBundle/Controller/ExtDirectRouterController.php b/Symfony/3.0/src/AppBundle/Controller/ExtDirectRouterController.php new file mode 100644 index 0000000..7f97a93 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/ExtDirectRouterController.php @@ -0,0 +1,154 @@ +get('logger'); + $logger->info('AppBundle\Controller\ExtDirectRouterController.php\indexAction() - Start'); + + $postData = trim(file_get_contents('php://input')); + if (isset($postData)) { + $extCall = json_decode($postData, true); + } else { + $logger->info('AppBundle\Controller\ExtDirectRouterController.php\indexAction() - ERRROR: Invalid request, dying as it does not make sense to push forward'); + throw new \Exception('Unable to decode request'); + } + + $logger->info('AppBundle\Controller\ExtDirectRouterController.php\indexAction() - Call: ' . json_encode($extCall)); + + if (!isset($extCall['action'])) {// Means there is more than one single call in request + //If Ext.Direct is making multiple calls simultaneously, an array of calls is received + $logger->info('AppBundle\Controller\ExtDirectRouterController.php\indexAction() - Multi-Call request'); + $response = self::processMultiExtCall($extCall); + + } else { + //Alternatively, Ext.Direct could make one single call + $logger->info('AppBundle\Controller\ExtDirectRouterController.php\indexAction() - Single-Call request'); + $response = self::processSingleExtCall($extCall); + } + + return new JsonResponse($response); + } + + + //http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential + private function isAssoc(array $array) { + return (bool)count(array_filter(array_keys($array), 'is_string')); + } + + private function processMultiExtCall($extCallBatch) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Services\RouterService\processMultiExtCall() - Start'); + foreach ($extCallBatch as $idx=>$extCall) { + $logger->info('AppBundle\Services\RouterService\processMultiExtCall() - Processing Ext Call: ' . $idx); + $extCallBatch[$idx] = self::processSingleExtCall($extCall); + } + return $extCallBatch; + } + + private function processSingleExtCall($extCall) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Services\RouterService\processSingleExtCall() - Start'); + + $callAction = $extCall['action']; + $callMethod = $extCall['method']; + + if (self::checkMethodAction($callAction, $callMethod) === true) { + // QUERY + // {"action":"Sources","method":"getSources","data":[{"page":1,"start":0,"limit":25}],"type":"rpc","tid":16} + + // RESPONSE + // {"type":"rpc","tid":16,"action":"Sources","method":"getSources","result":{"results":[{"SOU_ID":"1","NAME":"SOURCE 1","SOURCEID":"1","WEIGHT":"0","REMOTE_HOST":""},{"SOU_ID":"2","NAME":"source 2","SOURCEID":"2","WEIGHT":"2","REMOTE_HOST":""}],"total":2} + return self::runAction($extCall); + } else { + throw new Exception("Insufficient privileges to access method: $callMethod on action $callAction"); + } + + } + + private function runAction($extCall) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Services\RouterService\runAction() - Start'); + + $callAction = $extCall['action']; + $callMethod = $extCall['method']; + $callData = $extCall['data']; + + $controllerFolder = $this->getParameter('extMethodsConfig')[$callAction]['folder']; + $logger->info('AppBundle\Services\RouterService\runAction() - Folder: ' . $controllerFolder); + + if (isset($callData['data']) && isset($callData['data']['SOURCEID'])) { + if ($this->get('app.svc.user')->hasCurrentUserAccessToSourceId($callData['data']['SOURCEID']) === false) { + throw new Exception("Insufficient privileges to access source: ". $callData['data']['SOURCEID']); + } + } + + if (is_file($this->getParameter('kernel.root_dir') . '/../src/AppBundle/Controller/' . $controllerFolder . '/' . $callAction .'Controller.php')) { + $logger->info('AppBundle\Services\RouterService\runAction() - Controller: ' . $controllerFolder . '/' . $callAction . ':' . $callMethod . ' - Input: ' . serialize($callData)); + + //Handle multiple updates in a single call. + //If associative, one single entity to be updated + //If not associative, multiple entities to be updated (array of arrays) + if (self::isAssoc($callData[0]) === true) { + $jsonResponse = $this->forward('AppBundle:' . $controllerFolder . '/' . $callAction . ':' . $callMethod, array('inputParams' => $callData[0])); + $extCall['result'] = json_decode($jsonResponse->getContent(), true); + } else { + foreach($callData[0] as $inputParams) { + $jsonResponse = $this->forward('AppBundle:' . $controllerFolder . '/' . $callAction . ':' . $callMethod, array('inputParams' => $inputParams)); + $extCall['result'] = json_decode($jsonResponse->getContent(), true); + } + } + + $logger->info('AppBundle\Services\RouterService\runAction() - Controller: ' . $controllerFolder . '/' . $callAction . ':' . $callMethod . ' - Response: ' . serialize($extCall['result'])); + + unset($extCall['data']); + + return $extCall; + + } else { + $logger->info('AppBundle\Services\RouterService\runAction() - Controller does not exist, skipping ... ' . $this->getParameter('kernel.root_dir') . '/../src/AppBundle/Controller/' . $controllerFolder . '/' . $callAction); + throw new Exception("Unable to locate controller related to access method: $callMethod on action $callAction"); + } + } + + /* + * Check if the method exist in configuration and if user is allowed to use it + */ + private function checkMethodAction($callAction, $callMethod) { + $logger = $this->get('logger'); + $logger->info('AppBundle\Services\RouterService\checkMethodAction() - Start'); + + if (!isset($this->getParameter('extMethodsConfig')[$callAction])) { + $logger->info('AppBundle\Controller\ExtDirectRouterController.php\checkMethodAction() - ERROR: Call to undefined action: ' . $callAction); + throw new Exception('Call to undefined action: ' . $callAction); + } elseif (!isset($this->getParameter('extMethodsConfig')[$callAction]['methods'][$callMethod])) { + $logger->info('AppBundle\Controller\ExtDirectRouterController.php\checkMethodAction() - ERROR: Call to undefined method: ' . $callMethod . ' on action ' . $callAction); + throw new Exception("Call to undefined method: $callMethod on action $callAction"); + } + + return $this->get('app.svc.user')->isMethodAllowed($callAction, $callMethod, $this->getParameter('extMethodsConfig')); + } + + +} diff --git a/Symfony/3.0/src/AppBundle/Controller/Misc/DownloadController.php b/Symfony/3.0/src/AppBundle/Controller/Misc/DownloadController.php new file mode 100644 index 0000000..c62720f --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Misc/DownloadController.php @@ -0,0 +1,57 @@ +get('logger'); + + $page = str_replace("..", "", $page); // We strip any .. to avoid user trying to move to parent directory + $completePath = $this->container->getParameter('dir_sources') . $page; + + $explodedPath = explode("/", $page); + $logger->info('AppBundle\Controller\DownloadController.php\indexAction() - Complete Path: ' . $completePath . ' Source: ' . $explodedPath[0]); + $sourceId = str_replace("source", "", $explodedPath[0]); + if ($this->get('app.svc.sources')->isUserAllowed($sourceId)) { + $fs = new Filesystem(); + if ($fs->exists($completePath) && is_dir($completePath)) { + return $this->get('app.svc.download')->serveDirectory($completePath); + } else if ($fs->exists($completePath)) { + return $this->get('app.svc.download')->serveFile($completePath, $request->query->get('width')); + } else { + return $this->get('app.svc.response')->htmlDoesNotExist($page); + } + } else { + return $this->get('app.svc.response')->htmlUnableToAccessContent($page); + } + } +} + + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Misc/OnlineStatusController.php b/Symfony/3.0/src/AppBundle/Controller/Misc/OnlineStatusController.php new file mode 100644 index 0000000..18545c6 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Misc/OnlineStatusController.php @@ -0,0 +1,48 @@ +get('logger'); + $logger->info('AppBundle\Controller\OnlineStatusController.php\indexAction() - Start'); + + $tokenStorage = $this->container->get('security.token_storage'); + $authorizationChecker = $this->container->get('security.authorization_checker'); + + $userEntity = $tokenStorage->getToken()->getUser(); + + if ($userEntity && $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + $results = array("success" => true + , "message" => "Server is online, user is authenticated on client and server" + , "status" => "AUTHENTICATED" + , "USERNAME" => $userEntity->getUsername()); + } else { + $results = array("success" => true, "message" => "Server is online, user not authenticated on server", "status" => "NOTAUTHENTICATED"); + } + return new JsonResponse($results); + } +} + + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Misc/PhpinfoController.php b/Symfony/3.0/src/AppBundle/Controller/Misc/PhpinfoController.php new file mode 100644 index 0000000..84b574f --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Misc/PhpinfoController.php @@ -0,0 +1,30 @@ +get('logger'); + $logger->info('AppBundle\Controller\PhpinfoController.php - Starting indexAction()'); + + return $this->render('AppBundle:Phpinfo:index.html.php'); + } + +} diff --git a/Symfony/3.0/src/AppBundle/Controller/Misc/StatusController.php b/Symfony/3.0/src/AppBundle/Controller/Misc/StatusController.php new file mode 100644 index 0000000..e354813 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Misc/StatusController.php @@ -0,0 +1,63 @@ +get('logger'); + $logger->info('AppBundle\Controller\StatusController.php\indexAction() - Start'); + + $receivedUsername = $request->request->get('USERNAME'); + + $tokenStorage = $this->container->get('security.token_storage'); + $authorizationChecker = $this->container->get('security.authorization_checker'); + + $userEntity = $tokenStorage->getToken()->getUser(); + + if ($userEntity && $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + $results = array( + "success" => true + , "build" => $this->get('app.svc.status')->getBuildVersion() + , "uptime" => $this->get('app.svc.status')->getSystemUptime() + , "disk" => $this->get('app.svc.status')->getDiskStatus() + , "cameras" => $this->get('app.svc.status')->getCameras() + , "bootdate" => $this->get('app.svc.status')->getSystemBootDate() + , "sources" => $this->get('app.svc.status')->getSourcesStatus() + , "authentication" => $this->get('app.svc.status')->getAuthenticationStatus($this, $receivedUsername) + ); + } else { + $results = array( + "success" => true + , "build" => $this->get('app.svc.status')->getBuildVersion() + , "authentication" => $this->get('app.svc.status')->getAuthenticationStatus($this, $receivedUsername) + ); + } + + return new JsonResponse($results); + } + + +} + + + diff --git a/Symfony/3.0/src/AppBundle/Controller/Misc/SystemController.php b/Symfony/3.0/src/AppBundle/Controller/Misc/SystemController.php new file mode 100644 index 0000000..55f76d7 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Misc/SystemController.php @@ -0,0 +1,48 @@ +get('logger'); + $logger->info('AppBundle\Controller\PhpinfoController.php - Starting systemRebootAction()'); + + $tokenStorage = $this->container->get('security.token_storage'); + $authorizationChecker = $this->container->get('security.authorization_checker'); + $userEntity = $tokenStorage->getToken()->getUser(); + if ($userEntity && $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + $userService = $this->get('app.svc.user'); + $userPermissions = $userService->getUserPermissions($userEntity); + if (in_array('SOURCES_CONFIGURATION_EXPERT', $userPermissions)) { + $createConfiguration = new Process('echo test > /tmp/abcde'); + $createConfiguration->run(); + $results = array("success" => true, "message" => "Server will reboot soon"); + } else { + $results = array("success" => false, "message" => "User not allowed to perform this operation"); + } + } else { + $results = array("success" => false, "message" => "User not authenticated"); + } + return new JsonResponse($results); + } + +} diff --git a/Symfony/3.0/src/AppBundle/Controller/Root/DashboardController.php b/Symfony/3.0/src/AppBundle/Controller/Root/DashboardController.php new file mode 100644 index 0000000..69bc6fa --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Root/DashboardController.php @@ -0,0 +1,43 @@ +get('logger'); + $logger->info('AppBundle\Controller\DashboardController.php\indexAction() - Start'); + + if (is_file('../../../../build.txt')) { + $currentBuild = file_get_contents('../../../../build.txt'); + $currentBuild = preg_replace('/[^(\x20-\x7F)]*/','', $currentBuild); + $logger->info('AppBundle\Controller\DashboardController.php\indexAction() - Current Build: ' . $currentBuild); + } else { + $currentBuild = time(); + $logger->info('AppBundle\Controller\DashboardController.php\indexAction() - Current Build: ' . $currentBuild); + } + + return $this->render('AppBundle:Dashboard:dashboard.html.php', array('currentBuild' => $currentBuild, 'language' => $language)); + } +} diff --git a/Symfony/3.0/src/AppBundle/Controller/Root/DesktopController.php b/Symfony/3.0/src/AppBundle/Controller/Root/DesktopController.php new file mode 100644 index 0000000..b652cd2 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/Root/DesktopController.php @@ -0,0 +1,43 @@ +get('logger'); + $logger->info('AppBundle\Controller\Root\DesktopController.php\indexAction() - Start'); + + if (is_file('../../../../build.txt')) { + $currentBuild = file_get_contents('../../../../build.txt'); + $currentBuild = preg_replace('/[^(\x20-\x7F)]*/','', $currentBuild); + $logger->info('AppBundle\Controller\Root\DesktopController.php\indexAction() - Current Build: ' . $currentBuild); + } else { + $currentBuild = time(); + $logger->info('AppBundle\Controller\Root\DesktopController.php\indexAction() - Current Build: ' . $currentBuild); + } + + return $this->render('AppBundle:Desktoproot:desktoproot.html.php', array('currentBuild' => $currentBuild, 'language' => $language)); + } +} diff --git a/Symfony/3.0/src/AppBundle/Controller/SecurityController.php b/Symfony/3.0/src/AppBundle/Controller/SecurityController.php new file mode 100644 index 0000000..4c0e10d --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Controller/SecurityController.php @@ -0,0 +1,34 @@ +get('security.authentication_utils'); + + return $this->render('AppBundle:Security:login.html.php', array( + 'last_username' => $helper->getLastUsername(), + 'error' => $helper->getLastAuthenticationError(), + )); + } +} +?> diff --git a/Symfony/3.0/src/AppBundle/Entities/Configuration/Configuration.php b/Symfony/3.0/src/AppBundle/Entities/Configuration/Configuration.php new file mode 100644 index 0000000..71abc03 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Configuration/Configuration.php @@ -0,0 +1,92 @@ +") + * @JMS\XmlList(entry="section") + */ + private $sections; + /** + * @JMS\Type("string") + */ + private $permission; + + public function __construct() + { + $this->sections = new ArrayCollection(); + } + + + public function getName() + { + return $this->name; + } + + // Setters + public function setName($name) + { + $this->name = $name; + } + + public function setSections(array $sections) + { + $this->sections = $sections; + } + + public function getSections() + { + return $this->sections; + } + + public function getPermission() + { + return $this->permission; + } + + public function setPermission($permission) + { + $this->permission = $permission; + } + + public function findParameterByName($parameterName) + { + foreach($this->sections as $section) { + foreach($section->getParameters() as $parameter) { + if ($parameter->getName() == $parameterName) { + return $parameter; + } + } + } + return false; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Configuration/Parameter.php b/Symfony/3.0/src/AppBundle/Entities/Configuration/Parameter.php new file mode 100644 index 0000000..63f3e54 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Configuration/Parameter.php @@ -0,0 +1,133 @@ +") + */ + private $values; + + /** + * @JMS\Type("AppBundle\Entities\Configuration\Section") + */ + private $section; + + // Getters + public function getName() + { + return $this->name; + } + + // Setters + public function setName($name) + { + $this->name = $name; + } + + // Getters + public function getPermission() + { + return $this->permission; + } + + // Setters + public function setPermission($permission) + { + $this->permission = $permission; + } + + // Getters + public function getDefault() + { + return $this->default; + } + + // Setters + public function setDefault($default) + { + $this->default = $default; + } + + // Getters + public function getType() + { + return $this->type; + } + + // Setters + public function setType($type) + { + $this->type = $type; + } + + // Getters + public function getDescription() + { + return $this->description; + } + + // Setters + public function setDescription($description) + { + $this->description = $description; + } + + public function setSection(Section $section) + { + $this->section = $section; + } + + public function getSection() + { + return $this->section; + } + + public function setValues(array $values) + { + $this->values = $values; + } + + public function getValues() + { + return $this->values; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Configuration/Section.php b/Symfony/3.0/src/AppBundle/Entities/Configuration/Section.php new file mode 100644 index 0000000..29973ab --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Configuration/Section.php @@ -0,0 +1,85 @@ +") + */ + private $parameters; + /** + * @JMS\Type("Configuration") + */ + private $configuration; + + + // Getters + public function getName() + { + return $this->name; + } + + // Setters + public function setName($name) + { + $this->name = $name; + } + + // Getters + public function getPermission() + { + return $this->permission; + } + + // Setters + public function setPermission($permission) + { + $this->permission = $permission; + } + + public function setParameters(array $parameters) + { + $this->parameters = $parameters; + } + + public function getParameters() + { + return $this->parameters; + } + + public function setConfiguration(Configuration $configuration) + { + $this->configuration = $configuration; + } + + public function getConfiguration() + { + return $this->configuration; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Configuration/Value.php b/Symfony/3.0/src/AppBundle/Entities/Configuration/Value.php new file mode 100644 index 0000000..cafde67 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Configuration/Value.php @@ -0,0 +1,105 @@ +name; + } + + // Setters + public function setName($name) + { + $this->name = $name; + } + + // Getters + public function getDefault() + { + return $this->default; + } + + // Setters + public function setDefault($default) + { + $this->default = $default; + } + + // Getters + public function getType() + { + return $this->type; + } + + // Setters + public function setType($type) + { + $this->type = $type; + } + + // Getters + public function getDescription() + { + return $this->description; + } + + // Setters + public function setDescription($description) + { + $this->description = $description; + } + + public function setParameter(Parameter $parameter) + { + $this->parameter = $parameter; + } + + public function getParameter() + { + return $this->parameter; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/Applications.php b/Symfony/3.0/src/AppBundle/Entities/Database/Applications.php new file mode 100644 index 0000000..90ac4de --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/Applications.php @@ -0,0 +1,142 @@ +appId; + } + + /** + * Set name + * + * @param string $name + * @return Applications + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set code + * + * @param string $code + * @return Applications + */ + public function setCode($code) + { + $this->code = $code; + + return $this; + } + + /** + * Get code + * + * @return string + */ + public function getCode() + { + return $this->code; + } + + /** + * Set notes + * + * @param string $notes + * @return Applications + */ + public function setNotes($notes) + { + $this->notes = $notes; + + return $this; + } + + /** + * Get notes + * + * @return string + */ + public function getNotes() + { + return $this->notes; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/ApplicationsRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/ApplicationsRepository.php new file mode 100644 index 0000000..ede26ab --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/ApplicationsRepository.php @@ -0,0 +1,30 @@ +concId; + } + + /** + * Set file + * + * @param integer $file + * @return Configuration + */ + public function setFile($file) + { + $this->file = $file; + + return $this; + } + + /** + * Get file + * + * @return integer + */ + public function getFile() + { + return $this->file; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/ConfigurationRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/ConfigurationRepository.php new file mode 100644 index 0000000..ebf18c5 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/ConfigurationRepository.php @@ -0,0 +1,30 @@ +cusId; + } + + /** + * Set name + * + * @param string $name + * @return Customers + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/CustomersRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/CustomersRepository.php new file mode 100644 index 0000000..cd177ba --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/CustomersRepository.php @@ -0,0 +1,30 @@ +groId; + } + + + /** + * Set name + * + * @param string $name + * @return Groups + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + + /** + * Set notes + * + * @param string $notes + * @return Groups + */ + public function setNotes($notes) + { + $this->notes = $notes; + + return $this; + } + + /** + * Get notes + * + * @return string + */ + public function getNotes() + { + return $this->notes; + } + + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/GroupsApplications.php b/Symfony/3.0/src/AppBundle/Entities/Database/GroupsApplications.php new file mode 100644 index 0000000..b95d5bb --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/GroupsApplications.php @@ -0,0 +1,145 @@ +groappId; + } + + /** + * Set access + * + * @param integer $access + * @return GroupsApplications + */ + public function setAccess($access) + { + $this->access = $access; + + return $this; + } + + /** + * Get access + * + * @return integer + */ + public function getAccess() + { + return $this->access; + } + + /** + * Set gro + * + * @param \AppBundle\Entities\Database\Groups $gro + * @return GroupsApplications + */ + public function setGro(\AppBundle\Entities\Database\Groups $gro = null) + { + $this->gro = $gro; + + return $this; + } + + /** + * Get gro + * + * @return \AppBundle\Entities\Database\Groups + */ + public function getGro() + { + return $this->gro; + } + + /** + * Set pag + * + * @param \AppBundle\Entities\Database\Applications $app + * @return GroupsApplications + */ + public function setApp(\AppBundle\Entities\Database\Applications $app = null) + { + $this->app = $app; + + return $this; + } + + /** + * Get app + * + * @return \AppBundle\Entities\Database\Applications + */ + public function getApp() + { + return $this->app; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/GroupsApplicationsRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/GroupsApplicationsRepository.php new file mode 100644 index 0000000..231ea42 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/GroupsApplicationsRepository.php @@ -0,0 +1,30 @@ +groperId; + } + + /** + * Set access + * + * @param integer $access + * @return GroupsPermissions + */ + public function setAccess($access) + { + $this->access = $access; + + return $this; + } + + /** + * Get access + * + * @return integer + */ + public function getAccess() + { + return $this->access; + } + + /** + * Set gro + * + * @param \AppBundle\Entities\Database\Groups $gro + * @return GroupsPermissions + */ + public function setGro(\AppBundle\Entities\Database\Groups $gro = null) + { + $this->gro = $gro; + + return $this; + } + + /** + * Get gro + * + * @return \AppBundle\Entities\Database\Groups + */ + public function getGro() + { + return $this->gro; + } + + /** + * Set per + * + * @param \AppBundle\Entities\Database\Permissions $per + * @return GroupsPermissions + */ + public function setPag(\AppBundle\Entities\Database\Permissions $per = null) + { + $this->per = $per; + + return $this; + } + + /** + * Get per + * + * @return \AppBundle\Entities\Database\Permissions + */ + public function getPer() + { + return $this->per; + } + + /** + * Set per + * + * @param \AppBundle\Entities\Database\Permissions $per + * @return GroupsPermissions + */ + public function setPer(\AppBundle\Entities\Database\Permissions $per = null) + { + $this->per = $per; + + return $this; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/GroupsPermissionsRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/GroupsPermissionsRepository.php new file mode 100644 index 0000000..bfaf20a --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/GroupsPermissionsRepository.php @@ -0,0 +1,30 @@ +loghisId; + } + + /** + * Set userAgent + * + * @param string $userAgent + * @return LoginHistory + */ + public function setUserAgent($userAgent) + { + $this->userAgent = $userAgent; + + return $this; + } + + /** + * Get userAgent + * + * @return string + */ + public function getUserAgent() + { + return $this->userAgent; + } + + /** + * Set ipAddress + * + * @param string $ipAddress + * @return LoginHistory + */ + public function setIpAddress($ipAddress) + { + $this->ipAddress = $ipAddress; + + return $this; + } + + /** + * Get ipAddress + * + * @return string + */ + public function getIpAddress() + { + return $this->ipAddress; + } + + /** + * Set username + * + * @param string $username + * @return LoginHistory + */ + public function setUsername($username) + { + $this->username = $username; + + return $this; + } + + /** + * Get username + * + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Set dateAccess + * + * @param \DateTime $dateAccess + * @return LoginHistory + */ + public function setDateAccess($dateAccess) + { + $this->dateAccess = $dateAccess; + + return $this; + } + + /** + * Get dateAccess + * + * @return \DateTime + */ + public function getDateAccess() + { + return $this->dateAccess; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/LoginHistoryRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/LoginHistoryRepository.php new file mode 100644 index 0000000..eb7be29 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/LoginHistoryRepository.php @@ -0,0 +1,30 @@ +perId; + } + + /** + * Set name + * + * @param string $name + * @return Permissions + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + + /** + * Set notes + * + * @param string $notes + * @return Permissions + */ + public function setNotes($notes) + { + $this->notes = $notes; + + return $this; + } + + /** + * Get notes + * + * @return string + */ + public function getNotes() + { + return $this->notes; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/PermissionsRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/PermissionsRepository.php new file mode 100644 index 0000000..e64d88e --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/PermissionsRepository.php @@ -0,0 +1,30 @@ +picId; + } + + /** + * Set sourceid + * + * @param integer $sourceid + * @return Pictures + */ + public function setSourceid($sourceid) + { + $this->sourceid = $sourceid; + + return $this; + } + + /** + * Get sourceid + * + * @return integer + */ + public function getSourceid() + { + return $this->sourceid; + } + + /** + * Set pictureName + * + * @param string $pictureName + * @return Pictures + */ + public function setPictureName($pictureName) + { + $this->pictureName = $pictureName; + + return $this; + } + + /** + * Get pictureName + * + * @return string + */ + public function getPictureName() + { + return $this->pictureName; + } + + /** + * Set comment + * + * @param string $comment + * @return Pictures + */ + public function setComment($comment) + { + $this->comment = $comment; + + return $this; + } + + /** + * Get comment + * + * @return string + */ + public function getComment() + { + return $this->comment; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/PicturesRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/PicturesRepository.php new file mode 100644 index 0000000..59231ae --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/PicturesRepository.php @@ -0,0 +1,30 @@ +souId; + } + + /** + * Set sourceId + * + * @param integer $sourceId + * @return Sources + */ + public function setSourceId($sourceId) + { + $this->sourceId = $sourceId; + + return $this; + } + + /** + * Get sourceId + * + * @return integer + */ + public function getSourceId() + { + return $this->sourceId; + } + + /** + * Set quota + * + * @param integer $quota + * @return Sources + */ + public function setQuota($quota) + { + $this->quota = $quota; + + return $this; + } + + /** + * Get quota + * + * @return integer + */ + public function getQuota() + { + return $this->quota; + } + + /** + * Set name + * + * @param string $name + * @return Sources + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set weight + * + * @param integer $weight + * @return Sources + */ + public function setWeight($weight) + { + $this->weight = $weight; + + return $this; + } + + /** + * Get weight + * + * @return integer + */ + public function getWeight() + { + return $this->weight; + } + + /** + * Set remoteHost + * + * @param string $remoteHost + * @return Sources + */ + public function setRemoteHost($remoteHost) + { + $this->remoteHost = $remoteHost; + + return $this; + } + + /** + * Get remoteHost + * + * @return string + */ + public function getRemoteHost() + { + return $this->remoteHost; + } + + /** + * Set remotePassword + * + * @param string $remotePassword + * @return Sources + */ + public function setRemotePassword($remotePassword) + { + $this->remotePassword = $remotePassword; + + return $this; + } + + /** + * Get remotePassword + * + * @return string + */ + public function getRemotePassword() + { + return $this->remotePassword; + } + + /** + * Set remoteUsername + * + * @param string $remoteUsername + * @return Sources + */ + public function setRemoteUsername($remoteUsername) + { + $this->remoteUsername = $remoteUsername; + + return $this; + } + + /** + * Get remoteUsername + * + * @return string + */ + public function getRemoteUsername() + { + return $this->remoteUsername; + } + + public function updateSourceEntity($inputParams) + { + if (isset($inputParams['NAME'])) { + $this->setName($inputParams['NAME']); + } + if (isset($inputParams['SOURCEID'])) { + $this->setSourceId($inputParams['SOURCEID']); + } + if (isset($inputParams['QUOTA'])) { + $this->setQuota($inputParams['QUOTA']); + } + if (isset($inputParams['WEIGHT'])) { + $this->setWeight($inputParams['WEIGHT']); + } + if (isset($inputParams['REMOTE_HOST'])) { + $this->setRemoteHost($inputParams['REMOTE_HOST']); + } + if (isset($inputParams['REMOTE_USERNAME'])) { + $this->setRemoteUsername($inputParams['REMOTE_USERNAME']); + } + if (isset($inputParams['REMOTE_PASSWORD'])) { + $this->setRemotePassword($inputParams['REMOTE_PASSWORD']); + } + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/SourcesGroups.php b/Symfony/3.0/src/AppBundle/Entities/Database/SourcesGroups.php new file mode 100644 index 0000000..5a1a343 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/SourcesGroups.php @@ -0,0 +1,139 @@ +sougroId; + } + + /** + * Set username + * + * @param string $username + * @return SourcesGroups + */ + public function setUsername($username) + { + $this->username = $username; + + return $this; + } + + /** + * Get username + * + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Set usergroup + * + * @param string $usergroup + * @return SourcesGroups + */ + public function setUsergroup($usergroup) + { + $this->usergroup = $usergroup; + + return $this; + } + + /** + * Get usergroup + * + * @return string + */ + public function getUsergroup() + { + return $this->usergroup; + } + + /** + * Set permission + * + * @param string $permission + * @return SourcesGroups + */ + public function setPermission($permission) + { + $this->permission = $permission; + + return $this; + } + + /** + * Get permission + * + * @return string + */ + public function getPermission() + { + return $this->permission; + } +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/SourcesGroupsRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/SourcesGroupsRepository.php new file mode 100644 index 0000000..d77e48f --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/SourcesGroupsRepository.php @@ -0,0 +1,30 @@ +username = $username; + $this->password = $password; + $this->salt = $salt; + $this->roles = $roles; + $this->groups = new ArrayCollection(); + } + + /** + * Set activeFlag + * + * @param string $activeFlag + * @return Users + */ + public function setActiveFlag($activeFlag) + { + $this->activeFlag = $activeFlag; + + return $this; + } + + /** + * Get activeFlag + * + * @return string + */ + public function getActiveFlag() + { + return $this->activeFlag; + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set username + * + * @param string $username + * @return Users + */ + public function setUsername($username) + { + $this->username = $username; + + return $this; + } + + /** + * Get username + * + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Set password + * + * @param string $password + * @return Users + */ + public function setPassword($password) + { + $this->password = $password; + + return $this; + } + + /** + * Get password + * + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * Set salt + * + * @param string $salt + * @return Users + */ + public function setSalt($salt) + { + $this->salt = $salt; + + return $this; + } + + /** + * Get salt + * + * @return string + */ + public function getSalt() + { + return $this->salt; + } + + /** + * Set changePwdFlag + * + * @param string $changePwdFlag + * @return Users + */ + public function setChangePwdFlag($changePwdFlag) + { + $this->changePwdFlag = $changePwdFlag; + + return $this; + } + + /** + * Get changePwdFlag + * + * @return string + */ + public function getChangePwdFlag() + { + return $this->changePwdFlag; + } + + /** + * Set firstname + * + * @param string $firstname + * @return Users + */ + public function setFirstname($firstname) + { + $this->firstname = $firstname; + + return $this; + } + + /** + * Get firstname + * + * @return string + */ + public function getFirstname() + { + return $this->firstname; + } + + /** + * Set lastname + * + * @param string $lastname + * @return Users + */ + public function setLastname($lastname) + { + $this->lastname = $lastname; + + return $this; + } + + /** + * Get lastname + * + * @return string + */ + public function getLastname() + { + return $this->lastname; + } + + /** + * Set email + * + * @param string $email + * @return Users + */ + public function setEmail($email) + { + $this->email = $email; + + return $this; + } + + /** + * Get email + * + * @return string + */ + public function getEmail() + { + return $this->email; + } + + /** + * Set lang + * + * @param string $lang + * @return Users + */ + public function setLang($lang) + { + $this->lang = $lang; + + return $this; + } + + /** + * Get lang + * + * @return string + */ + public function getLang() + { + return $this->lang; + } + + /** + * Set lastLogin + * + * @param integer $lastLogin + * @return Users + */ + public function setLastLogin($lastLogin) + { + $this->lastLogin = $lastLogin; + + return $this; + } + + /** + * Get lastLogin + * + * @return integer + */ + public function getLastLogin() + { + return $this->lastLogin; + } + + /** + * Get useId + * + * @return integer + */ + public function getUseId() + { + return $this->useId; + } + + /** + * Set cus + * + * @param \AppBundle\Entities\Database\Customers $cus + * @return Users + */ + public function setCus(\AppBundle\Entities\Database\Customers $cus = null) + { + $this->cus = $cus; + + return $this; + } + + /** + * Get cus + * + * @return \AppBundle\Entities\Database\Customers + */ + public function getCus() + { + return $this->cus; + } + + /** + * Set gro + * + * @param \AppBundle\Entities\Database\Groups $gro + * @return Users + */ + public function setGro(\AppBundle\Entities\Database\Groups $gro = null) + { + $this->gro = $gro; + + return $this; + } + + /** + * Get gro + * + * @return \AppBundle\Entities\Database\Groups + */ + public function getGro() + { + return $this->gro; + } + + + /** + * @inheritDoc + */ + public function getRoles() + { + return array('ROLE_USER'); + } + + /** + * @inheritDoc + */ + public function eraseCredentials() + { + } + + /** + * @see \Serializable::serialize() + */ + public function serialize() + { + return serialize(array( + $this->useId, + )); + } + + /** + * @see \Serializable::unserialize() + */ + public function unserialize($serialized) + { + list ( + $this->useId, + ) = unserialize($serialized); + } + + public function isEqualTo(UserInterface $user) + { + return $this->useId === $user->getUseId(); + } + + + public function isAccountNonExpired() + { + return true; + } + + public function isAccountNonLocked() + { + return true; + } + + public function isCredentialsNonExpired() + { + return true; + } + + public function isEnabled() + { + if ($this->activeFlag == 'Y') { + return true; + } else { + return false; + } + } + + public function updateUserEntity($inputParams) + { + if (isset($inputParams['CUS'])) { + $this->setCus($inputParams['CUS']); + } + if (isset($inputParams['GRO'])) { + $this->setGro($inputParams['GRO']); + } + if (isset($inputParams['FIRSTNAME'])) { + $this->setFirstname($inputParams['FIRSTNAME']); + } + if (isset($inputParams['LASTNAME'])) { + $this->setLastname($inputParams['LASTNAME']); + } + if (isset($inputParams['EMAIL'])) { + $this->setEmail($inputParams['EMAIL']); + } + if (isset($inputParams['ACTIVE_FLAG'])) { + $this->setActiveFlag($inputParams['ACTIVE_FLAG']); + } + if (isset($inputParams['CHANGE_PWD_FLAG'])) { + $this->setChangePwdFlag($inputParams['CHANGE_PWD_FLAG']); + } + } + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/UsersIcons.php b/Symfony/3.0/src/AppBundle/Entities/Database/UsersIcons.php new file mode 100644 index 0000000..dd6067c --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/UsersIcons.php @@ -0,0 +1,190 @@ +useicoId; + } + + /** + * Set use + * + * @param \AppBundle\Entities\Database\Users $use + * @return UsersIcons + */ + public function setUse(\AppBundle\Entities\Database\Users $use = null) + { + $this->use = $use; + + return $this; + } + + /** + * Get use + * + * @return \AppBundle\Entities\Database\Users + */ + public function getUse() + { + return $this->use; + } + + /** + * Set app + * + * @param \AppBundle\Entities\Database\Applications $app + * @return UsersIcons + */ + public function setApp(\AppBundle\Entities\Database\Applications $app = null) + { + $this->app = $app; + + return $this; + } + + /** + * Get app + * + * @return \AppBundle\Entities\Database\Applications + */ + public function getApp() + { + return $this->app; + } + + /** + * Set iconVisibleFlag + * + * @param string $iconVisibleFlag + * @return UsersIcons + */ + public function setIconVisibleFlag($iconVisibleFlag) + { + $this->iconVisibleFlag = $iconVisibleFlag; + + return $this; + } + + /** + * Get iconVisibleFlag + * + * @return string + */ + public function getIconVisibleFlag() + { + return $this->iconVisibleFlag; + } + + /** + * Set iconXCoordinate + * + * @param string $iconXCoordinate + * @return UsersIcons + */ + public function setIconXCoordinate($iconXCoordinate) + { + $this->iconXCoordinate = $iconXCoordinate; + + return $this; + } + + /** + * Get iconXCoordinate + * + * @return string + */ + public function getIconXCoordinate() + { + return $this->iconXCoordinate; + } + + /** + * Set iconYCoordinate + * + * @param string $iconYCoordinate + * @return UsersIcons + */ + public function setIconYCoordinate($iconYCoordinate) + { + $this->iconYCoordinate = $iconYCoordinate; + + return $this; + } + + /** + * Get iconYCoordinate + * + * @return string + */ + public function getIconYCoordinate() + { + return $this->iconYCoordinate; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/UsersIconsRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/UsersIconsRepository.php new file mode 100644 index 0000000..59253bf --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/UsersIconsRepository.php @@ -0,0 +1,30 @@ +usepreId; + } + + /** + * Set widget + * + * @param string $widget + * @return UsersPreferences + */ + public function setWidget($widget) + { + $this->widget = $widget; + + return $this; + } + + /** + * Get widget + * + * @return string + */ + public function getWidget() + { + return $this->widget; + } + + /** + * Set statefulconfig + * + * @param string $statefulconfig + * @return UsersPreferences + */ + public function setStatefulconfig($statefulconfig) + { + $this->statefulconfig = $statefulconfig; + + return $this; + } + + /** + * Get statefulconfig + * + * @return string + */ + public function getStatefulconfig() + { + return $this->statefulconfig; + } + + /** + * Set senchaApp + * + * @param string $senchaApp + * @return UsersPreferences + */ + public function setSenchaApp($senchaApp) + { + $this->senchaApp = $senchaApp; + + return $this; + } + + /** + * Get senchaApp + * + * @return string + */ + public function getSenchaApp() + { + return $this->senchaApp; + } + + /** + * Set use + * + * @param \AppBundle\Entities\Database\Users $use + * @return UsersApplications + */ + public function setUse(\AppBundle\Entities\Database\Users $use = null) + { + $this->use = $use; + + return $this; + } + + /** + * Get gro + * + * @return \AppBundle\Entities\Database\Users + */ + public function getUse() + { + return $this->use; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/UsersPreferencesRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/UsersPreferencesRepository.php new file mode 100644 index 0000000..ab471ad --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/UsersPreferencesRepository.php @@ -0,0 +1,30 @@ +usesouId; + } + + /** + * Set use + * + * @param \AppBundle\Entities\Database\Users $use + * @return UsersSources + */ + public function setUse(\AppBundle\Entities\Database\Users $use = null) + { + $this->use = $use; + + return $this; + } + + /** + * Get gro + * + * @return \AppBundle\Entities\Database\Users + */ + public function getUse() + { + return $this->use; + } + + /** + * Set sou + * + * @param \AppBundle\Entities\Database\Sources $sou + * @return UsersSources + */ + public function setSou(\AppBundle\Entities\Database\Sources $sou = null) + { + $this->sou = $sou; + + return $this; + } + + /** + * Get sou + * + * @return \AppBundle\Entities\Database\Sources + */ + public function getSou() + { + return $this->sou; + } + + /** + * Set alertsFlag + * + * @param string $alertsFlag + * @return Users + */ + public function setAlertsFlag($alertsFlag) + { + $this->alertsFlag = $alertsFlag; + + return $this; + } + + /** + * Get alertsFlag + * + * @return string + */ + public function getAlertsFlag() + { + return $this->alertsFlag; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Entities/Database/UsersSourcesRepository.php b/Symfony/3.0/src/AppBundle/Entities/Database/UsersSourcesRepository.php new file mode 100644 index 0000000..13a90bf --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Entities/Database/UsersSourcesRepository.php @@ -0,0 +1,30 @@ +logger = $logger; + } + + public function onKernelException(GetResponseForExceptionEvent $event) { + //public function onKernelException(GetResponseEvent $event) { + $this->logger->warn('AppBundle\EventListener\ExceptionListerner.php\onKernelException() - Start'); + + // You get the exception object from the received event + $exception = $event->getException(); + $this->logger->warn('AppBundle\EventListener\ExceptionListerner.php\onKernelException() - Exception Message: ' . $exception->getMessage()); + $this->logger->warn('AppBundle\EventListener\ExceptionListerner.php\onKernelException() - Exception Code: ' . $exception->getCode()); + $this->logger->warn('AppBundle\EventListener\ExceptionListerner.php\onKernelException() - Exception Trace: ' . $exception->getTraceAsString()); + + $results = array("success" => false, "message" => $exception->getMessage(), "fullmessage" => $exception->getMessage(), "code" => $exception->getCode()); + $response = new JsonResponse($results); + $response->headers->set( 'X-Status-Code', 200 ); + + $event->setResponse($response); + } + +} +?> diff --git a/Symfony/3.0/src/AppBundle/EventListener/LoginListener.php b/Symfony/3.0/src/AppBundle/EventListener/LoginListener.php new file mode 100644 index 0000000..34e44d6 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/EventListener/LoginListener.php @@ -0,0 +1,114 @@ +tokenStorage = $tokenStorage; + $this->authorizationChecker = $authorizationChecker; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->requestStack = $requestStack; + } + + /** + * Do the magic. + * + * @param InteractiveLoginEvent $event + */ + public function onSecurityInteractiveLogin() { + $this->logger->info('AppBundle\EventListerner\LoginListerner.php\onSecurityInteractiveLogin() - User authenticated successfully'); + $userEntity = $this->tokenStorage->getToken()->getUser(); + $request = $this->requestStack->getCurrentRequest(); + + $this->logger->info('AppBundle\EventListerner\LoginListerner.php\onSecurityInteractiveLogin() - Username: ' . $userEntity->getUsername()); + $this->logger->info('AppBundle\EventListerner\LoginListerner.php\onSecurityInteractiveLogin() - Use_id: ' . $userEntity->getUseId()); + $this->logger->info('AppBundle\EventListerner\LoginListerner.php\onSecurityInteractiveLogin() - Change_Password_Flag: ' . $userEntity->getChangePwdFlag()); + $this->logger->info('AppBundle\EventListerner\LoginListerner.php\onSecurityInteractiveLogin() - Firstname: ' . $userEntity->getFirstName()); + $this->logger->info('AppBundle\EventListerner\LoginListerner.php\onSecurityInteractiveLogin() - IP: ' . $request->getClientIp()); + $this->logger->info('AppBundle\EventListerner\LoginListerner.php\onSecurityInteractiveLogin() - USER_AGENT: ' . $request->headers->get('User-Agent')); + + if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) { + // user has just logged in + } + + if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + // user has logged in using remember_me cookie + } + + $loginHistoryEntity = new LoginHistory(); + $loginHistoryEntity->setIpAddress($request->getClientIp()); + $loginHistoryEntity->setUsername($userEntity->getUsername()); + $userAgent = $request->headers->get('User-Agent'); + if (isset($userAgent)) { + $loginHistoryEntity->setUserAgent(substr($userAgent, 0, 49)); + } + $loginHistoryEntity->setDateAccess(new \DateTime("now")); + $this->em->persist($loginHistoryEntity); + + // Prepare login history container to get users connected/disconnected status + if (isset($userAgent) && $userAgent != '') { + $searchConnectedStatusEntity = $this->doctrine + ->getRepository('AppBundle:LoginHistory') + ->findOneBy(array('username' => $userEntity->getUsername(), 'userAgent' => 'CONNECTEDPING')); + if (!$searchConnectedStatusEntity) { + $searchConnectedStatusEntity = new LoginHistory(); + $searchConnectedStatusEntity->setUsername($userEntity->getUsername()); + $searchConnectedStatusEntity->setUserAgent('CONNECTEDPING'); + } + $searchConnectedStatusEntity->setIpAddress($request->getClientIp()); + $searchConnectedStatusEntity->setDateAccess(new \DateTime("now")); + $this->em->persist($searchConnectedStatusEntity); + } + $this->em->flush(); + } + +} + +?> diff --git a/Symfony/3.0/src/AppBundle/Resources/views/Dashboard/dashboard.html.php b/Symfony/3.0/src/AppBundle/Resources/views/Dashboard/dashboard.html.php new file mode 100644 index 0000000..7bfb03d --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Resources/views/Dashboard/dashboard.html.php @@ -0,0 +1,101 @@ +getEnvironment() == 'dev') { + $senchaAppPath = "../extjs/Dashboard/"; +} elseif ($app->getEnvironment() == 'preprod' || $app->getEnvironment() == 'test') { + $senchaAppPath = "../extjs/build/testing/WPAKT/"; +} else { + $senchaAppPath = "../extjs/build/production/WPAKT/"; +} +?> + + + + + Webcampak 3.0 Dashboard + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + getEnvironment() == 'dev' || $app->getEnvironment() == 'preprod' || $app->getEnvironment() == 'test') { ?> + + + + + + + + + getEnvironment() == 'dev') { ?> + + + + + + + + + + diff --git a/Symfony/3.0/src/AppBundle/Resources/views/Desktoproot/desktoproot-ext5.1.html.php b/Symfony/3.0/src/AppBundle/Resources/views/Desktoproot/desktoproot-ext5.1.html.php new file mode 100644 index 0000000..d081917 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Resources/views/Desktoproot/desktoproot-ext5.1.html.php @@ -0,0 +1,56 @@ + +getEnvironment() == 'dev') { + $senchaAppPath = "../extjs/Desktop/"; +} elseif ($app->getEnvironment() == 'preprod' || $app->getEnvironment() == 'preprod') { + $senchaAppPath = "../extjs/build/testing/WpakD/"; +} else { + $senchaAppPath = "../extjs/build/production/WpakD/"; +} +?> + + + + + Webcampak 3.0 Desktop + + + + + + + + + + + + + + + + getEnvironment() == 'dev' || $app->getEnvironment() == 'preprod' || $app->getEnvironment() == 'testing') { ?> + + + + + + + getEnvironment() == 'dev') { ?> + + + + + + + + + + + + + + + + diff --git a/Symfony/3.0/src/AppBundle/Resources/views/Desktoproot/desktoproot.html.php b/Symfony/3.0/src/AppBundle/Resources/views/Desktoproot/desktoproot.html.php new file mode 100644 index 0000000..64054a7 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Resources/views/Desktoproot/desktoproot.html.php @@ -0,0 +1,140 @@ + +getEnvironment() == 'dev') { + $senchaAppPath = "../extjs/Desktop/"; +} elseif ($app->getEnvironment() == 'preprod' || $app->getEnvironment() == 'test') { + $senchaAppPath = "../extjs/build/testing/WPAKD/"; +} else { + $senchaAppPath = "../extjs/build/production/WPAKD/"; +} +?> + + + + + Webcampak 3.0 Desktop + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + getEnvironment() == 'dev' || $app->getEnvironment() == 'preprod' || $app->getEnvironment() == 'test') { ?> + + + + + + + + + getEnvironment() == 'dev') { ?> + + + + + + + + + + + diff --git a/Symfony/3.0/src/AppBundle/Resources/views/Download/index.html.php b/Symfony/3.0/src/AppBundle/Resources/views/Download/index.html.php new file mode 100644 index 0000000..8dbee8e --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Resources/views/Download/index.html.php @@ -0,0 +1,36 @@ + + + + +"; + // Is the file a directory or a file + echo ""; + + // Link to the file or directory + echo ""; + + // Display size + echo ""; + echo ""; + } +?> + +
"; + echo $file['type']; + echo ""; + echo "" . $file['relativePath']; + if (is_dir($file['realPath'])) { + echo "/"; + } + echo ""; + echo ""; + echo $file['fileSize']; + echo "
+ + diff --git a/Symfony/3.0/src/AppBundle/Resources/views/Emails/resetpassword.html.twig b/Symfony/3.0/src/AppBundle/Resources/views/Emails/resetpassword.html.twig new file mode 100644 index 0000000..dd3b52f --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Resources/views/Emails/resetpassword.html.twig @@ -0,0 +1,14 @@ +Hello {{ username }}!

+ +We have received a password request, and generated a new password for you.

+ +Your credentials are:
+Username: {{ username }}
+Password: {{ newPassword }}

+ +You will be requested to change this password next time you connect.

+ +Best Regards,
+Webcampak team,

+ +This password request has been initiated by IP: {{ currentIP }}

diff --git a/Symfony/3.0/src/AppBundle/Resources/views/Phpinfo/index.html.php b/Symfony/3.0/src/AppBundle/Resources/views/Phpinfo/index.html.php new file mode 100644 index 0000000..82530b9 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Resources/views/Phpinfo/index.html.php @@ -0,0 +1,6 @@ +getEnvironment(); + +echo phpinfo(); + +?> diff --git a/Symfony/3.0/src/AppBundle/Resources/views/Security/login.html.php b/Symfony/3.0/src/AppBundle/Resources/views/Security/login.html.php new file mode 100644 index 0000000..6883e46 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Resources/views/Security/login.html.php @@ -0,0 +1,54 @@ + +getEnvironment() == 'dev') { + $senchaAppPath = "../extjs/Desktop/"; +} elseif ($app->getEnvironment() == 'preprod' || $app->getEnvironment() == 'preprod') { + $senchaAppPath = "../extjs/build/testing/WPAKD/"; +} else { + $senchaAppPath = "../extjs/build/production/WPAKD/"; +} +?> + + + + + Webcampak 3.0 Desktop + + + + + + + + + + + + + + getEnvironment() == 'dev' || $app->getEnvironment() == 'preprod' || $app->getEnvironment() == 'testing') { ?> + + + + + + + getEnvironment() == 'dev') { ?> + + + + + + + + + + + + + + + + diff --git a/Symfony/3.0/src/AppBundle/Services/AlertsService.php b/Symfony/3.0/src/AppBundle/Services/AlertsService.php new file mode 100644 index 0000000..885ea0c --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/AlertsService.php @@ -0,0 +1,81 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + } + + //Returns the list of users and sources with the alert flag enabled + public function getUsersSourcesWithAlertsFlag() { + $this->logger->info('AppBundle\Services\AlertsService\getUsersWithAlertsFlag() - Start'); + + $sqlQuery = " + SELECT + USE.USE_ID USE_ID + , USE.EMAIL EMAIL + , USESOU.ALERTS_FLAG ALERTS_FLAG + , SOU.SOURCEID SOURCEID + , SOU.NAME SOURCENAME + FROM + USERS USE + LEFT JOIN USERS_SOURCES USESOU ON USE.USE_ID = USESOU.USE_ID + LEFT JOIN SOURCES SOU ON USESOU.SOU_ID = SOU.SOU_ID + WHERE USESOU.ALERTS_FLAG = 'Y' + ORDER BY USE.USERNAME + "; + return $this->doctrine + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery); + } + + public function getSingleUsersSourcesWithAlertsFlag() { + $this->logger->info('AppBundle\Services\AlertsService\getUsersWithAlertsFlag() - Start'); + + $sqlQuery = " + SELECT + USE.USE_ID USE_ID + , USE.EMAIL EMAIL + , USESOU.ALERTS_FLAG ALERTS_FLAG + FROM + USERS USE + LEFT JOIN USERS_SOURCES USESOU ON USE.USE_ID = USESOU.USE_ID + WHERE USESOU.ALERTS_FLAG = 'Y' AND USE.EMAIL != '' + GROUP BY USE.EMAIL + ORDER BY USE.USERNAME + "; + return $this->doctrine + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery); + } + + public function getUserSourcesWithAlertsFlag($useId) { + $this->logger->info('AppBundle\Services\AlertsService\getUsersWithAlertsFlag() - Start'); + + $sqlQuery = " + SELECT + SOU.SOURCEID SOURCEID + , SOU.NAME SOURCENAME + FROM + USERS_SOURCES USESOU + LEFT JOIN SOURCES SOU ON USESOU.SOU_ID = SOU.SOU_ID + WHERE USESOU.USE_ID = :useId AND USESOU.ALERTS_FLAG = 'Y' + "; + return $this->doctrine + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('useId' => $useId)); + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/ConfigurationService.php b/Symfony/3.0/src/AppBundle/Services/ConfigurationService.php new file mode 100644 index 0000000..143dfde --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/ConfigurationService.php @@ -0,0 +1,325 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->sourceService = $sourceService; + $this->userService = $userService; + $this->logService = $logService; + $this->paramDirLog = $paramDirLog; + $this->jmsSerializer = $jmsSerializer; + } + + public function saveConfigurationChange($configFile, $configName, $configNewValue, $container) { + $this->logger->info('AppBundle\Services\ConfigurationService\saveConfigurationChange() - Start'); + $this->logger->info('AppBundle\Services\ConfigurationService\saveConfigurationChange() - File: ' . $configFile); + + $userEntity = $this->tokenStorage->getToken()->getUser(); + + $convert = explode("\n", file_get_contents($configFile)); + $arraySize = count($convert); + for ($i=0;$i<$arraySize;$i++) { + if (strpos($convert[$i],'#EDIT:') !== false) { + $convert[$i] = '#EDIT: Last modified by ' . $userEntity->getUsername() . ' on ' . date(DATE_RFC822); + } else if (isset($convert[$i][0]) && $convert[$i][0] != "#") { + $wecampakConf = explode("=",$convert[$i]); + if (str_replace(' ', '', $wecampakConf[0]) == $configName) { + //Specific case if the config is a calendar day + if (strpos($configName, "cfgcronday") !== false) {$configNewValue = str_replace(',', '","', $configNewValue);} + $convert[$i] = $configName . '="' . $configNewValue . '" '; + } + } + } + $f=fopen($configFile, "w"); + $arraySize = count($convert); + for ($i=0;$i<$arraySize;$i++) { + if ($convert[$i] != "") { + fwrite($f, $convert[$i] . "\n"); + } + } + fclose($f); + + //In some situations additional actions need to be performed + //Update GPHOTO Owner + if ($configName == "cfgsourcegphotoowner") { + $sourceConfigurationRaw = parse_ini_file($configFile, FALSE, INI_SCANNER_RAW); + $gphotoCommand = new GphotoCommand(); + $gphotoCommand->setContainer($container); + $input = new ArrayInput(array('--port' => $sourceConfigurationRaw['cfgsourcegphotocameraportdetail'], '--owner' => $configNewValue)); + $output = new BufferedOutput(); + $resultCode = $gphotoCommand->run($input, $output); + $commandOutput = explode("\n", $output->getBuffer()); + foreach($commandOutput as $commandOutputLine) { + $this->logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\saveConfigurationChange() - Gphoto2 owner Console Subprocess: ' . $commandOutputLine); + } + $this->logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\saveConfigurationChange() - Gphoto2 owner Command Result code: ' . $resultCode); + } + + //Update Crontab + if ($configName == "cfgcroncaptureinterval" || $configName == "cfgcroncapturevalue") { + $sourceCronCommand = new SourceCronCommand(); + $sourceCronCommand->setContainer($container); + $input = new ArrayInput(array()); + $output = new BufferedOutput(); + $resultCode = $sourceCronCommand->run($input, $output); + $commandOutput = explode("\n", $output->getBuffer()); + foreach($commandOutput as $commandOutputLine) { + $this->logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\saveConfigurationChange() - Cron update Console Subprocess: ' . $commandOutputLine); + } + $this->logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\saveConfigurationChange() - Cron update Command Result code: ' . $resultCode); + } + + //Update FTP Accounts + if ($configName == "cfglocalftppass") { + $sourceFTPCommand = new SourceFTPCommand(); + $sourceFTPCommand->setContainer($container); + $input = new ArrayInput(array()); + $output = new BufferedOutput(); + $resultCode = $sourceFTPCommand->run($input, $output); + $commandOutput = explode("\n", $output->getBuffer()); + foreach($commandOutput as $commandOutputLine) { + $this->logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\saveConfigurationChange() - FTP update Console Subprocess: ' . $commandOutputLine); + } + $this->logger->info('AppBundle\Controller\Desktop\AccesscontrolSourcesController.php\saveConfigurationChange() - FTP update Command Result code: ' . $resultCode); + } + } + + + public function openConfigFile($configurationFile) { + return parse_ini_file($configurationFile, FALSE, INI_SCANNER_RAW); + } + + public function getSourceConfiguration($sourceId, $configurationFile, $configurationSettingsFile) { + $userEntity = $this->tokenStorage->getToken()->getUser(); + + if ($this->sourceService->isUserAllowed($sourceId)) { + $userPermissions = $this->userService->getUserPermissions($userEntity); + if (is_file($configurationFile)) { + $sourceConfigurationRaw = self::openConfigFile($configurationFile); + $configurationSettingsJson = file_get_contents($configurationSettingsFile); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + + $sourceconfigurationValues = array(); + foreach($sourceConfigurationRaw as $key=>$value) { + $parameterSetting = $configurationSettings->findParameterByName($key); + if ($parameterSetting !== false && $parameterSetting->getName() == $key) { + $this->logger->info('AppBundle\Services\ConfigurationService\getSourceConfiguration() - Parameter Name : ' . $parameterSetting->getName() . ' - Permission: ' . $parameterSetting->getPermission()); + if (in_array($parameterSetting->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + $this->logger->info('AppBundle\Services\ConfigurationService\getSourceConfiguration() - Adding Parameter: ' . $key . ' Value: ' . $value); + $value = trim(str_replace("\"", "", $value)); + array_push($sourceconfigurationValues, array('NAME' => $key, 'VALUE' => $value, 'SOURCEID' => $sourceId)); + } else { + $this->logger->info('AppBundle\Services\ConfigurationService\getSourceConfiguration() - Parameter not allowed'); + } + } + } + $results['results'] = $sourceconfigurationValues; + $results['total'] = count($sourceconfigurationValues); + } else { + $results = array("success" => false, "title" => "Source Configuration", "message" => "Unable to access source config file"); + } + } else { + $results = array("success" => false, "title" => "Access Denied", "message" => "You are not allowed to access this source"); + } + return $results; + } + + public function updateSourceConfiguration($clientIP, $sourceId, $receivedName, $receivedValue, $configurationFile, $configurationSettingsFile, $container) { + $userEntity = $this->tokenStorage->getToken()->getUser(); + if ($this->sourceService->isUserAllowed($sourceId)) { + $userPermissions = $this->userService->getUserPermissions($userEntity); + if (is_file($configurationFile)) { + $sourceConfigurationRaw = self::openConfigFile($configurationFile); + + $oldValue = trim(str_replace("\"", "", $sourceConfigurationRaw[$receivedName])); + $configurationSettingsJson = file_get_contents($configurationSettingsFile); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + $parameterSetting = $configurationSettings->findParameterByName($receivedName); + if ($parameterSetting->getName() == $receivedName) { + $this->logger->info('AppBundle\Services\ConfigurationService\updateSourceConfiguration() - Parameter Name : ' . $parameterSetting->getName() . ' - Permission: ' . $parameterSetting->getPermission()); + if (in_array($parameterSetting->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + $this->logService->logConfigurationChange( + $clientIP + , $sourceId + , $configurationFile + , $receivedName + , $receivedValue + , $oldValue); + self::saveConfigurationChange($configurationFile, $receivedName, $receivedValue, $container); + $results = array("success" => true, "message" => "Configuration successfully updated"); + } else { + $results = array("success" => false, "message" => "User not allowed to edit parameter: " . $receivedName); + } + } + } else { + $results = array("success" => false, "message" => "Unable to access source config file"); + } + } else { + $results = array("success" => false, "message" => "User not allowed to access source"); + } + return $results; + } + + public function getSectionConfiguration($configurationSettingsFile) { + $userEntity = $this->tokenStorage->getToken()->getUser(); + + $userPermissions = $this->userService->getUserPermissions($userEntity); + + $configurationSettingsJson = file_get_contents($configurationSettingsFile); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + + $sectionsAllowed = array(); + foreach($configurationSettings->getSections() as $section) { + $this->logger->info('AppBundle\Controller\Desktop\SCCaptureController.php\getSectionConfiguration() - Section Name : ' . $section->getName() . ' - Permission: ' . $section->getPermission()); + if (in_array($section->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + $this->logger->info('AppBundle\Controller\Desktop\SCCaptureController.php\getSectionConfiguration() - Adding Section: ' . $section->getName()); + array_push($sectionsAllowed, array('NAME' => $section->getName())); + } else { + $this->logger->info('AppBundle\Controller\Desktop\SCCaptureController.php\getSectionConfiguration() - Section not allowed'); + } + } + $results['results'] = $sectionsAllowed; + $results['total'] = count($sectionsAllowed); + + return $results; + } + + public function getConfigurationTabs($sysConfig, $userPermissions) { + $this->logger->info('AppBundle\Services\ConfigurationService\configurationSettingsFile() - Start'); + + $userEntity = $this->tokenStorage->getToken()->getUser(); + + $tabsAllowed = array(); + $configurationSettingsJson = file_get_contents($sysConfig . "config-source.json"); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + if (in_array($configurationSettings->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + array_push($tabsAllowed, array('NAME' => $configurationSettings->getName())); + } + $configurationSettingsJson = file_get_contents($sysConfig . "config-source-video.json"); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + if (in_array($configurationSettings->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + array_push($tabsAllowed, array('NAME' => $configurationSettings->getName())); + } + $configurationSettingsJson = file_get_contents($sysConfig . "config-source-videocustom.json"); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + if (in_array($configurationSettings->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + array_push($tabsAllowed, array('NAME' => $configurationSettings->getName())); + } + $configurationSettingsJson = file_get_contents($sysConfig . "config-source-videopost.json"); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + if (in_array($configurationSettings->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + array_push($tabsAllowed, array('NAME' => $configurationSettings->getName())); + } + $configurationSettingsJson = file_get_contents($sysConfig . "config-source-ftpservers.json"); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + if (in_array($configurationSettings->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + array_push($tabsAllowed, array('NAME' => $configurationSettings->getName())); + } + + return $tabsAllowed; + } + + + public function getSystemConfiguration($configurationFile, $configurationSettingsFile) { + $userEntity = $this->tokenStorage->getToken()->getUser(); + + $userPermissions = $this->userService->getUserPermissions($userEntity); + if (is_file($configurationFile)) { + $sourceConfigurationRaw = self::openConfigFile($configurationFile); + $configurationSettingsJson = file_get_contents($configurationSettingsFile); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + + $sourceconfigurationValues = array(); + foreach($sourceConfigurationRaw as $key=>$value) { + $parameterSetting = $configurationSettings->findParameterByName($key); + $this->logger->info('AppBundle\Services\ConfigurationService\getSystemConfiguration() - Parameter Key : ' . $key); + $this->logger->info('AppBundle\Services\ConfigurationService\getSystemConfiguration() - Parameter Setting : ' . serialize($parameterSetting)); + if ($parameterSetting !== false && $parameterSetting->getName() == $key) { + $this->logger->info('AppBundle\Services\ConfigurationService\getSystemConfiguration() - Parameter Name : ' . $parameterSetting->getName() . ' - Permission: ' . $parameterSetting->getPermission()); + if (in_array($parameterSetting->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + $this->logger->info('AppBundle\Services\ConfigurationService\getSystemConfiguration() - Adding Parameter: ' . $key . ' Value: ' . $value); + $value = trim(str_replace("\"", "", $value)); + array_push($sourceconfigurationValues, array('NAME' => $key, 'VALUE' => $value)); + } else { + $this->logger->info('AppBundle\Services\ConfigurationService\getSystemConfiguration() - Parameter not allowed'); + } + } + } + $results['results'] = $sourceconfigurationValues; + $results['total'] = count($sourceconfigurationValues); + } else { + $results = array("success" => false, "title" => "Source Configuration", "message" => "Unable to access source config file"); + } + return $results; + } + + public function updateSystemConfiguration($clientIP, $receivedName, $receivedValue, $configurationFile, $configurationSettingsFile, $container) { + $userEntity = $this->tokenStorage->getToken()->getUser(); + $userPermissions = $this->userService->getUserPermissions($userEntity); + if (is_file($configurationFile)) { + $sourceConfigurationRaw = self::openConfigFile($configurationFile); + + $oldValue = trim(str_replace("\"", "", $sourceConfigurationRaw[$receivedName])); + $configurationSettingsJson = file_get_contents($configurationSettingsFile); + $configurationSettings = $this->jmsSerializer->deserialize($configurationSettingsJson, 'AppBundle\Entities\Configuration\Configuration', 'json'); + $parameterSetting = $configurationSettings->findParameterByName($receivedName); + if ($parameterSetting->getName() == $receivedName) { + $this->logger->info('AppBundle\Services\ConfigurationService\updateSystemConfiguration() - Parameter Name : ' . $parameterSetting->getName() . ' - Permission: ' . $parameterSetting->getPermission()); + if (in_array($parameterSetting->getPermission(), $userPermissions) || $userEntity->getUsername() == 'root') { + $this->logService->logConfigurationChange( + $clientIP + , null + , $configurationFile + , $receivedName + , $receivedValue + , $oldValue); + self::saveConfigurationChange($configurationFile, $receivedName, $receivedValue, $container); + $results = array("success" => true, "message" => "Configuration successfully updated"); + } else { + $results = array("success" => false, "message" => "User not allowed to edit parameter: " . $receivedName); + } + } + } else { + $results = array("success" => false, "message" => "Unable to access source config file"); + } + + return $results; + } + + public function getSourceConfigurationParameterValue($configurationFile, $parameter) { + $this->logger->info('AppBundle\Services\ConfigurationService\getSourceConfigurationParameterValue() - Start'); + $this->logger->info('AppBundle\Services\ConfigurationService\getSourceConfigurationParameterValue() - File: ' . $configurationFile); + if (is_file($configurationFile)) { + $sourceConfigurationRaw = self::openConfigFile($configurationFile); + foreach($sourceConfigurationRaw as $key=>$value) { + if ($key == $parameter) { + $value = trim(str_replace("\"", "", $value)); + $this->logger->info('AppBundle\Services\ConfigurationService\getSourceConfigurationParameterValue() - Key: ' . $key . ' = ' . $value); + return $value; + } + } + } + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/DevicesService.php b/Symfony/3.0/src/AppBundle/Services/DevicesService.php new file mode 100644 index 0000000..0fb456b --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/DevicesService.php @@ -0,0 +1,123 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->configurationService = $configurationService; + $this->paramDirEtc = $paramDirEtc; + } + + public function getGphotoDir() { + $this->logger->info('AppBundle\Services\DevicesService\getGphotoDir()'); + $configurationFile = $this->paramDirEtc . 'config-general.cfg'; + $generalConfig = $this->configurationService->openConfigFile($configurationFile); + if (isset($generalConfig['cfggphotodir']) && $generalConfig['cfggphotodir'] != '') { + return $generalConfig['cfggphotodir']; + } else { + throw new \Exception("Gphoto2 bin directory has not been set"); + } + } + + public function getGphotoCapabilities() { + $this->logger->info('AppBundle\Services\DevicesService\getGphotoCapabilities()'); + + $outputtext = ''; + $process = new Process('gphoto2 --auto-detect'); + $process->run(); + foreach (explode("\n", $process->getOutput()) as $gphotoOutput) { + if (strpos($gphotoOutput,'usb:') !== false) { + $this->logger->info('AppBundle\Services\DevicesService\getGphotoCapabilities() - Gphoto Output:' . $gphotoOutput); + preg_match("/usb:...,.../", $gphotoOutput, $gphotoOutputUsbPort); + preg_match("/.+?(?=usb)/", $gphotoOutput, $gphotoOutputCameraName); + + if (isset($gphotoOutputCameraName[0])) { + $this->logger->info('AppBundle\Services\DevicesService\getGphotoCapabilities() - Gphoto Camera Name:' . $gphotoOutputCameraName[0]); + } + + if (isset($gphotoOutputUsbPort[0])) { + $this->logger->info('AppBundle\Services\DevicesService\getGphotoCapabilities() - Gphoto Port:' . $gphotoOutputUsbPort[0]); + $command = self::getGphotoDir() . 'gphoto2 --port ' . trim($gphotoOutputUsbPort[0]) . ' --abilities'; + $getGphotoAbilities = new Process($command); + $getGphotoAbilities->run(); + if (!$getGphotoAbilities->isSuccessful()) { + $this->logger->info('AppBundle\Services\DevicesService\getGphotoCapabilities(): Unable to access gphoto2'); + return false; + } + $outputtext = $getGphotoAbilities->getOutput() . '\n'; + } + } + } + return $outputtext; + } + + public function getGphotoList() { + $this->logger->info('AppBundle\Services\DevicesService\getGphotoList()'); + + $command = self::getGphotoDir() . 'gphoto2 --auto-detect'; + $getGphotoList = new Process($command); + $getGphotoList->run(); + if (!$getGphotoList->isSuccessful()) { + $this->logger->info('AppBundle\Services\DevicesService\getGphotoList(): Unable to access gphoto2'); + return false; + } + return $getGphotoList->getOutput(); + } + + public function getLsusb() { + $this->logger->info('AppBundle\Services\DevicesService\getLsusb()'); + $getLsUsb = new Process('lsusb'); + $getLsUsb->run(); + if (!$getLsUsb->isSuccessful()) { + $this->logger->info('AppBundle\Services\DevicesService\getLsusb(): Unable to access lsusb'); + return false; + } + return $getLsUsb->getOutput(); + } + + public function getDevices() { + $this->logger->info('AppBundle\Services\DevicesService\getDevices()'); + + $dbresults = array('GPHOTOLIST' => self::getGphotoList() + , 'LSUSB' => self::getLsusb() + , 'GPHOTOCAPABILITIES' => self::getGphotoCapabilities()); + + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return $results; + } + + public function getUsbPorts() { + $this->logger->info('AppBundle\Services\DevicesService\getUsbPorts()'); + + $detectedCameras = array(); + + $process = new Process('gphoto2 --auto-detect'); + $process->run(); + foreach (explode("\n", $process->getOutput()) as $gphotoOutput) { + if (strpos($gphotoOutput,'usb:') !== false) { + $this->logger->info('AppBundle\Services\DevicesService\getUsbPorts() - Gphoto Output:' . $gphotoOutput); + preg_match("/usb:...,.../", $gphotoOutput, $gphotoOutputUsbPort); + preg_match("/.+?(?=usb)/", $gphotoOutput, $gphotoOutputCameraName); + array_push($detectedCameras, array( + 'ID' => trim($gphotoOutputUsbPort[0]) + , 'NAME' => trim($gphotoOutputCameraName[0]) + //, 'NAME' => trim($gphotoOutputCameraName[0]) . ' (' . $gphotoOutputUsbPort[0] . ')' + )); + } + } + return $detectedCameras; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/DownloadService.php b/Symfony/3.0/src/AppBundle/Services/DownloadService.php new file mode 100644 index 0000000..8cf9dd7 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/DownloadService.php @@ -0,0 +1,97 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->templating = $templating; + $this->filesService = $filesService; + } + + public function serveDirectory($completePath) { + $this->logger->info('AppBundle\Services\DownloadService\serveDirectory() - Start'); + $finder = new Finder(); + $finder->in($completePath); + $finder->sortByType(); + $finder->depth('== 0'); + $filesArray = array(); + foreach ($finder as $file) { + $this->logger->info('AppBundle\Services\DownloadService\serveDirectory() - Found: ' . $file->getRelativePathname()); + $currentFile = array(); + if (is_dir($file->getRealpath())) {$currentFile['type'] = "[D]";} + else {$currentFile['type'] = "[F]";} + $currentFile['relativePath'] = $file->getRelativePathname(); + $currentFile['realPath'] = $file->getRealpath(); + $currentFile['fileSize'] = $this->filesService->getSymbolByQuantity(filesize($file->getRealpath())); + array_push($filesArray, $currentFile); + } + return $this->templating->renderResponse('AppBundle:Download:index.html.php', array('files' => $filesArray)); + } + + public function serveFile($completePath, $pictureWidth = null) { + $this->logger->info('AppBundle\Services\DownloadService\serveFile() - Path is a file'); + $fileFormat = pathinfo($completePath, PATHINFO_EXTENSION); + $allowedExtensions = array('png', 'jpg', 'raw', 'txt', 'jpeg', 'json', 'mp3', 'JPG', 'JPEG', 'RAW', 'CR2', 'mp4', 'avi'); + if (in_array($fileFormat, $allowedExtensions) && $pictureWidth === null) { + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $contentType = finfo_file($finfo, $completePath); + finfo_close($finfo); + $this->logger->info('AppBundle\Services\DownloadService\serveFile() - Extension: ' . $contentType); + return new StreamedResponse( + function () use ($completePath) { + readfile($completePath); + }, 200, array('Content-Type' => $contentType) + ); + } else if (intval($pictureWidth) > 0) { + $this->logger->info('AppBundle\Services\DownloadService\serveFile() - Path is a picture to be resized'); + //Resize an image on the fly and serves it as a streamed response + $originalPictureInfo = getimagesize($completePath); + $originalPictureWidth = $originalPictureInfo[0]; + $originalPictureHeight = $originalPictureInfo[1]; + $pictureHeight = intval($pictureWidth * $originalPictureHeight / $originalPictureWidth); + $this->logger->info('AppBundle\Services\DownloadService\serveFile() - Original Size: ' . $originalPictureWidth . 'x' . $originalPictureHeight); + $this->logger->info('AppBundle\Services\DownloadService\serveFile() - Target Size: ' . $pictureWidth . 'x' . $pictureHeight); + + $dstPicture = \imagecreatetruecolor($pictureWidth, $pictureHeight); + $srcPicture = \imagecreatefromjpeg($completePath); + \imagecopyresized($dstPicture, $srcPicture, 0, 0, 0, 0, $pictureWidth, $pictureHeight, $originalPictureWidth, $originalPictureHeight); + + $tmpPath = tempnam("/tmp", "PIC"); + \imagejpeg($dstPicture, $tmpPath); + + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $contentType = finfo_file($finfo, $completePath); + finfo_close($finfo); + $this->logger->info('AppBundle\Services\DownloadService\serveFile() - Extension: ' . $contentType); + + return new StreamedResponse( + function () use ($tmpPath) { + readfile($tmpPath); + unlink($tmpPath); + }, 200, array('Content-Type' => $contentType) + ); + } else { + $response = new Response(); + $response->setContent('

This type of file is not allowed

File type:' . $fileFormat . '

'); + $response->setStatusCode(Response::HTTP_OK); + $response->headers->set('Content-Type', 'text/html'); + return $response; + } + + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/EmailsService.php b/Symfony/3.0/src/AppBundle/Services/EmailsService.php new file mode 100644 index 0000000..eb0218e --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/EmailsService.php @@ -0,0 +1,140 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->sourceService = $sourceService; + $this->paramEmailFrom = $paramEmailFrom; + $this->dirSources = $dirSources; + $this->dirEmails = $dirEmails; + } + + public function validateDomain($emailAddress) { + $this->logger->info('AppBundle\Services\EmailsService\validateDomain() - Start'); + $this->logger->info('AppBundle\Services\EmailsService\validateDomain() - Validate Email address: ' . $emailAddress); + $domain = substr($emailAddress, strpos($emailAddress, '@') + 1); + if (checkdnsrr($domain) !== FALSE) { + $this->logger->info('AppBundle\Services\EmailsService\validateDomain() - Domain exists: ' . $domain); + return true; + } else { + $this->logger->info('AppBundle\Services\EmailsService\validateDomain() - Domain does not exist: ' . $domain); + return false; + } + } + + public function createEmailsArray($emailsString) { + $this->logger->info('AppBundle\Services\EmailsService\createEmailsArray() - Start'); + $this->logger->info('AppBundle\Services\EmailsService\createEmailsArray() - Emails String: ' . serialize($emailsString)); + + $emailPattern = '/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i'; + preg_match_all($emailPattern, $emailsString, $identifiedEmails); + $identifiedEmailsArray = array(); + foreach ($identifiedEmails[0] as $processEmail) { + $this->logger->info('AppBundle\Services\EmailsService\createEmailsArray() - Processing: ' . $processEmail); + if (self::validateDomain($processEmail) === false) { + throw new \Exception("The following email address appears incorrect:
" . $processEmail . "
Please correct or remove it and try again"); + } + $identifiedUsers = $this->doctrine->getRepository('AppBundle:Users')->findBy(array('email' => $processEmail)); + if (count($identifiedUsers) == 0 || count($identifiedUsers) > 1) { + $newEmail = array(); + $newEmail['email'] = $processEmail; + } else { + $newEmail = array(); + $newEmail['email'] = $processEmail; + $newEmail['name'] = $identifiedUsers[0]->getFirstname() . ' ' . $identifiedUsers[0]->getLastname(); + $this->logger->info('AppBundle\Services\EmailsService\createEmailsArray() - Found Alias: ' . $newEmail['name']); + } + array_push($identifiedEmailsArray, $newEmail); + } + if (count($identifiedEmailsArray) == 0) { + return null; + } else { + return $identifiedEmailsArray; + } + } + + public function prepareEmailForQueue($inputParams) { + $this->logger->info('AppBundle\Services\EmailsService\prepareEmailForQueue() - Start'); + + $receivedEmailFrom = trim($inputParams['EMAIL_FROM']); + $receivedEmailTo = $inputParams['EMAIL_TO']; + $receivedEmailCc = $inputParams['EMAIL_CC']; + $receivedSubject = $inputParams['SUBJECT']; + $receivedBody = $inputParams['BODY']; + if (isset($inputParams['BODYHTML']) && $inputParams['BODYHTML'] != '') { + $receivedBodyHtml = $inputParams['BODYHTML']; + } + $receivedAttachmentPath = $inputParams['ATTACHMENT_PATH']; + $receivedAttachmentName = $inputParams['ATTACHMENT_NAME']; + $receivedAttachmentSourceId = $inputParams['ATTACHMENT_SOURCEID']; + + $this->logger->info('AppBundle\Services\EmailsService\prepareEmailForQueue() - EMAIL_FROM: ' . $receivedEmailFrom); + + + + $userEntity = $this->tokenStorage->getToken()->getUser(); + + $newEmailContent = array(); + if ($userEntity->getEmail() != $this->paramEmailFrom) { + $this->logger->info('AppBundle\Services\EmailsService\prepareEmailForQueue() - FROM: Webcampak sent on behalf of: ' . $userEntity->getFirstname() . ' ' . $userEntity->getLastName()); + $newEmailContent['FROM']['name'] = 'Webcampak on behalf of ' . $userEntity->getFirstname() . ' ' . $userEntity->getLastName(); + $newEmailContent['FROM']['email'] = $userEntity->getEmail(); + } else { + $newEmailContent['FROM']['name'] = 'Webcampak'; + $newEmailContent['FROM']['email'] = $userEntity->getEmail(); + } + + $this->logger->info('AppBundle\Services\EmailsService\prepareEmailForQueue() - Create Email TO'); + $newEmailContent['TO'] = self::createEmailsArray($receivedEmailTo); + $this->logger->info('AppBundle\Services\EmailsService\prepareEmailForQueue() - Create Email CC'); + $newEmailContent['CC'] = self::createEmailsArray($receivedEmailCc); + + if ($userEntity->getEmail() != '') { + $newEmailContent['BODY'] = $receivedBody; + if (isset($receivedBodyHtml)) {$newEmailContent['BODYHTML'] = $receivedBodyHtml;} + $newEmailContent['SUBJECT'] = $receivedSubject; + + //Check if the user is allowed to access the source associated to the attachment being sent + if ($receivedAttachmentPath > '' && $receivedAttachmentName != '' && intval($receivedAttachmentSourceId) > 0) { + if ($this->sourceService->isUserAllowed($receivedAttachmentSourceId)) { + $attachmentFullPath = $this->dirSources . 'source' . $receivedAttachmentSourceId . $receivedAttachmentPath; + if (is_file($attachmentFullPath)) { + $newEmailContent['ATTACHMENTS'] = array(array('PATH' => $attachmentFullPath, 'NAME' => $receivedAttachmentName)); + } + } else { + throw new Exception("ERROR: You are not allowed to access this source (" . $receivedAttachmentSourceId . ")"); + } + } + + $currentDate = \DateTime::createFromFormat('U.u', microtime(true)); + + //Create a MD5 hash used to identify duplicate emails sent in one batch (and avoid spamming an email address by error). + $emailHash = md5(json_encode($newEmailContent['TO'], JSON_FORCE_OBJECT) . json_encode($newEmailContent['CC'], JSON_FORCE_OBJECT) . json_encode($newEmailContent['SUBJECT'], JSON_FORCE_OBJECT)); + + $newEmail = array('status' => 'queued', 'hash' => $emailHash, 'content' => $newEmailContent, 'logs' => array()); + + $fs = new Filesystem(); + $fs->dumpFile($this->dirEmails . '/queued/' . $currentDate->format("Y-m-d_His_u") . '.json', json_encode($newEmail, JSON_FORCE_OBJECT)); + $results = array("success" => true, "message" => "Email queued"); + } else { + $results = array("success" => false, "message" => "Your email address is missing in the system, unable to send email"); + } + + return $results; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/FilesService.php b/Symfony/3.0/src/AppBundle/Services/FilesService.php new file mode 100644 index 0000000..0871bbc --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/FilesService.php @@ -0,0 +1,24 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + } + + public function getSymbolByQuantity($bytes) { + $symbols = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); + $exp = floor(log($bytes)/log(1024)); + return sprintf('%.1f '.$symbols[$exp], ($bytes/pow(1024, floor($exp)))); + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/FtpService.php b/Symfony/3.0/src/AppBundle/Services/FtpService.php new file mode 100644 index 0000000..9b9608b --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/FtpService.php @@ -0,0 +1,133 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->configurationService = $configurationService; + } + + public function getServersFromConfigFile($configFile, $receivedSourceid = null) { + $this->logger->info('AppBundle\Services\FtpService\getServersFromConfigFile() - File: ' . $configFile); + if (is_file($configFile)) { + $sourceConfigurationRaw = $this->configurationService->openConfigFile($configFile); + $sourceconfigurationFTPServers = array(); + foreach($sourceConfigurationRaw as $key=>$value) { + if ($key != "cfgftpserverslistnb") { + $value = trim(str_replace("\"", "", $value)); + $serverID = str_replace('cfgftpserverslist', '', $key); + $serverParameters = explode(",", $value); + if($serverParameters[0][0] == " ") {$serverName = substr($serverParameters[0],1);} else {$serverName = $serverParameters[0];} + if($serverParameters[1][0] == " ") {$serverHost = substr($serverParameters[1],1);} else {$serverHost = $serverParameters[1];} + if($serverParameters[2][0] == " ") {$serverUsername = substr($serverParameters[2],1);} else {$serverUsername = $serverParameters[2];} + if($serverParameters[3][0] == " ") {$serverPassword = substr($serverParameters[3],1);} else {$serverPassword = $serverParameters[3];} + if($serverParameters[4][0] == " ") {$serverDirectory = substr($serverParameters[4],1);} else {$serverDirectory = $serverParameters[4];} + if($serverParameters[5][0] == " ") {$serverActive = substr($serverParameters[5],1);} else {$serverActive = $serverParameters[5];} + if($serverParameters[6][0] == " ") {$serverXferEnable = substr($serverParameters[6],1);} else {$serverXferEnable = $serverParameters[6];} + if($serverParameters[7][0] == " ") {$serverXferThreads = substr($serverParameters[7],1);} else {$serverXferThreads = $serverParameters[7];} + array_push($sourceconfigurationFTPServers, array( + 'ID' => $serverID + , 'NAME' => $serverName + , 'HOST' => $serverHost + , 'USERNAME' => $serverUsername + , 'PASSWORD' => $serverPassword + , 'DIRECTORY' => $serverDirectory + , 'ACTIVE' => $serverActive + , 'XFERENABLE' => $serverXferEnable + , 'XFERTHREADS' => $serverXferThreads + , 'SOURCEID' => $receivedSourceid + ) + ); + } + } + return $sourceconfigurationFTPServers; + } else { + return array("success" => false, "title" => "Source Access", "message" => "Unable to access source config file"); + } + } + + public function updateServersConfigFile($configFile, $sourceconfigurationFTPServers, $deleteRecordId = null) { + $userEntity = $this->tokenStorage->getToken()->getUser(); + $this->logger->info('AppBundle\Services\FtpService\updateServersConfigFile() - File: ' . $configFile); + + $cfgftpserverslistnb = count($sourceconfigurationFTPServers); + + $f=fopen($configFile, "w"); + fwrite($f, "#EDIT: Last modified by " . $userEntity->getUsername() . " on " . date(DATE_RFC822) . "\n"); + fwrite($f, "cfgftpserverslistnb=" . $cfgftpserverslistnb . "\n"); + foreach ($sourceconfigurationFTPServers as $idx=>$ftpServer) { + if ($ftpServer['ID'] != $deleteRecordId) { + $configName = "cfgftpserverslist" . $ftpServer['ID']; + $configValue = "\"" . $ftpServer['NAME'] . "\",\"" . $ftpServer['HOST'] . "\",\"" . $ftpServer['USERNAME'] . "\",\"" . $ftpServer['PASSWORD'] . "\",\"" . $ftpServer['DIRECTORY'] . "\",\"" . $ftpServer['ACTIVE']. "\",\"" . $ftpServer['XFERENABLE']. "\",\"" . $ftpServer['XFERTHREADS']. "\""; + fwrite($f, $configName . "=" . $configValue . "\n"); + } + } + fclose($f); + } + + public function updateFtpServer($sourceconfigurationFTPServers, $inputParams) { + $this->logger->info('AppBundle\Services\FtpService\updateFtpServer()'); + foreach ($sourceconfigurationFTPServers as $idx=>$ftpServer) { + if ($ftpServer['ID'] == $inputParams['ID']) { + $sourceconfigurationFTPServers[$idx]['NAME'] = $inputParams['NAME']; + $sourceconfigurationFTPServers[$idx]['HOST'] = $inputParams['HOST']; + $sourceconfigurationFTPServers[$idx]['USERNAME'] = $inputParams['USERNAME']; + $sourceconfigurationFTPServers[$idx]['PASSWORD'] = $inputParams['PASSWORD']; + $sourceconfigurationFTPServers[$idx]['DIRECTORY'] = $inputParams['DIRECTORY']; + $sourceconfigurationFTPServers[$idx]['ACTIVE'] = $inputParams['ACTIVE']; + $sourceconfigurationFTPServers[$idx]['XFERENABLE'] = $inputParams['XFERENABLE']; + $sourceconfigurationFTPServers[$idx]['XFERTHREADS'] = $inputParams['XFERTHREADS']; + $sourceconfigurationFTPServers[$idx]['SOURCEID'] = $inputParams['SOURCEID']; + } + } + return $sourceconfigurationFTPServers; + } + + public function getFtpServerbyId($sourceconfigurationFTPServers, $serverId) { + $this->logger->info('AppBundle\Services\FtpService\updateFtpServer()'); + $returnFtpServer = null; + foreach ($sourceconfigurationFTPServers as $idx=>$ftpServer) { + if ($ftpServer['ID'] == $serverId) { + $returnFtpServer = $ftpServer; + } + } + return $returnFtpServer; + } + + public function getLastServerId($sourceconfigurationFTPServers) { + $this->logger->info('AppBundle\Services\FtpService\updateFtpServer()'); + $lastId = 0; + foreach ($sourceconfigurationFTPServers as $idx=>$ftpServer) { + if ($ftpServer['ID'] >= $lastId) { + $lastId = $ftpServer['ID']; + } + } + return $lastId; + } + + public function calculateFTPServerHash($sourceconfigurationFTPServers, $serverId) { + $this->logger->info('AppBundle\Services\FtpService\calculateFTPServerHash()'); + # Hash is an md5 of the remote host and the username + $identifiedFtpServer = null; + foreach ($sourceconfigurationFTPServers as $idx=>$ftpServer) { + if ($ftpServer['ID'] == $serverId) { + $identifiedFtpServer = $ftpServer; + } + } + return md5($identifiedFtpServer['HOST'] . $identifiedFtpServer['USERNAME']); + + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/GroupsService.php b/Symfony/3.0/src/AppBundle/Services/GroupsService.php new file mode 100644 index 0000000..0ce73fa --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/GroupsService.php @@ -0,0 +1,111 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + } + + + public function getCurrentApplicationsByGroId($groId) { + $this->logger->info('AppBundle\Services\GroupsService\getCurrentApplicationsByGroId()'); + $sqlQuery = " + SELECT + APP.APP_ID APP_ID + , APP.NAME NAME + , APP.NOTES NOTES + , GROAPP.GRO_ID GRO_ID + , GROAPP.GROAPP_ID GROAPP_ID + FROM + GROUPS_APPLICATIONS GROAPP + LEFT JOIN APPLICATIONS APP ON APP.APP_ID = GROAPP.APP_ID + WHERE + GROAPP.GRO_ID = :receivedGroId + ORDER BY APP.NAME + "; + + $dbresults = $this->doctrine + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('receivedGroId' => $groId)); + + return $dbresults; + } + + public function getAvailableApplicationsByGroId($groId) { + $this->logger->info('AppBundle\Services\GroupsService\getAvailableApplicationsByGroId()'); + $sqlQuery = " + SELECT + APP.APP_ID APP_ID + , APP.NAME NAME + , APP.NOTES NOTES + , :receivedGroId GRO_ID + FROM + APPLICATIONS APP + WHERE + APP_ID NOT IN (SELECT APP_ID FROM GROUPS_APPLICATIONS WHERE GRO_ID = :receivedGroId) + ORDER BY APP.NAME + "; + $dbresults = $this->doctrine + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('receivedGroId' => $groId)); + return $dbresults; + } + + public function getCurrentPermissionsByGroId($groId) { + $this->logger->info('AppBundle\Services\GroupsService\getCurrentPermissionsByGroId()'); + $sqlQuery = " + SELECT + PER.PER_ID PER_ID + , PER.NAME NAME + , PER.NOTES NOTES + , GROPER.GRO_ID GRO_ID + , GROPER.GROPER_ID GROPER_ID + FROM + GROUPS_PERMISSIONS GROPER + LEFT JOIN PERMISSIONS PER ON PER.PER_ID = GROPER.PER_ID + WHERE + GROPER.GRO_ID = :receivedGroId + ORDER BY PER.NAME + "; + + $dbresults = $this->doctrine + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('receivedGroId' => $groId)); + + return $dbresults; + } + + public function getAvailablePermissionsByGroId($groId) { + $this->logger->info('AppBundle\Services\GroupsService\getAvailablePermissionsByGroId()'); + $sqlQuery = " + SELECT + PER.PER_ID PER_ID + , PER.NAME NAME + , PER.NOTES NOTES + , :receivedGroId GRO_ID + FROM + PERMISSIONS PER + WHERE + PER_ID NOT IN (SELECT PER_ID FROM GROUPS_PERMISSIONS WHERE GRO_ID = :receivedGroId) + ORDER BY PER.NAME + "; + $dbresults = $this->doctrine + ->getManager() + ->getConnection() + ->fetchAll($sqlQuery, array('receivedGroId' => $groId)); + return $dbresults; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/LogService.php b/Symfony/3.0/src/AppBundle/Services/LogService.php new file mode 100644 index 0000000..4472f06 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/LogService.php @@ -0,0 +1,41 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->paramDirLog = $paramDirLog; + } + + public function logConfigurationChange($clientIP, $sourceId, $configFile, $configName, $configNewValue, $configOldValue) { + $this->logger->info('AppBundle\Services\LogService\logConfigurationChange() - Start'); + $userEntity = $this->tokenStorage->getToken()->getUser(); + $this->logger->info('AppBundle\Services\LogService\logConfigurationChange() - Parameter: ' . $configName . ' Old Value: ' . $configOldValue . ' New Value: ' . $configNewValue); + + $logLine = array( + 'DATE' => date(DATE_RFC822) + , 'USERNAME' => $userEntity->getUsername() + , 'IP' => $clientIP + , 'TYPE' => 'CONFIG' + , 'FILE' => $configFile + , 'PARAMETER' => $configName + , 'OLD' => $configOldValue + , 'NEW' => $configNewValue + ); + + if ($sourceId === null) {$logFile = 'edit-config-general-';} + else {$logFile = 'edit-source-' . $sourceId . '-';} + + file_put_contents($this->paramDirLog . $logFile . date("Y-m-d") . ".log", json_encode($logLine, JSON_FORCE_OBJECT) . "\r\n", FILE_APPEND | LOCK_EX); + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/PhidgetsService.php b/Symfony/3.0/src/AppBundle/Services/PhidgetsService.php new file mode 100644 index 0000000..523de0c --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/PhidgetsService.php @@ -0,0 +1,39 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + } + + public function getPhidgetsPorts($configFile) { + $this->logger->info('AppBundle\Services\PhidgetsService\getPhidgetsPorts() - Start'); + + if (is_file($configFile)) { + $phidgetsensors = array(); + array_push($phidgetsensors, array('ID' => 0, 'NAME' => 'Disabled')); + $getconfig = parse_ini_file($configFile, FALSE, INI_SCANNER_RAW); + foreach($getconfig as $key=>$value) { + $value = trim(str_replace("\"", "", $value)); + if (substr($key, 0,20) == "cfgphidgetsensortype" && $key != "cfgphidgetsensortypenb") { + $srcfgparameters = explode(",", $value); + if($srcfgparameters[0][0] == " ") {$sensorName = substr($srcfgparameters[0],1);} else {$sensorName = $srcfgparameters[0];} + array_push($phidgetsensors, array('ID' => substr($key, 20,21), 'NAME' => $sensorName)); + } + } + return $phidgetsensors; + } else { + return array("success" => false, "title" => "Source Access", "message" => "Unable to access global config file"); + } + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/PicturesDirectoryService.php b/Symfony/3.0/src/AppBundle/Services/PicturesDirectoryService.php new file mode 100644 index 0000000..b103bf1 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/PicturesDirectoryService.php @@ -0,0 +1,310 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->paramDirSources = $paramDirSources; + } + + public function getHoursFromCaptureDirectory($receivedSourceid = null, $receivedDay = null) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getHoursFromCaptureDirectory() - Source: ' . $receivedSourceid . ' - Day: ' . $receivedDay); + if (intval($receivedSourceid) > 0) { + if ($receivedDay === null) { + //If no day received, automatically looking for the latest directory with pictures + $receivedDay = self::getLatestPictureDay($receivedSourceid); + } + + $picturesDirectory = $this->paramDirSources . 'source' . $receivedSourceid . '/pictures/' . $receivedDay . '/'; + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getHoursFromCaptureDirectory() - Looking inside directory: ' . $picturesDirectory); + + $checkpics = self::listPicturesInDirectory($picturesDirectory, 'jpg', 'time'); + + $dbresults = array(); + for ($i=0;$i<24;$i++) { + $tmpresults = array(); + if ($i < 10) {$currenthour = "0" . $i;} else {$currenthour = (string)$i;} + $tmpresults['id'] = $currenthour; + for ($j=0;$j<60;$j++) { + if ($j < 10) {$currentminute = "0" . $j;} else {$currentminute = (string)$j;} + if (isset($checkpics[$currenthour][$currentminute])) { + if ($checkpics[$currenthour][$currentminute] != "0") { + $tmpresults[$currentminute] = $checkpics[$currenthour][$currentminute]; + } + } else { + $tmpresults[$currentminute] = "0"; + } + } + array_push($dbresults, $tmpresults); + } + + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return $results; + } else { + $results = array("success" => false, "title" => "Source Access", "message" => "Unable to access the source"); + } + } + + public function getFirstPictureDayAmongstAllSources() { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getFirstPictureDayAmongstAllSources()'); + + $firstDay = null; + $availableSources = $this->doctrine + ->getRepository('AppBundle:Sources')->findAll(); + foreach ($availableSources as $sourceEntity) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getFirstPictureDayAmongstAllSources() - Processing Source: ' . $sourceEntity->getSourceId()); + $sourceFirstDay = self::getFirstPictureDay($sourceEntity->getSourceId()); + if (($firstDay === null || $sourceFirstDay < $firstDay) && $sourceFirstDay !== null) { + $firstDay = $sourceFirstDay; + } + } + return $firstDay; + + } + + public function getFirstPictureDay($sourceId) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getFirstPictureDay()'); + $firstDay = null; + $finder = new Finder(); + $finder->directories(); + $finder->sortByName(); + $finder->directories()->name('20*'); + $finder->in($this->paramDirSources . 'source' . $sourceId . '/pictures/'); + foreach ($finder as $directory) { + $finderFiles = new Finder(); + $finderFiles->files(); + $finderFiles->files()->name('20*.jpg'); + $finderFiles->in($this->paramDirSources . 'source' . $sourceId . '/pictures/' . $directory->getFilename() . '/'); + if (iterator_count($finderFiles) > 0) { + $firstDay = $directory->getFilename(); + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getFirstPictureDay() - First day with pictures is: ' . $firstDay . ' with ' . iterator_count($finderFiles) . ' JPG pictures'); + break; + } + } + return $firstDay; + } + + public function getLatestPictureDay($sourceId) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getLatestPictureDay()'); + $baseDir = $this->paramDirSources . 'source' . $sourceId . '/pictures/'; + if (is_dir($baseDir)) { + $latestDay = null; + $finder = new Finder(); + $finder->directories(); + $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($b->getRealpath(), $a->getRealpath()); }); + $finder->directories()->name('20*'); + $finder->in($this->paramDirSources . 'source' . $sourceId . '/pictures/'); + foreach ($finder as $directory) { + $finderFiles = new Finder(); + $finderFiles->files(); + $finderFiles->files()->name('20*.jpg'); + $finderFiles->in($this->paramDirSources . 'source' . $sourceId . '/pictures/' . $directory->getFilename() . '/'); + if (iterator_count($finderFiles) > 0) { + $latestDay = $directory->getFilename(); + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getLatestPictureDay() - Latest day with pictures is: ' . $latestDay . ' with ' . iterator_count($finderFiles) . ' JPG pictures'); + break; + } + } + return $latestDay; + } + return null; + } + + public function getLatestPictureForSource($sourceId) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getLatestPictureForSource()'); + + $latestDay = self::getLatestPictureDay($sourceId); + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getLatestPictureForSource() - ' . $sourceId . ' - Latest Day: ' . $latestDay); + + $latestPicture = self::latestPictureFile($sourceId, $latestDay); + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getLatestPictureForSource() - ' . $sourceId . ' - Latest Picture: ' . $latestPicture); + + return $latestPicture; + } + + public function latestPictureFile($sourceId, $pictureDay) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\latestPictureFile()'); + $baseDir = $this->paramDirSources . 'source' . $sourceId . '/pictures/' . $pictureDay . '/'; + if (is_dir($baseDir)) { + $latestPicture = null; + $finder = new Finder(); + $finder->files(); + $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($b->getRealpath(), $a->getRealpath()); }); + $finder->files()->name('20*.jpg'); + $finder->in($this->paramDirSources . 'source' . $sourceId . '/pictures/' . $pictureDay . '/'); + foreach ($finder as $file) { + if (getimagesize($file->getRealpath()) !== false) { + $latestPicture = $file->getFilename(); + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getLatestPictureDay() - Latest picture is: ' . $latestPicture . ' on Day: ' . $pictureDay); + break; + } + } + return $latestPicture; + } + return null; + } + + public function listPicturesInDirectory($picturesDirectory, $fileFormat = 'jpg', $outputType = "flat") { + //outputType takes two values: + // - flat to return an array of Filenames + // - time to return a multidimensional array using hours and minutes + $this->logger->info('AppBundle\Services\PicturesDirectoryService\listPicturesInDirectory()'); + $finder = new Finder(); + $finder->files(); + $finder->sortByName(); + $finder->files()->name('20*.' . $fileFormat); + $finder->in($picturesDirectory); + $checkpics = array(); + foreach ($finder as $file) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\listPicturesInDirectory() - Looking at file: ' . $file->getFilename()); + if ($outputType == "time") { + $currenthour = substr($file->getFilename(), 8,2); + $currentminute = substr($file->getFilename(),10,2); + //SEND BACK FILENAME + $checkpics[$currenthour][$currentminute] = $file->getFilename(); + } else if ($outputType == "size") { + $fileTime = substr($file->getFilename(), 0,12); + $checkpics[$fileTime] = array( + 'filename' => $file->getFilename() + , 'size' => $file->getSize() + ); + } else { + array_push($checkpics, $file->getFilename()); + } + } + return $checkpics; + } + + public function listDaysBetweenTwoDates($startDate, $endDate) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\listDaysBetweenTwoDates()'); + // takes two dates formatted as YYYYMMDD and creates an inclusive array of the dates between the from and to dates. + // Taken from: http://stackoverflow.com/questions/4312439/php-return-all-dates-between-two-dates-in-an-array + $dateRange=array(); + $iDateFrom=mktime(1,0,0,substr($startDate,4,2),substr($startDate,6,2),substr($startDate,0,4)); + $iDateTo=mktime(1,0,0,substr($endDate,4,2),substr($endDate,6,2),substr($endDate,0,4)); + if ($iDateTo>=$iDateFrom) { + array_push($dateRange,date('Ymd',$iDateFrom)); // first entry + while ($iDateFrom<$iDateTo) { + $iDateFrom+=86400; // add 24 hours + array_push($dateRange,date('Ymd',$iDateFrom)); + } + } + return $dateRange; + } + + public function buildDatePickerDisabledDays($allDays, $firstDay, $lastDay) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\listDaysBetweenTwoDates()'); + + $dateRange = self::listDaysBetweenTwoDates($firstDay, $lastDay); + $disabledDays = null; + foreach($dateRange as $idx=>$currentday) { + if (!isset($allDays[$currentday])) { + if ($disabledDays !== null) { $disabledDays = $disabledDays . ", ";} + $disabledDays = $disabledDays . "'" . substr($currentday, 4,2) . "/" . substr($currentday, 6,2) . "/" . substr($currentday, 0,4) . "'"; + } + } + return $disabledDays; + } + + public function convertDay($day) { + if ($day !== null) { + $day = mktime(8, 8, 8, substr($day, 4,2), substr($day, 6,2), substr($day, 0,4)) * 1000; + } + return $day; + } + + public function getDaysFromCaptureDirectory($receivedSourceid = null) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getDaysFromCaptureDirectory() - Source: ' . $receivedSourceid); + if (intval($receivedSourceid) > 0) { + + $finder = new Finder(); + $finder->directories(); + $finder->sortByName(); + $finder->directories()->name('20*'); + $finder->in($this->paramDirSources . 'source' . $receivedSourceid . '/pictures/'); + $firstDay = null; + $lastDay = null; + $allDays = array(); + foreach ($finder as $directory) { + $finderFiles = new Finder(); + $finderFiles->files(); + $finderFiles->files()->name('20*.jpg'); + $finderFiles->in($this->paramDirSources . 'source' . $receivedSourceid . '/pictures/' . $directory->getFilename() . '/'); + if (iterator_count($finderFiles) > 0) { + if ($firstDay === null) {$firstDay = $directory->getFilename();} + $lastDay = $directory->getFilename(); + $allDays[$lastDay] = iterator_count($finderFiles); + $this->logger->info('AppBundle\Services\PicturesDirectoryService\getHoursFromCaptureDirectory() - ' . iterator_count($finderFiles) . ' JPG Pictures available on: ' . $directory->getFilename()); + } + } + + $results['results'] = array( + 'MIN' => self::convertDay($firstDay) + , 'MAX' => self::convertDay($lastDay) + , 'DISABLED' => self::buildDatePickerDisabledDays($allDays, $firstDay, $lastDay + )); + $results['total'] = 1; + return $results; + } else { + $results = array("success" => false, "title" => "Source Access", "message" => "Unable to access the source"); + } + } + + public function countPicturesForDay($sourceId, $day) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\countPicturesForDay()'); + if (is_dir($this->paramDirSources . 'source' . $sourceId . '/pictures/' . $day . '/')) { + $finderFiles = new Finder(); + $finderFiles->files(); + $finderFiles->files()->name('20*.jpg'); + $finderFiles->in($this->paramDirSources . 'source' . $sourceId . '/pictures/' . $day . '/'); + return iterator_count($finderFiles); + } else { + return 0; + } + } + + /** + * Calculate the total size of pictures (raw and jpg) for a particular day + * + * @param int $sourceId The SOURCEID of the source + * @param int $day Day in numeric format (20160324 for example) + * + * @return int Total size in bytes for the specified day + */ + public function sizePicturesForDay($sourceId, $day) { + $this->logger->info('AppBundle\Services\PicturesDirectoryService\sizePicturesForDay()'); + $totalSize = 0; + if (is_dir($this->paramDirSources . 'source' . $sourceId . '/pictures/' . $day . '/')) { + $finderFiles = new Finder(); + $finderFiles->files(); + $finderFiles->files()->name('20*.jpg'); + $finderFiles->in($this->paramDirSources . 'source' . $sourceId . '/pictures/' . $day . '/'); + foreach($finderFiles as $file) { + $totalSize += $file->getSize(); + } + } + if (is_dir($this->paramDirSources . 'source' . $sourceId . '/pictures/raw/' . $day . '/')) { + $finderFiles = new Finder(); + $finderFiles->files(); + $finderFiles->files()->name('20*.raw'); + $finderFiles->in($this->paramDirSources . 'source' . $sourceId . '/pictures/raw/' . $day . '/'); + foreach($finderFiles as $file) { + $totalSize += $file->getSize(); + } + } + return $totalSize; + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/PicturesService.php b/Symfony/3.0/src/AppBundle/Services/PicturesService.php new file mode 100644 index 0000000..947d861 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/PicturesService.php @@ -0,0 +1,195 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + $this->picturesDirectoryService = $picturesDirectoryService; + $this->configurationService = $configurationService; + $this->paramDirSources = $paramDirSources; + $this->etcDir = $etcDir; + + } + + public function getPicture($receivedSourceid = null, $receivedPictureDate = null) { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Source: ' . $receivedSourceid . ' - PictureDate: ' . $receivedPictureDate); + if (intval($receivedSourceid) > 0) { + $tmpresults = array(); + + $latestDay = $this->picturesDirectoryService->getLatestPictureDay($receivedSourceid); + $latestPicture = $this->picturesDirectoryService->latestPictureFile($receivedSourceid, $latestDay); + $tmpresults['LAST'] = basename($latestPicture); + + if ($receivedPictureDate === null) { + $receivedPictureDate = basename($latestPicture); + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Latest Picture for source: ' . $receivedPictureDate); + } + + if ($receivedPictureDate != "") { + $pictureDay = substr($receivedPictureDate, 0,8); + $pictureDirectory = $this->paramDirSources . 'source' . $receivedSourceid . '/pictures/' . $pictureDay . '/'; + + $listPictures = $this->picturesDirectoryService->listPicturesInDirectory($pictureDirectory, 'jpg', 'flat'); + + $tmpresults['PICTURE'] = $receivedPictureDate; + $tmpresults['PICTUREEXIF'] = ''; + if (is_file($this->paramDirSources . 'source' . $receivedSourceid . '/pictures/' . $pictureDay . '/' . $receivedPictureDate)) { + $tmpresults['PICTUREJPGSIZE'] = filesize($this->paramDirSources . 'source' . $receivedSourceid . '/pictures/' . $pictureDay . '/' . $receivedPictureDate); + $tmpresults['PICTUREEXIF'] = json_encode(@exif_read_data($this->paramDirSources . 'source' . $receivedSourceid . '/pictures/' . $pictureDay . '/' . $receivedPictureDate, 'ANY_TAG')); + } + if (is_file($this->paramDirSources . 'source' . $receivedSourceid . '/pictures/raw/' . $pictureDay . '/' . substr($receivedPictureDate, 0,14) . '.raw')) { + $tmpresults['PICTURERAWSIZE'] = filesize($this->paramDirSources . 'source' . $receivedSourceid . '/pictures/raw/' . $pictureDay . '/' . substr($receivedPictureDate, 0,14) . '.raw'); + $tmpresults['PICTUREEXIF'] = json_encode(@exif_read_data($this->paramDirSources . 'source' . $receivedSourceid . '/pictures/raw/' . $pictureDay . '/' . substr($receivedPictureDate, 0,14) . '.raw', 'ANY_TAG')); + } + + //Get Picture Date + $sourceTimezone = $this->configurationService->getSourceConfigurationParameterValue($this->etcDir . 'config-source' . $receivedSourceid . '.cfg', 'cfgcapturetimezone'); + $tmpresults['PICTUREDATE'] = \DateTime::createFromFormat('YmdHis', substr($tmpresults['PICTURE'], 0,14), new \DateTimeZone($sourceTimezone)); + if ($tmpresults['PICTUREDATE'] instanceof \DateTime) { + $tmpresults['PICTUREDATE'] = $tmpresults['PICTUREDATE']->format('c'); + } else { + $tmpresults['PICTUREDATE'] = false; + } + + if ($tmpresults['PICTURE'] == $tmpresults['LAST']) { + $tmpresults['LAST'] = null; + } + + $originalPictureInfo = getimagesize($pictureDirectory . $receivedPictureDate); + $tmpresults['PICTUREWIDTH'] = $originalPictureInfo[0]; + $tmpresults['PICTUREHEIGHT'] = $originalPictureInfo[1]; + $tmpresults['ZOOMLEVEL'] = 0; + + $nbPictures = count($listPictures); + for($i=0;$i<$nbPictures; $i++) { + if (substr($listPictures[$i], 0,14) == substr($receivedPictureDate, 0,14)) { + if (isset($listPictures[$i-15])) { + if ($listPictures[$i-15] != "") { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Thumbnail 1 is: ' . $listPictures[$i-15]); + $tmpresults['THUMB1'] = $listPictures[$i-15]; + } + } else { + $tmpresults['THUMB1'] = null; + } + if (isset($listPictures[$i-10])) { + if ($listPictures[$i-10] != "") { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Thumbnail 2 is: ' . $listPictures[$i-10]); + $tmpresults['THUMB2'] = $listPictures[$i-10]; + } + } else { + $tmpresults['THUMB2'] = null; + } + if (isset($listPictures[$i-5])) { + if ($listPictures[$i-5] != "") { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Thumbnail 3 is: ' . $listPictures[$i-5]); + $tmpresults['THUMB3'] = $listPictures[$i-5]; + } + } else { + $tmpresults['THUMB3'] = null; + } + if (isset($listPictures[$i-1])) { + if ($listPictures[$i-1] != "") { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Previous picture is: ' . $listPictures[$i-1]); + $tmpresults['PREVIOUS'] = $listPictures[$i-1]; + } + } else { + $tmpresults['PREVIOUS'] = null; + } + if (isset($listPictures[$i+1])) { + if ($listPictures[$i+1] != "") { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Next picture is: ' . $listPictures[$i+1]); + $tmpresults['NEXT'] = $listPictures[$i+1]; + } + } else { + $tmpresults['NEXT'] = null; + } + if (isset($listPictures[$i+5])) { + if ($listPictures[$i+5] != "") { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Thumbnail 4 is: ' . $listPictures[$i+5]); + $tmpresults['THUMB4'] = $listPictures[$i+5]; + } + } else { + $tmpresults['THUMB4'] = null; + } + if (isset($listPictures[$i+10])) { + if ($listPictures[$i+10] != "") { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Thumbnail 5 is: ' . $listPictures[$i+10]); + $tmpresults['THUMB5'] = $listPictures[$i+10]; + } + } else { + $tmpresults['THUMB5'] = null; + } + + if (isset($listPictures[$i+15])) { + if ($listPictures[$i+15] != "") { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Thumbnail 6 is: ' . $listPictures[$i+15]); + $tmpresults['THUMB6'] = $listPictures[$i+15]; + } + } else { + $tmpresults['THUMB6'] = null; + } + } + } + + $dbresults = array(); + array_push($dbresults, $tmpresults); + + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + } else { + $results = array("success" => false, "title" => "No Pictures", "message" => "No pictures have been captured yet for the source"); + } + } else { + $results = array("success" => false, "title" => "Source Error", "message" => "Unable to access the source"); + } + return $results; + } + + public function getSensors($receivedSourceid = null, $receivedPictureDate = null) { + $this->logger->info('AppBundle\Services\PicturesService\getPicture() - Source: ' . $receivedSourceid . ' - PictureDate: ' . $receivedPictureDate); + if (intval($receivedSourceid) > 0) { + + if ($receivedPictureDate === null) { + $receivedPictureDate = $this->picturesDirectoryService->getLatestPictureDay($receivedSourceid); + } + + $tmpresults = array(); + + $pictureDay = substr($receivedPictureDate, 0,8); + $pictureDirectory = $this->paramDirSources . 'source' . $receivedSourceid . '/pictures/' . $pictureDay . '/'; + + $finder = new Finder(); + $finder->files(); + $finder->sortByName(); + $finder->files()->name('Sensor-*.png'); + $finder->in($pictureDirectory); + $sensorCount = 1; + foreach ($finder as $file) { + $this->logger->info('AppBundle\Services\PicturesService\getSensors() - Looking at file: ' . $file->getFilename()); + $tmpresults['SENSOR' . $sensorCount] = $pictureDay . "/" . $file->getFilename(); + $sensorCount++; + } + + $dbresults = array(); + array_push($dbresults, $tmpresults); + + $results['results'] = $dbresults; + $results['total'] = count($dbresults); + return $results; + } else { + $results = array("success" => false, "title" => "Source Error", "message" => "Unable to access the source"); + } + } + +} diff --git a/Symfony/3.0/src/AppBundle/Services/ResponseService.php b/Symfony/3.0/src/AppBundle/Services/ResponseService.php new file mode 100644 index 0000000..bff1f01 --- /dev/null +++ b/Symfony/3.0/src/AppBundle/Services/ResponseService.php @@ -0,0 +1,37 @@ +tokenStorage = $tokenStorage; + $this->em = $doctrine->getManager(); + $this->logger = $logger; + $this->connection = $doctrine->getConnection(); + $this->doctrine = $doctrine; + } + + public function htmlDoesNotExist($page) { + $this->logger->info('AppBundle\Services\ResponseService\logConfigurationChange() - Start'); + $response = new Response(); + $response->setContent('

This page does not exists

' . $page . '

'); + $response->setStatusCode(Response::HTTP_OK); + $response->headers->set('Content-Type', 'text/html'); + return $response; + } + + public function htmlUnableToAccessContent($page) { + $response = new Response(); + $response->setContent('

Unable to access content

Possible reasons: