Пример #1
0
        private async Task <IActionResult> RunSSH(int ServerInformationID, string sshCode)
        {
            var server = await factory.ServerInformations.GetServerInformationByServerInformationID(ServerInformationID);

            if (server == null)
            {
                return(NotFound());
            }
            SshSystem ssh        = new SshSystem(server.ServerAdress, server.UserName, server.Password, server.Port);
            string    outmessage = "";

            if (!ssh.RunSSHCode(sshCode, ref outmessage))
            {
                return(Unauthorized(outmessage));
            }
            return(Ok(outmessage));
        }
Пример #2
0
        public async Task <IActionResult> Upload(int DomainInformationID, int TemplateID, int ServerInformationID)
        {
            var domain = await factory.Domains.GetDomainInformationByDomainInformationID(DomainInformationID);

            if (domain == null)
            {
                return(NotFound("Domain information not found in database!"));
            }

            var template = await factory.Templates.GetByTeplateID(TemplateID);

            if (template == null)
            {
                return(NotFound("Template information not found in database!"));
            }

            var server = await factory.ServerInformations.GetServerInformationByServerInformationID(ServerInformationID);

            if (server == null)
            {
                return(NotFound("Server information not found in database!"));
            }

            SshSystem ssh = new SshSystem(server.ServerAdress, server.UserName, server.Password, server.Port);

            if (ssh.CheckConnection())
            {
                if (!ssh.UploadStringWithSCP(template.TemplateCode.Replace("{domain}", domain.DomainAdress), "/etc/nginx/sites-enabled/" + domain.DomainName + ".conf"))
                {
                    return(Unauthorized("Undefined error!"));
                }
                else
                {
                    return(Ok("Ready!"));
                }
            }
            else
            {
                return(Unauthorized("Server information is not correct!"));
            }
        }