INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,guest,meta,hidden) VALUES
	 ('XADDMLS','get_daemons_list','PADMDMN','getDaemonsList','','administration/daemons','administration','Get daemons list','EXE','',1,false,NULL,false),
	 ('BDAENEW','administration_daemons_new_row','PADMDMN','','','administration/daemons','administration','New row button','BUT','fas fa-plus-square',1,false,NULL,false),
	 ('BDAESAV','administration_daemons_save','PADMDMN','','','administration/daemons','administration','Daemons save button','BUT','fas fa-save',1,false,NULL,false),
	 ('BDAEDEL','administration_daemons_del','PADMDMN','','','administration/daemons','administration','Daemons delete button','BUT','fas fa-trash',1,false,NULL,false),
	 ('XDAEUPD','update_daemon','PADMDMN','updDaemon','','administration/daemons','administration','Update daemon row','EXE','',1,false,NULL,false),
	 ('XDAENEW','add_new_daemon','PADMDMN','addDaemon','','administration/daemons','administration','Add daemon row','EXE','',1,false,NULL,false),
	 ('XDAEDEL','delete_daemon','PADMDMN','delDaemon','','administration/daemons','administration','Delete daemon row','EXE','',1,false,NULL,false),
	 ('BDAEENA','administration_daemons_enable','PADMDMN','','','administration/daemons','administration','Button to enable daemon','BUT','fas fa-toggle-on',1,false,NULL,false),
	 ('BDAEDIS','administration_daemons_disable','PADMDMN','','','administration/daemons','administration','Button to disable daemon','BUT','fas fa-toggle-off',1,false,NULL,false),
	 ('BDAESTR','administration_daemons_start','PADMDMN','','','administration/daemons','administration','Button to start daemon','BUT','fas fa-play-circle',1,false,NULL,false);
INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,guest,meta,hidden) VALUES
	 ('BDAESTP','administration_daemons_stop','PADMDMN','','','administration/daemons','administration','Button to start daemon','BUT','fas fa-stop-circle',1,false,NULL,false),
	 ('PADMDMN','administration_daemons','MADM','getObjects','','administration/daemons','administration','Permission to access daemons page','PAG','fas fa-tasks',5000,false,NULL,false);

INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,guest,meta,hidden) VALUES
	 ('SADMMSC','','MADM','','','','administration','Non GUI section to handle misc execute permissions','SEC','',1,false,NULL,false),
	 ('XDAESTR','misc_daemon_start','SADMMSC','daemonStart','','','administration','Execute daemon start','EXE','',1,false,NULL,false),
	 ('XDAESTP','misc_daemon_stop','SADMMSC','daemonStop','','','administration','Execute daemon stop','EXE','',1,false,NULL,false),
	 ('XDAEENA','misc_daemon_enable','SADMMSC','daemonEnable','','','administration','Execute daemon enable (at system startutp)','EXE','',1,false,NULL,false),
	 ('XDAEDIS','misc_daemon_disable','SADMMSC','daemonDisable','','','administration','Execute daemon disable (at system startutp)','EXE','',1,false,NULL,false),
	 ('XMSCMOD','misc_get_modules','SADMMSC','getModules',NULL,'administration/daemons','administration','Get installed modules list','EXE',NULL,1,false,NULL,false),
	 ('XMSCPLD','misc_get_payloads','SADMMSC','getPayloads',NULL,'administration/daemons','administration','Get installed payloads for all modules.','EXE',NULL,1,false,NULL,false);

-- core daemons
CREATE TABLE public.core_daemons (
	id serial4 NOT NULL,
	"name" varchar(255) NOT NULL,
	"module" varchar(255) NOT NULL,
	payload varchar(255) NOT NULL,
	did varchar(3) NOT NULL,
	enabled bool NOT NULL DEFAULT false,
	last_execution_time information_schema."time_stamp" NULL DEFAULT now(),
	properties jsonb NOT NULL DEFAULT '{}'::json,
	started bool NOT NULL DEFAULT false
);
