Represent one instance of this bot
Esempio n. 1
0
 public static void deleteInstance(Instance instance)
 {
     try
     {
         lock (Instances)
         {
             if (Instances.Contains(instance))
             {
                 Instances.Remove(instance);
             }
         }
         lock (ProjectList)
         {
             foreach (Nova project in ProjectList)
             {
                 if (project.instances.Contains(instance))
                 {
                     project.instances.Remove(instance);
                 }
             }
         }
     }
     catch (Exception r)
     {
         core.handleException(r);
     }
 }
Esempio n. 2
0
 public Network(string server, Instance Instance, WmIrcProtocol protocol)
     : base(server, (libirc.Protocols.ProtocolIrc)protocol)
 {
     this.instance = Instance;
     this.Config.TrafficInterval = Configuration.IRC.Interval;
     this.Config.Nick = Instance.Nick;
     if (Configuration.IRC.UsingBouncer)
         this.IsLoaded = true;
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="wmib.Channel"/> class.
        /// </summary>
        /// <param name='name'>
        /// Name.
        /// </param>
        public Channel(string name)
        {
            Name = name;
            Suppress = false;
            SystemUsers = new Security(this);
            LoadConfig();
            if (DefaultInstance == "any")
            {
                PrimaryInstance = Instance.GetInstance();
                // we need to save the instance so that next time bot reconnect to bouncer it uses the same instance
                DefaultInstance = PrimaryInstance.Nick;
                SaveConfig();
            }
            else
            {
                if (!Instance.Instances.ContainsKey(DefaultInstance))
                {
                    Syslog.WarningLog("There is no instance " + DefaultInstance + " reassigning channel " + this.Name +
                                      " to a different instance");
                    this.PrimaryInstance = Instance.GetInstance();
                    Syslog.Log("Reassigned to " + this.PrimaryInstance.Nick);
                }
                else
                {
                    PrimaryInstance = Instance.Instances[DefaultInstance];
                }
            }
            if (!Directory.Exists(Configuration.WebPages.HtmlPath))
                Directory.CreateDirectory(Configuration.WebPages.HtmlPath);

            foreach (Module module in ExtensionHandler.ExtensionList)
            {
                try
                {
                    if (module.IsWorking)
                    {
                        Channel self = this;
                        module.Hook_Channel(self);
                    }
                }
                catch (Exception fail)
                {
                    Syslog.Log("MODULE: exception at Hook_Channel in " + module.Name, true);
                    Core.HandleException(fail);
                }
            }
        }
Esempio n. 4
0
 public Network(string server, Instance Instance, WmIrcProtocol protocol)
     : base(server, (libirc.Protocols.ProtocolIrc)protocol)
 {
     this.instance = Instance;
 }
Esempio n. 5
0
        public void JSON()
        {
            try
            {
                string URL = "https://labsconsole.wikimedia.org/wiki/Special:Ask/-5B-5BResource-20Type::instance-5D-5D/-3FInstance-20Name/-3FInstance-20Type/-3FProject/-3FImage-20Id/-3FFQDN/-3FLaunch-20Time/-3FPuppet-20Class/-3FModification-20date/-3FInstance-20Host/-3FNumber-20of-20CPUs/-3FRAM-20Size/-3FAmount-20of-20Storage/limit%3D500/format%3Djson";
                string temp = System.IO.Path.GetTempFileName();
                if (Download(URL, temp))
                {
                    List<Instance> deleted = new List<Instance>();
                    lock (Instances)
                    {
                        deleted.AddRange(Instances);
                    }
                    System.IO.StreamReader a = System.IO.File.OpenText(temp);
                    JsonTextReader b = new JsonTextReader(a);
                    string name = "{unknown}";
                    string host = "{unknown}";
                    string ip = "{unknown}";
                    string project = "{unknown}";
                    string resource = "{unknown}";
                    string image = "{unknown}";
                    string Ram = "{unknown}";
                    string NumberOfCpu = "{unknown}";
                    string ModifyTime = "{unknown}";
                    string Storage = "{unknown}";
                    string FullUrl = "{unknown}";
                    string fqdn = "{unknown}";
                    string LaunchTime = "{unknown}";
                    string type = "{unknown}";
                    while (b.Read())
                    {
                        if (b.TokenType == JsonToken.PropertyName)
                        {
                            if (b.Value == null)
                            {
                                core.Log("DEBUG: null at value");
                                continue;
                            }
                            string value = b.Value.ToString();
                            if (value.StartsWith("Nova Resource:"))
                            {
                                value = value.Substring("Nova Resource:".Length);
                                if (resource != "{unknown}")
                                {
                                    Instance instance = getInstance(resource);
                                    if (instance != null)
                                    {
                                        if (deleted.Contains(instance))
                                        {
                                            deleted.Remove(instance);
                                        }
                                        deleteInstance(instance);
                                    }
                                    try
                                    {
                                        IPAddress[] addresslist = Dns.GetHostAddresses(resource);

                                        if (addresslist.Length > 0)
                                        {
                                            ip = addresslist[0].ToString();
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        core.Log("Debug: can't resolve" + resource);
                                    }
                                    instance = new Instance(resource, name, host, ip, type, true);
                                    instance.fqdn = fqdn;
                                    instance.FullUrl = FullUrl;
                                    instance.ImageID = image;
                                    instance.LaunchTime = LaunchTime;
                                    instance.ModifyTime = ModifyTime;
                                    instance.NumberOfCpu = NumberOfCpu;
                                    instance.Project = project;
                                    instance.Ram = Ram;
                                    instance.Storage = Storage;
                                    lock (Instances)
                                    {
                                        Instances.Add(instance);
                                    }
                                    name = "{unknown}";
                                    host = "{unknown}";
                                    ip = "{unknown}";
                                    project = "{unknown}";
                                    resource = "{unknown}";
                                    image = "{unknown}";
                                    Ram = "{unknown}";
                                    NumberOfCpu = "{unknown}";
                                    ModifyTime = "{unknown}";
                                    Storage = "{unknown}";
                                    FullUrl = "{unknown}";
                                    fqdn = "{unknown}";
                                    LaunchTime = "{unknown}";
                                    type = "{unknown}";
                                }
                                resource = value;
                            }
                            switch (b.Value.ToString())
                            {
                                case "Instance Name":
                                    name = getValue(ref b);
                                    break;
                                case "Instance Type":
                                    type = getValue(ref b);
                                    break;
                                case "Project":
                                    project = getValue(ref b);
                                    break;
                                case "Image Id":
                                    image = getValue(ref b);
                                    break;
                                case "FQDN":
                                    fqdn = getValue(ref b);
                                    break;
                                case "Launch Time":
                                    continue;
                                case "Puppet Class":
                                    break;
                                case "Modification date":
                                    ModifyTime = getValue(ref b);
                                    break;
                                case "Instance Host":
                                    host = getValue(ref b);
                                    break;
                                case "Number of CPUs":
                                    NumberOfCpu = getValue(ref b);
                                    break;
                                case "RAM Size":
                                    Ram = getValue(ref b);
                                    break;
                                case "Amount of Storage":
                                    Storage = getValue(ref b);
                                    break;
                                case "fullurl":
                                    FullUrl = getValue(ref b);
                                    break;
                            }
                        }
                    }
                    System.IO.File.Delete(temp);
                    foreach (Instance x in deleted)
                    {
                        deleteInstance(x);
                    }
                }
                else
                {
                    core.Log("Failed to download db file", true);
                }
                URL = "https://labsconsole.wikimedia.org/wiki/Special:Ask/-5B-5BResource-20Type::project-5D-5D/-3F/-3FMember/-3FDescription/mainlabel%3D-2D/searchlabel%3Dprojects/offset%3D0/limit%3D500/format%3Djson";
                temp = System.IO.Path.GetTempFileName();
                if (Download(URL, temp))
                {
                    System.IO.StreamReader a = System.IO.File.OpenText(temp);
                    JsonTextReader b = new JsonTextReader(a);
                    string name = "{unknown}";
                    List<Nova> projectlist2 = new List<Nova>();
                    List<string> members = new List<string>();
                    string description = "{unknown}";
                    while (b.Read())
                    {
                        if (b.Value == null)
                        {
                            continue;
                        }
                        //Console.WriteLine(b.Value.ToString());
                        string value = b.Value.ToString();
                        if (value.StartsWith("Nova Resource:"))
                        {
                            value = value.Substring("Nova Resource:".Length);
                            if (name != "{unknown}")
                            {
                                Nova project = null;
                                foreach (Nova x in projectlist2)
                                {
                                    if (x.Name == value)
                                    {
                                        project = x;
                                        break;
                                    }
                                }
                                if (project == null)
                                {
                                    project = new Nova(name);
                                }
                                project.users.AddRange(members);
                                if (!(description == "" && project.Description == ""))
                                {
                                    project.Description = description;
                                }
                                else if (project.Description == "")
                                {
                                    project.Description = "there is no description for this item";
                                }
                                description = "";
                                if (!projectlist2.Contains(project))
                                {
                                    projectlist2.Add(project);
                                }
                                members.Clear();
                            }
                            name = value;
                        }
                        if (value.StartsWith("User:"******"Description")
                        {
                            description = getValue(ref b, true);
                        }
                    }
                    System.IO.File.Delete(temp);
                    lock (ProjectList)
                    {
                        ProjectList.Clear();
                        ProjectList.AddRange(projectlist2);
                    }
                    lock (Instances)
                    {
                        foreach (Instance i in Instances)
                        {
                            Nova nova = getProject(i.Project);
                            if (nova != null)
                            {
                                i.project = nova;
                                lock (nova.instances)
                                {
                                    if (!nova.instances.Contains(i))
                                    {
                                        nova.instances.Add(i);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    core.Log("Failed to download db file", true);
                }
                OK = true;
                LastUpdate = DateTime.Now;
            }
            catch (Exception t)
            {
                core.Log(t.Data + t.StackTrace);
                core.handleException(t);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="name"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public static Instance CreateInstance(string name, int port = 0)
 {
     Syslog.DebugLog("Creating instance " + name + " with port " + port);
     Instance instance = new Instance(name, port);
     if (Instances.ContainsKey(name))
     {
         throw new Exception("Can't load instance " + name + " because this instance is already running");
     }
     Instances.Add(name, instance);
     return instance;
 }
Esempio n. 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name">Channel</param>
 public channel(string name)
 {
     Name = name;
     conf = "";
     Language = "en";
     SharedLinkedChan = new List<channel>();
     shared = "";
     suppress = false;
     LoadConfig();
     if (DefaultInstance == "any")
     {
         instance = core.getInstance();
         // we need to save the instance so that next time bot reconnect to bouncer it uses the same instance
         DefaultInstance = instance.Nick;
         SaveConfig();
     }
     else
     {
         lock (core.Instances)
         {
             if (!core.Instances.ContainsKey(DefaultInstance))
             {
                 core.DebugLog("There is no instance " + DefaultInstance);
                 instance = core.getInstance();
             }
             else
             {
                 instance = core.Instances[DefaultInstance];
             }
         }
     }
     if (!Directory.Exists(path_txt))
     {
         Directory.CreateDirectory(path_txt);
     }
     if (!Directory.Exists(path_txt + "/" + Name))
     {
         Directory.CreateDirectory(path_txt + "/" + Name);
     }
     if (!Directory.Exists(path_htm))
     {
         Directory.CreateDirectory(path_htm);
     }
     if (!Directory.Exists(path_htm + Path.DirectorySeparatorChar + Name))
     {
         Directory.CreateDirectory(path_htm + Path.DirectorySeparatorChar + Name);
     }
     LogDir = Path.DirectorySeparatorChar + Name + Path.DirectorySeparatorChar;
     Users = new IRCTrust(Name);
     lock (Module.module)
     {
         foreach (Module module in Module.module)
         {
             try
             {
                 if (module.working)
                 {
                     channel self = this;
                     module.Hook_Channel(self);
                 }
             }
             catch (Exception fail)
             {
                 core.Log("MODULE: exception at Hook_Channel in " + module.Name, true);
                 core.handleException(fail);
             }
         }
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Creates a new instance of IRC
 /// </summary>
 /// <param name="_server">Server to connect to</param>
 /// <param name="_nick">Nickname to use</param>
 /// <param name="_ident">Ident</param>
 /// <param name="_username">Username</param>
 /// <param name="_instance">Instance</param>
 public IRC(string _server, string _nick, string _ident, string _username, Instance _instance)
 {
     Server = _server;
     Queue = new MessageQueue(this);
     UserName = _username;
     NickName = _nick;
     Ident = _ident;
     ParentInstance = _instance;
 }
Esempio n. 9
0
 /// <summary>
 /// Creates a new instance of IRC
 /// </summary>
 /// <param name="_server">Server to connect to</param>
 /// <param name="_nick">Nickname to use</param>
 /// <param name="_ident">Ident</param>
 /// <param name="_username">Username</param>
 public IRC(string _server, string _nick, string _ident, string _username, Instance instance)
 {
     Server = _server;
     Password = "";
     _SlowQueue = new SlowQueue(this);
     UserName = _username;
     NickName = _nick;
     Ident = _ident;
     ParentInstance = instance;
 }