How check entrance data before web service without getting slowly? - nginx

I want to check some character in all entrance data before API.
I check in middle-ware but it makes API slowly.
I mean this:
1 Client send request => 2 NGINX =>3 Kestrel => 4 middle-ware=> 5 Code
I want to check in steps before code. I use .net core 2.2
thanks

I want to check body of request to remove extra space and check Persian character.
I do this with Lua !and I say to NGINX to call it.
local string_format = string.format
ngx.req.read_body()
local body = ngx.req.get_body_data() or ""
-- Replace 'Ye' and 'Kaf' arabic char with persian
body = ngx.re.gsub(body, "ي", "ی") -- remove id and name
body = ngx.re.gsub(body, "ك", "ک") -- remove id and name
-- Remove useless space
body = ngx.re.gsub(body, " ", " ") -- remove id and name
body = ngx.re.gsub(body, '" ', '"') -- remove id and name
body = ngx.re.gsub(body, ' "', '"') -- remove id and name
ngx.req.set_body_data(body)
in above I check body and replace it with proper data and again set body.
I hope it will be help other.

Related

KQL extend column with a static link

I have a query that I am parsing using an automation runbook. When I extend a column that has a static URL reference, I get the error:
BadArgumentError- Query could not be parsed at 'https'
The extend looks like this:
| extend Body = strcat(#"<p>The following items are expiring <strong>within 30 days</strong></p>", "<p>Plan to remediate as soon as possible.</p>", "<p>If the item is no longer valid, please remove it from ", "Application Insights</p>", "<p>Property: ", Name, "</p>", "<p>Expires In: ", ExpiresIn, " day(s) " "</p>")
The runbook posts to a logic app via a webhook which sends a readable output to users.
We can use triple backtick (```) to qualify strings that contain single and/or double quotes.
P.S.
Also note the following:
Splicing string literals
Two or more string literals are automatically joined to form a new string literal in the query if they have nothing between them, or they're separated only by whitespace and comments.
print Name = "MyName", ExpiresIn = "7"
| extend Body =
strcat
(
"<p>The following items are expiring <strong>within 30 days</strong></p>"
"<p>Plan to remediate as soon as possible.</p>"
"<p>If the item is no longer valid, please remove it from "
```Application Insights</p>```
"<p>Property: "
, Name
, "</p>"
"<p>Expires In: "
,ExpiresIn
," day(s) "
"</p>"
)
Name
ExpiresIn
Body
MyName
7
The following items are expiring within 30 daysPlan to remediate as soon as possible.If the item is no longer valid, please remove it from Application InsightsProperty: MyNameExpires In: 7 day(s)
Fiddle

Notification Email Entry Won't Work For Date Box Value

So I am using the following in the onValueEdit field of an entry form
var widgets = widget.root.descendants;
var to = 'xxxx#yyy.com';
var subject = 'Delivery Date Change For: ' + widgets.ProjectName.value;
var msg = "The Delivery Date for [ " + widgets.UsersPosition.value + " ] on [ " + widgets.ProjectName.value + " ] has been changed;
sendMessage(to, subject, msg);
So when a user changes a Delivery Date (by adjusting a Date Box) a notification email is sent out. I would like to add the actual in the Date Box but when I add " + widgets.DeliveryDate.value + " it says it is unrecognized.
Since the DeliveryDate is a Date Box, do I need something different? widgets.DeliveryDate.???
Thank you for any help.
"value" property is the one you need. Please note that it's JavaScript Date object so in some cases you need to convert it. But code you provided looks good to me.
What do you mean by "unrecognized"? Could you provide error details?
BTW: it's better to use Server Script to generate email message.

How to handle ampersands in URL parameters?

I am having the following issue:
I am using an application that allows users to concatenate text to build a URL that passes parameters to an ASP page via GET method, i.e. something like:
http://myhostname/process.asp?param1=value1&param2=value2
Problem is value1 and value2 can contain the ampersand symbol, which is not interpreted as a text character.
The most popular solution to this issue is to encode the URL, which is not an option for me because I cannot modify the program that builds the URL. I can modify the process.asp page, but not the program that concatenates the text fields and builds the URL.
Things I've tried to search for are:
How to encode a URL using javascript directly in the browser
How to change IIS default behaviour when reading an &
Alternative ways to pass parameters, i.e. something like passing them as a single string of characters separated with pipes
Hope you can give me some guidance.
You can read the entire query string and parse it yourself, like this:
q = Request.QueryString
a = Split(q, "=")
i = 1
For Each s In a
If i mod 2 = 0 Then
If InStr(s, "&") <> InStrRev(s, "&") Then
Response.Write "Value: " & Left(s, InStrRev(s, "&") - 1) & "<br/>"
hidingParam = Right(s, Len(s) - InStrRev(s, "&"))
Response.Write "PAramName: " & hidingParam & "<br/>"
i = i + 1
Else
Response.Write "Value: " & s & "<br/>"
End If
Else
Response.Write "PAramName: " & s & "<br/>"
End If
i = i + 1
Next
Result:
URL: ...?Q=abc&def&P=123 produces
PAramName: Q Value: abc&def PAramName: P Value: 123
Note that this is less than robust. I am only illustrating my idea. I didn't test with no &.
It also doens't handle multiple "=" characters (if that's a possiblity as well).
If there are 2 (or more) ampersands in-between the equals, then only the last one is a parameter separator. So, using your URL above, and assuming that value1 = "abc&def", and value2 = "123", then the URL will look like:
http://myhostname/process.asp?param1=abc&def&param2=123
Notice there's 2 ampersands in-between the 2 equals. The last one will be your parameter separator, the rest are part of the value. And any ampersands after the last equals are also part of the value.
You'll have to dissect the incoming URL and apply the appropriate logic.

create txt file and display it in internet browser inside vfp form

I'm facing difficulty when creating some kind of a report in vfp. I created a text file, used the ?/?? command to write to the file, then opened it using web browser (OLE Object in vfp form).
Set Printer To 'C:\temp\test.txt'
set printer on
set console off
?? 'test'
and then i called my prg :
PARAMETERS pUrl
lcURL = pUrl
PUBLIC oForm
oForm = CREATEOBJECT('IEForm')
oForm.SHOW()
oForm.oIE.Navigate2(m.lcURL)
READ events
DEFINE CLASS IEForm AS FORM
CAPTION = 'Report Preview'
HEIGHT = 512
WIDTH = 792
AUTOCENTER = .t.
ADD OBJECT oIE AS OLECONTROL WITH ;
HEIGHT=512,WIDTH=792,OLECLASS="Shell.Explorer",ANCHOR=195
PROCEDURE oIE.REFRESH
NODEFAULT
ENDPROC
ENDDEFINE
and used the C:\temp\test.txt as the url.
This works fine. But the problem occurs when I use fcreate to create the text file( not using the already existing text file)
lcfile ='C:\temp\'+SYS(2015)+'.txt'
lchandle=FCREATE(lcfile)
Set Printer To lcfile
sometimes the problem occurs when using ? ( resulting in blank doc), and sometimes the browser can't navigate to the file.
The second problem is : the browser can't navigate to the text file if i set the windowtype property to modal in the IEform. I need to set it modal because I have to delay the rest of the execution until the preview form is closed.
I hope I described the situation clear enough.
Thank You for helping Me :)
I would avoid using SET PRINTER TO, and just use the fcreate(), fwrite() and fclose(), especially if writing a large amount of text. If only writing a small amount of data, I would just build one long string by just appending each component to the prior and add cr/lf instead of "?" for new lines, then write the entire result to a file ONCE via StrToFile(). This way, you don't have to worry if things are actually closed (if you dont clear the set printer off, set printer to, or fclose(). Being an incomplete file, the browser won't navigate since the file handle may be "locked" to read anything.
Option 1 -- building a string
lcCRLF = chr(13)+chr(10)
lcMyOutput = "Some Text to Start with" + lcCRLF ;
+ "Today is: " + dtoc( date() ) + lcCRLF
use SomeTable
scan
lcMyOutput = lcMyOutput + "Some Field: " + SomeCharField;
+ "A numeric field: " + transform( SomeNumberField, "999,999.99" ) + lcCRLF
endscan
lcMyOutput = lcMyOutput + "All Done"
lcOutputFile = "C:\Temp\" + sys(2015) + ".txt"
StrToFile( lcMyOutput, lcOutputFile )
Option 2 -- using fcreate(), fwrite(), fclose()
lnHandle = 0
do while .t.
lcOutputFile = "C:\Temp\" + sys(2015) + ".txt"
lnHandle = fcreate( lcOutputFile )
*/ Only get out if we have a proper handle and thus
*/ we are exclusive to it for duration of our process
if( lnHandle > 0 )
exit
endif
enddo
lcCRLF = chr(13)+chr(10)
fwrite( lnHandle, "Some Text to Start with" + lcCRLF ;
+ "Today is: " + dtoc( date() ) + lcCRLF )
use SomeTable
scan
fwrite( lnHandle, "Some Field: " + SomeCharField;
+ "A numeric field: " + transform( SomeNumberField, "999,999.99" ) + lcCRLF )
endscan
fwrite( lnHandle, "All Done" )
fclose( lnHandle )
For running your "batch" file attempt with the RUN command, build the WHAT you want into a string, then run that... ex:
lcCommandToRun = '"' + sys(5) + sys(2003) + '\Compress.tzs"'
run ( lcCommandToRun )
I don't know if it was failing due to a space being in the path of your sys(2003) result turning the RUN into a multi-parameter interpretation, it would fail. By wrapping the entire text within double-quotes, it will prevent such "path" issue.
ADDITIONAL FEEDBACK
Trying to simulate a preview of a DOT-matrix printer using "?" to a text file is not something I would try. I would just do a standard report and draw it with all the data you are doing manually with the "?". If the user want's to preview the report, or send to a laser printer, let the normal report version handled through Windows for generation, font, and such do it for you. Leave the ancient code going to dot-matrix with whatever specific font rendering code as you have. I would just keep the actual report version CLOSE TO your "?" version.

Edit an email before sending

My application uses following function to send email.
Function SendHTMLEMail (strFrom, strTo, strCC, strSubject, strBodyHTML)
' create NewMail object
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
' set sender and recipients (latter can be ';' separated lists)
objNewMail.From = strFrom
objNewMail.To = "abc#xyz.com"
objNewMail.Cc = "def#stu.com"
' set Email Subject
objNewMail.Subject = strSubject
' construct and set Email's body
strHTMLStart = "" & strSubject & ""
strHTMLEnd = ""
objNewMail.Body = strHTMLStart & strBodyHTML & "To : " & strTo & "CC :" & strCC & strHTMLEnd
' set parameters to Normal importance MIME-encoded and HTML-formatted Email
objNewMail.Importance = 1 '9-low, 1-normal, 2-high
objNewMail.BodyFormat = 0 '0-HTML, 1-Text
objNewMail.MailFormat = 0 '0-MIME, 1-Text
' send Email now
objNewMail.Send
' release NewMail object
Set objNewMail = Nothing
End Function
I do not want the email to be sent automatically. It should open in outlook and allow me to edit it.
Can anyone help me with the change I should put here in the code so that the email opens instead of being sent automatically ?
The data is coming from a classic asp page and the above function is in utils.inc
You need to understand that you are processing the mail in the server and only sending HTML to the client (the web browser).
There is no possible way to manipulate a program (Outlook) in the client PC from the server, unless you have some piece of software (ActiveX, Add-on, etc.) in the client computer.
That said, you can do this trick
response.redirect("mailto:name#hotmail.com?subject=Hello&body=Place body here")
This will open the mail program configured in the client (it will depend on how the client PC is configured)
Be aware that you are very limited on the length of subject and body.
Tested in Firefox 3.6, Chrome and Internet Explorer 8 (it raises a security warning)

Resources