Unix-style password readline - crystal-lang

I understand how to read a string from STDIN (noted below), but my problem is that the characters are displayed on the screen. How can I make the string hidden like the Unix/Linux password prompts?
print "Password: "
pass = gets.as(String).strip

The standard library currently provides no way for this. A quick workaround is to bind getpass(3):
lib LibC
fun getpass(prompt : Char*) : Char*
end
def getpass(prompt : String)
password = LibC.getpass(prompt)
raise Errno.new("getpass") unless password
String.new(password)
end
password = getpass("Enter password: ")
However note that this function is deprecated by glibc and the termios(3) interface should be used. I opened a pull request for this, so hopefully in Crystal version 0.19.0 or later you'll be able to:
print "Enter password: "
password = STDIN.noecho &.gets.try &.chomp
puts

Related

Google Apps Script Form textValidationBuilder does not recognize regex pattern

I am trying to create a Form with apps script and for some reason it will not allow the simplest phone number validation in a TextItem input field. I only need the user to enter their 10 digit number with no spaces, dashes, dots, with area code included. I know this isn't the technical "best" way to validate phone numbers but for our purposes it works. This is section of code I have to generate the field. (edited to make a more reproducible example)
function CreateForm() {
var form = FormApp.create('Test');
var tenantNum = form.addTextItem()
.setTitle("Tenant Phone #");
var phoneValid = FormApp.createTextValidation()
.setHelpText("Please enter valid phone number, 10-digits, no symbols or spaces.")
.requireTextMatchesPattern(/\d{10}/g)
.build();
tenantNum.setValidation(phoneValid);
console.log(form.getPublishedUrl())
}
I have also tried other things like:
(No capture group or global tag, both individually)
.requireTextMatchesPattern(/\d{10}/)
Entering the regex as a string literal.
.requireTextMatchesPattern("\d{10}")
Even dumdum stuff like.
.requireTextMatchesPattern(/[0-9]{10}/)
or
.requireTextMatchesPattern(/\d\d\d\d\d\d\d\d\d\d/)
Just to see if it works. I have also tried .requireTextContainsPattern() as well.
Whenever you enter in the form however i get this response:
Please enter valid phone number, 10-digits, no symbols or spaces.
My only thought is that there might be some confusion with whether or not the user is entering a string vs. number and this method only works on strings. But this validation
and regex work fine when you enter it into the form creation manually so I'm completely lost. Any help is appreciated!
Just a guess... Try this:
.requireTextMatchesPattern("\\d{10}")
Update
It works fine for me:
function CreateForm() {
var form = FormApp.create('Test');
var tenantNum = form.addTextItem()
.setTitle("Tenant Phone #");
var phoneValid = FormApp.createTextValidation()
.setHelpText("Please enter valid phone number, 10-digits, no symbols or spaces.")
.requireTextMatchesPattern("\\d{10}")
.build();
tenantNum.setValidation(phoneValid);
console.log(form.getPublishedUrl())
}
And the "not existed" method setHelpText() works fine as well, as you can tell from the screenshots.

C++. I want to save a specific line of characters, that change, in a string

I run a command in CMD through my C++ app which saves the output from that command. In that output, there is a port number and a remote API token, that changes upon each restart of the application im targeting.
This is the output I'm getting through my CMD command, which I store in a string:
"C:/Riot Games/League of Legends/LeagueClientUx.exe" "--riotclient-auth-token=5NFOIOqKB9EfSVsxBMrFUw" "--riotclient-app-port=63498" "--no-rads" "--disable-self-update" "--region=EUW" "--locale=en_GB" "--remoting-auth-token=***vx5yZOk_TkAt9YKq-PEucw***" "--respawn-command=LeagueClient.exe" "--respawn-display-name=League of Legends" "--app-port=63530" "--install-directory=C:\Riot Games\League of Legends" "--app-name=LeagueClient" "--ux-name=LeagueClientUx" "--ux-helper-name=LeagueClientUxHelper" "--log-dir=LeagueClient Logs" "--crash-reporting=crashpad" "--crash-environment=EUW1" "--crash-pipe=\\.\pipe\crashpad_19692_AJMBMQYOZVYYJMRF" "--app-log-file-path=C:/Riot Games/League of Legends/Logs/LeagueClient Logs/2020-07-09T12-55-09_19692_LeagueClient.log" "--app-pid=19692" "--output-base-dir=C:\Riot Games\League of Legends" "--no-proxy-server"
I've tried some stuff with the regex library, and managed to split my results up into words, but I still can't figure out how I save a specific line, that is the port number and the result of remoting-auth-token="characters I want to save".
My code to find out how many words are in the output string:
std::string output = exec("wmic PROCESS WHERE name='LeagueClientUx.exe' GET commandline");
std::regex wregex("(\\w+)");
auto words_begin = std::sregex_iterator(output.begin(), output.end(), wregex);
auto words_end = std::sregex_iterator();
std::cout << "Found: " << std::distance(words_begin, words_end) << std::endl;
PrintMatch(words_begin, words_end);
Output:
´´
Found: 110 CommandLine, C, Riot, Games, League, of, Legends, LeagueClientUx, exe, riotclient, auth, token, 5NFOIOqKB9EfSVsxBMrFUw, riotclient, app, port, 63498, no, rads, disable, self, update, region, EUW, locale, en_GB, remoting, auth, token, vx5yZOk_TkAt9YKq, PEucw, respawn, command, LeagueClient, exe, respawn, display, name, League, of, Legends, app, port, 63530, ´´ And a bit more but character restriction limits me, however the output which I need to store is there. I've set commas to mark new lines in the output.
‘’
It depends on what you mean by "save". Save to file or just assign to a variable? My guess is that you are confused about how iterators work and are wondering how you can fetch the remote-auth-token and the port number to from the words_begin variable. If the number of "words" in the cmd output is always the same you can use:
std::advance(words_begin,16);
std::string port = words_begin->str();
std::advance(words_begin,13);
std::string authToken = words_begin->str();
now, normally you would write the regex so as to only match the part you are interested in. Currently, since you are matching every "word", you are dependent on what position the remote auth token and port number are in the cmd output which might cause your application to break if that output ever changes order or add another word in front.

Python 2 and AppleScript. Dialogue prompts and default answers

Here is just a small snippet of the Python code I use to read the XML data of Mac System Profiler files for the purpose of adding the data to a database without having to copy/paste the details manually.
Specifically this snippet of code prompts the user to enter an "Article Number" to save the given ".spx" (System Profiler Report) under.
import subprocess
exampleString = "12345"
theText = subprocess.check_output(['osascript', '-e',
r'''set theText to text returned of (display dialog "Enter new Article Number here:
\n\nElse just press OK" default answer "" with title "Hardware Paster v1.0" with icon 2)'''
])
"theText" will go to on dictate the name of the spx file.
I would like to set the value of the "default answer" inside of the AppleScript prompt with the value of another variable inside the main python script ("exampleString" in this case). The "12345" is just placeholder text here.
The ultimate aim is to minimise data-entry by the end user.
Thanks for your help.
Just string format and you're good!
>>> exampleString = "world"
>>> 'hello there "{}"!'.format(exampleString)
'hello there "world"!'
And applied to your program:
exampleString = "12345"
template = r'''set theText to text returned of (display dialog "Enter new Article Number here:
\n\nElse just press OK" default answer "{}" with title "Hardware Paster v1.0" with icon 2)'''
theText = subprocess.check_output(
['osascript', '-e', template.format(exampleString)])

Regex grab password from net use

SecondEdit: We have command line auditing enabled and the logs going to elasticsearch. Basically, I'll be doing this subst in logstash, or trying to. It's actually been almost nil but I'm trying to cover all the bases.
We are monitoring cmd line activity on hosts and while it's policy that you aren't supposed to enter your password in clear text on the cmd line, people will.
So I'm looking for a way to detect when someone enters their password and then subst out the password for hashes. The 1.1.1.8 is an example, it could be any ip address.
From this I want to detect if there is a password there
net use I: \1.1.1.8\E$ /user:domain\username password /persistent:yes
Look behind, almost seems to have it but I can't get it to stop after the space after username...
(?<=/user:)(.*)(?<=\s)
net use I: \1.1.1.8\E$ /user:domain\username password /persistent:yes
when I need it to get -
net use I: \1.1.1.8\E$ /user:domain\username password /persistent:yes
https://regexr.com/3i6va
... it would be something like this to gsub the password out and replace with ###
filter {
if [event_id] == 4688 {
mutate {
gsub => ["[event_data][CommandLine]", "(?<=\/user:)(.*)(?<=\s)",
"########" ]
}
}
}

Is it possible to customize the subject of an email-ext generated email based on the build that finished

I know you can use a few tokens to customize the subject of the email, but I am looking for something a little more dynamic. I was hoping I could set an environment variable or write to a file somewhere from my build script, and have email-ext use that when formatting its email subject.
Is there anything available that might allow this?
Thanks for the help
You can modify the email subject using a pre-send groovy script as well.
For example, the following script checks for certain conditions and prepends some text on the subject line:
boolean isClaimed = false;
build.actions.each { action ->
if(action.class.name == "hudson.plugins.claim.ClaimBuildAction"
&& action.isClaimed()) {
isClaimed = true;
hudson.model.User user = hudson.model.User.get(action.getClaimedBy());
logger.println("[addClaimerOrCulprits.groovy] Build is claimed by " + user);
logger.println("[addClaimerOrCulprits.groovy] Sending email to claimer");
address = user.getProperty(hudson.tasks.Mailer.UserProperty).getAddress() ;
msg.addRecipients(javax.mail.Message.RecipientType.TO, address );
msg.setSubject("Attn " + action.getClaimedBy() + ": " + msg.getSubject());
}
}