Issues (5)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Services/HostService.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of the teamneusta/hosts project.
4
 * Copyright (c) 2017 neusta GmbH | Ein team neusta Unternehmen
5
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
6
 * @license http://www.opensource.org/licenses/mit-license.html  MIT License
7
 *
8
 */
9
10
namespace TeamNeusta\Hosts\Services;
11
12
use TeamNeusta\Hosts\Services\Provider\Filesystem;
13
14
class HostService
15
{
16
    /**
17
     * @var Filesystem
18
     */
19
    private $fs;
20
21
    /**
22
     * scope to interact with.
23
     *
24
     * @var string
25
     */
26
    private $_scope = null;
27
28
    /**
29
     * HostService constructor.
30
     */
31 5
    public function __construct(Filesystem $fs = null)
32
    {
33 5
        $this->fs = $fs ?? new Filesystem();
34 5
    }
35
36
    /**
37
     * Add given configuration to .magehost file.
38
     *
39
     * @param $name
40
     * @param $host
41
     * @param $user
42
     * @param int $port
43
     */
44 1
    public function update($name, $host, $user, $port = 22)
45
    {
46
        $config = [
47 1
            'name' => $name,
48 1
            'host' => $host,
49 1
            'user' => $user,
50 1
            'port' => $port
51
        ];
52
53 1
        $this->fs->addHostToConfiguration($config, $this->_scope);
54 1
    }
55
56
57 5
    public function getHosts($scope) : array
58
    {
59
        switch ($scope) {
60 5
            case 'local':
0 ignored issues
show
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
61 3
                $config = $this->fs->getLocalConfiguration();
62 3
                break;
63 2
            case 'project':
64 1
                $config = $this->fs->getProjectConfiguration();
65 1
                break;
66
            default:
67 1
                $local = $this->fs->getLocalConfiguration();
68 1
                $project = $this->fs->getProjectConfiguration();
69 1
                $global = $this->fs->getGlobalConfiguration(); // temporary disabled.
70 1
                $config = $this->mergeConfigs($local, $project, $global);
71 1
                break;
72
        }
73 5
        return $config['hosts'];
74
    }
75
76 1
    private function mergeConfigs() : array
77
    {
78 1
        $args = func_get_args();
79 1
        $config = ['hosts' => []];
80 1
        foreach ($args as $hosts) {
81 1
            if (isset($hosts['hosts'])) {
82 1
                foreach ($hosts['hosts'] as $entry) {
83 1
                    $config['hosts'][] = $entry;
84
                }
85
            }
86
        }
87 1
        return $config;
88
    }
89
90 1
    public function getHostsForQuestionhelper() : array
91
    {
92 1
        $config = $this->getHosts($this->_scope);
93 1
        $hosts = [];
94 1
        foreach ($config as $host) {
95 1
            $hosts[] = $host['name'];
96
        }
97 1
        return $hosts;
98
    }
99
100 1
    public function getConnectionStringByName($host) : string
101
    {
102 1
        $config = $this->getHosts($this->_scope);
103
104 1
        $hostKey = array_search($host, array_column($config, 'name'));
105
106 1
        $sshCommand = $config[$hostKey]['user'] . '@' . $config[$hostKey]['host'] . ' -p ' . $config[$hostKey]['port'];
107
108 1
        return $sshCommand;
109
    }
110
111 5
    public function setScope($scope)
112
    {
113 5
        $this->_scope = $scope;
114
    }
115
}