server-based email attachements - codeigniter

I'm using codeigniter to work on an intranet based system that will allow users from within the company to send price sheets and marketing materials to our clients via a codeigniter based mailing system.
I'm able to send an email just fine without adding the line
$this -> email -> attach('/uploads/'.$file_name.$file_extension);
The uploads are added by staff members and put into an 'uploads' folder that's in public_html.
I store the file's information in a database table and then call it to get the required name and extension when I'm going to send the email. I've already tested to make sure that it's pulling the right name and extension from the database.
I still keep getting an error that says:
Unable to locate the following email attachment: /uploads/company_canadian_catalog.pdf
220 smtp.mandrillapp.com ESMTP
hello: 250-ip-10-33-129-14
250-PIPELINING
250-SIZE 26214400
250-STARTTLS
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250 8BITMIME
from: 250 2.1.0 Ok
to: 250 2.1.5 Ok
data: 354 End data with .
250 2.0.0 Ok: queued as A20963C201A
quit: 221 2.0.0 Bye
Your message has been successfully sent using the following protocol: smtp
User-Agent: CodeIgniter
Date: Wed, 3 Sep 2014 12:24:55 -0700
From: "me" <my_company#email.com>
Return-Path: <my_company#email.com>
To: me
Subject: =?utf-8?Q?TESt?=
Reply-To: "my_company#email.com" <my_company#email.com>
X-Sender: my_company#email.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Mime-Version: 1.0
The uploads folder clearly works because I've been successfully able to send files to it and store said files information in the database. I can also download the files fine on the front end when I click on a generated link.
I've exhausted by google-foo resources and have turned to the wise inter-webs gurus of stack overflow. Please let me know my minuscule and tiny mistake that will make me forever want to stub my pinky toe on my bed frame.
EDIT: I have also put:
$this -> email -> clear(TRUE);
at the beginning of my function

The uploads are added by staff members and put into an 'uploads' folder that's in public_html.
If that 'uploads' directory is a sub-directory of 'public_html', then '/uploads/' couldn't possibly be pointing to it. '/uploads/' is an absolute path, while you're trying to use it as a relative one.
The solution is simple, just use the right directory path.
If you have your application/ directory is inside public_html/ as well, then you need this:
FCPATH.'/uploads/'
If application/ directory is at the same level as public_html/ (it should be, for security purposes), then:
APPPATH.'/uploads/'

Related

How to make self hosted prebid server work with AMP?

The github repo does not mention any thing on how to use the self hosted server work with AMP . They have given an endpoint to access after storing the request in the server:
/openrtb2/amp?tag_id={ID} //id is the file name of request stored.
I do get the empty targeting response(since server is on local setup).But how will this data reach the amp page? where should this endpoint be requested?
I read in AMP docs that user generated js doesn't work in AMP. I also setup rtc config on amp ad tag and adding vendor as per vendor config(callout-vendor.js)which sends request to the bidder's prebid server url. For example:
If i add appnexus in rtc-config vendors, the request is getting sent to:
https://prebid.adnxs.com/pbs/v1/openrtb2/amp?tag_id={id of tag}
How do i make the request to go to self hosted prebid server url
ok, figured this thing out..
Doc reference: https://github.com/ampproject/amphtml/blob/master/extensions/amp-a4a/rtc-publisher-implementation-guide.md#setting-up-rtc-config
So, first we make an amp-ad tag wherein we have rtc-config attribute. Since, we are using our own server, we'll need to add it in url property as mentioned in that example in doc.
<amp-ad width="320" height="50"
type="network-foo"
data-slot="/1234/5678"
rtc-config={"urls":["our-server-url"]}>
</amp-ad>
The targeting data returned by server will be fetched by amp-ad tag and will be appended to adserver request.
Additionally, we can make a pull request to amphtml repo on github to add our server url in callout-vendor.js file
file reference: https://github.com/ampproject/amphtml/blob/master/extensions/amp-a4a/0.1/callout-vendors.js
Then, the amp-ad tag will look like this:
<amp-ad width="320" height="50"
type="network-foo"
data-slot="/1234/5678"
rtc-config={"vendors": {"serverAliasAsSetInCalloutVendorFile": {"MACRO1": "MacroValue"}}>
</amp-ad>

Why do I need a trailing slash for the root URI in Spring Data Rest?

I'm using Spring Data Rest. I can access a resource from the command line using httpie with:
http :8080/myapp/books
but if I try to access the root URI
http :8080/myapp
I obtain a 302 redirection:
HTTP/1.1 302
Date: Wed, 21 Dec 2016 13:30:57 GMT
Location: http://localhost:8080/myapp/
Transfer-Encoding: chunked
Testing this url in Firefox redirects me to http://localhost:8080/myapp/ and display correctly the list of resources. If I add a trailing slash with httpie:
http :8080/myapp/
I obtain the list of resources. Why do I have to add a trailing slash to avoid the redirect? Can someone explain me the logic behind this behavior?
P.S.: I'm running the application with Spring Boot, from STS.
I think the answer is
If you add a trailing / it will be understood as a resource group but without that trailing / we can not say that, the last part of the url myapp may be the resource id, so it needs to check for the resource with id myapp first if it does not exist then it will take it as a resource bundle/group and redirects by appending /. The / indicates that the result will be a group, but without slash it will think as a resource with id.
Ex. users/user fetching user with id user.
users/ fetching the set of users. So it will check for the id first if it did not find any resource, then appends a / and redirect.
For more info refer the link https://softwareengineering.stackexchange.com/questions/186959/trailing-slash-in-restful-api

IIS 7 - CodeIgniter Application name error 404 if not in correct case

I host my CodeIgniter website under IIS 7 with application name NewApp. So the URL can be reach on URL "my-domain.com/NewApp". The landing page can be access through "my-domain.com/newapp" link. But when I tried to access the other page like "my-domain.com/NewApp/Module" using "my-domain.com/newapp/Module" URL format, it gave me 404 error.
I have tried to un-tick the "ignore case" under "URL Rewrite" section but it makes "my-domain.com/newapp/Module" accessible and "my-domain.com/NewApp/Module" error 404.
Here is the setting that I applied on the IIS "URL Rewrite" section
Update Aug 12, 2015
The working application name is depend on what URL that we accessed after IIS Application Pool recycle period. So if I access "newapp" after the recycle period, we cannot access "NewApp". The same behaviour also applied when I access "NewApp" at the first time.
I found out that if I call codeigniter function $this->uri->uri_string() on "newapp" (assume I run "NewApp" after recycle period) the string that returned by the function is "NewApp/Controller/Function". And if I call the same function on "NewApp" it will returned "Controller/Function"
The temporary solution is to modify the router core class to make the function return the same output string.
Is there anyone know what to do in IIS so I don't use this temporary solution?

The photos don't appear after an update to vTiger 6.2

After an update or a fresh install of vtiger 6.2, it's possible that contact photos don't appear. It looks like a dead link.
Problem
vTiger 6.2 puts all your uploads (incl. user & product pictures) into /storage and denys access to this folder from the web through a htaccess-File (/storage/.htaccess):
deny from all
These files will only be accessible by the webserver/php directly, which is perfect from a security point of view and it should be kept that way (deleting this htaccess-file is a very bad thing, cause then everybody outside will be able to read your files given he has the right path)!!!
The correct way to deal with these files inside the Web-Application would be to never reference the files directly in HTML (<img src="path/to/file">, cause you would not see them due to the htaccess-File) but to always route their data through a gateway-PHP-Script which checks if the requesting user is authenticated (<img src="file.php?filename=path/to/file">). The PHP-Script can (as I said above) bypass the Apache/htaccess-Security cause it directly accesses the filesystem. This is done in the Document-Section where you can see that downloading a file leads to "http://domain/index.php?module=Documents&action=DownloadFile&record=10&fileid=11"
However, unfortunatly vTiger has places in its Web-Application where it still references files in /storage directly in HTML as with User Pictures and Product Pictures therefor they are not shown.
UPDATE: Bugfix
I found that the Apps Contacts, Users and Products have this problem.
I bugfixed them in 2 steps:
Add Actions for each App as Gateway-Scripts
Create the files (vTiger is installed on /opt/vtiger)
/opt/vtiger/modules/Users/actions/DownloadPicture.php
<?php
class Users_DownloadPicture_Action extends Vtiger_Action_Controller {
public function checkPermission(Vtiger_Request $request) {
$moduleName = $request->getModule();
if(!Users_Privileges_Model::isPermitted($moduleName, 'DetailView', $request->get('record'))) {
throw new AppException(vtranslate('LBL_PERMISSION_DENIED', $moduleName));
}
}
public function process(Vtiger_Request $request) {
$userRecordModel = Vtiger_Record_Model::getInstanceById($request->get('record'), $request->getModule());
$userPictureDetails = $userRecordModel->getImageDetails();
$pictureData = file_get_contents($userPictureDetails[0]['path'] . '_' . $userPictureDetails[0]['orgname']);
header("Content-type: image/jpeg");
header("Pragma: public");
header("Cache-Control: private");
echo $pictureData;
}
}
?>
/opt/vtiger/modules/Products/actions/DownloadPicture.php
The same but: class Products_Download...
/opt/vtiger/modules/Contacts/actions/DownloadPicture.php
The same but: class Contacts_Download...
Adapt the Templates to serve Image-Tags with the Gateway-Script
Go in the files, find the <img ... >-Tag and change its src-Attribute:
/opt/vtiger/layouts/vlayout/modules/Users/ListViewContents.tpl
index.php?module={$MODULE}&action=DownloadPicture&record={$LISTVIEW_ENTRY->get('id')}
/opt/vtiger/layouts/vlayout/modules/Users/PreferenceDetailViewHeader.tpl
index.php?module={$MODULE}&action=DownloadPicture&record={$RECORD->get('id')}
/opt/vtiger/layouts/vlayout/modules/Users/UserViewHeader.tpl
index.php?module={$MODULE}&action=DownloadPicture&record={$RECORD->get('id')}
/opt/vtiger/layouts/vlayout/modules/Vtiger/DetailViewBlockView.tpl
index.php?module={$MODULE}&action=DownloadPicture&record={$RECORD->get('id')}
/opt/vtiger/layouts/vlayout/modules/Vtiger/uitypes/Image.tpl
index.php?module={$MODULE}&action=DownloadPicture&record={$RECORD_ID}
/opt/vtiger/layouts/vlayout/modules/Contacts/DetailViewHeaderTitle.tpl
index.php?module={$MODULE}&action=DownloadPicture&record={$RECORD->get('id')}
Now it is for sure you can see your pictures everywhere, but without beeing logged in you cannot access the files!
Possible open problem: I do not know so much about rights management in vTiger to tell you that now only users with access rights on the records have access to the files. It is possible that now every user can access them. If somebody knows how to control this. Please comment!
Hope everything works out, as by me.
Servus
Lukas
To solve that, simply yourself connect to your server through an FTP client. Empty or remove the ".htaccess" file in the "/storage" folder.
That's it!
Or in the .htaccess file change from:
deny from all
to:
Options -Indexes
I rewrote my .htaccess file from "deny from all" to…
# If the URI is an image then we allow accesses
SetEnvIfNoCase Request_URI "\\.(gif|jpe?g|png|bmp)$" let_me_in
Order Deny,Allow
Deny from All
# Allow accesses only if an images was requested
Allow from env=let_me_in
Now my images show up.

How can I rewrite URLs in the Zeus web server for Mobile useragent?

I need to redirect anyone with a mobile user agent to a file called mobile.php.
My web hosting provider, Net Registry uses the Zeus web server.
Here's the script I've written from my research
RULE_1_START:
# get the document root
map path into SCRATCH:DOCROOT from /
match IN:User-Agent into $ with iPad|iPod|iPhone|Android|s+Mobile
if matched then
set OUT:Location = /mobile.php
endif
RULE_1_END:
I used the instructions on my host's site.
I pasted that into their console and it has worked to do redirects. Net registry have some odd console thing that you submit and it takes 10 minutes to update the zeus server config (annoying as hell).
Anyway my issue is that it redirects me to the wrong location:
So if you visit the site, with a user agent string that contains ipad|ipod|android|\s+mobile then you will trigger it ()
It takes me here:
http://example.com.au/mobile.php,%20catalog/index.php
I can't work out how to fix that, or why that happens because at the moment this file exists:
http://example.com.au/mobile.php
as does this one:
http://example.com.au/index.php. Contents of this file are:
<?php header("Location: catalog/index.php");
Any ideas on how I can make this work more like an apache .htaccess url Rewrite?
the official Zeus documentation
Fixed it by changing
set OUT:Location = /mobile.php
to
set URL = /mobile.php
From the manual...
Using Request Rewrite Scripts
To use the request rewriting functionality, create a script in the Zeus Request
Rewrite Scripting Language. The script contains instructions telling the
Virtual Server how to change the URL or headers of requests that match specified criteria.
The Virtual Server compiles the script, and (if the rewrite functionality is
enabled) uses it every time it receives a request. It runs the commands in the
script, changing the URL if it matches the specified criteria. Once the script is
finished, the Virtual Server continues processing the resulting URL.Zeus Web Server 4.3 User Guide
142 Configuring URL Handling
When changing the URL, the rewrite functionality can only change the local
part of it, that is, the part of the URL after the host name. For example, if a
user requests http://www.myhost.com/sales/uk.html, the rewrite
functionality can only make changes to /sales/uk.html. This means that
you cannot use the rewrite functionality to change the request to refer to a
file on another Virtual Server.
For example, the following script illustrates how to change requests for any
HTML files in the /sales directory so that the user receives them from the
/newsales directory instead:
match URL into $ with ^/sales/(.).html
if matched set URL=/newsales/$1.html
The rewrite functionality can also change the HTTP headers that were received
with a request, and create new HTTP headers to be returned to the user. For
example, the following script changes the HTTP host header, so that a request
for www.mysite.com/subserver is redirected to the Subserver
www.subserver.mysite.com:
match URL into $ with ^/([^/]+)/(.)$
if matched then
set IN:Host = www.$1.mysite.com
set URL = /$2
endif

Resources