1+ <?php
2+ /**
3+ * sites_web_domain_plugin plugin
4+ *
5+ * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
6+ */
7+
8+ class sites_web_domain_plugin {
9+
10+ var $ plugin_name = 'sites_web_domain_plugin ' ;
11+ var $ class_name = 'sites_web_domain_plugin ' ;
12+
13+ /*
14+ This function is called when the plugin is loaded
15+ */
16+ function onLoad () {
17+ global $ app ;
18+ //Register for the events
19+ $ app ->plugin ->registerEvent ('sites:web_domain:on_after_insert ' ,'sites_web_domain_plugin ' ,'sites_web_domain_edit ' );
20+ }
21+
22+ /*
23+ Function to create the sites_web_domain rule and insert it into the custom rules
24+ */
25+ function sites_web_domain_edit ($ event_name , $ page_form ) {
26+ global $ app , $ conf ;
27+
28+ // make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
29+ // also make sure that the user can not delete domain created by a admin
30+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' && isset ($ page_form ->dataRecord ["client_group_id " ])) {
31+ $ client_group_id = intval ($ page_form ->dataRecord ["client_group_id " ]);
32+ $ app ->db ->query ("UPDATE web_domain SET sys_groupid = $ client_group_id, sys_perm_group = 'ru' WHERE domain_id = " .$ page_form ->id );
33+ }
34+ if ($ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ]) && isset ($ page_form ->dataRecord ["client_group_id " ])) {
35+ $ client_group_id = intval ($ page_form ->dataRecord ["client_group_id " ]);
36+ $ app ->db ->query ("UPDATE web_domain SET sys_groupid = $ client_group_id, sys_perm_group = 'riud' WHERE domain_id = " .$ page_form ->id );
37+ }
38+ // Get configuration for the web system
39+ $ app ->uses ("getconf " );
40+ $ web_config = $ app ->getconf ->get_server_config (intval ($ page_form ->dataRecord ['server_id ' ]),'web ' );
41+ $ document_root = str_replace ("[website_id] " ,$ page_form ->id ,$ web_config ["website_path " ]);
42+ // get the ID of the client
43+ if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' && !$ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
44+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
45+ $ client = $ app ->db ->queryOneRecord ("SELECT client_id FROM sys_group WHERE sys_group.groupid = $ client_group_id " );
46+ $ client_id = intval ($ client ["client_id " ]);
47+ } else {
48+ //$client_id = intval($this->dataRecord["client_group_id"]);
49+ $ client = $ app ->db ->queryOneRecord ("SELECT client_id FROM sys_group WHERE sys_group.groupid = " .intval ($ page_form ->dataRecord ["client_group_id " ]));
50+ $ client_id = intval ($ client ["client_id " ]);
51+ }
52+
53+ // Set the values for document_root, system_user and system_group
54+ $ system_user = $ app ->db ->quote ('web ' .$ page_form ->id );
55+ $ system_group = $ app ->db ->quote ('client ' .$ client_id );
56+ $ document_root = $ app ->db ->quote (str_replace ("[client_id] " ,$ client_id ,$ document_root ));
57+ $ php_open_basedir = str_replace ("[website_path] " ,$ document_root ,$ web_config ["php_open_basedir " ]);
58+ $ php_open_basedir = $ app ->db ->quote (str_replace ("[website_domain] " ,$ page_form ->dataRecord ['domain ' ],$ php_open_basedir ));
59+ $ htaccess_allow_override = $ app ->db ->quote ($ web_config ["htaccess_allow_override " ]);
60+ $ sql = "UPDATE web_domain SET system_user = ' $ system_user', system_group = ' $ system_group', document_root = ' $ document_root', allow_override = ' $ htaccess_allow_override', php_open_basedir = ' $ php_open_basedir' WHERE domain_id = " .$ page_form ->id ;
61+ $ app ->db ->query ($ sql );
62+ }
63+ }
0 commit comments