Esempio n. 1
0
 private void checkSecurityKey()
 {
     try
     {
         Log.Info("Checking if System Security Key exist");
         string cSSK = OSAE.OSAEObjectPropertyManager.GetObjectPropertyValue("System", "SecurityKey").Value;
         if (cSSK == " " || cSSK == "" || cSSK.Length < 16)
         {
             Log.Info("System Security Key found, but is not valid.");
             Log.Info("Generating a new Security Key...");
             OSAEObjectPropertyManager.ObjectPropertySet("System", "SecurityKey", OSAESecurity.GenerateSecurityKey(), "Rest");
         }
         else
         {
             Log.Info("System Security Key found.");
         }
     }
     catch
     {
         Log.Info("System Security Key does not exist..");
         Log.Info("Creating System object property: SecurityKey.");
         OSAEObjectTypeManager.ObjectTypePropertyAdd("System", "SecurityKey", "String", "", "", false, true, "This key is used in HTTP and Rest authorization. Must be 16 characters.");
         Log.Info("Generating a new Security Key...");
         OSAEObjectPropertyManager.ObjectPropertySet("System", "SecurityKey", OSAESecurity.GenerateSecurityKey(), "Rest");
     }
 }
        public List <OSAEPropertyHistory> GetPropertyHistory(string objName, string propName, string from, string to, string authkey)
        {
            if (OSAESecurity.Authorize(authkey, objName))
            {
                List <OSAEPropertyHistory> list = new List <OSAEPropertyHistory>();
                DataSet             ds          = OSAEObjectPropertyManager.ObjectPropertyHistoryGet(objName, propName, from, to);
                OSAEPropertyHistory ph          = new OSAEPropertyHistory();
                ph.label = objName + " - " + propName;
                List <List <double> > vals = new List <List <double> >();
                ph.data = vals;

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    List <double> p = new List <double>();
                    p.Add((double)Common.GetJavascriptTimestamp(DateTime.Parse(dr["history_timestamp"].ToString())));
                    p.Add(double.Parse(dr["property_value"].ToString()));
                    vals.Add(p);
                }
                list.Add(ph);
                return(list);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
 private void checkAPIKey()
 {
     try
     {
         Log.Info("Checking if REST API Key exist");
         string cRAK = OSAE.OSAEObjectPropertyManager.GetObjectPropertyValue("Rest", "APIKEY").Value;
         if (cRAK == " " || cRAK == "" || cRAK.Length < 32)
         {
             Log.Info("REST API Key found, but is not valid.");
             Log.Info("Creating a new REST API Key...");
             OSAEObjectPropertyManager.ObjectPropertySet("Rest", "APIKEY", OSAESecurity.GenerateAPIKey(), "Rest");
         }
         else
         {
             Log.Info("REST API Key found.");
         }
     }
     catch
     {
         Log.Info("REST API Key does not exist..");
         Log.Info("Creating Rest Plugin property: APIKEY.");
         OSAEObjectTypeManager.ObjectTypePropertyAdd("Rest", "APIKEY", "String", "", "", false, true, "This is the Rest Plugin API Key. This property is used by remote clients and devices to encrypt and decrypt user information for authentication.");
         Log.Info("Generating a new REST API Key...");
         OSAEObjectPropertyManager.ObjectPropertySet("Rest", "APIKEY", OSAESecurity.GenerateAPIKey(), "Rest");
     }
 }
Esempio n. 4
0
 protected void UpdateButton_Click(object sender, EventArgs e)
 {
     //foreach (var control in Page.Controls.OfType<ASP.ctrlStateImage>())
     //{
     //    if (OSAEObjectStateManager.GetObjectStateValue(control.ObjectName).Value != control.CurState)
     //    {
     //        control.Update();
     //    }
     //}
     authkey2.Value = OSAESecurity.generateCurrentAuthKey(currentuser);
 }
 public Boolean UpdateObject(string oldName, string newName, string alias, string description, string type, string address, string container, int mintruestlevel, string enabled, string authkey)
 {
     if (OSAESecurity.Authorize(authkey, oldName))
     {
         OSAEObjectManager.ObjectUpdate(oldName, newName, alias, description, type, address, container, mintruestlevel, Convert.ToBoolean(StringToBoolean(enabled)));
         Log.Debug("Oject Update:  " + oldName + ", " + newName + ", " + alias + ", " + description + ", " + type + ", " + address + ", " + container + ", " + mintruestlevel + ", " + enabled);
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public OSAEObjectState GetObjectState(string name, string authkey)
 {
     if (OSAESecurity.Authorize(authkey, name))
     {
         OSAEObjectState state = OSAEObjectStateManager.GetObjectStateValue(name);
         Log.Debug("Looking up object state:  " + name + ".  I Found " + state.StateLabel + ".");
         return(state);
     }
     else
     {
         return(null);
     }
 }
 public Boolean AddObject(string name, string alias, string description, string type, string address, string container, int mintruestlevel, string enabled, string authkey)
 {
     if (OSAESecurity.Authorize(authkey, name))
     {
         OSAEObjectManager.ObjectAdd(name, alias, description, type, address, container, mintruestlevel, StringToBoolean(enabled));
         Log.Debug("Oject Add:  " + name + ", " + alias + ", " + description + ", " + type + ", " + address + ", " + container + ", " + mintruestlevel + ", " + enabled);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
        /// </summary>
        /// <param name="pluginName">The name of the plugin from the system</param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            OwnTypes();
            try
            {
                this.Log.Info("Starting Rest Interface");

                bool showHelp = bool.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Show Help").Value);
                int  restPort = 8732;

                if (!OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Id.Equals(String.Empty))
                {
                    try
                    {
                        restPort = int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Value);
                        Log.Info("Rest Port read in as: " + restPort);
                    }
                    catch (FormatException ex)
                    { Log.Error("Error pulling REST port from property (not a valid number)", ex); }
                    catch (OverflowException ex)
                    { Log.Error("Error pulling REST port from property (too large)", ex); }
                    catch (ArgumentNullException ex)
                    { Log.Error("Error pulling REST port from property (null)", ex); }
                }

                String restUrl = "http://localhost:" + restPort.ToString() + "/api";
                serviceHost = new WebServiceHost(typeof(OSAERest.api), new Uri(restUrl));

                WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.None);
                binding.CrossDomainScriptAccessEnabled = true;

                var endpoint = serviceHost.AddServiceEndpoint(typeof(IRestService), binding, "");

                ServiceDebugBehavior sdb = serviceHost.Description.Behaviors.Find <ServiceDebugBehavior>();
                sdb.HttpHelpPageEnabled = false;
                if (showHelp)
                {
                    serviceHost.Description.Endpoints[0].Behaviors.Add(new WebHttpBehavior {
                        HelpEnabled = true
                    });
                }

                OSAESecurity.GenerateAPIKey();
                OSAESecurity.GenerateSecurityKey();
                serviceHost.Open();
            }
            catch (Exception ex)
            { Log.Error("Error starting RESTful web service", ex); }
        }
        public Boolean SetObjectProperty(string objName, string propName, string propVal, string authkey)
        {
            string uAuth = OSAESecurity.DecryptUser(authkey);

            if (uAuth != null)
            {
                OSAEObjectPropertyManager.ObjectPropertySet(objName, propName, propVal, uAuth);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 10
0
 public OSAEObject GetObject(string name, string authkey)
 {
     // lookup object
     if (OSAESecurity.Authorize(authkey, name))
     {
         OSAEObject OSAEobj = OSAEObjectManager.GetObjectByName(name);
         OSAEobj.Properties = getProperties(OSAEobj.Name);
         Log.Debug("Retrieving object:  " + name + ".");
         return(OSAEobj);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 11
0
        public Boolean SetObjectState(string name, string state, string authkey)
        {
            string uAuth = OSAESecurity.DecryptUser(authkey);

            if (uAuth != null)
            {
                OSAEObjectStateManager.ObjectStateSet(name, state, uAuth);
                Log.Debug("Setting object state:  " + name + " set to: " + state + ".");
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 12
0
        public Boolean ExecuteMethod(string name, string method, string param1, string param2, string authkey)
        {
            string uAuth = OSAESecurity.DecryptUser(authkey);

            if (uAuth != null)
            {
                // execute a method on an object
                OSAEMethodManager.MethodQueueAdd(name, method, param1, param2, uAuth);
                Log.Debug("Executing Method:  " + name + "." + method + "." + param1 + "." + param2);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 13
0
 /// <summary>
 /// OSA Plugin Interface - Commands the be processed by the plugin
 /// </summary>
 /// <param name="method">Method containging the command to run</param>
 public override void ProcessCommand(OSAEMethod method)
 {
     Log.Info("Processing Method: " + method.MethodLabel);
     //No commands to process
     if (method.MethodLabel == "GenerateApiKey")
     {
         OSAESecurity.GenerateAPIKey();
     }
     if (method.MethodLabel == "GenerateSecurityKey")
     {
         OSAESecurity.GenerateSecurityKey();
     }
     if (method.MethodLabel == "GenerateCurrentAuthKey")
     {
         Log.Info("currentAPIAuthKey: " + OSAESecurity.generateCurrentAuthKey(method.Parameter1));
     }
 }
Esempio n. 14
0
        public List <string> GetSystemStates(string authkey)
        {
            if (OSAESecurity.Authorize(authkey, "System"))
            {
                List <string> states = new List <string>();
                DataSet       ds     = OSAESql.RunSQL("select state_name from osae_v_object_state where object_name = 'SYSTEM'");
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    states.Add(dr["state_name"].ToString());
                }

                return(states);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 15
0
        public List <string> getPropertyList(string objName, string propName, string authkey)
        {
            if (OSAESecurity.Authorize(authkey, objName))
            {
                List <string> list = new List <string>();
                DataSet       ds   = OSAEObjectPropertyManager.ObjectPropertyArrayGetAll(objName, propName);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    list.Add(dr["item_name"].ToString());
                }

                return(list);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// OSA Plugin Interface - Commands the be processed by the plugin
 /// </summary>
 /// <param name="method">Method containging the command to run</param>
 public override void ProcessCommand(OSAEMethod method)
 {
     Log.Info("Processing Method: " + method.MethodLabel);
     //No commands to process
     if (method.MethodLabel == "GenerateApiKey")
     {
         OSAEObjectPropertyManager.ObjectPropertySet("Rest", "APIKEY", OSAESecurity.GenerateAPIKey(), "Rest");
         Log.Debug("New APIKEY Generated");
     }
     if (method.MethodLabel == "GenerateSecurityKey")
     {
         OSAEObjectPropertyManager.ObjectPropertySet("System", "SecurityKey", OSAESecurity.GenerateSecurityKey(), "Rest");
         Log.Debug("New SecurityKey Generated");
     }
     if (method.MethodLabel == "GenerateCurrentAuthKey")
     {
         Log.Info("currentAPIAuthKey: " + OSAESecurity.generateCurrentAuthKey(method.Parameter1));
     }
 }
Esempio n. 17
0
 public List <OSAEStateHistory> GetStateHistory(string objName, string from, string to, string authkey)
 {
     if (OSAESecurity.Authorize(authkey, objName))
     {
         List <OSAEStateHistory> list = new List <OSAEStateHistory>();
         DataSet ds = OSAEObjectStateManager.ObjectStateHistoryGet(objName, from, to);
         foreach (DataRow dr in ds.Tables[0].Rows)
         {
             OSAEStateHistory sh = new OSAEStateHistory();
             sh.obj      = dr["object_name"].ToString();
             sh.state    = dr["state_label"].ToString();
             sh.datetime = (double)Common.GetJavascriptTimestamp(DateTime.Parse(dr["history_timestamp"].ToString()));
             list.Add(sh);
         }
         return(list);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 18
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] == null)
        {
            Response.Redirect("~/Default.aspx");
        }
        currentuser = Session["Username"].ToString();
        int objSet = OSAEAdminManager.GetAdminSettingsByName("Screen Trust");
        int tLevel = Convert.ToInt32(Session["TrustLevel"].ToString());

        if (tLevel < objSet)
        {
            Response.Redirect("~/permissionError.aspx");
        }
        SetSessionTimeout();
        getRestPort();
        hdnUserTrust.Value    = Session["TrustLevel"].ToString();
        debuglabel.Text       = Session["TrustLevel"].ToString();
        authkey2.ID           = "authkey2";
        authkey2.ClientIDMode = ClientIDMode.Static;
        authkey2.Value        = OSAESecurity.generateCurrentAuthKey(currentuser);
        UpdatePlaceholder.Controls.Add(authkey2);
        gScreen = Request.QueryString["id"];

        try
        {
            OSAEObject screen = OSAEObjectManager.GetObjectByName(gScreen);
            //List<OSAEScreenControl> controls = OSAEScreenControlManager.GetScreenControls(gScreen);
            OSAEObjectCollection screenObjects = OSAEObjectManager.GetObjectsByContainer(gScreen);
            string    sImg = OSAEObjectPropertyManager.GetObjectPropertyValue(gScreen, "Background Image").Value.ToString();
            OSAEImage img  = imgMgr.GetImage(sImg);
            imgBackground.ImageUrl = "~/ImageHandler.ashx?id=" + img.ID;
            foreach (OSAEObject obj in screenObjects)
            {
                LoadControl(obj);
            }
        }
        catch
        { return; }
    }
Esempio n. 19
0
        public Boolean SendPattern(string match, string authkey)
        {
            //  try
            //  {
            //     oRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(oRecognizer_SpeechRecognized);
            //oRecognizer.AudioStateChanged += new EventHandler<AudioStateChangedEventArgs>(oRecognizer_StateChanged);
            //   }
            //   catch (Exception ex)
            //   {
            //      Log.Error("Unable to configure oRecognizer", ex);
            //   }

            //   oRecognizer = OSAEGrammar.Load_Direct_Grammar(oRecognizer);
            //   oRecognizer = OSAEGrammar.Load_Voice_Grammars(oRecognizer);
            //  oRecognizer = OSAEGrammar.Load_Text_Only_Grammars(oRecognizer);

            //REPLACE WITH GRAMMAR



            // string patternName = Common.MatchPattern(match,"");
            // if (patternName != "")
            //  {
            string uAuth = OSAESecurity.DecryptUser(authkey);

            if (uAuth != null)
            {
                OSAEScriptManager.RunScript(match, "", "Rest");
                Log.Debug("Executing Script:  " + match);
                return(true);
            }
            else
            {
                return(false);
            }
            //  }
            //  else
            //return false;
        }
Esempio n. 20
0
 public static string refreshAuthKey()
 {
     authKey2 = OSAESecurity.generateCurrentAuthKey(currentuser);
     return(authKey2);
 }