Apache-SdnFw

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

lib/Apache/SdnFw/template/db/views/employees_v_login.sql
lib/Apache/SdnFw/template/db/views/group_actions_v.sql
lib/Apache/SdnFw/template/db/views/group_actions_v_action.sql
lib/Apache/SdnFw/template/db/views/group_actions_v_group.sql
lib/Apache/SdnFw/template/db/views/groups_v.sql
lib/Apache/SdnFw/template/object/employee.pm
lib/Apache/SdnFw/template/object/group.pm
lib/Apache/SdnFw/template/object/group/copy.tt
lib/Apache/SdnFw/template/object/group/edit_permission.tt
lib/Apache/SdnFw/template/object/me.pm
lib/Apache/SdnFw/template/object/me/change_password.tt
lib/Apache/SdnFw/template/object/me/edit.tt
lib/Apache/SdnFw/template/object/me/list.tt
lib/Apache/SdnFw/template/startup.pl
lib/Apache/SdnFw/template/tt/menu.tt
lib/Apache/SdnFw/tt/addnote.tt
lib/Apache/SdnFw/tt/address_form.tt
lib/Apache/SdnFw/tt/alert.tt
lib/Apache/SdnFw/tt/alert.tt.xml
lib/Apache/SdnFw/tt/api_object.tt.xml
lib/Apache/SdnFw/tt/confirm.tt

lib/Apache/SdnFw/db/install/pg.sql  view on Meta::CPAN

-------------------------------
CREATE TABLE employee_groups (
	employee_id		int4 not null references employees,
	group_id		int4 not null references groups);
CREATE UNIQUE INDEX employee_groups_idx ON employee_groups (employee_id, group_id);
GRANT ALL ON employee_groups TO sdnfw;
CREATE INDEX employee_groups_employee_id ON employee_groups (employee_id);
CREATE INDEX employee_groups_group_id ON employee_groups (group_id);

CREATE VIEW employees_v_login (employee_id, login, cookie, passwd, name, email,
	password_expired, locked_out, account_expired, groups, admin) AS
SELECT e.employee_id, e.login, e.cookie, e.passwd, e.name, e.email,
	CASE WHEN passwd_expire < now() THEN TRUE ELSE NULL END as password_expired,
	e.locked_out,
	CASE WHEN expired_ts < now() THEN TRUE ELSE NULL END as account_expired,
	concat(eg.group_id) as groups,
	CASE WHEN count(g.admin) > 0 THEN TRUE ELSE NULL END as admin
FROM employees e
	LEFT JOIN employee_groups eg ON e.employee_id=eg.employee_id
	LEFT JOIN groups g ON eg.group_id=g.group_id
GROUP BY 1,2,3,4,5,6,7,8,9;
GRANT ALL ON employees_v_login TO sdnfw;

lib/Apache/SdnFw/js/tinymce/jscripts/tiny_mce/tiny_mce.js  view on Meta::CPAN

(function(c){var a=/^\s*|\s*$/g,d;var b={majorVersion:"3",minorVersion:"3.8",releaseDate:"2010-06-30",_init:function(){var r=this,o=document,m=navigator,f=m.userAgent,l,e,k,j,h,q;r.isOpera=c.opera&&opera.buildNumber;r.isWebKit=/WebKit/.test(f);r.isIE...

lib/Apache/SdnFw/js/tinymce/jscripts/tiny_mce/tiny_mce_src.js  view on Meta::CPAN

			if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
				u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;

			// Relative path http:// or protocol relative //path
			if (!/^\w*:?\/\//.test(u))
				u = (s.base_uri.protocol || 'http') + '://mce_host' + t.toAbsPath(s.base_uri.path, u);

			// Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
			u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
			u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
			each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
				var s = u[i];

				// Zope 3 workaround, they use @@something
				if (s)
					s = s.replace(/\(mce_at\)/g, '@@');

				t[v] = s;
			});

			if (b = s.base_uri) {

lib/Apache/SdnFw/js/tinymce/jscripts/tiny_mce/tiny_mce_src.js  view on Meta::CPAN

		},
		radio: function(elem){
			return "radio" === elem.type;
		},
		checkbox: function(elem){
			return "checkbox" === elem.type;
		},
		file: function(elem){
			return "file" === elem.type;
		},
		password: function(elem){
			return "password" === elem.type;
		},
		submit: function(elem){
			return "submit" === elem.type;
		},
		image: function(elem){
			return "image" === elem.type;
		},
		reset: function(elem){
			return "reset" === elem.type;
		},

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

	croak "Unknown local working directory for that vendor" unless($vendor->{local_path});
	croak "Could not find local inbox for vendor" unless(-e "$vendor->{local_path}/inbox");
	#croak "Could not find local outbox for vendor" unless(-e "$vendor->{local_path}/outbox");

	my $ftp;
	if ($vendor->{ftp_type} eq 'ftps') {
		eval "use Net::FTPSSL";
		if ($@) { croak "$@"; }

		my ($server,$port) = split ':', $vendor->{ftp_server};
		print "Logging into $server : $port : $vendor->{ftp_username} : $vendor->{ftp_password}\n" if ($s->{v});
		$port = '21' unless($port);
		$ftp = Net::FTPSSL->new($server,
			Port => $port,
			useSSL => 1,
			Debug => 2,
			) 
			|| die "Can not connect to $vendor->{ftp_server}: $@";
		$ftp->login($vendor->{ftp_username},$vendor->{ftp_password}) 
			|| die "Login failed to $vendor->{ftp_server}: $@";

		print "Connected\n" if ($s->{v});
		my @dirs = $ftp->nlst();

		foreach my $d (@dirs) {
			if ($d =~ m/^(outbox|outgoing)$/i) {
				$ftp->cwd($d) || die "Error cwd to $d: ", $ftp->message;
				foreach my $f ($ftp->nlst()) {
					print "Downloading $f to inbox\n" if ($s->{v});

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

						$ftp->message;
					$ftp->delete($f) || die "Error delete $f: ",
						$ftp->message;
				}
			}
		}
	} elsif ($vendor->{ftp_type} eq 'ftp') {
		print "Logging into $vendor->{ftp_server}\n" if ($s->{v});
		$ftp = Net::FTP->new($vendor->{ftp_server}) 
			|| die "Can not connect to $vendor->{ftp_server}: $@";
		$ftp->login($vendor->{ftp_username},$vendor->{ftp_password}) 
			|| die "Login failed to $vendor->{ftp_server}: $@";
	
		print "Connected\n" if ($s->{v});
		my @dirs = $ftp->ls();

		foreach my $d (@dirs) {
			if ($d =~ m/^(outbox|outgoing)$/i) {
				$ftp->cwd($d) || die "Error cwd to $d: ", $ftp->message;
				foreach my $f ($ftp->ls()) {
					print "Downloading $f to inbox\n" if ($s->{v});

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

	my %hash = $s->db_q("
		SELECT *
		FROM edi_vendors_v
		WHERE edi_vendor_id=?
		",'hash',
		v => [ $edi_vendor_id ]);

	croak "Invalid edi_vendor $edi_vendor_id" unless($hash{edi_vendor_id});

	if ($s->{env}{DEV}) {
		foreach my $k (qw(ftp_username ftp_server ftp_password ftp_path)) {
			$hash{$k} = $hash{"test_$k"} if ($hash{"test_$k"});
		}
	}

	my $ext = $hash{fileext} || '.edi';
	my $filename = "$hash{filepre}$document_code-$edi_trans_id-$s->{datetime}{ymdhms}$ext";

	if ($hash{ftp_type} eq 'ftps') {
		open F, ">/tmp/$filename";
		print F $text;

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN


	eval "use Net::FTPSSL";
	if ($@) { croak "$@"; }

	my ($server,$port) = split ':', $hash->{ftp_server};
	$port = '21' unless($port);
	my $ftp = Net::FTPSSL->new($server,
		Port => $port,
		) 
		|| die "Can not connect to $hash->{ftp_server}: $@";
	$ftp->login($hash->{ftp_username},$hash->{ftp_password}) 
		|| die "Login failed to $hash->{ftp_server}: $@";

	if ($hash->{ftp_path}) {
		print "CWD $hash->{ftp_path}\n";
		$ftp->cwd($hash->{ftp_path}) || die "Error cwd to $hash->{ftp_path}: ",$ftp->message;
	}

	my @dirs = $ftp->nlst();

	foreach my $f (@dirs) {

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

	}

	die "Did not find inbox/incoming on $hash->{ftp_server}";
}

sub _ftp_file {
	my $hash = shift;
	my $filename = shift;

	my $ftp = Net::FTP->new($hash->{ftp_server}) || die "Can not connect to $hash->{ftp_server}: $@";
	$ftp->login($hash->{ftp_username},$hash->{ftp_password}) || die "Login failed to $hash->{ftp_server}: $@";

	if ($hash->{ftp_path}) {
		#print "CWD $hash->{ftp_path}\n";
		$ftp->cwd($hash->{ftp_path}) || die "Error cwd to $hash->{ftp_path}: ",$ftp->message;
	}

	my @dirs = $ftp->ls();

	foreach my $f (@dirs) {
		$f =~ s/^\.\///;

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN


	my $str = qq(<input type="checkbox" name="$key" value="$value");
	$str .= ' checked' unless ($checked eq undef);
	$str .= qq( id="$id") if ($id);
	$str .= '>';
	$str .= " $desc" if ($desc);

	return $str;
}

sub html_password {

=head2 html_password

 my $html = $s->html_password($key,$value,[$size]);

=cut

	my $s = shift;
	my $key = $s->escape(shift);
	my $value = $s->escape(shift);
	my $size = shift;

	$key = "$s->{acfb}::$key" if ($s->{acfb});

	my $str = qq(<input type="password" name="$key" value="$value" autocomplete="off");
	$str .= qq( size="$size") if ($size);
	$str .= '>';

	return $str;
}

sub html_upload {

=head2 html_upload

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

	$s->{title} = 'Login';

	$s->tt('interface_login.tt',{ s => $s });

	return 0;
}

sub _interface_check_login {
	my $s = shift;

	if ($s->{in}{interface_email} && $s->{in}{interface_password}) {
		$s->{in}{interface_email} = lc $s->{in}{interface_email};
		my %hash = $s->db_q("
			SELECT *
			FROM $s->{o}{view}
			WHERE interface_email=?
			",'hash',
			v => [ $s->{in}{interface_email} ],
			);

		my $md5pass;
		if ($s->{env}{DEV}) {
			# skip password checking on dev
			$md5pass = $hash{interface_password};
		} else {
			$md5pass = md5_hex($hash{interface_email}.$s->{in}{interface_password});
		}

		if ($md5pass eq $hash{interface_password}) {
			my $cookie = $s->_interface_cookie_key(
				id => $hash{$s->{o}{id}},
				password => $hash{interface_password},
				);
			$s->{$s->{o}{id}} = $hash{$s->{o}{id}};
			$s->{$s->{o}{interface}} = { %hash };
			push @{$s->{r}{set_cookie}}, "IL=$cookie; path=/;";
			$s->db_update_key($s->{o}{table},$s->{o}{id},$hash{$s->{o}{id}},{
				interface_cookie => $cookie,
				});
			return 1;
		} else {
			$s->{error}{login} = "Invalid password";
		}
	}

	return 0;
}

sub _interface_check_cookie {
	my $s = shift;

	if ($s->{cookies}{IL}) {

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

			SELECT *
			FROM $s->{o}{view}
			WHERE interface_cookie=?
			",'hash',
			v => [ $s->{cookies}{IL} ],
			);

		if ($hash{$s->{o}{id}}) {
			my $validate = $s->_interface_cookie_key(
				id => $hash{$s->{o}{id}},
				password => $hash{interface_password},
				);

			if ($validate eq $s->{cookies}{IL}) {
				$s->{$s->{o}{id}} = $hash{$s->{o}{id}};
				$s->{$s->{o}{interface}} = { %hash };
				return 1;
			} else {
				push @{$s->{r}{set_cookie}}, 'IL=; path=/;';
				$s->db_update_key($s->{o}{table},$s->{o}{id},$hash{$s->{o}{id}},{
					interface_cookie => '',

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

				my $new = int(rand(1)*100000);
				$s->db_q("
					UPDATE employees SET passwd=?
					WHERE employee_id=?
					",undef,
					v => [ $new, $employee{employee_id} ]);

				$s->sendmail(to => $employee{email},
					from => 'root@'.$s->{server_name},
					subject => 'Password Reset',
					body => "Your password at $s->{server_name} has has been reset\n\n".
						"username: $employee{login}\n".
						"password: $new\n\n".
						"Please login, and then go change your password.");

				$s->{error}{login} = "Your password has been reset and sent to $employee{email}";
			} else {
				$s->{error}{login} = "Unknown email";
				$s->{in}{forgot} = 1;
			}
		} else {
			$s->{error}{login} = "That is not a valid email";
			$s->{in}{forgot} = 1;
		}
	}	

lib/Apache/SdnFw/lib/Core.pm  view on Meta::CPAN

				foreach my $kv (split '&', $s->{in}{ori_args}) {
					my ($k,$v) = split '=', $kv;
					$v =~ tr/+/ /;
					$v =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
					$s->{in}{$k} = $v;
				}
			}

			return 1;
		} else {
			$s->{error}{login} = "Invalid password or login";
		}
	} elsif ($s->{env}{IP_LOGIN}) {
		my %hash = $s->db_q("
			SELECT *
			FROM employees_v_login
			WHERE ip_addr>>=?
			",'hash',
			v => [ $s->{remote_addr} ],
			);

lib/Apache/SdnFw/template/db/views/employees_v_login.sql  view on Meta::CPAN

CREATE VIEW employees_v_login (employee_id, login, cookie, passwd, name, email,
	password_expired, account_expired, groups, admin) AS
SELECT e.employee_id, e.login, e.cookie, e.passwd, e.name, e.email,
	CASE WHEN passwd_expire < now() THEN TRUE ELSE NULL END as password_expired,
	CASE WHEN expired_ts < now() THEN TRUE ELSE NULL END as account_expired,
	concat(eg.group_id) as groups,
	CASE WHEN count(g.admin) > 0 THEN TRUE ELSE NULL END as admin
FROM employees e
	LEFT JOIN employee_groups eg ON e.employee_id=eg.employee_id
	LEFT JOIN groups g ON eg.group_id=g.group_id
GROUP BY 1,2,3,4,5,6,7,8;
GRANT ALL ON employees_v_login TO sdnfw;

lib/Apache/SdnFw/template/object/me.pm  view on Meta::CPAN

use Carp;

sub config {
	my $s = shift;

	return {
		id => 'employee_id',
		table => 'employees',
		view => 'employee_v',
		functions => {
			change_password => 'Change Password',
			save => 'Save',
			edit => 'Edit',
			list => 'List',
			},
		fields => [ { k => '', t => '', }, ],
		};
}

sub change_password {
	my $s = shift;

	$s->add_action(function => 'list', title => 'display');

	if ($s->{in}{passwd}) {
		if (length $s->{in}{passwd} < 4) {
			$s->alert("Your new password must be at least 4 characters");
		} else {
			if ($s->{in}{passwd} eq $s->{in}{confirm_passwd}) {
				$s->db_q("UPDATE employees SET passwd=?
					WHERE employee_id=?
					",undef,
					v => [ $s->{in}{passwd}, $s->{employee_id} ]);

				$s->notify("Your password has been changed.  You will need to login again...");
				return;
			} else {
				$s->alert("Your new password and confirm password do not match");
			}	
		}
	}

	$s->tt("me/change_password.tt", { s => $s });
}

sub save {
	my $s = shift;

	my %hash = $s->db_q("
		SELECT *
		FROM employees_v
		WHERE employee_id=?
		",'hash',

lib/Apache/SdnFw/template/object/me.pm  view on Meta::CPAN

	my $s = shift;

	my %hash = $s->db_q("
		SELECT *
		FROM employees_v
		WHERE employee_id=?
		",'hash',
		v => [ $s->{employee_id} ]);

	$s->add_action(function => 'list', title => 'display');
	$s->add_action(function => 'change_password');

	$s->tt('me/edit.tt',{ s => $s, hash => \%hash });
}

sub list {
	my $s = shift;

	my %hash = $s->db_q("
		SELECT *
		FROM employees_v
		WHERE employee_id=?
		",'hash',
		v => [ $s->{employee_id} ]);

	$s->add_action(function => 'edit');
	$s->add_action(function => 'change_password');

	$s->tt('me/list.tt',{ s => $s, hash => \%hash });
}

1;

lib/Apache/SdnFw/template/object/me/change_password.tt  view on Meta::CPAN

<form method="POST" action="[% s.ubase %]/[% s.object %]/change_password">
<div class="floatleft">
<table>
	<caption>Change Your Password</caption>
	<tbody>
		<tr>
			<th>New Password</th>
			<td><input name="passwd" value="" type="password"></td>
		</tr>
		<tr>
			<th>Confirm New Password</th>
			<td><input name="confirm_passwd" value="" type="password"></td>
		</tr>
	</tbody>
</table>
<input type="submit" value="Change">
</div>
</form>

lib/Apache/SdnFw/tt/install.txt  view on Meta::CPAN

mkdir -m 0700 /etc/skel/.ssh
touch /etc/skel/.ssh/authorized_keys
chmod 0600 /etc/skel/.ssh/authorized_keys
echo 'Port 6056' >/etc/ssh/sshd_config
echo 'LoginGraceTime 1m' >>/etc/ssh/sshd_config
echo 'PermitRootLogin without-password' >>/etc/ssh/sshd_config
echo '#PasswordAuthentication no' >>/etc/ssh/sshd_config
echo '#UsePAM yes ? default is no?' >>/etc/ssh/sshd_config
echo 'UseDNS no' >>/etc/ssh/sshd_config
echo 'MaxStartups 5' >>/etc/ssh/sshd_config
echo '# override default of no subsystems' >>/etc/ssh/sshd_config
echo 'Subsystem       sftp    /usr/libexec/openssh/sftp-server' >>/etc/ssh/sshd_config
service sshd restart

# disable firewall and SELinux

lib/Apache/SdnFw/tt/install.txt  view on Meta::CPAN

DateTime::Locale IO::Socket::INET Net::IMAP::Simple XML::Simple \
Lingua::EN::Numbers Google::SAML::Response

# Generally you don't need to install mysql, only if you need wordpress
yum -y install mysql-devel.x86_64 mysql-server.x86_64 mysql.x86_64
chkconfig --add mysqld
chkconfig mysqld on
vim /etc/my.cnf
# add bind-address=127.0.0.1
service mysqld start
/usr/bin/mysqladmin -u root password 'what ever you want password to be'

# now back to normal install packages
cd /root/src
mkdir apache
cd apache
wget http://www.apache.org/dist/perl/mod_perl-1.30.tar.gz
tar -zxf mod_perl-1.30.tar.gz
wget http://archive.apache.org/dist/httpd/apache_1.3.37.tar.gz
tar -zxf apache_1.3.37.tar.gz
wget http://www.modssl.org/source/mod_ssl-2.8.28-1.3.37.tar.gz

lib/Apache/SdnFw/tt/interface_login.tt  view on Meta::CPAN

<div class="login">
<form method="POST" action="[% s.uri %]">
<h1>Login to [% s.o.interface %] interface</h1>
[% IF s.error.login %]
<div class="error">[% s.error.login %]</div>
[% END %]
<b>Email Address</b><br>
<input name="interface_email" value="[% s.in.interface_email %]"><br>
<b>Password</b><br>
<input type="password" name="interface_password" value=""><br>
<input type="submit" value="Login">
</form>
</div>

lib/Apache/SdnFw/tt/login.tt  view on Meta::CPAN

<div class="login">
<form method="POST" action="[% s.uri %]">
[% s.html_hidden('ori_args',s.in.ori_args) %]
<h1>Login</h1>
[% IF s.error.login %]
<div class="alert">[% s.error.login %]</div>
[% END %]
<b>Username</b><br>
[% s.html_input('login',s.in.login) %]<br>
<b>Password</b><br>
[% s.html_password('passwd','') %]<br>
<input type="submit" value="Login">
<br><br>
<a href="[% s.uri %]?forgot=1">forgot password?</a>
</form>
</div>

lib/Apache/SdnFw/tt/system.tt  view on Meta::CPAN

			<td>/code/[% s.obase %]</td>
		</tr>
	</tbody>
</table>
</div>

<h2 style="clear: both;">Root</h2>

<p>In order to do anyting to your system, you need root access to the server above.  Root is the 
administrator account on Linux.  There is no way to login to server under the root account using 
a password, instead you need a ssh key, or you need direct access to the server.</p>

<h2>Server Hosting Location</h2>

<p>If the <b>Server</b> above is <b>server.smalldognet.com</b> then that means this site
is hosted on the Smalldog Net Solutions dedicated server which is hosted at
<a href="http://www.m5hosting.com">M5 Hosting</a>.  If you call their support line, they
will be able to get root access to the server if Chris is no longer available.
Your site is running on a server under the Smalldog Net Solutions account.</p>

<p>If the server is NOT server.smalldognet.com, then that means you have your own server

lib/Apache/SdnFw/tt/system.tt  view on Meta::CPAN

<h2>Gaining Root Access</h2>

<p>This is the command to login to root: <code>ssh -p 6056 root@[% s.env.APACHE_SERVER_NAME %]</code></p>

<p>Normally the ssh service runs under port 22, but for an additional level of security I have
moved the service to run under port 6056, hence the "-p 6056".</p>

<p>If you get a "connection refused", then maybe your ssh is not setup on port 6056, so try 
connecting without the -p: <code>ssh root@[% s.env.APACHE_SERVER_NAME %]</code></p>

<p>The ONLY way to login to root is with an ssh key.  If it asks for a password, it doesn't
matter what you try, it will never let you in.</p>

<h2>No SSH key</h2>

<p>If you can not login as root using the above command, then you need the hosting company
to add your key to the root account on the server.  First you need to create yourself a key.</p>

<p>On a Mac, you need to open the terminal program.  Once there run the following command: 
<code>ssh-keygen -d</code></p>

<p>When you run the command, you will be asked where you want to save the key file.  Just hit 
enter and accept the default location (probably something like /Users/chrissutton/.ssh/id_dsa).</p>

<p>Next it will ask for a password.  Just skip that and hit enter.  Also hit enter again for the
password confirm.</p>

<p>Now you should have a couple of files, one private (id_dsa), and the other public (id_dsa.pub).
You need to give the public key to the hosting company.</p>

<p>Run this command to get your key: <code>ssh-keygen -d -y</code></p>

<p>This command should output something that looks like this:</p>

<code>ssh-dss AAAAB3NzaC1kc3MAAACBAJ//L8EFLM+A1VvoA506SFEbB2DF934uGRSl8UpzPH
/Hi5R2VHk9Rg0i8d7GQSsf2sG4Rg2F4JlYoCHs8Y7qOWRaqm3Qwjsv72rbLKmEJhk6gnYaCrou9r



( run in 0.668 second using v1.01-cache-2.11-cpan-49f99fa48dc )