I need to put one word and obtain the html tag with the word inclusive.
Example:
Text input: Madhuparna
I need to obtain:
June 5, 2021 By Madhuparna
bla bla bla Madhuparna bla bla bla
Test text:
<p>The entire purpose speed up the process.</p><p>June 5, 2021 By Madhuparna</p>\r\n<p>The entire purpose of a terminal emulator is to imitate how the regular computer terminals perform and allowing the main computer to connect to and use a remote computer through a command-line or a graphical interface. The terminal emulators are known to carry out the functions using the software.</p>\r\n<a>It allows file transfer between the main and the remote computer using SSH (Secure Shell) and also enables the host system to execute applications on the remote system. While it features a graphical user interface, programmers rather prefer the text-based interface to gain more control over all functions and speed up the process.</a><p>bla bla bla Madhuparna bla bla bla</p>
What I do for now but not work:
<(\S*?)[^>]*>.*?Madhuparna.*?<\/\1>|<.*?\/>
please try the following:
*edit - getting slightly messier now (and quite "hacky")...
/<([pali]{1,2})>[^<>]*Madhuparna[^<>]*<\/\1>/g
Probably not entirely optimised but does the job as per your sample.
This assumes that the only tags you are encountering (as per your sample) are <p> and <a> but please update the first capturing group ([pa]) of the regex if needed.
Proof here: https://regex101.com/r/16jjLn/1 - (updated)
The explanation panel on the link above will explain what the regex is doing.
I have just tested this. It's working well.
Please try this again.
/<(\S+)(>| .*?>)[^<>]*Madhuparna[^<>]*<\/\1>/g
I have just changed your test text like this.
<p>The entire purpose speed up the process.</p>
<p class="test">June 5, 2021 By Madhuparna</p>
<p >The entire purpose of a terminal emulator is to imitate how the regular computer terminals perform and allowing the main computer to connect to and use a remote computer through a command-line or a graphical interface. The terminal emulators are known to carry out the functions using the software.</p>
<a>It allows file transfer between the main and the remote computer using SSH (Secure Shell) and also enables the host system to execute applications on the remote system. While it features a graphical user interface, programmers rather prefer the text-based interface to gain more control over all functions and speed up the process.</a>
<span>bla bla bla Madhuparna bla bla bla</span>
This can be applied to all tags.
I'm not sure if this is right for you, but I hope it helps you. :)
Related
My question is similar to this question, but i didn't get my answer.
I am trying to design a judge.
The users of the online judge system submit their source code, then
the server program compiles and runs it. So the server program must
keep the server safe.
And there are a lot of things a user can use to make changes to the server.
How can i change the permission of a program? So that compiled code won't be able to do anything except printing something!
P.S: searching for suspicioius words is not a good idea. For instance, The user can use the following command instead of word system in C++:
#define glue(a,b) a ## b
glue(sys,tem) ("rm *"); //DO NOT RUN THIS CODE
So actually user used the following code without using the word system:
system ("rm *"); //DO NOT RUN THIS CODE
The are two options for you: the one you are currently looking into - trying to make your compiler, aka the server process that runs the user provided source code detect "exploits". And that might be hard. If you allow users to send you c++ source code, there is a lot of things that become possible. I guess you would need some real c++ gurus in order to get that solution even "half way secure".
So, option two: you have to run that user-provided input within some sort of sandbox. Examples could be:
A docker container (but for sure: a non-privileged container; run by a user, not root)
A virtual machine
If you are serious about what you are doing, you would probably focus on option 2 first (because that gives you a lot of benefit, at medium cost); but you definitely want to look into option 1, too (because one could learn from that a lot).
You can run them in a chroot jail, with user id set to nobody or some nonce account if nobody actually can do something significant. (You can use su or sudo for this.) Or even in their own VM. Pipe the output into a file, and read it from your judge program.
I'm writing code on C++ that will map to the nearest available drive using "net use * \server...etc" and afterwards I want to open a file on it.
Is there a command that will let me interact with this new drive without needing to know on which drive it was mapped beforehand? (Usually it will be drive Z:, but not always!)
Clearer example:
system("net use * \\server\folder\ p455word /user:server\user /p:no")
(output: "Server succesfully mapped to drive Z:")
Then I would normally try to open the file:
system("Z:\\folder\mydoc.docx")
My question is on how to do this:
system("*\\\folder\mydoc.docx")
With * being whatever the drive the computer chose to map to, or if there's a workaround to this. Thanks!
If you're looking for some net use-specific magic here, you're going to be disappointed. Your program simply passes a text string to the Windows shell, and has no knowledge or information about the command you've performed. It certainly can't pull out status information about the result of that call, beyond reading the command's text output.
Fortunately, the text output is all you need — your quote shows that the assigned drive letter is right there. You just need to pull it out, then construct the subsequent system calls dynamically by building up a string from the now-known drive letter, and the fixed part of your path.
system is not really designed for any of this, though. Here's how to execute a command and retrieve its output. Extracting the drive letter from the string "Server succesfully mapped to drive Z:" would also be a separate question. In general, when you have a problem, break it down into component parts; then you'll be able to "look it up" with success.
I'm looking to do some things involving (removable) devices, so I was looking at WMI and other APIs, the 'Devices and Printers' screen and the Safely Remove Hardware popup as I want to have as seamless an experience as possible. Problem however.. is that I can't find any way to get the names as my user 'knows' them in his PC.
Example... I connect an iPod, this shows in both DaP and SRH as 'iPod', which is awesome. In WMI the closest I've been able to find are 'Apple Inc. iPod' and 'Apple iPod USB Device'. Similar stories apply for other hardware like a WD My Book and other such hardware. Where do I find the proper string?
Since I am beginning to doubt whether I'm approaching the bigger picture from the right direction with WMI, a bit more explanation... we do a fair bit with removable hardware around here, 99% disk drives. I thought over hard-coding a loop from A to Z and inspect each drive, but to my knowledge removable volumes do not NEED to be mounted on a letter, but can also be dumped in an empty folder on ntfs. That and my small doubt there might be other (non-drive) hardware that needs 'finalizing' before being unplugged is adding to a small nagging doubt that I might be asking the wrong question alltogether. (editors: if this is too much irrelevant information, feel free to edit this out of the question.)
You can get this with WMI. This Powershell script does just that, the interesting property being Label:
PS C:\>gwmi -Class Win32_Volume | select Name, Label
Name Label
---- -----
C:\ Windows 7
D:\ Windows 2008
C:\TEST\ MYUSBKEY
E:\ RECOVERY
As you can see, it also works with devices not mounted with a letter.
As far as i can see, this does not work. The Powershell code (which is nothing else than another wmi wrapper) only retrieves the volume information for the mounted devices, such as usb keys. I have an iphone connected, and i see noting..
The problem is that, well, it's C++. The way I've created them makes it such that they've always been run via a terminal/console window and wait for user input or else simply take a sample input and run with that. The output has also always been to the terminal screen or sometimes to a file. I'm not quite sure how I could take all of that and integrate it with a website while leaving the source code as it is, if that's at all possible. I guess what I'm trying to aim for is to have whatever website I use behave like a terminal window that will accept user input and then send it off to run the C++ program in question and return with the output (whatever it may be), all with minimal modification to the source code. Either that or else set up a more automated kind of page where a user can just click 'Go' and the program will run using a sample input.
When it comes to web I consider myself intermediate with HTML, CSS, PHP & MySQL, and a beginner with Javascript, so if this can be accomplished using those languages, that would be fantastic. If not, don't be afraid to show me something new though.
The easiest interaction model to bring to the web is an application that takes its input up front and produces its output on stdout. In this situation, as the unknown poster mentioned, you could use CGI. But due to the nature of CGI, this will only work (in the simplest sense) if all the information is collected from the user in one page, sent to the application and the results returned in one page. This is because each invocation of a page using CGI spawns a new indepdent process to serve the request. (There are other more efficient solutions now, such as FastCGI which keeps a pool of processes around.) If your application is interactive, in that it collects some information, presents some results, prints some options, collects some more user input, then produces more results, it will need to be adapted.
Here is about the simplest possible CGI program in C++:
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Content-type: text/plain\n" << std::endl;
std::cout << "Hello, CGI World!" << std::endl;
}
All it does is return the content type followed by a blank line, then the actual content with the usual boring greeting.
To accept user input, you would write a form in HTML, and the POST target would be your application. It will be passed a string containing the parameters of the request, in the usual HTTP style:
foo.cgi?QTY=123&N=41&DESC=Simple+Junk
You would then need to parse the query string (which is passed to the program via the QUERY_STRING environment variable) to gather the input fields from the form to pass to your application. Beware, as parsing parameter strings is the source of a great number of security exploits. It would definitely be worthwhile finding a CGI library for C++ (a Google search reveals many) that does the parsing for you. The query data can be obtained with:
const char* data = getenv("QUERY_STRING");
So at a minimum, you would need to change your application to accept its input from a query string of name=value pairs. You don't even need to generate HTML if you don't want to; simply return the content type as text/plain to begin with. Then you can improve it later with HTML (and change the content type accordingly).
There are other more sophisticated solutions, including entire web frameworks such as Wt. But that would involve considerable changes to your apps, which you said you wished to avoid.
Almost off-topic, but you might want to take a look at Wt.
have you considered using cgi ... its 19th century technology which lets webserver execute programs written in C/C++ to run and generate output
I do not know much about it ... but I used it for some school projects
Show it all off with Screencasts. I use Camtasia Studio, but there are a ton of them out there: http://en.wikipedia.org/wiki/Screencast
Camtasia will even generate all of the HTML and Flash you need to upload to your web server. Buy a nice USB microphone, and write a script of what you're going to say and show.
What is the purpose of showing off your projects? Do you wish to impress your friends or employers?
It doesn't seem feasible to emulate or port your C++ console apps through a web interface.
I suppose you could write a bridge between a server side script and your C++ binary which passes the user input through to your app, then returns the result through the web interface. Bear in mind this would be a huge task for you to undertake.
Ruby have a compiler on their website which demonstrates this can be done.
However no one on the web would expect to run your C++ apps in a web browser. Also I think that anyone who is interested in running a C++ app would be totally comfortable with downloading a C++ binary that you made and running it (apart from the security risk) but when you think about it we download apps and run them all the time, whilst trusting the source.
I have a portfolio website which I created for the purpose of letting employers see my work. Take a look, it will give you an idea of another way you can do things.
Basically I provide the binaries for download, videos, screenshots and links. Things that the user can use to see my work quickly if they don't have time (or an appropriate computer) to run my projects on.
Good luck
I have no experience with this (other than hearing a guy on BART talk about implementing his server-side code all in C), but you might consider taking a look at SWIG (http://www.swig.org/). It allows you to wrap C++ so that you can access C++ code when using languages such as PHP.
Please don't reply I should use ddd, nemiver, emacs, vim, or any other front-end, I just prefer gdb as it is, but would like to see its output with some terminal colors.
.gdbinit
You can tweak your ~/.gdbinit to have colors. You can use mammon's .gdbinit which is available here:
https://github.com/gdbinit/gdbinit
You can tweak it as much as you want too. I found this thanks to this SO answer. Here's the kind of output that you can obtain:
A GitHub repository is also available: https://github.com/gdbinit/Gdbinit
On a side note, the same idea was also applied to lldb.
GDB Dashboard
Following the same concept, GDB Dashboard provides a modular visual interface for GDB in Python.
(void)walker
Another similar project uses GDB's Python support to provide more extensibility, so this is worth checking out: https://github.com/dholm/voidwalker
#dholm also provides his own .gdbinit inspired from the previous one.
pwndbg
Some projects provide a set of useful functions, including improved display. This is the case for PEDA or pwndbg. The latter gives the following description:
A PEDA replacement. In the spirit of our good friend windbg, pwndbg is pronounced pwnd-bag.
Speed
Resiliency
Clean code
It provides commands to support debugging and exploit development similar to the ones from PEDA, and better display (although this is not the main focus of the project). The software is still under development, and has not been properly released yet.
voltron
The project description states:
Voltron is an extensible debugger UI for hackers. It allows you to
attach utility views running in other terminals to your debugger (LLDB
or GDB), displaying helpful information such as disassembly, stack
contents, register values, etc, while still giving you the same
debugger CLI you're used to.
You can modify your .gdbinit to automatically integrate it. However, the display itself is outside of GDB (e.g. in a tmux split).
GEF
GEF is another option, and it is described as:
It is aimed to be used mostly by exploiters and reverse-engineers, to
provide additional features to GDB using the Python API to assist
during the process of dynamic analysis and exploit development.
It's not colours, but consider gdb's text gui. It makes a vast difference to how usable gdb is.
You can launch it with:
gdb -tui executable.out
Screenshot:
As you can see, the main features are:
shows what line of the source we are on and surrounding lines
shows breakpoints
I know you did not want a frontend.
But how about cgdb it is very close to gdb,
it is textmode but has a source window above with syntax highlight on the code.
New in upcoming GDB 8.3!
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/NEWS
Terminal styling is now available for the CLI and the TUI. GNU Source
Highlight can additionally be used to provide styling of source code
snippets. See the "set style" commands, below, for more information.
It is possible to greatly enhance the appears of gdb through the use of colors. This is done via any of the following methods:
Colorized prompt via the "set prompt". E.g., make the prompt bold and red:
set prompt \033[1;31m(gdb) \033[m
or make the prompt a new shape, bold and red:
set prompt \033[01;31m\n\n#####################################> \033[0m
Colorized commands via hooks
Colorized syntax highlighting of the "list" command.
All examples are available at the following blog posts written by Michael Kelleher:
"Beautify GDB", May 12, 2010 (via archive.org)
"Experimental GDB syntax highlighting", May 15, 2010 (via archive.org)
cgdb is much better than gdb -tui
#into .gdbinit
shell mkfifo /tmp/colorPipe
define hook-disassemble
echo \n
shell cat /tmp/colorPipe | c++filt | highlight --syntax=asm -s darkness -Oxterm256 &
set logging redirect on
set logging on /tmp/colorPipe
end
define hookpost-disassemble
hookpost-list
end
define hook-list
echo \n
shell cat /tmp/colorPipe | c++filt | highlight --syntax=cpp -s darkness -Oxterm256 &
set logging redirect on
set logging on /tmp/colorPipe
end
define hookpost-list
set logging off
set logging redirect off
shell sleep 0.1s
end
define hook-quit
shell rm /tmp/colorPipe
end
define re
hookpost-disassemble
echo \033[0m
end
document re
Restore colorscheme
end
Warning: Buggy. No TUI support, 'user-mode' hack.
Found the main part here
and modified it a bit. Needs highlight, c++filt. If colors get messed up issue re command.
Neat, I just found this hack using colout: https://github.com/nojhan/colout/blob/master/colout/example.gdbinit
I wanted to highlight as follows: emphasise the lines of a stack trace which belong to my source files (rather than libraries).
The solution was to use gdb-python (on MSYS; on Linux typically gdb comes with Python built-in already?), hook backtrace, use
python stack_trace = gdb.execute('backtrace', False, True')
Then process stack_trace with Python's regexes, and print them out. Bold and other colours are achieved by a function like this:
def term_style(*v):
"""1 is bold, 30--37 are the 8 colours, but specifying bold may also
change the colour. 40--47 are background colours."""
return '\x1B['+';'.join(map(str, v))+'m'
#Use like this:
print term_style(1) + 'This will be bold' + term_style(0) #Reset.
print term_style(1,30) + 'This will be bold and coloured' + term_style(0)
print term_style(1,30,40) + 'Plus coloured background' + term_style(0)
Another good combination of colors is given by this configuration. It renders inspecting the backtraces a lot easier. To use it, just save that file as ~/.gdbinit and run gdb normally
you can get whatever colors you want;
# gdb
(gdb) shell echo -en '\E[47;34m'"\033[1m"
...
anything is now blue foreground and white background
...
(gdb) shell tput sgr0
... back to normal