public AnalyzeResult Audit(AuditMessage message, Configuration.Action setting)
        {
            var address = setting.GetSetting("address");
            var format  = setting.GetSetting("format");
            var headers = setting.GetSetting("headers");

            var webClient = new WebClient();

            if (headers != null)
            {
                foreach (var header in headers.Split(';'))
                {
                    var kvp = header.Split('=');
                    webClient.Headers.Add(kvp[0], kvp[1]);
                }
            }

            webClient.UploadStringCompleted += (sender, args) => {
                if (args.Error != null)
                {
                    Log.LogError(args.Error.ToString());
                }
            };
            webClient.UploadStringAsync(new System.Uri(address), Formatter.Format(message, format));

            return(AnalyzeResult.Ok);
        }
예제 #2
0
 public AdoRunAction(IContext context, Configuration.Action node, IConnectionFactory cf, IReader commandReader)
 {
     _context       = context;
     _node          = node;
     _cf            = cf;
     _commandReader = commandReader;
 }
예제 #3
0
        private IAction SwitchAction(IComponentContext ctx, Configuration.Action action)
        {
            var context = new PipelineContext(ctx.Resolve <IPipelineLogger>(), _process);

            switch (action.Type)
            {
            case "copy":
                return(action.InTemplate ? (IAction)
                       new ContentToFileAction(context, action) :
                       new FileCopyAction(context, action));

            case "move":
                return(new FileMoveAction(context, action));

            case "archive":
                return(new FileArchiveAction(context, action));

            case "replace":
                return(new FileReplaceAction(context, action));

            default:
                context.Error($"Attempting to register unsupported file action: {action.Type}");
                return(new NullAction());
            }
        }
예제 #4
0
        private static IAction SwitchAction(IComponentContext ctx, Process process, Configuration.Action action)
        {
            var context = new PipelineContext(ctx.Resolve <IPipelineLogger>(), process);

            switch (action.Type)
            {
            case "log":
                return(new LogAction(context, action));

            case "wait":
            case "sleep":
                return(new WaitAction(action));

            case "tfl":
                var cfg = string.IsNullOrEmpty(action.Url) ? action.File : action.Url;
                if (string.IsNullOrEmpty(cfg) && !string.IsNullOrEmpty(action.Body))
                {
                    cfg = action.Body;
                }
                return(new PipelineAction(context, action, cfg));

            case "exit":
                return(new ExitAction(context, action));

            default:
                context.Error("{0} action is not registered.", action.Type);
                return(new NullAction());
            }
        }
예제 #5
0
        public Configuration.Action ToAction()
        {
            var a = new Configuration.Action();

            if (bool.TryParse(this.After, out bool after))
            {
                a.After = after;
            }
            a.Arguments = this.Arguments;
            a.Bcc       = this.Bcc;
            if (bool.TryParse(this.Before, out bool before))
            {
                a.Before = before;
            }
            a.Body        = this.Body;
            a.Cc          = this.Cc;
            a.Command     = this.Command;
            a.Connection  = this.Connection;
            a.Description = this.Description;
            a.Class       = this.Class;
            a.Icon        = this.Icon;
            a.ErrorMode   = this.ErrorMode;
            a.File        = this.File;
            a.From        = this.From;
            if (bool.TryParse(this.Html, out bool html))
            {
                a.Html = html;
            }
            if (int.TryParse(this.Id, out int id))
            {
                a.Id = id;
            }
            a.Level            = this.Level;
            a.Message          = this.Message;
            a.Method           = this.Method;
            a.Mode             = this.Mode;
            a.Modes            = this.Modes.Select(nr => nr.ToNameReference()).ToList();
            a.Name             = this.Name;
            a.NewValue         = this.NewValue;
            a.OldValue         = this.OldValue;
            a.Parameters       = this.Parameters.Select(p => p.ToParameter()).ToList();
            a.PlaceHolderStyle = this.PlaceHolderStyle;
            a.Subject          = this.Subject;
            if (int.TryParse(this.TimeOut, out int timeOut))
            {
                a.TimeOut = timeOut;
            }
            a.To   = this.To;
            a.Type = this.Type;
            a.Url  = this.Url;
            return(a);
        }
        public AnalyzeResult Audit(AuditMessage message, Configuration.Action setting)
        {
            var path   = setting.GetSetting("Path");
            var format = setting.GetSetting("Format");

            path = Environment.ExpandEnvironmentVariables(path);

            var output = Formatter.Format(message, format);

            File.AppendAllText(path, output + Environment.NewLine);

            return(AnalyzeResult.Ok);
        }
예제 #7
0
        private IAction SwitchAction(IComponentContext ctx, Configuration.Action action)
        {
            var context = new PipelineContext(ctx.Resolve <IPipelineLogger>(), _process);

            switch (action.Type)
            {
            case "print":
                return(new PrintAction(action));

            default:
                context.Error($"Attempting to register unsupported file system action: {action.Type}");
                return(new NullAction());
            }
        }
예제 #8
0
        public AnalyzeResult Audit(AuditMessage message, Configuration.Action setting)
        {
            var hostname = setting.GetSetting("hostname");
            var port     = setting.GetSetting("port");
            var format   = setting.GetSetting("format");

            using (var client = new UdpClient(hostname, int.Parse(port)))
            {
                var output = Formatter.Format(message, format);
                var bytes  = Encoding.UTF8.GetBytes(output);
                client.Send(bytes, bytes.Length);
            }

            return(AnalyzeResult.Ok);
        }
예제 #9
0
        public AnalyzeResult Audit(AuditMessage message, Configuration.Action setting)
        {
            var hostname = setting.GetSetting("hostname");
            var port     = setting.GetSetting("port");
            var format   = setting.GetSetting("format");

            using (var tcpClient = new TcpClient(hostname, int.Parse(port)))
            {
                using (var streamWriter = new StreamWriter(tcpClient.GetStream()))
                {
                    streamWriter.WriteLine(Formatter.Format(message, format));
                }
            }

            return(AnalyzeResult.Ok);
        }
예제 #10
0
        private static IAction SwitchAction(IComponentContext ctx, Process process, Configuration.Action action)
        {
            var context = new PipelineContext(ctx.Resolve <IPipelineLogger>(), process);

            switch (action.Type)
            {
            case "log":
                return(new LogAction(context, action));

            case "wait":
            case "sleep":
                return(new WaitAction(action));

            case "tfl":
                var cfg = string.IsNullOrEmpty(action.Url) ? action.File : action.Url;
                if (string.IsNullOrEmpty(cfg) && !string.IsNullOrEmpty(action.Body))
                {
                    cfg = action.Body;
                }

                var root = ctx.Resolve <Process>(new NamedParameter("cfg", cfg));

                foreach (var warning in root.Warnings())
                {
                    context.Warn(warning);
                }
                if (root.Errors().Any())
                {
                    context.Error($"TFL Pipeline Action '{cfg.Left(30)}'... has errors!");
                    foreach (var error in root.Errors())
                    {
                        context.Error(error);
                    }
                    return(new NullAction());
                }
                return(new PipelineAction(DefaultContainer.Create(root, ctx.Resolve <IPipelineLogger>(), action.PlaceHolderStyle)));

            case "exit":
                return(new ExitAction(context, action));

            default:
                context.Error("{0} action is not registered.", action.Type);
                return(new NullAction());
            }
        }
예제 #11
0
        protected override void Load(ContainerBuilder builder)
        {
            var signatures = new CodeLocal().GetSignatures().ToArray();

            // get methods and shorthand from builder
            _methods   = builder.Properties.ContainsKey("Methods") ? (HashSet <string>)builder.Properties["Methods"] : new HashSet <string>();
            _shortHand = builder.Properties.ContainsKey("ShortHand") ? (ShorthandRoot)builder.Properties["ShortHand"] : new ShorthandRoot();

            RegisterShortHand(signatures);
            RegisterTransform(builder, c => c.Field.Remote ? (ITransform) new CodeRemote(c) : new CodeLocal(c), signatures);

            if (!builder.Properties.ContainsKey("Process"))
            {
                return;
            }

            var process = (Process)builder.Properties["Process"];

            if (process == null)
            {
                return;
            }

            if (process.Entities.Any() && process.GetAllTransforms().Any(t => t.Method == "csscript"))
            {
                if (!_setup)
                {
                    AppDomain.MonitoringIsEnabled      = true;
                    CSScript.EvaluatorConfig.Access    = EvaluatorAccess.Singleton;
                    CSScript.EvaluatorConfig.Engine    = EvaluatorEngine.CodeDom;
                    CSScript.GlobalSettings.SearchDirs = AssemblyDirectory + ";" + Path.Combine(AssemblyDirectory, "plugins");
                    CSScript.CacheEnabled = true;
                    CSSEnvironment.SetScriptTempDir(Path.Combine(AssemblyDirectory, "plugins", "cs-script"));
                    _setup = true;
                }

                var action = new Configuration.Action {
                    Type = "cs-script", Before = false, After = true, Key = "cs-script"
                };
                builder.Register <IAction>((c) => new RemoteUnload(c.Resolve <IContext>(), action)).Named <IAction>("cs-script");
                process.Actions.Add(action);
            }
        }
예제 #12
0
 public AnalyzeResult Audit(AuditMessage message, Configuration.Action setting)
 {
     return(AnalyzeResult.AdminBlock);
 }