Form action downloads ruby script instead of running it - html

I'm trying to send an email from a form made in HTML (haml). I've created a script called mailto.rb and I've set it as an action inside the form. The problem is that instead of running the code inside, when I press submit it just downloads the file (mailto.rb).
%form{:action => "mailto.rb", :method => "post"}
This is the code from the beginning of the form.
In HTML it would be:
<form method="post" action="mailto.rb">
Also, I've added the path to the ruby executable file on the first line of the ruby file.
#!~/.rbenv/shims/ruby
I know that It would be easier to use rails, but I'm not allowed. I have to use a ruby script.
PS: I'm using Middleman, and I work on localhost.

The idea is you can't POST request a static file with middleman. Same if you middleman build your application and pass everything to nginx/apache2. You'll get a 405 error
For example to use your script with nginx you have to install and use spawn-fcgi and fcgiwrap. Spawn a socket or a port from your ruby file and configure nginx to fastcgi_pass to fcgiwrap socket.
To use it with apache2, add your site to /var/www/html and put this in vhost:
AddHandler cgi-script .rb
<Directory /var/www/html>
Options +ExecCGI
</Directory>
Symlink cgid.conf and cgid.load to your mods-enabled folder and restart apache2.
Check error log for other problems, but it should work.
EDIT: In this case I'll choose apache2 over nginx. As a 3rd solution you should consider writing a rack script and pass it to unicorn.

Related

Index.html without XAMPP

Is it possible to automatically load index.html on a system folder without using XAMPP, IIS or similar?
It is for a school project and I can't use them, so I have to open the file putting the path (C:/...) into the address bar.
I know I could use .htaccess, but I don't know what to write and if it gets read without any web server solutions!
This can get a little tricky... but is possible without any "administrator" privileges, nor without installing anything.
Download Python 3.8.2 - Windows x86-64 embeddable zip file
Create a folder on "python" on the c:\
Extract the "Zip" file into this folder
Change the folder name from "python-3.8.2-embed-amd64" to "python_src"
Create a folder named "python_html"
The folder structure should look like:
c:\python\
c:\python\python_src\
c:\python\python_html\
Create a file named "webserver.py" in the "c:\python\python_html" folder
Place the following code into that file:
#webserver.py
import http.server
import socketserver
PORT = 80
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
Save and close the file
Create index.html file in the "python_html" folder and place the following code in that file:
<html>
<head>
<title>Web Title</title>
</head>
<body>
<h1>Python Web Server File</h1>
<p>Congratulations! The HTTP Server is working!</p>
</body>
</html>
Open the "Command Prompt" and type the following commands
cd\
cd python\python_html\
c:\python\python_src\python ./webserver.py
Open a web browser and navigate to "http://localhost/"
Once you have confirmed this works, you can build an entire website within that "python_html" folder. As long as you don't close the command prompt it will continue acting as a "Web Server".
I know I could use .htaccess
.htaccess is an Apache (Web Server) config file, so unless you have Apache installed (ie. the "A" in XAMPP) then you can't use that. (If .htaccess was available then index.html would likely load automatically anyway.)
On Apache, being able to load index.html by default when requesting a directory requires mod_dir (an Apache module). In this case, mod_dir issues an internal subrequest for the DirectoryIndex - this all requires additional processes.
I can't install extensions... I have to open the file on my school computer
If you can't install anything then you can't do this I'm afraid. You appear to be limited to direct file requests.
When using a webserver (such as Apache or IIS) then you have a differentiation between a URL and a filesystem path. The webserver maps the URL to a filesystem path. Without a webserver you don't have that abstraction.
There are lighter webservers, other than Apache and IIS, but you need to install something extra.
Just give your file(s) meaningful names (ie. not index.html) and use those instead? eg. fox-project.html

How to setup PhpStorm to debug OctoberCMS

I have tried debugbar, but this does not give me enough information.
I have also tried setting up OctoberCMS using that same method to debug as I would with Laravel, but when I set a break point it stops at index.php. Also, I have tried the validation script inside PhpStorm, but it gives a 404 error.
I am trying to debug a plugin that I am developing, and it would be easier using an IDE like PhpStorm or NetBeans. Any help would be appreciated.
I have setup phpstorm to debug a laravel project by setting the URL:/phpstorm/public in the PHP Web Page settings but when I try some thing simular in my octobercms project all I get is waiting for connection meaning that the break point never gets hit here are the setting I am using
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port= 9000
xdebug.remote_autostart=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir ="c:/wamp64/tmp/"
xdebug.idekey=PHPSTORM
in the PHP Web page I have
start URL: /octobercms/backend/rainlab/blog/Posts
I have not set path mappings in the server as did not do this for the Laravel project I am using WAMP64 with the following settings c:/wamp64/www/octobercms/
and this is my vitrual host file
<VirtualHost *:80>
ServerName octobercms.test
DocumentRoot "c:/wamp64/www/octobercms"
<Directory "c:/wamp64/www/octobercms">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
DirectoryIndex index.php index.html
Require local
</Directory>
</VirtualHost>
any advise on the setting I should use for Octobercms would be helpful
I am not sure if this helps but after several attemps to get this to work I managed to get phpstorm to stop at the breakpoint I selected by the following
Set up wamp up as above
In the PHP Web Page section I set the Start URL: to
/octobercms/backend/rainlab/blog/posts and apply settings
Set a break point in Posts.php
pressed the run button
and all is well with the world, I can now try to figure out why my plugin is not doing what its supposed to.

CGI Script displayed as Plain Text in Apache2 (localhost)

I currently have to do a web server in Apache2 that consists on a Login/Register web, and I have to call a CGI Script to validate the input data from the user. Well, when I call the script with the submit button, the CGI Script appears as Plain Text, and I don't know what else to do to fix it.
I have tried uncommenting CGI Modules in /etc/apache2/httpd.conf, setting a default directory for CGI Scripts, uncommenting the AddHandler for CGI and changing Options values in my localhost directory and in the CGI directory adding ExecCGI in them all. But it still does not work, it just appears as plain text.
P.S.: I followed this tutorial (http://httpd.apache.org/docs/2.2/howto/cgi.html) and also looked for the solution here in StackOverflow, but I got nothing working for me.
Edit: Also thank you for helping if you do :)
The problem was the directory configuration, so I kept the default http.config file, that has a preset ScriptAlias for the /cgi-bin/ directory to the following directory:
/Library/WebServer/CGI-Executables
Then I enabled the CGI Module by uncommenting the line (removing the '#' before the line) in the httpd.conf file from apache2:
LoadModule cgi_module libexec/apache2/mod_cgi.so
Finally I saved the file, and then I restarted the Apache2 server using the command:
sudo /usr/sbin/apachectl restart
Then I just pasted the .cgi script in the CGI-Executables directory, setting the permissions of the file as chmod a+x.
To run the script now you just have to access
localhost/cgi-bin/script.cgi
Thank you for the help anyways!

how to run html on python openshift server

I have an OpenShift server running python. However when I call php via SSL the php interpreter starts running. It suggests that there might be a way to run php as well. However, HTML if fair enough for me. Now, I do not know how to be able to reach html files on my server as when I am trying I always get 404 not found. I've read about a solution of placing a .htaccess file:
AddType application/x-httpd-php .html
I am not exactly sure where to place this file but placing in the folder of the .html file still not helps.
Could you please help me how I can make .html files reachable at an OpenShift server running Python? How about php?
Put the .html file in your app-root/repo/wsgi/static folder (or in that folder in your git repository). if you want it to be displayed like app-domain.rhcloud.com/file.html, you will have to use a .htaccess file in your wsgi folder that rewrites file.html to static/file.html

403 forbidden error cgi

I have a public html folder with my html pages and CGI script written in c. Within that, I have my cgi-bin folder with my GCI executable. However when I try to access my cgi page in my browser, it gives me the forbidden error. I'm using firefox and a linux system. I've looked around for the correct permissions but resources often advise different combinations. Any help is appreciated!
With a FTP client, or with console, check the rights to execute for the file. The apache process sould be able to execute it.
If this is right, and it still not work, then you have to properly configure the server.
As per your design ( 8 years ago on 2021), you did not provide permission for your cgi directory in the web server (possibly APACHE) configuration file.
Example in *nix:
Lets say your cgi-bin directory is actually is in /usr/home/your-name/cgi-bin
Then you have to add this to your that domains cgi section of your servers (ie Apache 2.4++) configuration file.
ScriptAlias /cgi-bin/ "/usr/local/www/ceo/cgi-bin/"
<Directory "/usr/local/www/ceo/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
And of course don't forget to turn on CGI module ( remove the #).