-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
console.php
executable file
·89 lines (74 loc) · 2.38 KB
/
console.php
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
#!/usr/bin/env php
<?php
if(php_sapi_name() != 'cli')
die('This script must be executed from command line.'."\n");
if(!isset($argv[1]))
die('Please specify an action as first parameter.'."\n");
require_once(__DIR__.'/loader.inc.php');
$extensionMethods = $ext->getAggregatedConf('console-methods');
try {
switch($argv[1]) {
case 'housekeeping':
$houseKeeping = new HouseKeeping($db, $ext, true);
$houseKeeping->cleanup();
break;
case 'mdmcron':
$mdcc = new MobileDeviceCommandController($db, true);
$mdcc->mdmCron();
break;
case 'applesync':
echo 'Syncing devices...'."\n";
$ade = new Apple\AutomatedDeviceEnrollment($db);
$ade->syncDevices();
$vpp = new Apple\VolumePurchaseProgram($db);
$vppToken = null;
try {
$vppToken = $vpp->getToken();
} catch(RuntimeException $ignored) {}
if($vppToken) {
echo 'Syncing assets...'."\n";
$vpp->syncAssets();
}
break;
case 'applelicenses':
echo 'Syncing licenses...'."\n";
$ade = new Apple\VolumePurchaseProgram($db);
$ade->reassignLicenses();
break;
case 'applepush':
if(empty($argv[2])) throw new Exception('Please give the device serial number as second parameter!');
$ade = new Apple\AutomatedDeviceEnrollment($db);
$md = $db->selectMobileDeviceBySerialNumber($argv[2]);
if(!$md) throw new InvalidRequestException('Serial number not found');
$apnCert = $ade->getMdmApnCert();
$apn = new Apple\PushNotificationService($db, $apnCert['certinfo']['subject']['UID'], $apnCert['cert'], $apnCert['privkey']);
$apn->send($md->push_token, $md->push_magic);
break;
case 'ldapsync':
$ldapSync = new LdapSync($db, true);
echo '<===== Syncing System Users =====>'."\n";
$ldapSync->syncSystemUsers();
echo '<===== Syncing Domain Users =====>'."\n";
$ldapSync->syncDomainUsers();
break;
case 'upgradeschema':
$migrator = new DatabaseMigrationController($db->getDbHandle(), true);
if($migrator->upgrade()) {
echo 'Database schema upgraded successfully.'."\n";
} else {
echo 'Database schema is already up to date.'."\n";
}
break;
default:
if(array_key_exists($argv[1], $extensionMethods)) {
call_user_func($extensionMethods[$argv[1]], $db);
die();
}
throw new Exception('unknown command');
}
} catch(Exception $e) {
echo $argv[1].' ERROR: '.$e->getMessage()."\n";
echo $e->getTraceAsString();
echo "\n";
exit(1);
}