How to make controller opencart function - opencart

I have this script for making subdomain and I want to placed it in the opencart contoller. How to do that and how to make it work with the insert function?
$cpanel_user = 'root';
$cpanel_pass = 'password';
$cpanel_skin = 'x2';
$cpanel_host = 'yourdomain.com';
$subdomain = 'mysubdomain';
$dir = 'public_html/mysubdomain';
$sock = fsockopen($cpanel_host,2082);
if(!$sock) {
print('Socket error');
exit();
}
$pass = base64_encode("$cpanel_user:$cpanel_pass");
$in = "GET /frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$cpanel_host&domain=$subdomain&dir=$dir\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$cpanel_host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";
fputs($sock, $in);
while (!feof($sock)) {
$result .= fgets ($sock,128);
}
fclose($sock);

Related

powershell System.Collections.Generic.List[System.String] and foreach

I'm finding that I have the following Generic List, and I can see it has items in it, but when I try to run the code, it's not hitting inside the foreach. This is my code:
function SQLQueryWriteToFile([string]$SQLquery, [string]$extractFile)
{
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server=blah;Database=blah;User ID=blah;Password=blah" #production #I have an error in this so it doesn't connect
$sqlConnection.Open()
if($sqlConnection.State -ne 'Open'){
$global:ErrorStrings.Add("Exception: $("Couldn't connect to DB with connection string given");; ") #this gets hit
}
###
$global:ErrorStrings = New-Object System.Collections.Generic.List[System.String] #System.Object]
$query = "Select blah"
$dir = "C:\blah"
SQLQueryWriteToFile $query $dir
$errorCodeAsString = ""
foreach ($item in $global:ErrorStrings.Members){
$errorCodeAsString += $item #this isn't hit
}
Any idea why it's not finding the error string in my list for the foreach loop, when I can see it's in there looking at $global:ErrorStrings? Based on this foreach list, I'm doing it correctly. I'm having trouble finding examples like what I'm doing. Thanks!
try this:
function SQLQueryWriteToFile([string]$SQLquery, [string]$extractFile)
{
[System.Data.SqlClient.SqlConnection] $sqlConnection=$null
[System.Data.SqlClient.SqlCommand] $command=$null
try
{
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server=blah;Database=blah;User ID=blah;Password=blah"
$command = New-Object System.Data.SqlClient.SqlCommand
$command.Connection=$sqlConnection
$command.CommandText=$SQLquery
$sqlConnection.Open()
$command.ExecuteNonQuery()
}
catch
{
$global:ErrorStrings.Add($_.Exception.Message)
}
finally
{
if ($sqlConnection -ne $null)
{
$sqlConnection.Close()
$sqlConnection.Dispose()
}
if ($command -ne $null)
{
$command.Dispose()
}
}
}
$global:ErrorStrings = New-Object System.Collections.Generic.List[System.String]
$query = "Select blah"
$dir = "C:\blah"
$global:ErrorStrings.Clear()
SQLQueryWriteToFile $query $dir
$errorCodeAsString=""
for ($i = 0; $i -lt $global:ErrorStrings.Count; $i++)
{
$errorCodeAsString +=$global:ErrorStrings.Item($i)
}
$errorCodeAsString

Perl Regex Extract first two section of windows path

I want to write a method to extract first two sections of windows path in Perl.
For example,
'D:\git_root_tfs\WorkStation\Projects\InterACT\Tools\server-rule-checker'
Extract as:
'D:\git_root_tfs\WorkStation'
sub Split_Location_as_VMPath {
my $location = shift;
# ^([d-z]:\\.+?\\.+?)\\
# ^(?:\\.*\\.*)\\
if($location ~~ m/^(?:\\.*\\.*)\\/){ # the path drive start from D to E;
# print "VMPath=$1\n";
# push #$vmPathList, $1;
return Convert_to_Lowercase($1);
}
return "Invalid Path $location";
}
How to write the regex?
Test case:
{
my $item = Split_Location_as_VMPath('D:\VM\ia7-BGCDev8.1\test.vhd');
my $expected = Convert_to_Lowercase('D:\VM\ia7-BGCDev8.1');
ok( $item eq $expected, "Test Split_Location_as_VMPath=$item");
$item = Split_Location_as_VMPath('E:\Hyper-V-2\ia-int-7.1Beta\test.vhd');
$expected = Convert_to_Lowercase('E:\Hyper-V-2\ia-int-7.1Beta');
ok( $item eq $expected, "Test Split_Location_as_VMPath=$item");
$item = Split_Location_as_VMPath('D:\VM\ia7-int-7.1\test.vhd');
$expected = Convert_to_Lowercase('D:\VM\ia7-int-7.1');
ok( $item eq $expected, "Test Split_Location_as_VMPath=$item");
$item = Split_Location_as_VMPath('D:\VM\ia7-int-8.1B153\test.vhd');
$expected = Convert_to_Lowercase('D:\VM\ia7-int-8.1B153');
ok( $item eq $expected, "Test Split_Location_as_VMPath=$item");
$item = Split_Location_as_VMPath('D:\Hyper-v\IA5-SDE-WIN2K3(Feng Tong)\test.vhd');
$expected = Convert_to_Lowercase('D:\Hyper-v\IA5-SDE-WIN2K3(Feng Tong)');
ok( $item eq $expected, "Test Split_Location_as_VMPath=$item");
$item = Split_Location_as_VMPath('D:\git_root_tfs\WorkStation\Projects\InterACT\Tools\server-rule-checker');
$expected = Convert_to_Lowercase('D:\git_root_tfs\WorkStation');
ok( $item eq $expected, "Test Split_Location_as_VMPath=$item");
}
Don't use a regex for file processing.
Instead use a module like File::Spec or Path::Tiny.
use strict;
use warnings;
use File::Spec;
while (<DATA>) {
my ($vol, $dir, $file) = File::Spec->splitpath($_);
my #dirs = File::Spec->splitdir($dir);
#dirs = #dirs[0..2] if #dirs > 3;
$dir = File::Spec->catdir(#dirs);
my $path = File::Spec->catpath($vol, $dir);
print "$path\n";
}
__DATA__
D:\VM\ia7-BGCDev8.1\test.vhd
E:\Hyper-V-2\ia-int-7.1Beta\test.vhd
D:\VM\ia7-int-7.1\test.vhd
D:\VM\ia7-int-8.1B153\test.vhd
D:\Hyper-v\IA5-SDE-WIN2K3(Feng Tong)\test.vhd
D:\git_root_tfs\WorkStation\Projects\InterACT\Tools\server-rule-checker
Outputs:
D:\VM\ia7-BGCDev8.1
E:\Hyper-V-2\ia-int-7.1Beta
D:\VM\ia7-int-7.1
D:\VM\ia7-int-8.1B153
D:\Hyper-v\IA5-SDE-WIN2K3(Feng Tong)
D:\git_root_tfs\WorkStation
Correct regex is ^([d-z]:\.+?\.+?)\.
sub Split_Location_as_VMPath {
my $location = shift;
# ^([d-z]:\\.+?\\.+?)\\
# ^(?:\\.*\\.*)\\
if($location ~~ m/^([D-Z]:\\.+?\\.+?)\\/){ # the path drive start from D to E;
# print "VMPath=$1\n";
# push #$vmPathList, $1;
return Convert_to_Lowercase($1);
}
return "Invalid Path $location";
}
Using regex in this context is an interesting homework for students. Outside school, you should use the standard modules dedicated for this task:
use File::Spec;
sub Split_Location_as_VMPath {
my $location = shift;
my ($volume, $directories, $file) = File::Spec->splitpath($location);
my #dirs = File::Spec->splitdir($directories);
return "Invalid Path $location" unless #dirs > 2;
return lc File::Spec->catpath($volume, File::Spec->catdir(#dirs[0..2]));
}

How to share pass via email

I created a pass and can add it via app or web server in MAMP. What about sharing via email , how can I share it ?
Something like this should do the trick. Note that the MIME type needs to be application/vnd.apple.pkpass in order for the device to recognise it as a Passbook pass.
$pass = "pass.pkpass";
$path = "/path/to/pass/";
$from_name = "smallgirl";
$from_mail = "smallgirl#smallgirl.co.kr";
$reply_to = "smallgirl#smallgirl.co.kr";
$subject = "Your Passbook Pass.";
$message = "Hello,\r\nHere's your pass.";
email_pass($pass, $path, "recipient#mail.org",
$from_mail, $from_name, $reply_to, $subject, $message);
function email_pass($pass, $path, $mail_to, $from_mail, $from_name, $reply_to, $subject, $message) {
$content = chunk_split(base64_encode(file_get_contents($path.$pass)));
$uid = md5(uniqid(time()));
$name = basename($pass);
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$reply_to."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=utf-8\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/vnd.apple.pkpass; name=\"".$pass."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$pass."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($mail_to, $subject, "", $header)) {
return true;
} else {
return false;
}
}
By using Mail.app, now I can send a pass to others to add to passbook !

Error occurs with while Loop PHP / MySQL NuSOAP

I have created a PHP / MySQL based web service. I wrote client.php as mentioned here
and server.php as below:
<?php
require_once("lib/nusoap.php");
$host = $_SERVER['HTTP_HOST'];
$miURL = 'http://'.$host.'/WS-Demo';
$server = new nusoap_server();
$server->configureWSDL('L3M_WebService', $miURL);
$server->wsdl->schemaTargetNamespace=$miURL;
$server->register('getDemoData',
array('fldpara' => 'xsd:Array', 'tblpara' => 'xsd:Array', 'cndpara' => 'xsd:Array'),
array('return' => 'xsd:string'),
$miURL);
function decryptRJ256($string_to_decrypt)
{
$key = 'salt_key - I';
$iv = 'salt_key - II';
$string_to_decrypt = base64_decode($string_to_decrypt);
$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv);
$rtn = rtrim($rtn, "\4");
return($rtn);
}
function encryptRJ256($string_to_encrypt)
{
$key = 'salt_key - I';
$iv = 'salt_key - II';
$rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv);
$rtn = base64_encode($rtn);
return($rtn);
}
function getDemoData($flds, $tbls, $cnds){
$mysqli = new mysqli("localhost", "root", "", "test");
for($i=0;$i< count($flds); $i++) {
$flds[$i] = decryptRJ256($flds[$i]);
}
for($i=0;$i< count($tbls); $i++) {
$tbls[$i] = decryptRJ256($tbls[$i]);
}
for($i=0;$i< count($cnds); $i++) {
$cnds[$i] = decryptRJ256($cnds[$i]);
}
if(! empty($flds)) {
$what = implode(", ", $flds);
} else {
$what = "*";
}
if(! empty($tbls)) {
$from = implode(", ", $tbls);
}else {
$err = 1;
}
if(! empty($cnds)) {
$cond = " WHERE ";
$cond .= $cnds[0] . " = '" . $cnds[1] . "'";
} else {
$cond = "";
}
$sql = "SELECT ".$what." FROM ".$from . $cond;
$rsGetData = $mysqli->query($sql);
$responseData = '<?xml version="1.0" encoding="UTF-8"?>
<L3MDataSets>';
while($rowGetData = $rsGetData->fetch_assoc()) {
$responseData .= '<L3DataSet>';
foreach($rowGetData as $k => $v) {
$responseData .= '<' . $k . '>' . $v . '</' . $k . '>';
}
$responseData .= '</L3DataSet>';
}
$responseData .= '</L3MDataSets>';
$responseData = encryptRJ256($responseData);
$responseString = new soapval('return', 'xsd:string', $responseData );
return $responseData;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
From the Above code in the getDemoData function, if I remove the while loop, it gives the proper output. But when I put back the while loop it shows me output as "-Error: Response not of type text/xml: text/html" even if the SQL query is correct. I have copied and paste the generated SQL query which works in phpMyAdmin.

Doctrine2 Iteration

I have the following code for a <select> on a form.
$query = $em->createQuery("SELECT g.name, g.id FROM SSMURBS\Group g ORDER BY g.name ASC");`
$groups = $query->iterate();`
$groups_option = "";
foreach( $groups as $row ){
$group = $row[0];
$groups_option .= "<option val=\"{$group['id']}\">{$group['name']}</option>\n";
}
But this throws an error. What works is...
$query = $em->createQuery("SELECT g.name, g.id FROM SSMURBS\Group g ORDER BY g.name ASC");
$groups = $query->iterate();
$groups_option = "";
$i = 0;
foreach( $groups as $row ){
$group = $row[$i];
$groups_option .= "<option val=\"{$group['id']}\">{$group['name']}</option>\n";
$i++;
}
Am I doing something wrong? The reference manual cites the first option as correct...
I found the answer to my own question:
While DQL permits SELECT g.id, g.name without throwing an error, this is actually SQL, not DQL. (Thanks, doctrine reference manual, for being so clear on this...)
The correct way to code this is
$query = $em->createQuery("SELECT partial g.{id,name} FROM SSMURBS\Group g ORDER BY g.name ASC");
$groups = $query->iterate();
$groups_option = "";
foreach( $groups as $group ){
$group = $group[0];
$groups_option .= "<option value=\"{$group->id}\">{$group->name}</option>\n";
}
Your variable names are mismatched.
Remove $group = $row[0] and use foreach ($groups as $group)
$query = $em->createQuery("SELECT g.name, g.id FROM SSMURBS\Group g ORDER BY g.name ASC");
$groups = $query->iterate();
$groups_option = "";
foreach ( $groups as $group ){
$groups_option .= "<option val=\"{$group['id']}\">{$group['name']}</option>\n";
}