How can I write a rule that selects on all pages? - krl

In KRL (Kynetx Rule Language), how can I write a select statement that selects on all pages?

Because the select statements for web events in KRL are regular expressions you can use the following select statement to fire on all pages viewed:
select when web pageview ".*"
Example in context of full ruleset:
ruleset a60x425 {
meta {
name "test select on all pages"
description <<
this will select on all pageviews
>>
author "Mike Grace"
logging on
}
dispatch { }
rule selection_test_on_all_pages {
select when web pageview ".*"
{
notify("I selected on this page!","woot!") with sticky = true;
}
}
}
Note 1: This doesn't address the issue of dispatch domains and browser extensions. This will work as expected when executed from a bookmarklet. Browser extensions won't make it to the selection expression unless the currently viewed domain matches a domain set in the dispatch block. This examples dispatch domain is blank because I am making the assumption that the app will be run from a bookmarklet.
Note 2: Selection expressions get compiled into a regular expression so it's important to remember that you don't need to use the 're//' format for the expression like you do everywhere else in language you use a regular expression.

select when pageview ".*"

Related

Multiple conditional emails sent based on Google Form submission

I use the below script with a google form which sends an email to different people based on the answer chosen on the form. The script works and sends an email to the correct person when I use it with a form where the user can only choose one option.
But now I have a form where a user can choose between 1 and 6 options for the selection of cases to match. For every option chosen, I need an email to be sent to the corresponding department. With switch command, I understand that it tests an expression against a list of cases and returns the corresponding value of the first matching case. What I need is for it to test against a list of cases and return ALL corresponding values and then email based on that. Sometimes that would be one email, sometimes that could be 3 emails to 3 different people, etc.
The question on the google form is a checkbox question so a user can choose any and all if it applies. Each option correlates with a different email in my script.
Currently, if the form is filled out and only one option is chosen (see screenshot question "announcement outlet"), the script runs and sends the email as it should. But if two or more options are selected, no email goes out. When I check the trigger notes, the error is:
Exception: Failed to send email: no recipient
at sendFormByEmail(Code:47:13)
Here is my current script which works when only one option can be chosen. I believe I need a different command other than switch, but don't know what. I looked into fallthrough, but don't think that would work for this either.
function sendFormByEmail(e)
{      
// Remember to replace XYZ with your own email address  
var named_values = e.namedValues  
var teachername = named_values["Teacher Name"];    
var info = named_values["Your message/announcement"];  
var time = named_values["Please include time frame"];  
var photos = named_values["Include photos with this form if applicable; you can also create the graphic for social media and include below"];  
var announce = named_values["Choose announcement outlet"].toString();  
var email;
 
 // Optional but change the following variable  
// to have a custom subject for Google Docs emails  
  
// The variable e holds all the form values in an array.  
// Loop through the array and append values to the body.  
var message = "";      
for(var field in e.namedValues) {    
message += field + ' :: ' 
              + e.namedValues[field].toString() + "\n\n"; 
 }   
  switch (announce) {    
case "School Intercom Announcement":      
var email = "person1#school.net";      
break;    
case "MHHS Website":      
var email = "person2#school.net";      
break;    
case "MHHS Social Media (Instagram, Facebook, Twitter)":      
var email = "person3#school.net"     
break;    
case "Week in Pics":      
var email = "person4#school.net"  
var body = "Week in Pics Request"    
break;  
case "Remind text message (goes to students - please specify in your message info if it is all grades or specific grades)":
var email = "person5#school.net"
var subject = "Remind Text Request"
break;
case "Phone call home":
var email = "person6#school.net"
break;
}  
 // This is the MailApp service of Google Apps Script  
// that sends the email. You can also use GmailApp here.  
MailApp.sendEmail(email, subject, message);   
}
When multiple options are chosen, the data in the cell reads "Option 2, Option 4" and all my listed cases in the script above are for only "Option 2" or "Option 4", etc. Is there a way make this happen without having to make a case for every possible combination of the 6 choices that could potentially happen?
One way to fix the code
Remove .toString() from var announce = named_values["Choose announcement outlet"].toString();. Rationale: There is no need to convert an Array into a string for this case.
Instead of switch use if's, more specifically, add one if for each case clause, using an expression to test if the case label is included in announce. Example:
Replace
case "School Intercom Announcement":
by
if(announce.includes("School Intercom Announcement")){
// put here the case clause, don't include break;
// Add the following line before the closing `}` of the if statement
MailApp.sendEmail(email, subject, message);
}
Rationale: It's easier to implement the required control logic using if and Array.prototype.includes rather than doing it using switch.

GraphQL | Can we implement search by programming language in GitHub GraphQL API using Directives?

I'm experimenting with GraphQL and I want to create a GraphQL script for advanced search. I'm stuck at figuring out how to search for a repository containing a specific language. For example, I only want to search for repos written in Kotlin. This is what my query looks like
query AdvancedSearch($query: String!, $type: SearchType!, $numOfResults: Int!, $nextPageCursor: String) {
search(type: $type, query: $query, first: $numOfResults, after: $nextPageCursor) {
pageInfo {
hasNextPage
endCursor
}
repositoryCount
nodes {
... on Repository {
name
nameWithOwner
description
languages(first: 100) {
nodes {
name
}
}
}
}
}
}
I'm thinking along the lines of having a #skip directive in languages, something like
languages(first:100) #skip(if:$filterLanguage != "Kotlin")
I don't want to pass "language:kotlin" in the search query, I want to do this using Directives. Is something like this possible?
From the spec: http://spec.graphql.org/June2018/#sec--skip
The #skip directive may be provided for fields, fragment spreads, and inline fragments, and allows for conditional exclusion during execution as described by the if argument.
In other words, the #skip (and its #include counterpart) directive only determines whether a field is included in the request. Skipping a field this way is the same as not including it in the first place. Additionally, the if argument of the directive may only be passed true, false or a Boolean variable -- no sort of expression syntax is supported.
More importantly, including or omitting a particular field will have no impact on how any parent field is executed. If your intent is to modify what results are returned by the search field, then you need to provide the appropriate arguments to that field. The schema could provide some kind of argument to let you filter by languages specifically but that does not appear to be the case -- the only way to do it is through the query argument.

Allowed approaches for addressing SQL Injection in Fortify

I have the following code for implementing a drop down menu. The user selects two values, and, based on the input, the query selects the relevant columns to be shown to the user:
String sql = "SELECT :first, :second from <table>";
sql = sql.replace(":first", <first_user_input>);
sql = sql.replace(":second", <second_user_input>);
Now, Fortify catches these lines as allowing SQL Injection. My question is, will Fortify accept a RegEx based whitelisting approach as a solution?
I was thinking of adopting the following approach:
if(isValidSQL(<first_user_input>) && isValidSQL(<second_user_input>))
{
sql = sql.replace(...);
}
else
throw new IllegalSQLInputException
and
public boolean isValidSQL(String param)
{
Pattern p = Pattern.compile([[A-Z]_]+); //RegEx for matching column names like "FIRST_NAME", "LNAME" etc. but NOT "DROP<space>TABLE"
Matcher m = p.matcher(param);
return m.matches(param);
}
So, would Fortify accept this as a valid whitelisting method? If Fortify works on the below grammar:
valid_sql := <immutable_string_literal> //Something like "SELECT * FROM <table> WHERE x = ?" or //SELECT * FROM <table>
valid_sql := valid_sql + valid_sql //"SELECT * FROM <table>" + "WHERE x = ?"
then I don't suppose RegEx-based whitelisting would work. In that case, only this example would work, since it appends strings that are fixed at run time. I would not prefer this approach since it would result in a massive amount of switch-case statements.
Thank You
So, after trying the above mentioned approach, I found that Fortify is still catching the line as a potential threat. However, after reading about how Fortify works, I'm not sure if the "strictness" comes from Fortify itself, or the corporate rules defined in the XML configuration file for the same. I think that, if one's corporate rules allow regular expression-based whitelisting to work, then that should do the trick.

Select Option text value retrieval in Protractor - non angular [duplicate]

self teaching protractor and fighting issues of non angular web app and getting the list of all values out of a select control. here is the html but can't seem to validate the list. (first weight select box at this site)
http://halls.md/body-surface-area/bsa.htm
and my failed syntax. my script executes successfully referencing the element and option but can't correctly evaluate the capture of option values in the list:
var tempstr = browser.driver.findElement(by.xpath('//select[#name="wu"]')); //get all the options
var tempstrs = tempstr.findElements(by.tagName('option'));
console.log(tempstrs[1]);
First of all, use element notation - would at least look cleaner.
If you want to see the option text or value on the console, you need to resolve promises:
var weightUnitSelect = element(by.name("wu"));
var options = weightUnitSelect.all(by.tagName("option"));
options.first().getText().then(function (text) {
console.log(text);
});
Also, I recommend to abstract select->option HTML constructions with the help of this answer:
Select -> option abstraction

Variables for fields in MS Word

We have a template in Word, where we find and replace variables. e.g:Client Name.
Is there a way to autofill the variables with the content entered. I explored through mail merge and template/form fields. But did not get a user friendly material for a novice.
Kindly let me know if there is an walkthrough for the same.
I think you can do it with some fields. I recently had to overcome some of the limitations of Word's mail merge features by creating local variables.
You can create local variables in word by doing the following
{ SET localClientName { MERGEFIELD ClientName }}
The above creates a local variable called localClientName which can be referenced anywhere in the document by the following:
{ localClientName }
You just need to be sure to use the matched quotes. These are created by pressing 'ctr + F9.' It will not work if you use normal curly braces.
I hope this helps.
You can set variables like this:
{ SET someTextToRepeat "Here's some plain text" }
{ SET paymentDetails "Payment Details: { MERGEFIELD Invoice.Total }" }
And you can reference paymentDetails like this
{ paymentDetails }
Remember not to just type the {} but press Ctrl-F9 to create them.