-
Notifications
You must be signed in to change notification settings - Fork 2
/
hosting.install
635 lines (542 loc) · 20 KB
/
hosting.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
<?php
/**
* @file
* Define database schemas and update functions for the hosting module.
*/
// HOSTING_MAX_ALIAS_LENGTH is defined here:
require_once(dirname(__FILE__) . '/hosting.module');
/**
* Implements hook_uninstall().
*/
function hosting_uninstall() {
variable_del('hosting_dispatch_last_run');
variable_del('hosting_features_form_settings');
variable_del('hosting_queue_tasks_items');
variable_del('hosting_default_db_server');
variable_del('hosting_own_db_server');
variable_del('hosting_update_6008_run');
variable_del('hosting_dispatch_enabled');
variable_del('hosting_cron_backup');
variable_del('hosting_task_update_6000_run');
variable_del('hosting_package_update_6002_run');
variable_del('hosting_package_update_6004_run');
variable_del('hosting_platform_update_6004_run');
variable_del('hosting_queued_process_started');
variable_del('hosting_queue_tasks_enabled');
}
/**
* Implements hook_schema().
*/
function hosting_schema() {
$schema['hosting_context'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'name' => array(
'type' => 'varchar',
'length' => HOSTING_MAX_ALIAS_LENGTH,
'not null' => TRUE,
),
),
'primary key' => array('nid'),
'unique keys' => array(
'name' => array('name'),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function hosting_install() {
hosting_create_roles();
variable_set('error_level', ERROR_REPORTING_HIDE);
}
/**
* Implements hook_update_N().
*
* Set weight for hosting module.
*/
function hosting_update_1() {
$ret = array();
$ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE type='module' and name='hosting'");
return $ret;
}
/**
* Implements hook_update_N().
*
* Update function to remove unused table
*/
function hosting_update_2() {
$ret = array();
$ret[] = update_sql("DROP TABLE {hosting_config_template}");
return $ret;
}
/**
* Implements hook_update_N().
*
* Hide hostmaster and hostslave profiles.
*/
function hosting_update_3() {
$ret = array();
$result = db_query("select n.nid from {node} n left join hosting_package p on n.nid = p.nid where short_name in ('hostslave', 'hostmaster')");
while ($obj = db_fetch_object($result)) {
$in[] = (int) $obj->nid;
}
$in = implode(", ", $in);
$ret[] = update_sql("UPDATE {node} SET status = 0 WHERE nid IN (" . $in . ")", $values);
return $ret;
}
/**
* Implements hook_update_N().
*
* Enable the modalframe and jquery_ui modules.
*/
function hosting_update_6000() {
$ret = array();
module_enable(array('modalframe', 'jquery_ui'));
return $ret;
}
/**
* Implements hook_update_N().
*
* Change the default configured blocks to match eldir.
*/
function hosting_update_6001() {
$ret = array();
module_enable(array('install_profile_api'));
drupal_load('module', 'install_profile_api');
install_include(array('block'));
$theme = 'eldir';
install_disable_block('hosting', 'hosting_queues_summary', $theme);
install_set_block('user', 0 , $theme, 'right', 0);
install_set_block('user', 1 , $theme, 'right', 0);
install_set_block('hosting', 'hosting_queues', $theme, 'right', 5);
install_set_block('hosting', 'hosting_summary', $theme, 'right', 10);
return $ret;
}
/**
* Implements hook_update_N().
*
* no-op - this used to verify one platform and all sites but breaks
* major upgrades.
*/
function hosting_update_6002() {
return array();
}
/**
* Implements hook_update_N().
*
* Lower the default amount of concurrent tasks.
*/
function hosting_update_6003() {
$ret = array();
variable_set('hosting_queue_tasks_items', 5);
return $ret;
}
/**
* Implements hook_update_N().
*
* Stricter initial permissions for the anonymous user.
*/
function hosting_update_6004() {
$ret = array();
install_include(array('user'));
install_remove_permissions(install_get_rid('anonymous user'), array('access content', 'access all views'));
install_remove_permissions(install_get_rid('authenticated user'), array('access content', 'access all views'));
return $ret;
}
/**
* Implements hook_update_N().
*
* Move some menu items to the primary links menu.
*/
function hosting_update_6005() {
drupal_install_modules(array('hosting_server'));
menu_rebuild();
install_include(array('menu'));
$menu_name = variable_get('menu_primary_links_source', 'primary-links');
$items = install_menu_get_items('hosting/servers');
$item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
$item['menu_name'] = $menu_name;
$item['customized'] = 1;
$item['options'] = unserialize($item['options']);
install_menu_update_menu_item($item);
$items = install_menu_get_items('hosting/sites');
$item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
$item['menu_name'] = $menu_name;
$item['customized'] = 1;
$item['options'] = unserialize($item['options']);
install_menu_update_menu_item($item);
menu_rebuild();
return array();
}
/**
* Implements hook_update_N().
*
* Move the platforms into primary links.
*/
function hosting_update_6006() {
install_include(array('menu'));
$menu_name = variable_get('menu_primary_links_source', 'primary-links');
$items = install_menu_get_items('hosting/platforms');
$item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
$item['menu_name'] = $menu_name;
$item['customized'] = 1;
$item['options'] = unserialize($item['options']);
install_menu_update_menu_item($item);
return array();
}
/**
* Implements hook_update_N().
*
* Update the default db_server now that we've merged the webserver and dbserver nodes
* See http://drupal.org/node/731550
*/
function hosting_update_6007() {
variable_set('hosting_default_db_server', variable_get('hosting_default_web_server', 3));
variable_set('hosting_own_db_server', variable_get('hosting_default_web_server', 3));
return array();
}
/**
* Implements hook_update_N().
*
* Add hosting_context table to map alias names.
*/
function hosting_update_6008() {
$return = array();
if (!variable_get('hosting_update_6008_run', FALSE)) {
db_create_table($return, 'hosting_context', array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'name' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
),
),
'primary key' => array('nid'),
'unique keys' => array(
'name' => array('name')
),
));
variable_set('hosting_update_6008_run', TRUE);
$records = array();
$result = db_query("SELECT n.nid, title FROM {node} n LEFT JOIN {hosting_site} s ON n.nid=s.nid WHERE s.status <> -2 AND n.type='site'");
while ($object = db_fetch_object($result)) {
$records[$object->nid] = $object->title;
}
$result = db_query("SELECT n.nid, title FROM {node} n LEFT JOIN {hosting_server} s ON n.nid=s.nid WHERE n.status = 1 AND n.type='server'");
while ($object = db_fetch_object($result)) {
$records[$object->nid] = 'server_' . preg_replace("/[!\W\.\-]/", "", $object->title);
}
// We start with the web server because we assume that the main hostmaster site is installed locally.
$server_id = variable_get('hosting_default_web_server', 3);
$records[$server_id] = 'server_master';
foreach ($records as $nid => $name) {
hosting_context_register($nid, $name);
}
}
return $return;
}
/**
* Implements hook_update_N().
*
* Fix the reference to the master server so that it no longer points at localhost.
*/
function hosting_update_6009() {
// This undoes the change we made previously in update_6008, but can be run again.
$ret = array();
db_query("UPDATE {hosting_context} SET name='server_master' WHERE name='server_localhost'");
$nid = db_result(db_query("SELECT nid from {hosting_context} WHERE name='server_master'"));
$uname = php_uname('n');
db_query("UPDATE {node} SET title='%s' WHERE nid=%d", $uname, $nid);
db_query("UPDATE {node_revisions} SET title='%s' WHERE nid=%d", $uname, $nid);
return $ret;
}
/**
* Implements hook_update_N().
*
* Add url aliases for the context names that are registered.
*/
function hosting_update_6010() {
// We include the file instead of enabling the module,
// because we do not want the overhead of having all the
// path UI stuff on nodes.
require_once("./modules/path/path.module");
$ret = array();
$result = db_query("SELECT nid, name FROM {hosting_context}");
while ($obj = db_fetch_object($result)) {
path_set_alias("node/$obj->nid", "hosting/c/$obj->name");
}
return $ret;
}
/**
* Implements hook_update_N().
*
* Clients and packages were imported as belonging to the anonymous user. Reassign them to the admin user.
*/
function hosting_update_6011() {
$ret = array();
db_query("UPDATE {node} SET uid=1 WHERE uid=0 AND type IN ('client', 'package')");
return $ret;
}
/**
* Implements hook_update_N().
*
* Remove the hosting summary block.
*/
function hosting_update_6012() {
$ret = array();
drupal_load('module', 'install_profile_api');
install_include(array('block'));
$theme = 'eldir';
install_disable_block('hosting', 'hosting_summary', $theme);
return $ret;
}
/**
* Implements hook_update_N().
*
* Add a permission allowing users to view the 'site disabled' message, which got
* lost when 'access content' permission was revoked a while ago.
*/
function hosting_update_6013() {
$ret = array();
install_include(array('user'));
install_add_permissions(install_get_rid('anonymous user'), array('access disabled sites'));
install_add_permissions(install_get_rid('authenticated user'), array('access disabled sites'));
return $ret;
}
/**
* Implements hook_update_N().
*
* Restore proper weight to the hosting module.
*
* For some obscure reason, the weight is 10 which makes its updates run
* after all others, which gave us constant issues during upgrades.
*/
function hosting_update_6014() {
$ret = array();
$ret[] = update_sql("UPDATE {system} SET weight = 0 WHERE type='module' and name='hosting'");
return $ret;
}
/**
* Implements hook_update_N().
*
* Delete URL aliases for sites that have been deleted.
*
* Ideally we'd do this in a single DB query, but there isn't a nice performant
* way to do it, so we do more DB queries instead of using potentially a lot of
* memory. Basically this may take a long time to run, but it shouldn't run out
* of resources doing so.
*/
function hosting_update_6015(&$sandbox) {
$ret = array();
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_pid'] = 0;
$sandbox['max'] = db_result(db_query('SELECT COUNT(pid) FROM {url_alias} WHERE dst LIKE "hosting/c/%" AND pid > 0'));
}
$aliases = db_query_range("SELECT pid, src, dst FROM {url_alias} WHERE dst LIKE 'hosting/c/%' AND pid > %d ORDER BY pid ASC", $sandbox['current_pid'], 0, 50);
while ($alias = db_fetch_object($aliases)) {
// Get the node ID for the alias.
$nid = preg_replace('#^node/#', '', $alias->src);
if (is_numeric($nid)) {
// Check to see if the corresponding context has been deleted.
if (!db_result(db_query('SELECT COUNT(nid) FROM {hosting_context} WHERE nid = %d', $nid))) {
db_query('DELETE FROM {url_alias} WHERE pid = %d', $alias->pid);
}
}
$sandbox['progress']++;
$sandbox['current_pid'] = $alias->pid;
}
$ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
return $ret;
}
/**
* Replace lists with Views.
*/
function hosting_update_6201() {
$ret = array();
// Remove menu links that will be replaced by Views
menu_link_delete(NULL, 'hosting/platforms');
menu_link_delete(NULL, 'hosting/sites');
// Enable and install Views and Views Bulk operations.
drupal_install_modules(array('views', 'views_bulk_operations'));
// Flush all Drupal caches.
drupal_flush_all_caches();
// Temporarily enable Install Profile API module and load includes.
module_enable(array('install_profile_api'));
drupal_load('module', 'install_profile_api');
install_include(array('block'));
// Enable blocks.
$theme = 'eldir';
install_set_block('views', 'hosting_task_list-block' , $theme, 'right', 0);
install_set_block('views', '-exp-hosting_site_list-page_sites' , $theme, 'content_top', 0, 1, 'hosting/sites');
install_set_block('views', 'hosting_site_list-block_platform' , $theme, 'content_bottom', 0, 1, 'hosting/c/platform_*');
install_set_block('views', 'hosting_site_list-block_profile' , $theme, 'content_bottom', 0, 2, "<?php\n\$node = menu_get_object();\nif (!empty(\$node)) {\n return \$node->package_type == 'profile';\n}\n?>");
install_set_block('views', 'hosting_site_list-block_client' , $theme, 'content_bottom', 0, 2, "<?php\n\$node = menu_get_object();\nif (!empty(\$node)) {\n return \$node->type == 'client';\n}\n?>");
module_disable(array('install_profile_api'));
return $ret;
}
/**
* Provide a welcome message for anonymous users.
*/
function hosting_update_6202() {
$ret = array();
// Flush the menu cache.
menu_rebuild();
return $ret;
}
/**
* Delete hosting features junk variables.
*/
function hosting_update_6203() {
$ret = array();
$features = hosting_get_features(TRUE);
foreach ($features as $feature => $info) {
if (variable_get($feature, FALSE) != FALSE) {
variable_del($feature);
}
}
}
/**
* Create new roles.
*/
function hosting_update_6204() {
$ret = array();
// Temporarily enable Install Profile API module and load includes.
module_enable(array('install_profile_api'));
module_load_include('inc', 'install_profile_api', 'core/user');
install_remove_permissions(install_get_rid('aegir client'), array('access all views'));
install_add_role('aegir platform manager');
install_add_permissions(install_get_rid('aegir platform manager'), array('create clone task', 'create migrate task', 'create platform', 'delete platform', 'edit platform', 'view locked platforms', 'view platform', 'create dlock task', 'create dunlock task', 'create site', 'delete site', 'edit site', 'view site', 'access task logs', 'create lock task', 'create unlock task', 'view revisions', 'search content', 'use advanced search'));
install_add_role('aegir administrator');
install_add_permissions(install_get_rid('aegir administrator'), array('access disabled sites', 'access hosting wizard', 'administer hosting', 'administer hosting features', 'administer hosting queues', 'administer hosting settings', 'administer hosting aliases', 'create site aliases', 'administer clients', 'create client', 'delete own client', 'edit client uname', 'edit client users', 'edit own client', 'view client', 'create clone task', 'create migrate task', 'create package', 'delete package', 'edit package', 'view package', 'create platform', 'delete platform', 'edit platform', 'view locked platforms', 'view platform', 'create dlock task', 'create dunlock task', 'edit all quotas', 'view all quotas', 'view own quota', 'create server', 'delete server', 'edit server', 'view server', 'access hosting signup form', 'administer sites', 'create site', 'delete site', 'edit site', 'view site', 'create ssl certificate', 'access task logs', 'administer tasks', 'cancel own tasks', 'create backup task', 'create backup-delete task', 'create delete task', 'create disable task', 'create enable task', 'create lock task', 'create login-reset task', 'create restore task', 'create unlock task', 'create verify task', 'retry failed tasks', 'view own tasks', 'view task'));
module_disable(array('install_profile_api'));
return $ret;
}
/**
* Add permissions to roles.
*/
function hosting_update_6205() {
$ret = array();
// Temporarily enable Install Profile API module and load includes.
module_enable(array('install_profile_api'));
module_load_include('inc', 'install_profile_api', 'core/user');
install_add_permissions(install_get_rid('aegir client'), array('view own quota', 'create site aliases', 'create verify task', 'create clone task', 'create migrate task', 'create ssl certificate', 'access task logs', 'view package', 'view platform', 'view revisions', 'edit site'));
install_add_permissions(install_get_rid('aegir account manager'), array('administer clients', 'access content', 'access user profiles', 'edit all quotas', 'view all quotas', 'view own quota', 'edit client uname', 'view_site'));
install_add_permissions(install_get_rid('aegir platform manager'), array('view package', 'administer platforms', 'cancel own tasks', 'view own tasks', 'access content', 'view task', 'administer sites', 'create verify task', 'retry failed tasks', 'administer clients', 'administer tasks'));
install_add_permissions(install_get_rid('aegir administrator'), array('access administration menu', 'administer platforms', 'administer servers', 'access content', 'view revisions', 'administer hosting aliases', 'create site aliases', 'edit all quotas', 'view all quotas', 'view own quota', 'access hosting signup form', 'create ssl certificate', 'access user profiles', 'update status of tasks'));
module_disable(array('install_profile_api'));
return $ret;
}
/**
* Enable the jquery_update module.
*/
function hosting_update_6206() {
$ret = array();
module_enable(array('jquery_update'));
return $ret;
}
/**
* Alter the length available for a site alias to 235.
*
* https://drupal.org/node/1971348
*/
function hosting_update_6207() {
$ret = array();
$spec = array(
'type' => 'varchar',
// @see HOSTING_MAX_ALIAS_LENGTH
'length' => 235,
'not null' => TRUE,
);
db_change_field($ret, 'hosting_context', 'name', 'name', $spec);
return $ret;
}
/**
* Remove old BOA menu links.
*/
function hosting_update_6208() {
$ret = array();
hosting_menu_rebuild();
menu_link_delete(NULL, 'hosting/clients');
menu_link_delete(NULL, 'hosting/signup');
menu_link_delete(NULL, 'node/add/client');
menu_link_delete(NULL, 'node/add/site');
hosting_menu_rebuild();
drupal_flush_all_caches();
return $ret;
}
/**
* Save 'aegir_hostmaster_site_nid' variable.
*/
function hosting_update_7000() {
$nid = db_query('SELECT site.nid
FROM hosting_site site
JOIN hosting_package_instance pkgi
ON pkgi.rid = site.nid
JOIN hosting_package pkg
ON pkg.nid = pkgi.package_id
WHERE pkg.short_name = \'hostmaster\'')->fetchField();
variable_set('aegir_hostmaster_site_nid', $nid);
}
/**
* Fix old comments in the hostmaster site.
*/
function hosting_update_7001() {
if (db_table_exists('comment')) {
db_update('comment')
->fields(array('language' => 'und'))
->condition('status', '1')
->execute();
}
if (db_table_exists('field_data_comment_body')) {
db_update('field_data_comment_body')
->fields(array('comment_body_format' => 'filtered_html'))
->condition('comment_body_format', '1')
->execute();
}
}
/**
* Suppress error messages by default.
*/
function hosting_update_7002() {
variable_set('error_level', ERROR_REPORTING_HIDE);
}
/**
* Force a re-verification of all enabled sites,
* to re-generate their Apache virtualhost configurations to use
* mitigation measures for SA 2018-002.
*/
function hosting_update_7302() {
return array(); // never fail
}
/**
* Force a re-verification of all enabled sites.
*/
function hosting_update_7303() {
// node_access_rebuild from the the update hook fails without the following defintion.
return array(); // never fail
}
/**
* Upgrade existing hosting_task_logs_types_display variable to an array.
*/
function hosting_update_7304() {
$display = variable_get('hosting_task_logs_types_display', 'error warning info message ok status success');
if (is_string($display)) {
$display = explode(' ', $display);
$display = array_combine($display, $display);
variable_set('hosting_task_logs_types_display', $display);
}
}