issue in calling upload hook in file upload - perl

I am trying a file upload by drag and drop.For this ui side i have used blueimp file upload plugin and server side i am using the same upload.cgi that i am using for simple browse and file upload.Issue i am facing is in my main method of cgi hook method is not getting called :-
$cgi = CGI->new(\&hook, "file_upload");
here control is not going in hook method.
sub hook
{
&logMsg("In Hook1");
my ($name, $buffer, $bytesRead, $data) = #_;
&logMsg("In Hook");
&logMsg("name=$name,bytesRead=$bytesRead");
if (defined $lastSeenName)
{
if (($name ne $lastSeenName) || ($bytesRead < $lastSeenTotal))
{
$subTotal += $lastSeenTotal;
}
}
else
{
$uploadSize = $ENV{'CONTENT_LENGTH'};
&logPct(0);
}
$lastSeenName = $name;
$lastSeenTotal = $bytesRead;
$fileSizeMap{$name} = $bytesRead;
$totalBytes = $subTotal + $bytesRead;
if ($uploadSize > 0)
{
my $curPct = int((100 * $totalBytes)/$uploadSize);
$curPct = 98 if ($curPct > 98);
&logPct($curPct);
}
}
when i am using my using my old style browse and upload file hook method is getting called.Can anybody let me know in what i am missing and why hook method is not getting called.
Thanks,
Manish

Related

Error in moxiemanager with PHP7

After updating the version from PHP5 to PHP7, an error appears when trying to insert images from the moxiemanager plugin of the tinymce that I have integrated into the project.
just tell me:
Error:
Array to string conversion
After a few hours, I could find the error
Specifically in: /home/user/website/admin/js/vendor/tinymce/plugins/moxiemanager/classes/Util/EventDispatcher.php:118
In the method:
public function dispatch($sender, $name, $args) {
$name = strtolower($name);
if (isset($this->observers[$name])) {
$observers = $this->observers[$name];
$args->setSender($sender);
for ($i = 0, $l = count($observers); $i < $l; $i++) {
$value = $observers[$i][1]->$observers[$i][0]($args);
// Is stopped then break the loop
if ($value === false || $args->isStopped()) {
return $args;
}
}
}
return $args;
}
you must replace the following line:
$value = $observers[$i][1]->$observers[$i][0]($args);
For this:
$value = $observers[$i][1]->{$observers[$i][0]}($args);
PHP7 uses an abstract syntactic tree when analyzing the source files. Indirect access to variables, properties and methods will now be strictly evaluated from left to right.

Generate Mail and Open it in Outlook using Perl

Does anyone know as how can I make a mail in perl using outlook and not send it just open it on the screen at the end of making the mail and let the user verify and send the mail. I am using Win32::OLE for making the mail.
PFB the code I am using:
sub Final_Mail_Outlook{
my($mailTo,$mailFrom,$subject,$body) = (#_);
my $Outlook = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application');
# Create Mail Item
my $item = $Outlook->CreateItem(0); # 0 = mail item.
unless ($item)
{
die "Outlook is not running, cannot send mail.\n";
}
$item->{'Subject'} = $subject;
$item->{'To'} = $mailTo;
$item->{'Body'} = $body;
$item->{'From'} = $mailFrom;
my $attach = $item->{'Attachments'};
my #outputFiles = glob("$OutputPath\\*.*");
foreach my $file (#outputFiles){
$attach->add($file);
}
$item->Send();
}
This sends the mail as I have called Send function, but I want to verify the mail generated. So is there a way to do so???
I just found an answer to it so thought of posting it also so that someone else needing an answer to this can get help. The key is to use the function Display() instead of Send(). PFB the modified code to open the mail and not send it.
sub Final_Mail_Outlook{
my($mailTo,$mailFrom,$subject,$body) = (#_);
my $Outlook = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application');
# Create Mail Item
my $item = $Outlook->CreateItem(0); # 0 = mail item.
unless ($item)
{
die "Outlook is not running, cannot send mail.\n";
}
$item->{'Subject'} = $subject;
$item->{'To'} = $mailTo;
$item->{'Body'} = $body;
$item->{'From'} = $mailFrom;
my $attach = $item->{'Attachments'};
my #outputFiles = glob("$OutputPath\\*.*");
foreach my $file (#outputFiles){
$attach->add($file);
}
$item->Display();
}

Convert a php script to codeigniter 3

Please i am working on a project and need to generate pincode per request. This is the script i have for php but i need to implement codeigniter 3. Also please can i set it in such a way that if i want 10 pin i input 10 and generate 10 into the database and if want 50 i input 50. i am new to codeigniter 3 and i have read the tutorials but doesnt seems to help on this.
Here is my code on php
Please i want to be able to generate base on the number i want per request.
<?php
$connect = mysqli_connect("localhost","hadassa","root", "")
or die("Cannot connect");
$digits = 5;
function gen_ran($digits) {
$n = "";
for ($x = 1; $x <= $digits; $x++) {
$n.=mt_rand(0,9);
}
return $n;
}
function gen_ran2($digits)
{
$n2 = "";
for($a=1; $a<=$digits; $a++)
{
$n2 .=mt_rand(0,9);
}
return $n2;
}
for($a=1; $a<=20; $a++)
{
$codes = gen_ran($digits) . gen_ran2($digits);
$query = "INSERT INTO pin (pin)
VALUES ('$codes')";
$result = mysqli_query($connect, $query)
or die("Error");
if($result)
echo"$codes<br>";
}
?>
<script type="text/javascript">
alert("PIN Generated Successfully");
window.location = "#";
</script>
codeignater use the MVC So
create a controller in controller folder to write logic
create a model in models folder for write database code
in the viewer, folder create a view for the user view code
https://www.youtube.com/watch?v=K71j-rWXejk&index=2&list=PLUpnKy5Si8zDouvZiUMHwSSyVrowJmH22
https://www.youtube.com/watch?v=IOZqRgOgSu4

CodeIgniter Preventing Uploads?

I am using CodeIgniter for an iPhone app I have. The app allows for users to share images to specific individuals. It works great great, but it seems that after a certain amount of pictures to sent to an individual, posts fail to upload. I was wondering if there is something within CodeIgniter that is causing this issue and how to fix it.
here is part of our config file:
$config['proxy_ips'] = '';
$config['upload_group_path'] = "./upload/group";
$config['upload_user_path'] = "./upload/users";
$config['upload_photo_path'] = "./upload/photo";
$config['upload_video_path'] = "./upload/video";
$config['upload_weblink_path'] = "./upload/weblink";
$config['upload_drawing_path'] = "./upload/drawing";
$config['upload_text_path'] = "./upload/text";
$config['upload_movietype'] = 'mp4|flv|3gp|wmv';
$config['upload_moviesize'] = 100 * 1024; // 100M
$config['upload_alltype'] = '*';
$config['upload_allsize'] = 100 * 1024; // 100M
$config['upload_imgtype'] = 'gif|jpg|png|bmp|jpeg|jpe';
$config['upload_imgsize'] = 5 * 1024; // 5M
$config['upload_thumb_mw'] = '80';
$config['upload_thumb_mh'] = '60';
$config['upload_kmltype'] = 'kml';
$config['upload_kmlsize'] = 10 * 1024; // 10M
$config['main_category'] = array(
'user' => 'Users',
'photo' => 'Photos',
);
$config['difficulty'] = array(
'Easy' => 'Easy',
'Moderate' => 'Moderate',
'Difficult' => 'Difficult',
);
$config['max_count_per_page'] = 5;
$config['thumb_name'] = "_thumb";
$config['photo_name'] = "_photo";
And part of our api file (that draws the error 'fail to upload' in xcode's output):
$tbl_name = "posts";
$new_idx = $this->api_m->get_next_insert_idx($tbl_name);
if (isset($_FILES['datafile']) && $_FILES['datafile']['name'] != '') {
$conf = array();
$conf['upload_path'] = $this->api_m->get_upload_path($postType, $ownerID."_".$format);
$conf['allowed_types'] = $this->config->item('upload_alltype');
$conf['max_size'] = $this->config->item('upload_allsize');
$conf['overwrite'] = FALSE;
$conf['remove_spaces'] = TRUE;
if (!file_exists($conf['upload_path'])) {
mkdir($conf['upload_path']);
}
$this->upload->initialize($conf);
if ($this->upload->do_upload('datafile')) {
$fileinfo = $this->upload->data();
if ($fileinfo['file_size'] > 0) {
$postURL = base_url().substr($conf['upload_path'], 2)."/".$fileinfo['file_name'];
if ($postType == "video") {
$referenceData = base_url().substr($conf['upload_path'], 2)."/".$fileinfo['file_name'];
if (isset($_FILES['thumbfile']) && $_FILES['thumbfile']['name'] != '') {
$conf = array();
$conf['upload_path'] = $this->api_m->get_upload_path($postType, $ownerID."_".$format);
$conf['allowed_types'] = $this->config->item('upload_alltype');
$conf['max_size'] = $this->config->item('upload_allsize');
$conf['overwrite'] = FALSE;
$conf['remove_spaces'] = TRUE;
if (!file_exists($conf['upload_path'])) {
mkdir($conf['upload_path']);
}
$this->upload->initialize($conf);
if ($this->upload->do_upload('thumbfile')) {
$fileinfo = $this->upload->data();
$baseName = $this->api_m->_img_resize($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
$postURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
$baseName = $this->api_m->_img_thumb($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
$thumbURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
}
}
} else {
$baseName = $this->api_m->_img_thumb($postType, $fileinfo, $fileinfo['raw_name'], $new_idx);
$thumbURL = base_url().substr($conf['upload_path'], 2)."/".$baseName;
}
$uploadMsg = "success";
}
} else {
$uploadMsg = "fail to upload";
}
} else {
$uploadMsg = "select the post data";
}
There is no limit in Codeigniter for how many files you can upload, however are you uploading more than one file at a time so that you might reach the limit for how big files you may upload? Either in CI config or the server config.
EDIT!
Try using $this->upload->display_errors() to see what's is going wrong according to CI. My guess now is that the filename allready exists, but I'm curios to see what you get.
2nd EDIT!
In your configuration or before you load your upload class you can set the setting: max_filename_increment. When overwrite is set to FALSE, use this to set the maximum filename increment for CodeIgniter to append to the filename.
$conf['max_filename_increment'] = // What ever number you think is reasonable
Fix this and you should be good to go again :)
3rd EDIT!
I'm sorry that setting isn't available yet. So either you have to add your own upload class in your applications folder there are guides for how to add custom libraries to codeigniter else you will have to edit the Upload class in system. Note that it is not recommended to update anything in the system folder since it would be overwritten if you would update you version of CI later.
But I will of course let you know how to edit the class if you want to;
In the folder libraries in CI system you find the file Upload.php. In the latest version you find the function set_filename() on row 390. Scroll down to row 406 and you should see
for ($i = 1; $i < 100; $i++)
This is the loop that takes too few turns for your file names to be incremented. exchange 100 to a new number and try again.
for ($i = 1; $i < 1000; $i++)
That will loop ten times more than before, but I guess the limit is there for performance so check your response times before and after editing this and when uploading 3-500 files with the same name?
Regards

Perl NetSNMP extension with multiple devices

I have got a machine (Debian based) with some temperature sensors attached to it, and i would like to query them over snmp, from one script. I can work with one sensor ok, but i am struggling when i plug another one in.
What I am trying to do is loop through each device, and give each one an id, then use this ID as part of the OID, then give it a value.
I've never worked with snmp before, and my perl is not great so any help would be much appreciated. Below is my code:
#!/usr/bin/perl
use NetSNMP::agent (':all');
use NetSNMP::ASN qw(ASN_OCTET_STR ASN_INTEGER);
$BASE_OID=".1.3.6.1.4.1.41050";
$dev_id=1;
$string_value;
$integer_value;
sub pimon_handler {
my ($handler, $registration_info, $request_info, $requests) = #_;
my $request;
my $oid_key;
for($request = $requests; $request; $request = $request->next()) {
$oid_key=$BASE_OID . '.' . $dev_id;
my $oid = $request->getOID();
if ($request_info->getMode() == MODE_GET) {
if ($oid == new NetSNMP::OID($oid_key . '.0')) {
$request->setValue(ASN_OCTET_STR, $string_value);
}
elsif ($oid == new NetSNMP::OID($oid_key . '.1')) {
$request->setValue(ASN_INTEGER, $integer_value);
}
} elsif ($request_info->getMode() == MODE_GETNEXT) {
if ($oid == new NetSNMP::OID($oid_key . '.0')) {
$request->setOID($oid_key . '.1');
$request->setValue(ASN_INTEGER, $integer_value);
}
elsif ($oid < new NetSNMP::OID($oid_key . '.0')) {
$request->setOID($oid_key . '.0');
$request->setValue(ASN_OCTET_STR, $string_value);
}
}
}
}
#location of where we are going to find the 1wire devices
#sensors = `cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves`;
chomp(#sensors);
#loop through the sensors we find
foreach $line(#sensors) {
#work out the temp we have got. Need to change this for other sensor types
$output = `cat /sys/bus/w1/devices/$line/w1_slave`;
$output =~ /t=(?<temp>\d+)/;
$integer_value = sprintf "%.0f",$+{temp} / 1000;
$string_value = $line;
my $agent = new NetSNMP::agent();
$agent->register("Pimon$looptest", $BASE_OID . '.' . $dev_id,
\&pimon_handler);
print "Dev $dev_id temp $line temp is $integer_value\n";
$dev_id ++;
}
Are you getting any errors or output?
I suspect that your problem lies in and around your reading the data file by shelling-out to cat instead of opening the file and looping over the linewise contents.
Try dumping the value of #sensors. if it is a single entry array, with the only element containing your entire file, then simply switch #sensors to be scalar. then split $sensors into an array and loop over that.
my $sensors = `read something`
chomp $sensors;
my #sensors = split(/\n/, $sensors);
foreach $line (#sensors) {
...