Skip to content
Browse files

Initial Import

  • Loading branch information...
0 parents commit 6ff405bcbc8ac8387694ab9343517375a61a9f37 @davglass committed Feb 14, 2009
Showing with 311 additions and 0 deletions.
  1. +48 −0 src/js/bp-apache.js
  2. +118 −0 src/service/Apache.rb
  3. +2 −0 src/service/dev.sh
  4. +99 −0 src/service/httpd.conf
  5. +1 −0 src/service/last.port
  6. +16 −0 src/service/manifest.json
  7. +27 −0 tests/apache.html
48 src/js/bp-apache.js
@@ -0,0 +1,48 @@
+(function() {
+ var Dom = YAHOO.util.Dom,
+ Event = YAHOO.util.Event;
+
+ BrowserPlus.init(function(res) {
+ if (res.success) {
+ BrowserPlus.require({
+ services: [
+ {
+ service: 'Apache',
+ version: '0',
+ minversion: '0.0.4'
+ }
+ ]
+ }, function(r) {
+ if (r.success) {
+ Event.on('start', 'click', function(e) {
+ Dom.get('stop').disabled = false;
+ Dom.get('start').disabled = true;
+
+ BrowserPlus.Apache.start({
+ htdocs: '/tmp/dav-root/',
+ callback: function(r) {
+ alert('Apache service started: ' + r.url);
+ }
+ }, function() { console.log(arguments); });
+ });
+ Event.on('stop', 'click', function(e) {
+ Dom.get('start').disabled = false;
+ Dom.get('stop').disabled = true;
+
+ BrowserPlus.Apache.stop({
+ callback: function() {
+ console.log(arguments);
+ alert('Apache intance stopped..');
+ }
+ }, function() { console.log(arguments); });
+ });
+ } else {
+ alert('BP-AddressBook failed to load..');
+ }
+ });
+ } else {
+ alert('Browser Plus failed to load...');
+ }
+ });
+
+})();
118 src/service/Apache.rb
@@ -0,0 +1,118 @@
+require 'ftools'
+
+class Apache
+
+ def initialize(args)
+ @dir = File.expand_path(args['service_dir'])
+ @datadir = File.expand_path(args['data_dir'])
+ @tempdir = File.expand_path(args['temp_dir'])
+ File.makedirs(@tempdir)
+ end
+
+ def start(bp, args)
+ loc = args['htdocs']
+ callback = args['callback']
+ port = ''
+ File.open("#{@dir}/last.port").each { |line|
+ port = line.chomp
+ }
+ @port = port
+
+ File.copy("#{@dir}/httpd.conf", "#{@tempdir}/httpd.conf")
+
+ File.open("#{@tempdir}/custom.conf", 'a') do |f1|
+ f1.puts "DocumentRoot \"#{loc}\"\n"
+ f1.puts "PidFile #{@tempdir}/apache2.pid\n"
+ f1.puts "LockFile #{@tempdir}/accept.lock\n"
+ f1.puts "Listen 127.0.0.1:#{port}\n"
+ f1.puts "ErrorLog #{@tempdir}/error_log\n"
+ f1.puts "<Directory \"#{loc}\">\n"
+ f1.puts " Options Indexes FollowSymLinks MultiViews\n"
+ f1.puts " AllowOverride All\n"
+ f1.puts "</Directory>\n"
+ end
+ File.open("#{@tempdir}/httpd.conf", 'a') do |f1|
+ f1.puts "include #{@tempdir}/custom.conf"
+ end
+
+ `httpd -D BPApache#{port} -d #{@tempdir} -f #{@tempdir}/httpd.conf`
+
+ nport = port.to_f + 1
+ nport = nport.to_s.split('.')[0]
+
+ File.open("#{@dir}/last.port", 'w') do |f1|
+ f1.puts "#{nport}\n"
+ end
+
+ url = "http://127.0.0.1:#{port}/"
+
+ callback.invoke({
+ 'url' => url,
+ 'port' => port
+ });
+ end
+
+ def stop(bp, args)
+ callback = args['callback']
+ pid = ''
+ File.open("#{@tempdir}/apache2.pid").each { |line|
+ pid = line.chomp
+ }
+ cmd = "kill #{pid}"
+ `#{cmd}`
+ `cd #{@tempdir} && rm *`
+
+ callback.invoke({
+ 'done' => true
+ });
+ end
+
+end
+
+
+rubyCoreletDefinition = {
+ 'class' => "Apache",
+ 'name' => "Apache",
+ 'major_version' => 0,
+ 'minor_version' => 0,
+ 'micro_version' => 4,
+ 'documentation' =>
+ 'Local Apache Server',
+
+ 'functions' =>
+ [
+ {
+ 'name' => 'start',
+ 'documentation' => "Start the Process",
+ 'arguments' =>
+ [
+ {
+ 'name' => 'htdocs',
+ 'type' => 'string',
+ 'required' => true,
+ 'documentation' => 'The file location (path) that you want to serve via Apache.'
+ },
+ {
+ 'name' => 'callback',
+ 'type' => 'callback',
+ 'required' => true,
+ 'documentation' => 'the callback to send a hello message to'
+ }
+ ]
+ },
+ {
+ 'name' => 'stop',
+ 'documentation' => "Stop the Process",
+ 'arguments' =>
+ [
+ {
+ 'name' => 'callback',
+ 'type' => 'callback',
+ 'required' => false,
+ 'documentation' => 'the callback to send a hello message to'
+ }
+ ]
+ }
+ ]
+}
+
2 src/service/dev.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+~/src/local/bpsdk/bin/ServiceInstaller -v -f .
99 src/service/httpd.conf
@@ -0,0 +1,99 @@
+ServerRoot "/usr"
+
+#LoadModule authn_file_module libexec/apache2/mod_authn_file.so
+#LoadModule authn_dbm_module libexec/apache2/mod_authn_dbm.so
+#LoadModule authn_anon_module libexec/apache2/mod_authn_anon.so
+#LoadModule authn_dbd_module libexec/apache2/mod_authn_dbd.so
+#LoadModule authn_default_module libexec/apache2/mod_authn_default.so
+#LoadModule authz_host_module libexec/apache2/mod_authz_host.so
+#LoadModule authz_groupfile_module libexec/apache2/mod_authz_groupfile.so
+#LoadModule authz_user_module libexec/apache2/mod_authz_user.so
+#LoadModule authz_dbm_module libexec/apache2/mod_authz_dbm.so
+#LoadModule authz_owner_module libexec/apache2/mod_authz_owner.so
+#LoadModule authz_default_module libexec/apache2/mod_authz_default.so
+#LoadModule auth_basic_module libexec/apache2/mod_auth_basic.so
+#LoadModule auth_digest_module libexec/apache2/mod_auth_digest.so
+#LoadModule cache_module libexec/apache2/mod_cache.so
+#LoadModule disk_cache_module libexec/apache2/mod_disk_cache.so
+#LoadModule mem_cache_module libexec/apache2/mod_mem_cache.so
+#LoadModule dbd_module libexec/apache2/mod_dbd.so
+#LoadModule dumpio_module libexec/apache2/mod_dumpio.so
+#LoadModule ext_filter_module libexec/apache2/mod_ext_filter.so
+LoadModule include_module libexec/apache2/mod_include.so
+LoadModule filter_module libexec/apache2/mod_filter.so
+LoadModule deflate_module libexec/apache2/mod_deflate.so
+LoadModule log_config_module libexec/apache2/mod_log_config.so
+LoadModule log_forensic_module libexec/apache2/mod_log_forensic.so
+LoadModule logio_module libexec/apache2/mod_logio.so
+LoadModule env_module libexec/apache2/mod_env.so
+LoadModule mime_magic_module libexec/apache2/mod_mime_magic.so
+#LoadModule cern_meta_module libexec/apache2/mod_cern_meta.so
+#LoadModule expires_module libexec/apache2/mod_expires.so
+LoadModule headers_module libexec/apache2/mod_headers.so
+LoadModule ident_module libexec/apache2/mod_ident.so
+#LoadModule usertrack_module libexec/apache2/mod_usertrack.so
+#LoadModule unique_id_module libexec/apache2/mod_unique_id.so
+LoadModule setenvif_module libexec/apache2/mod_setenvif.so
+LoadModule version_module libexec/apache2/mod_version.so
+#LoadModule proxy_module libexec/apache2/mod_proxy.so
+#LoadModule proxy_connect_module libexec/apache2/mod_proxy_connect.so
+#LoadModule proxy_ftp_module libexec/apache2/mod_proxy_ftp.so
+#LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so
+#LoadModule proxy_ajp_module libexec/apache2/mod_proxy_ajp.so
+#LoadModule proxy_balancer_module libexec/apache2/mod_proxy_balancer.so
+#LoadModule ssl_module libexec/apache2/mod_ssl.so
+LoadModule mime_module libexec/apache2/mod_mime.so
+#LoadModule dav_module libexec/apache2/mod_dav.so
+#LoadModule status_module libexec/apache2/mod_status.so
+#LoadModule autoindex_module libexec/apache2/mod_autoindex.so
+#LoadModule asis_module libexec/apache2/mod_asis.so
+#LoadModule info_module libexec/apache2/mod_info.so
+#LoadModule cgi_module libexec/apache2/mod_cgi.so
+#LoadModule dav_fs_module libexec/apache2/mod_dav_fs.so
+#LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
+LoadModule negotiation_module libexec/apache2/mod_negotiation.so
+LoadModule dir_module libexec/apache2/mod_dir.so
+LoadModule imagemap_module libexec/apache2/mod_imagemap.so
+LoadModule actions_module libexec/apache2/mod_actions.so
+#LoadModule speling_module libexec/apache2/mod_speling.so
+#LoadModule userdir_module libexec/apache2/mod_userdir.so
+LoadModule alias_module libexec/apache2/mod_alias.so
+#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
+#LoadModule bonjour_module libexec/apache2/mod_bonjour.so
+#LoadModule php5_module libexec/apache2/libphp5.so
+#LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so
+
+<IfModule !mpm_netware_module>
+User www
+Group www
+</IfModule>
+
+ServerAdmin davglass@gmail.com
+
+<Directory />
+ Options FollowSymLinks
+ AllowOverride None
+</Directory>
+
+
+<IfModule dir_module>
+ DirectoryIndex index.html index.htm
+</IfModule>
+
+
+#LogLevel warn
+
+#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
+#LogFormat "%h %l %u %t \"%r\" %>s %b" common
+
+#CustomLog /tmp/dav/access_log common
+
+
+DefaultType text/plain
+
+#TypesConfig ./mime.types
+#AddType application/x-compress .Z
+#AddType application/x-gzip .gz .tgz
+
+
+
1 src/service/last.port
@@ -0,0 +1 @@
+20001
16 src/service/manifest.json
@@ -0,0 +1,16 @@
+{
+ "type": "dependent",
+ "uses": {
+ "corelet": "RubyInterpreter",
+ "version": "4"
+ },
+ "arguments": {
+ "ScriptFile": "Apache.rb"
+ },
+ "strings": {
+ "en": {
+ "title": "Local Apache Server on OSX",
+ "summary": "Local Apache Server on OSX"
+ }
+ }
+}
27 tests/apache.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.6.0/build/reset-fonts-grids/reset-fonts-grids.css">
+ <title>apache test</title>
+ <style>
+ p {
+ text-align: left;
+ margin: 2em;
+ padding: 1em;
+ }
+ p strong {
+ font-weight: bold;
+ }
+ </style>
+</head>
+<body>
+<p>This demo loads a local Apache instance scoped to the directory that you supply. Press the start button to open an instance, it will alert you with the URL. <strong>Be sure and click the Stop button, I can't figure out how to make a destructor work so the apache instance will not be terminated when you close the tab/window.</strong></p>
+<p>
+<button id="start">Start Apache</button> - <button id="stop" disabled>Stop Apache</button>
+</p>
+<script type="text/javascript" charset="utf-8" src="http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&2.6.0/build/dragdrop/dragdrop-min.js&2.6.0/build/container/container-min.js&2.6.0/build/element/element-beta-min.js&2.6.0/build/resize/resize-min.js"></script>
+<script src="http://bp.yahooapis.com/2.1.11/browserplus.js"></script>
+<script type="text/javascript" src="../src/js/bp-apache.js"></script>
+</body>
+</html>

0 comments on commit 6ff405b

Please sign in to comment.
Something went wrong with that request. Please try again.