So I am trying to build my twitch bot through mIRC and I have been wanting it to timeout links for everysite except for any links from http://osu.ppy.sh/ and any links from http://puu.sh/ but block out anything else.
I have found script and tutorials but I cannot find anything that explains how to make an exception in enough detail to explain what each part of the exception is for nor can I find anything that includes these domains in the exception
Here is my old link protection script
on #*:text:*:#:linkpost $1-
on #*:action:*:#:linkpost $1-
on #*:notice:*:#:linkpost $1-
alias -l linkpost {
if ((!%p) && (!$hfind(permit,$nick))) { inc -u4 %p
var %purge /^!(link\so(n|ff)|(permit))\b/iS
var %domain com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk
var %link /(?<=^|\s)((?>\S{3,8}:\/\/|w{3}\56)\S+)|\56( $+ %domain $+ )\b/iS
if ($findtok(%chanon1,#,1,32)) && ($nick(#,$nick,vr)) && ($regex($1-,%link)) {
timeout # $nick | /mode # -b $nick
msg # $nick You did not have permission to post a link ask a mod to !permit you
msg # /timeout $nick 1
}
elseif (($regex($1-,%purge)) && ($regml(1) = permit) && ($nick isop #) && ($$2 ison #)) {
hadd -mz permit $v1 30 | notice $v1 You have 30 seconds to post a link. Starting now!
msg # You now have 30 seconds to post a link!
}
elseif (($regml(1) = link on) && ($nick isop #)) {
goto $iif(!$istok(%chanon1,#,32),a,b) | :a | set %chanon1 $addtok(%chanon,#,32)
.msg # My Link Protection Is Now on in: $+($chr(2),#)
halt | :b | .msg # $nick $+ , my link protection is already on in $&
$+($chr(2),#,$chr(2)) !
}
elseif (($regml(1) = link off) && ($nick isop #)) {
goto $iif($istok(%chanon1,#,32),c,d) | :c | set %chanon1 $remtok(%chanon,#,1,32)
.msg # My Link Protection Is Now off in: $+($chr(2),#)
halt | :d | .msg # $nick $+ , My link protection is already off . $&
!
}
}
}
Any will be appreciated, there is no other commands or script currently for the bot.
Code after edit
on #*:text:*:#:linkpost $1-
on #*:action:*:#:linkpost $1-
on #*:notice:*:#:linkpost $1-
alias -l linkpost {
if ((!%p) && (!$hfind(permit,$nick))) { inc -u4 %p
var %purge /^!(link\so(n|ff)|(permit))\b/iS
var %domain com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk
var %link /(?<=^|\s)((?>\S{3,8}:\/\/|w{3}\56)\S+)|\56( $+ %domain $+ )\b/iS
var %whitelistPattern = /.*http:\/\/(osu.ppy.sh|puu.sh)\/.*/i
if (!$regex($1-, %whitelistPattern)) {
return
}
if ($findtok(%chanon1,#,1,32)) && ($nick(#,$nick,vr)) && ($regex($1-,%link)) {
timeout # $nick | /mode # -b $nick
msg # $nick You did not have permission to post a link ask a mod to !permit you
msg # /timeout $nick 1
}
elseif (($regex($1-,%purge)) && ($regml(1) = permit) && ($nick isop #) && ($$2 ison #)) {
hadd -mz permit $v1 30 | notice $v1 You have 30 seconds to post a link. Starting now!
msg # You now have 30 seconds to post a link!
}
elseif (($regml(1) = link on) && ($nick isop #)) {
goto $iif(!$istok(%chanon1,#,32),a,b) | :a | set %chanon1 $addtok(%chanon,#,32)
.msg # My Link Protection Is Now on in: $+($chr(2),#)
halt | :b | .msg # $nick $+ , my link protection is already on in $&
$+($chr(2),#,$chr(2)) !
}
elseif (($regml(1) = link off) && ($nick isop #)) {
goto $iif($istok(%chanon1,#,32),c,d) | :c | set %chanon1 $remtok(%chanon,#,1,32)
.msg # My Link Protection Is Now off in: $+($chr(2),#)
halt | :d | .msg # $nick $+ , My link protection is already off . $&
!
}
}
}
A naive solution will be to add condition that will check the host and to stop the script from happening if it's not in the white list.
Change to this:
alias -l linkpost {
var %whitelistPattern = /.*http:\/\/(osu.ppy.sh|puu.sh)\/.*/i
if (!$regex($1-, %whitelistPattern)) {
return
}
; Rest of the current script
Fix: Forgot adding % before variable name.
Related
I'm configuring a freeradius server for authenticating Wifi clients with EAP-TLS.
The solution should check certificates with EAP-TLS and everything is working fine, but checking the "extended key usage" to reply with a specific VLAN is not working as expected.
So in my site config I have:
if (TLS-Client-Cert-Issuer == "/DC=de/DC=xxxxx/CN=XXX Sub CA" && TLS-Client-Cert-Subject-Alt-Name-Dns =~ /\.XY\.xxxxx\.de$/){
if(TLS-Client-Cert-X509v3-Extended-Key-Usage-OID == "1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.15380538.1") {
update reply {
&Tunnel-Type = 13,
&Tunnel-Medium-Type = 6,
&Tunnel-Private-Group-Id = "1"
}
}
if(TLS-Client-Cert-X509v3-Extended-Key-Usage-OID == "1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.15210945.2") {
update reply {
&Tunnel-Type = 13,
&Tunnel-Medium-Type = 6,
&Tunnel-Private-Group-Id = "2"
}
}
} elsif (TLS-Client-Cert-Issuer == "/DC=de/DC=xxxxx/CN=XXX Sub CA" && TLS-Client-Cert-Subject-Alt-Name-Dns =~ /\.XYZ\.xxxxx\.de$/) {
if(TLS-Client-Cert-X509v3-Extended-Key-Usage-OID == "1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.16530950.3") {
update reply {
&Tunnel-Type = 13,
&Tunnel-Medium-Type = 6,
&Tunnel-Private-Group-Id = "3"
}
}
} else {
update reply {
Reply-Message := "Certificate Extended-Key-Usage with wrong or missing Group."
Auth-Type := Reject
}
reject
}
In the log I see that the Attribute is in the tls-cert:
freeradius | (342) eap_tls: TLS-Client-Cert-Subject-Alt-Name-Dns := "user.XY.xxxxx.de"
freeradius | (342) eap_tls: TLS-Client-Cert-X509v3-Extended-Key-Usage += "TLS Web Client Authentication, 1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.15210945.7"
freeradius | (342) eap_tls: TLS-Client-Cert-X509v3-Extended-Key-Usage-OID += "1.3.6.1.5.5.7.3.2"
freeradius | (342) eap_tls: TLS-Client-Cert-X509v3-Extended-Key-Usage-OID += "1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.15210945.2"
But when I scroll down, I see that the result of the if-check is false:
freeradius | (343) if (TLS-Client-Cert-Issuer == "/DC=de/DC=xxxxx/CN=XXX Sub CA" && TLS-Client-Cert-Subject-Alt-Name-Dns =~ /\.XY\.xxxxx\.de$/){
freeradius | (343) if (TLS-Client-Cert-Issuer == "/DC=de/DC=xxxxx/CN=XXX Sub CA" && TLS-Client-Cert-Subject-Alt-Name-Dns =~ /\.XY\.xxxxx\.de$/) -> TRUE
freeradius | (343) if (TLS-Client-Cert-Issuer == "/DC=de/DC=xxxxx/CN=XXX Sub CA" && TLS-Client-Cert-Subject-Alt-Name-Dns =~ /\.XY\.xxxxx\.de$/) {
freeradius | (343) if (TLS-Client-Cert-X509v3-Extended-Key-Usage-OID == "1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.15380538.1") {
freeradius | (343) if (TLS-Client-Cert-X509v3-Extended-Key-Usage-OID == "1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.15380538.1") -> FALSE
freeradius | (343) if (TLS-Client-Cert-X509v3-Extended-Key-Usage-OID == "1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.15210945.2") {
freeradius | (343) if (TLS-Client-Cert-X509v3-Extended-Key-Usage-OID == "1.3.6.1.4.1.311.21.8.16510850.12376249.15288979.13711710.10124257.18.15210945.2") -> FALSE ### This should be TRUE ###
freeradius | (343) } # if (TLS-Client-Cert-Issuer == "/DC=de/DC=xxxxx/CN=XXX Sub CA" && TLS-Client-Cert-Subject-Alt-Name-Dns =~ /\.XY\.xxxxx\.de$/) = noop
TLS-Client-Cert-X509v3-Extended-Key-Usage-OID is a list, do I have to check it in a different way?
Thanks in advance.
Daniel
puts "Hello World"
scores = {"biology" => ['unit_test','final_exam'],
"maths" => ['quiz','class_participation','final_exam']
}
x = (scores["biology"] & %w[flying_test])
puts "result of x && scores[\"biology\"].any? => #{x && scores["biology"].any?}"# Why does this return true?
y = scores["maths"] & %w[quiz]
z = scores["maths"].any?
puts "result of scores[\"maths\"] & %w[quiz] => #{y}" # returns true
puts "result of scores[\"maths\"].any? => #{z}" # return true
puts "result of y && z => #{y && z}"
puts "******"
puts "Clubbing all conditions, returns no output, why? it is actually evluates to (true || true), right"
puts ( (scores["biology"].any? && (scores["biology"] & %w[flying_test])) ||
(scores["maths"].any? && (scores["maths"] & %w[quiz])) )
# But when above two sub-conditions are swapped puts print the value as true
puts "$$$$$$$"
puts ((scores["biology"] & %w[flying_test]) && scores["biology"].any?) ||
((scores["maths"] & %w[quiz]) && scores["maths"].any?)
puts "cross check"
# puts (1 == 1).any?
https://onlinegdb.com/YBmzutZOj - you can execute here
what are you actually trying to do with your "&"?
simplifying examples:
puts ( scores["biology"] & %w[flying_test] )
are you trying to check that the object exists, and only return the object, ala:
if scores["biology"].include?('flying_test')
or are you trying to do an addition:
scores["biology"] + %w[flying_test]
or return your list if there are no scores?
scores["biology"] || %w[flying_test]
...
or is it that you want to include the "&" as part of the test of what to return:
puts (scores['biology'].any? && scores['biology'].include?('flying_test') && %w[flying_test]) ||
(scores['maths'].any? && scores['maths'].include?('quiz') && %w[quiz])
or possibly, more like (closer to your style of coding):
puts (scores["biology"] & %w[flying_test]).any? && (scores["biology"] & %w[flying_test]) ||
scores["maths"] & %w[quiz]
?
&& returns the second operand, if both operands are truthy, and in ruby the empty list is truthy.
In your particular case, x = (scores["biology"] & %w[flying_test]) evaluates to the empty list [], so x && scores["biology"].any? actually evaluates to [] && true, so true.
Also, in
puts ( (scores["biology"].any? && (scores["biology"] & %w[flying_test])) ||
(scores["maths"].any? && (scores["maths"] & %w[quiz])) )
the first operand also evaluates to an empty list, so the entire || operation evaluates to the empty list []. Doing a puts [] results in a no output being generated.
I'm new to Ruby and I want to try to access a MySQL database:
require 'rubygems'
require "dbi"
class DBConnection
attr_accessor :dbh
#Connect to db
def connect?(driver_url,user,pass)
begin
#dbh = DBI.connect(driver_url, user,pass);
return true
rescue DBI::DatabaseError => e
puts "Error message: #{e.errstr}"
#dbh.rollback
return false
ensure
#dbh.disconnect if !dbh
end
end
def execute_customize(query,params)
stm = #dbh.prepare(query)
if( (params != nil) && !(params.empty?) )
stm.execute(params)
else
stm.execute
end
header = false
stm.fetch do |row|
if (!header)
puts("ID Name")
header = true
end
puts("#{row[0]} #{row[1]}")
end
end
end
db = DBConnection.new
db.connect?("DBI:Mysql:test:localhost", "root", "123456")
db.execute_customize("SELECT * FROM test.employee WHERE name = ? OR name = ? ",*["John","Terry"])
But the above returns the following error:
in `execute_customize': wrong number of arguments (3 for 2) (ArgumentError)
But the execution is successful with:
dbh.execute_customize("SELECT * FROM test.employee WHERE name = ?",*["John"])
What am I doing wrong?
Demo data from employee table :
+------+-------+
| id | name |
+------+-------+
| 1 | John |
| 2 | Terry |
| 3 | Vidal |
| 4 | CR7 |
| 5 | M10 |
| 6 | R10 |
| 7 | F4 |
+------+-------+
// Update : Your comment almost told me using IN in query, but if with other query like :
SELECT * FROM test.employee WHERE name = ? and id > ?
I still need a way to passing seperate paramer to every "?" character
You're passing three arguments instead of two.
The splat operator * expands the array, so its elements are treated as separate arguments.
Try
dbh.execute("SELECT * FROM test.employee WHERE name IN (?)", names)
where names is a comma-separated list of strings.
That should work, but you may not need to use execute for this.
If you're using Rails, you can just use
Employee.where(name: ["John","Terry"])
and ActiveRecord will understand what you mean.
See http://guides.rubyonrails.org/active_record_querying.html
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
I am learning PHP and I have used the post method to submit form data and I can not know why I get those two errors:
Notice: Undefined index: search_for in \xampp\htdocs\samir\indexes.php on line 5
Notice: Undefined index: replace_with in \xampp\htdocs\samir\indexes.php on line 6
if(isset($_POST['user_input']) && isset($_POST['search_for']) && isset($_POST['replace_with'])
&& !empty($_POST['user_input']) && !empty($_POST['search_for']) && !empty($_POST['replace_with']))
echo $user_input = $_POST['user_input'];
echo $search_for = $_POST['search_for'];
echo $replace_with = $_POST['replace_with'];
You forgot to add enclosing brackets for your if statement, like so:
if(isset($_POST['user_input']) && isset($_POST['search_for'])
&& isset($_POST['replace_with']) && !empty($_POST['user_input'])
&& !empty($_POST['search_for']) && !empty($_POST['replace_with'])) {
echo $user_input = $_POST['user_input'];
echo $search_for = $_POST['search_for'];
echo $replace_with = $_POST['replace_with'];
}
the above code should do what you want.
If you are using the variable before the form as been posted, e.g $var = $_POST['var'];
It will return an error.
It is best to check if the submit button has been pressed.
Example:
if(isset($_POST['submit'])){
//form has been posted
}
Then, I would make sure that all the post variables that you will be using are set, if not throw an error.
Example:
$error = false;
//['submit'] is the button used to post the form.
if(isset($_POST['submit'])){
$testVar = (isset($_POST['testVar']) && strlen($_POST['testVar']) > 0 ? $_POST : $error[] = 'Please enter something.');
if(!$error){
//Submit for
}
else{
foreach($error as $e){
echo $e;
}
}
}
When using $ _POST or $ _GET to retrieve the variables from a form, you may encounter this error:
Notice: Undefined index 'fields of the table' in 'path of php file being executes' on line 'current line'
This error appears because of your PHP error reporting settings. Usually, it appears when your variable is not properly set. There are two ways to handle this issue:
1.Check if $_POST['action'] or $GET['action'] is set before using it. For example:
if (!isset($_POST['action'])) {//your pure stuff }
if (!isset($_GET['action'])) {//your pure stuff }
2. Suppress Notice warnings
Notice warnings could be suppressed by changing the error_reporting variable in your PHP.ini. error_reporting could be set to show all errors except those for notices and coding standards warnings: error_reporting = E_ALL & ~E_NOTICE
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
but my personal suggestion is solve the warning instead of use the 2 method
updated question answer
you haven't add enclosing brackets {} so the only one line after if will consider as in if body and your 2nd and 3rd echo will be executed whether the result of your if is true or false
it should be
if(isset($_POST['user_input']) && isset($_POST['search_for'])
&& isset($_POST['replace_with']) && !empty($_POST['user_input'])
&& !empty($_POST['search_for']) && !empty($_POST['replace_with'])) {
echo $user_input = $_POST['user_input'];
echo $search_for = $_POST['search_for'];
echo $replace_with = $_POST['replace_with'];
}
I am trying to run the following mplayer command in rails using session:
mplayer -identify -vo null -ao null -frames 0 text.mov
I use require "session" and the following code works great in an individual ruby file.
mb = "mplayer"
mi = "-identify -vo null -ao null -frames 0"
dimensions_bitrate = Hash.new
stdout, stderr = '', ''
shell = Session::Shell.new
shell.execute "#{mb} #{mi} #{filename}", :stdout => stdout, :stderr => stderr
vars = (stdout.split(/\n/).collect! { |o| o if o =~ /^ID_/ } ).compact!
vars.each { |v|
a, b = v.split("=")
eval "##{a.to_s.downcase} = \"#{b}\""
if a == "ID_VIDEO_WIDTH"
dimensions_bitrate[0] = b.to_i
elsif a == "ID_VIDEO_HEIGHT"
dimensions_bitrate[1] = b.to_i
elsif a == "ID_VIDEO_BITRATE"
dimensions_bitrate[2] = b.to_i
end
}
HOWEVER, I am unable to load the session gem into ROR. I am not sure what the problem is. If I add require "session", I get the following error:
no such file to load -- session
I figure I am missing something relatively straightforward.
Any ideas?
I could not get this to work, so I did the following:
stdout = %x["mplayer" "-identify" "-vo" "-ao" "null" "-frames" "0" "#{filename}"]
vars = (stdout.split(/\n/).collect! { |o| o if o =~ /^ID_/ } ).compact!
vars.each { |v|
a, b = v.split("=")
eval "##{a.to_s.downcase} = \"#{b}\""
if a == "ID_VIDEO_WIDTH"
dimensions_bitrate[0] = b.to_i
elsif a == "ID_VIDEO_HEIGHT"
dimensions_bitrate[1] = b.to_i
elsif a == "ID_VIDEO_BITRATE"
dimensions_bitrate[2] = b.to_i
end
}
and it worked great. hope this is of use to someone running command line from ROR. The key is to set each parameter as a string.