GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 6a3289...514d99 )
by Anton
02:27
created

contrib/cpanel.php (2 issues)

1
<?php
2
3
namespace Deployer;
4
5
use Deployer\Task\Context;
6
use \Gufy\CpanelPhp\Cpanel;
0 ignored issues
show
The type Gufy\CpanelPhp\Cpanel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
/**
9
 * @return Cpanel
10
 * @throws Exception\Exception
11
 */
12
function getCpanel()
13
{
14
    $config = get('cpanel', []);
15
    $allowInStage = $config['allowInStage'];
16
    $stage = Context::get()->getInput()->getArgument('stage');
17
18
    if (!class_exists('\Gufy\CpanelPhp\Cpanel')) {
19
        throw new \RuntimeException("<comment>Please install php package</comment> <info>gufy/cpanel-php</info> <comment>to use CPanel API</comment>");
20
    }
21
22
    if (!in_array($stage, $allowInStage)) {
23
        throw new \RuntimeException(sprintf("Since it creates addon domains and databases, CPanel recipe is available only in the %s environments", implode($allowInStage)));
24
    }
25
26
27
    if (!is_array($config) ||
28
        !isset($config['host']) ||
29
        !isset($config['port']) ||
30
        !isset($config['username']) ||
31
        !isset($config['token']) ||
32
        !isset($config['user']) ) {
33
        throw new \RuntimeException("<comment>Please configure CPanel config:</comment> <info>set('cpanel', array('host' => 'xxx.xxx.xxx.xxx:', 'port' => 2087 , 'username' => 'root', 'token' => 'asdfasdf', 'cpaneluser' => 'guy'));</info>");
34
    }
35
36
    $cpanel = new Cpanel([
37
        'host'        =>  'https://' . $config['host'] . ':' . $config['port'],
38
        'username'    =>  $config['username'],
39
        'auth_type'   =>  $config['auth_type'],
40
        'password'    =>  $config['token'],
41
    ]);
42
43
    $cpanel->setTimeout($config['timeout']);
44
45
    return $cpanel;
46
}
47
48
function getDomainInfo()
49
{
50
    $domain = vsprintf(get('cpanel')['create_domain_format'], get('cpanel')['create_domain_values']);
51
    $cleanDomain = str_replace(['.', ',', ' ', '/', '-'], '', $domain);
52
    $subDomain = get('cpanel')['subdomain_prefix'] . $cleanDomain;
53
54
    return [
55
        'domain' => $domain,
56
        'subDomain' => $subDomain,
57
        'subDomainWithSuffix' => $subDomain . get('cpanel')['subdomain_suffix']
58
    ];
59
}
60
61
desc('Creating database though CPanel API');
62
task('cpanel:createdb', function () {
63
64
    $cpanel = getCPanel();
65
    $config = get('cpanel', []);
66
    if (!askConfirmation(sprintf('This will try to create the database %s on the host though CPanel API, ok?', get('cpanel_createdb'), get('deploy_path')), true)) {
67
        return;
68
    }
69
70
    $createDbDataResult = $cpanel->cpanel('MysqlFE', 'createdb', $config['user'], ['db' => get('cpanel_createdb')]);
71
    $addPrivilegesDataResult = $cpanel->cpanel('MysqlFE', 'setdbuserprivileges', $config['user'], ['privileges' => $config['db_user_privileges'], 'db'=> get('cpanel_createdb'), 'dbuser' => $config['db_user']]);
72
73
    $createDbData = json_decode($createDbDataResult, true);
74
    $addPrivilegesData = json_decode($addPrivilegesDataResult, true);
75
76
    if (isset($createDbData['cpanelresult']['error'])) {
77
        writeln($createDbData['cpanelresult']['error']);
78
    } else {
79
        writeln('Successfully created database!');
80
    }
81
82
    if (isset($addPrivilegesData['cpanelresult']['error'])) {
83
        writeln($addPrivilegesData['cpanelresult']['error']);
84
    } else {
85
        writeln('Successfully added privileges to database!');
86
    }
87
});
88
89
desc('Creating addon domain though CPanel API');
90
task('cpanel:createaddondomain', function () {
91
    $cpanel = getCPanel();
92
    $config = get('cpanel', []);
93
    $domain = getDomainInfo()['domain'];
94
    $subDomain = getDomainInfo()['subDomain'];
95
    if (!askConfirmation(sprintf('This will try to create the addon domain %s and point it to %s and subdomain %s, ok?', $domain, get('addondir'), $subDomain), true)) {
96
        return;
97
    }
98
99
    writeln(sprintf('Creating addon domain %s and pointing it to %s', $domain, get('addondir')));
100
101
    $addAddonDomainResult = $cpanel->cpanel('AddonDomain', 'addaddondomain', $config['user'], ['dir' => get('addondir'), 'newdomain'=> $domain, 'subdomain' => $subDomain]);
102
    $addAddonDomainData = json_decode($addAddonDomainResult, true);
103
104
    if (isset($delAddonDomainResult['cpanelresult']['error'])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $delAddonDomainResult does not exist. Did you maybe mean $addAddonDomainResult?
Loading history...
105
        writeln($addAddonDomainData['cpanelresult']['error']);
106
    } else {
107
        writeln('Successfully created addon domain!');
108
        writeln($addAddonDomainData['cpanelresult']['data'][0]['reason']);
109
    }
110
});
111
112
desc('Delete addon domain though CPanel API');
113
task('cpanel:deleteaddondomain', function () {
114
    $cpanel = getCPanel();
115
    $config = get('cpanel', []);
116
    $domain = getDomainInfo()['domain'];
117
    $subDomain = getDomainInfo()['subDomain'];
118
    $subDomainWithSuffix = getDomainInfo()['subDomainWithSuffix'];
119
120
    if (!askConfirmation(sprintf('This will delete the addon domain %s with corresponding subdomain %s, ok?', $domain, $subDomain), true)) {
121
        return;
122
    }
123
124
    writeln(sprintf('Deleting addon domain %s', $domain));
125
126
    $delAddonDomainResult = $cpanel->cpanel('AddonDomain', 'deladdondomain', $config['user'], ['domain'=> $domain, 'subdomain' => $subDomainWithSuffix]);
127
    $delAddonDomainResult = json_decode($delAddonDomainResult, true);
128
129
    if (isset($delAddonDomainResult['cpanelresult']['error'])) {
130
        writeln($delAddonDomainResult['cpanelresult']['error']);
131
    } else {
132
        writeln('Successfully deleted addon domain!');
133
        writeln($delAddonDomainResult['cpanelresult']['data'][0]['reason']);
134
    }
135
});
136