Add a route in osx's routing table programmatically - objective-c

In my app i want to add a specific route in OSX's routing table which i can easily add through the terminal like this
/sbin/route add -host X.X.X.X -interface en1
. for that i do some search on google and get to know that there is a file /etc/ppp/ip-up which consult by OS every time when a ppp link is up so i set my target to modify this file programmatically
but then OS not allow me without root access so now i have to make possible this command to run programmatically now i found on google "i have to run a helper tool with my app because it can be run as root user" and get SMJobBless API and run it's sample. It was successful
but now i have a question how i can add this route in routing table by this helper tool i mean if i use CreateAuthorization and use this command to run with this! it again prompt for root password which user already give at the time of installation of this app, which is very very annoying
as in this sample app
http://ideveloper.co/designing-writing-and-deploying-a-privileged-helper-on-mac-os-x/
now please tell me what i should do

The best place to look is the source code for Apple's pppd and route tools. Both should include code for adding routes.
http://www.opensource.apple.com/source/network_cmds/network_cmds-307.0.1

Related

How to set properly QPKG_WEBUI variable in QNAP

I am trying to developing an App for QNAP. I am really noob about QNAP, so please help me!
I succeeded in creating a qpkg package and installing it correctly, and it works. But the problem arises when I want to give my app a web interface.
I have just a index.html file that just has an helloworld text inside.
I create the environment with the QDK and I have the /share/XXX_DATA/.qpkg/QDK/MyApp folder
Now, a part of the other files, I create
/share/XXX_DATA/.qpkg/QDK/MyApp/Web
and put there my index.html with my HelloWorld message.
Ok now, I modify the /share/XXX_DATA/.qpkg/QDK/MyApp/qpkg.cfg file and set the variable
QPKG_WEBUI="/MyApp/Web"
From the documentation, for example https://edhongcy.gitbooks.io/qdk-qpkg-development-kit/content/qpkg-configuration-file.html , I can see
QPKG_WEBUI
Relative path to installed application's web interface (the
specified path is relative the configured location of web server data;
usually /share/Web or /share/Qweb.) The specified path must start with
a '/'. The displayed link can only be accessed when the QPKG is
enabled. A default value of '/' is set automatically at installation
if QPKG_WEB_PORT has been given a value and QPKG_WEBUI is empty.
Then I also create a link in /share/XXX_DATA/Web folder to my web folder.
(the /share/Web is just a link to /share/XXX_DATA/Web)
That is:
ln -s /share/XXX_DATA/.qpkg/QDK/MyApp/shared/Web /share/XXX_DATA/Web/MyApp/Web
Well, what happens that now, I can open a Window in my QNAP when I click on "open" in my app but it is completely blank. I tried a lot of different variants but my window is allways blank.
Must I modify something more a part from the qpkg.cfg file?
Do you have some documentation with sample codes?
Is QPKG_WEBUI the correct variable to modify?
Thanks very much to everyone
After a carefully study of the problem, and after trying other applications with the same problem, I found the conclusion that the problem was not the QPKG_WEBUI variable.
The problem was that my QNAP web interface (I do not know if it is a general thing for every QNAP or only in my case) has as default port 8080, but the WEBUI have as default port 80.
Then it seems that the web browser blocks the WEBUI in the iframe inside the QNAP interface in order to follow the Same Origin Policy. When opened in a new window, the WEBUI works correctly.
Setting the QPKG_USE_PROXY=1 variable let the iframe work too.

How do I backup to google drive using duplicity?

I have been trying to get duplicity to backup to google drive. But it looks like it is still using the old client API.
I found some thread saying that the new API should be supported but not much details on how to get it to work.
I got as far as compiling and using duplicity 7.0.3 but then I got this error:
BackendException: GOOGLE_DRIVE_ACCOUNT_KEY environment variable not set. Please read the manpage to fix.
Has anyone set up duplicity to work with Google Drive and know how to do this?
Now that Google has begun forcing clients to use OAuth, using Google Drive as a backup target has actually gotten very confusing. I found an excellent blog post that walked me through it. The salient steps are:
Install PyDrive
PyDrive is the library that lets Duplicity use OAuth to access Drive.
pip install pydrive
should be sufficient, or you can go through your distribution's package manager.
Create an API token
Navigate to the Google Developer Console and log in. Create a project and select it from the drop-down on the top toolbar.
Now select the "Enable APIs and Services" button in the Dashboard, which should already be pulled up, but if not, is in the hamburger menu on the left.
Search for and enable the Drive API. After it's enabled, you can actually create the token. Choose "Credentials" from the left navigation bar, and click "Add Credential" > "OAuth 2.0 Client ID." Set the application type to "Other."
After the credential is created, click on it to view the details. Your Client ID and secret will be displayed. Take note of them.
Configure Duplicity
Whew. Time to actually configure the program. Paste the following into a file, replacing your client ID and secret with the ones from the Console above.
client_config_backend: settings
client_config:
client_id: <your client ID>.apps.googleusercontent.com
client_secret: <your client secret>
save_credentials: True
save_credentials_backend: file
save_credentials_file: gdrive.cache
get_refresh_token: True
(I'm using the excellent Duply frontend, so I saved this as ~/.duply/<server name>/gdrive).
Duplicity needs to be given the name of this file in the GOOGLE_DRIVE_SETTINGS environment variable. So you could invoke duplicity like this:
GOOGLE_DRIVE_SETTINGS=gdrive duplicity <...>
Or if you're using Duply, you can export this variable in the Duply configuration file:
export GOOGLE_DRIVE_SETTINGS=gdrive
Running Duplicity for the first time will begin the OAuth process; you'll be given a link to visit, which will ask permission for the app you created earlier in the Console to access your Drive account. Accept, and it will give you another authentication token to paste back into the terminal. The authorization info will be saved in a .cache file alongside the gdrive settings file.
At this point you should be good to go, and Duplicity should behave normally. Good luck!

Hybris: cannot find CMSSite associated with current URL

I created a new Hybris extension using one of the given templates.
The build was successful and I am able to start the server, too.
But when opening the weblink from the HAC I get the error "Cannot find CMSSite associated with current URL".
Are there suggestions to solve or investigate this issue?
You need to use hosts file mappings or use the site-ID parameter to avoid a 500 error.
Please follow these link
https://wiki.hybris.com/display/accdoc/Just+One+Storefront
https://help.hybris.com/6.3.0/hcd/8ae0711f86691014877ae05249b2f5ac.html (Hybris 6)
If you have administrator rights, it is a good idea to add the following entries in your host file.
127.0.0.1 hybris.local [Example]
The etc hosts modification allows the accelerator to identify sites (CMSSites) from the url. This makes the URL neat and clean.
After host file change, You can access the site like this
http://hybris.local:9001/yacceleratorstorefront/
If you don't do this, the sites would need to be identified with an additional request parameter like this
http://localhost:9001/yacceleratorstorefront/?site=hybris&clear=true
Error "Cannot find CMSSite associated with current URL".
This is because you are not telling hybris which site you want to access.
There are three ways to do that
Simply pass your siteID as a request parameter(?site=SiteID) in your first request which helps the Hybris to understand which site you are trying to access. Let's say I'm trying to access powertools site then URL would be
https://localhost:9002/yacceleratorstorefront?site=powertools
Access site with siteID as DNS name. You can make 127.0.0.1 host with <siteID>.local. Let's say I want to access a powertools (It's CMSSite id for powertools), then add an entry like 127.0.0.1 powertools.local in your host file and then access your site using http://powertools.local:9001/yacceleratorstorefront/ instead of localhost
Add a new regular expression of your choice in the urlPatterns of your CMSSite. So that you can access your site as you want. Let's say I want to access site using localhost URL only and without passing ?site=powertools ever. So I need to add a new regex like (?i)^https?://[^/].*$ to urlPatterns of powertools CMSSite. Now I can directly open powertools site using https://localhost:9002/yacceleratorstorefront/
You can do that using Impex as well
$siteUid=mysite
# CMS Site
INSERT_UPDATE CMSSite ; uid[unique=true] ; urlPatterns ;
; $siteUid ; (?i)^https?://[^/]+(/[^?]*)?\?(.*\&)?(site=$siteUid)(|\&.*)$,(?i)^https?://$siteUid\.[^/]+(|/.*|\?.*)$,(?i)^https?://[^/].*$ ;
Find the detailed answer here
In addition to the host entry, make sure to add the appropriate regular expression for your website.
The CMS site has an attribute called urlPatterns. This is a list of regular expressions that the website CMS filters match to determine which storefront a user is trying to access.
The simplest thing is to add a further regular expression to the CMS site like the one below:
(?i)^https?://[^/]*/yacceleratorstorefront((?![\?\&]site=).)*
At run time, you can can do it in the hybris Management Console(hMC). Navigate to WCMS Website Your Site Name Properties tab and edit URL Patterns section.
To make the change permanent, add the appropriate code to the CMS site setup ImpEx script run during the project data phase of initialization e.g. for electronics storefront
# CMS Site
UPDATE CMSSite;uid[unique=true];urlPatterns;
;electronics;(?i)^https?://[^/]+(/[^?]*)?\?(.*\&)?(site=electronics)(|\&.*)$,(?i)^https?://electronics\.[^/]+(|/.*|\?.*)$,(?i)^https?://api\.hybrisdev\.com(:[\d]+)?/rest.*$,(?i)^https?://[^/]*/yacceleratorstorefront((?![\?\&]site=).)*;
This issue usually comes up if the server was started with unsatisfied spring bean dependencies. Please check your server startup log to confirm which particular bean or beans failed to initialise.

how can I create a new project in yii 2

I'm trying to follow the directions but after the init part I am lost. Where is this database that it speaks of? I don't see this config/db.php. Why can't I just create a new webapp like before (I searched somewhere and it said to do yii app/create (can't remember) but that did not work. How can I just create one?
I'm stuck with this screen at the moment.
when i click on this //local/project/backend/web/index.php?r=site%2Flogin
i get Unable to load the webpage because the server sent no data.
The best way is that you folow the getting started, also You can run with composer
php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
You need to get access key from github and then follow the procedure from the Yii documentation

Multiple Authorization In Cocoa App

I'm writing a cocoa app which needs to modify system proxy settings ( I'm using networksetup to do that ).The problem is that it needs system administrator level access to change proxy settings. I tried running both running an NSTask as administrator using Apple's default API ( I used STPrivilagedTask wrapper for it ) and running a shell script with administrator privileges. It works perfect either way, but the problem is that my app needs to change settings so many times, and user has to type his password every single time.
Is there anyway that I can get the privilege one time, and use it again and again ?
What you're looking to do is write a "privileged helper tool" which gets included (or delivered, or embedded) in your application bundle and you can then call using SMJobBless().
Creating a helper tool is not for the faint of heart, but here is a related question with answers that may set you off down the right path.