modify apache httpd.conf using ruby - ruby

Hey guys I'm trying to change in httpd.conf using ruby code 1.8.5 could you help me with it please
Apache configuration file The Apache configuration file must be configured specifically
for the server you have installed it on, i.e. the ServerName configuration item must be set to the IP address of the VM, not to 127.0.0.1 or any other generic address. TheServerAdmin configuration item must be set to cit470-sp2014-teamYOUR_TEAM_NUMBER#gmail.com. Create a gmail account with that name if you
have not done so already.
SSL All content must also be accessible using encrypted https versions of your URLs.
User directories Configure the server so that individual users can create their own web
sites by putting files in the public_html subdirectory of their home directory. These files should be available by both URLs of the form http://your_ip/~username and of the form http://your_ip/users/username. This may require that you create rewrite rules with mod_rewrite.
]# ./apconfigure.rb
./apconfigure.rb:8: warning: parenthesize argument(s) for future version
./apconfigure.rb:18: syntax error
.gsub(/ServerAdmin (.+)/, "ServerAdmin cit470su2015team2#gmail.com")
^
./apconfigure.rb:19: syntax error
.gsub(/UserDir disable/, "UserDir public_html")
^
./apconfigure.rb:20: syntax error
.gsub(userdir_regex, replacement) + "\nServerName 10.2.7.84 \nRewriteEngine on\nRewriteRule ^/users/(.*)$ /~$1 [PT]"
^
this is my code
#!/usr/bin/ruby
# This script edits the Apache configuration files and enables UserDir,
# as well as a custom RewriteRule
# path to apache config file
config_file = "/etc/httpd/conf/httpd.conf"
file = File.read(config _file)
# regex to uncomment the sample UserDir directives
userdir_regex = /#<Directory \/home\/\*\/public_html>.+?<\/Directory>/m
replacement = file.match(userdir_regex).to_s.gsub('#','')
# make some substitutions: change ServerName and ServerAdmin, enable UserDir,
# add rewrite rules.
edited_file =
file
.gsub(/ServerAdmin (.+)/, "ServerAdmin cit470su2015team2#gmail.com")
.gsub(/UserDir disable/, "UserDir public_html")
.gsub(userdir_regex, replacement) + "\nServerName 10.2.7.84 \nRewriteEngine on\nRewriteRule ^/users/(.*)$ /~$1 [PT]"
# write the changes to the file
File.open(config_file, 'w') do |f|
f.puts edited_file
end

Related

Unable to authenticate with Confluence server for Sphinx documentation

I am using sphinx for building documentation in confluence.I am able to make html file using sphinx. But when I am trying to connect confluence using the "make confluence" command it's throwing an error
I checked by changing the confluence password and checked using API token still getting the error and unable to connect with confluence.
Ref link-
https://github.com/Shravankumarhiregoudar/sphinxDocumentation
conf.py file:
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.append('/home/4px/sphinx/scripts/')
# -- Project information -----------------------------------------------------
project = 'sites'
copyright = '2021, divyank'
author = 'divyank'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
'sphinxcontrib.confluencebuilder'
]
confluence_publish = True
confluence_space_name = 'Documentation'
##confluence_ask_password = True
#confluence_parent_name = 'API Documentation'
# (for Confluence Cloud)
confluence_server_url = 'https://<....>.atlassian.net/wiki/spaces'
confluence_server_user = '<....>'
confluence_server_pass = '<.......>'
# (or, for Confluence Server)
#confluence_server_url = 'https://intranet-wiki.example.com/'
#confluence_server_user = 'myawesomeuser'
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns=[]
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'default'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
'preamble': '',
# Latex figure (float) alignment
'figure_align': 'htbp',
}
Error:
WARNING: normalizing confluence url from https://<......>.atlassian.net/wiki/ to https://<.......>.atlassian.net/wiki/
sphinxcontrib.confluencebuilder error:
---
Unable to authenticate with the Confluence server.
Ensure your username and password are correct. If your username and password is correct, you may need to unlock your Confluence account be re-logging in with your browser or asking your Confluence administrator for help.
---
make: *** [confluence] Error 2
I am able to resolve this issue using API token in the confluence password field in conf.py file.
How to generate API token-
Manage API tokens for your Atlassian account
Ref link-
Unable to authenticate with the Confluence server using sphinxcontrib.confluencebuilder

It's dangerous not recognizing URL Root

I'm using Flask's It's Dangerous to generate encrypted URLs. It's awesome, but I've encountered an issue - I'm running a script daily on Heroku Scheduler. The script lives outside of the app folder, in the directory where the run.py and Procfile are. I create the payload using three variables, the last one being the function assigned to a URL.
payload = reactivate_account_link(candidate.candidate_id, candidate.email, 'reactivate_account')
reactivate_account_link is the following...
def reactivate_account_link(candidate_id, candidate_email, path):
s = get_serializer()
loads = [candidate_id, candidate_email]
payload = s.dumps(loads)
return url_for(path, payload=payload, _external=True)
The problem is that the URL doesn't have the proper root. It creates...
http://localhost/candidates/reactivate_account/WzYsInN1cmFqa2FwQGdtYWlsLmNvbSJd.A484cnO8rRcAqe2M2mNrfoGludo/
as opposed to
http://[--DOMAIN--]/candidates/reactivate_account/WzYsInN1cmFqa2FwQGdtYWlsLmNvbSJd.A484cnO8rRcAqe2M2mNrfoGludo/
This is true for both local and prod. I want to avoid hardcoding the URL.
You need to configure the SERVER_NAME for the app, otherwise you get the default of 'localhost'. Wherever you create and configure your app, add:
SERVER_NAME = 'myapp.heroku.com' # or whatever the external url should be

MoinMoin seperate theme folder from MoinMoin htdocs folder

I'd like to seperate my custom theme folder from the default MoinMoin htdocs folder. Here is my directory structure of my current installation:
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/...
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/index.html
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/classic
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/modern
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/mytheme
/path/to/python2.7/lib/site-packages/MoinMoin/web/static/htdocs/mytheme/style.css
And my custom Git-versioned wiki/data directory:
/path/to/git-repo/wikiconfig.py
/path/to/git-repo/wikiserver.py
/path/to/git-repo/wiki/data/...
/path/to/git-repo/wiki/data/plugin/theme/mytheme.py
/path/to/git-repo/wiki/underlay/...
The wikiconfig.py contains the following configuration:
class LocalConfig(multiconfig.DefaultConfig):
wikiconfig_dir = os.path.abspath(os.path.dirname(__file__))
instance_dir = os.path.join(wikiconfig_dir, 'wiki')
data_dir = os.path.join(instance_dir, 'data', '') # path with trailing /
data_underlay_dir = os.path.join(instance_dir, 'underlay', '') # path with trailing /
DesktopEdition = True # give all local users full powers
acl_rights_default = u"All:read,write,delete,revert,admin"
surge_action_limits = None # no surge protection
sitename = u'Foo'
logo_string = u'<span><img src="...">Bar</span>' % url_prefix_static
page_front_page = u'StartPage'
theme_default = 'mytheme'
I would like to move the theme's static files to the /path/to/git-repo folder, because this directory is a Git repository which should contain all custom modifications, and also the theme's static files.
Any ideas how this could be done?
Regards
I suggest you just leave the builtin static stuff where it is.
What you can do for custom and separate theme development is to serve your static stuff at some specific URL and catch that URL in the web server before it gets given to moin.wsgi (and ends up being served by MoinMoin's builtin static file server), something like:
Alias /moin_static196/mytheme /path/to/git-repo/static
WSGIScriptAlias / /..../moin.wsgi
/moin_static196 is the url path moin 1.9.6 uses by default, you can modify it in wikiconfig.py to use anything you like.
You would put the theme python code also into your git repo and just symlink it from the instances data/plugin/theme/ directory.

How to setup mod_lua in Apache to access third party Lua modules?

I'm attempting to set up mod_lua module for Apache, but have encountered difficulty regarding accessing third party Lua modules. Say I have a hello_world.lua in Apache's htdocs folder that has something like this:
require "apache2"
function handle(r)
r.content_type = "text/html"
r:write "Hello World from <strong>mod_lua</strong>."
return apache2.OK
end
And I go to "http://localhost/hello_world.lua", that will function as expected. But if I try to add a line such as:
require "socket"
Or
require "cgilua"
I get the following output:
Error!
attempt to call a nil value
However, some modules do work, such as:
require "base"
That functions as expected.
If I navigate to base.lua in the filesystem (c:\program files\lua\5.1\lua\base.lua) and remove this file, then attempt to run my script I get the same error as stated above. So this must be the directory that mod_lua is checking for modules. Modules dlls are not in this folder, instead they are in c:\program files\lua\5.1\clibs\, which I set up the environment variable LUA_CPATH to point to.
Luasocket and cgilua are both present in this folder, yet they cause an error when I try to require them in my script.
From what I can gather, it works fine with any pure lua modules, but anything that has cmodules as well (socket, etc) causes problems.
Additional info:
OS: Windows 7 Home Premium
LUA_PATH = c:\program files\lua\5.1\lua\
LUA_CPATH = c:\program files\lua\5.1\clibs\
Apache version: 2.2.22
mod_lua version: http://www.corsix.org/content/mod-lua-win32#comment-3214
What needs to be done to be able to require modules in scripts run by mod_lua?
It looks like you need to add LuaPackageCPath and/or LuaPackagePath directives to your site configuration (in the global configuration file, or .htaccess, ...).
In your case, I'd assume that
LuaPackagePath c:\program files\lua\5.1\lua\
LuaPackageCPath c:\program files\lua\5.1\clibs\
should do the trick.

Solution to multi server environment with a CodeIgniter website

I have a local, staging and production environment for my CodeIgniter based site. Increasingly I find everytime I deploy a version I have more and more little bits of code to change because of server variations.
What would be a good (and quick) solution I could add that would allow me to set these variables by just using one setting. Where would be the best place to insert this in the index.php, some sort of hook?
If you're using Apache, you can set an environmental variable which can be read by PHP in your Virtual Hosts file for the site:
<VirtualHost *:80>
DocumentRoot /path/to/site
ServerName local.mysite.com
ErrorLog /path/to/error_log
CustomLog /path/to/access_log common
<Directory /path/to/site>
SetEnv ENVIRONMENT local
RewriteEngine On
Options FollowSymLinks Indexes
AllowOverride AuthConfig Options FileInfo
</Directory>
</VirtualHost>
So with that, you now can check for and set the server environment accordingly in your index.php file:
// always default to production for safety
$environment = 'production';
// check for an environment override
if (function_exists('apache_getenv') && apache_getenv("ENVIRONMENT")) {
$environment = apache_getenv("ENVIRONMENT");
} else if (getenv("ENVIRONMENT")) {
$environment = getenv("ENVIRONMENT");
}
// set the environment constant
define('ENVIRONMENT', $environment);
With this setup, you now have the freedom to deploy your sites and add additional configuration parameters to your application/config/[file].php files for each environment.
Alternative...
Another possibility for handling multi-environment setups is to create a file outside of the document root and is ignored by your version control system (i.e. .gitignore) which contains the value of the server environment. You could then just read that file via file_get_contents() or equivalent.
define a "LIVE" constant which is TRUE or FALSE based on the current domain its on (put this in your index.php file)
if(strpos($_SERVER['HTTP_HOST'], 'mylivesite.com'))
{
define('LIVE', TRUE);
}
else
{
define('LIVE', FALSE);
}
and then check to see if you are live or not and assign the variables accordingly
if(LIVE)
{
$active_group = "production";
}
else
{
$active_group = "test";
}
ive been doing this with our 5 environment setup for the past year with no problems
An old question, but Codeigniter Reactor has support for environment variables built in now. You simply open up the index.php file and choose your environment. There is a post about them here: http://ilikekillnerds.com/2011/03/how-to-use-codeigniter-reactor-environment-variables/
The official CodeIgniter doc suggests this for multiple database environment:
Gobal variable in config.php file to set the environment:
$active_group = "test";
Multiple settings in database.php
$db['test']['hostname'] = "localhost";
$db['test']['username'] = "root";
$db['test']['password'] = "";
$db['test']['database'] = "database_name";
...
$db['production']['hostname'] = "example.com";
$db['production']['username'] = "root";
$db['production']['password'] = "";
$db['production']['database'] = "database_name";
...
See the doc for further details.
Having many little bits of code that change because of server variations is a bad sign that you're modifying code that's not supposed to be modified for the application. The only things that you're supposed to change between servers is your configuration variables located in config.php, which should have default values for the developers to change depending on the environment.

Resources