Exemplo n.º 1
0
        private void ExecuteScriptLinux(APlugin plugin, string file, string args)
        {
            using var dllimport = new DllImportLaunchCmdUnix();
            var result = "";

            if (plugin.AdministratorRights)
            {
                result = dllimport.UseLaunchCommand(
                    $"sudo -u {plugin.AdministratorUsername} -s {file} -c {args} 2> /dev/null");
            }
            else
            {
                result = dllimport.UseLaunchCommand($"{file} {args} 2> /dev/null");
            }

            // if it's not a valid json
            try
            {
                JObject.Parse(result);
            }
            catch (JsonReaderException)
            {
                Log.Instance?.Error($"{plugin.Infos.Name}: result not in a json format: {result}");
                return;
            }

            plugin.RaiseOnExecutionFinished(result);
        }
Exemplo n.º 2
0
        public override void SetInterpreterNameConfiguration(IPluginMaster pluginMaster)
        {
            if (Root == null)
            {
                return;
            }

            var interpreterConfig = Root[MagicStringEnumerator.JSONIntepreter];

            foreach (var fileType in pluginMaster.AcceptedFilesTypes[PluginFileInfos.FileType.Script])
            {
                var key = fileType;
                var val = "";

                try
                {
                    // an intepreter can change depending the os
                    val = interpreterConfig[OSAttribute.GetOSFamillyName()]
                          ?.Value <string>(pluginMaster.ExtensionsNames[fileType]);
                }
                catch (NullReferenceException)
                {
                    // if we cant find one we need to search in the environment variables
                    var extensionName = pluginMaster.ExtensionsNames[fileType].ToUpper();

                    if (OSAttribute.IsWindows)
                    {
                        foreach (EnvironmentVariableTarget enumValue in Enum.GetValues(
                                     typeof(EnvironmentVariableTarget)))
                        {
                            val = Environment.GetEnvironmentVariable(extensionName, enumValue);

                            if (val != null)
                            {
                                Log.Instance?.Info($"Environment variable found: {extensionName} : {val}");
                                break;
                            }
                        }
                    }
                    else if (OSAttribute.IsLinux)
                    {
                        using var dllimport = new DllImportLaunchCmdUnix();

                        val = dllimport.UseLaunchCommand($"printenv | grep {extensionName} | cut -d '=' -f 2").Trim();

                        if (!string.IsNullOrEmpty(val))
                        {
                            Log.Instance?.Info($"Environment variable found: {extensionName} : {val}");
                        }
                    }
                }

                // if it can't be found, the default one is choose
                if (string.IsNullOrEmpty(val))
                {
                    val = pluginMaster.ExtensionsNames[fileType];
                }

                if (!File.Exists(val))
                {
                    return;
                }

                if (!pluginMaster.ExtensionsNames.ContainsKey(key))
                {
                    pluginMaster.AddScriptExtension(key, val);
                }
                else
                {
                    pluginMaster.ExtensionsNames[key] = val;
                }
            }
        }